https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124943

            Bug ID: 124943
           Summary: ICE:Internal Compiler Error(Segmentation fault / ASan:
                    memcpy-param-overlap) during initialization of massive
                    static array (4GB) in build_string
           Product: gcc
           Version: 16.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: 522024330006 at smail dot nju.edu.cn
  Target Milestone: ---

To reproduce: https://godbolt.org/z/Ev3cd7xaY

## Description
The compiler crashes when attempting to compile a source file that defines a
static array of roughly 4GB size (using __INT_MAX__) and performs an aggregate
initialization with a string literal.

The compiler crashes with an Internal Compiler Error: Segmentation fault. When
compiled with an AddressSanitizer-enabled GCC, the crash is identified as a
memcpy-param-overlap in build_string.

## Reproduction
Create a file named `repro.cpp`:
```c++

struct A {
    short a1[__INT_MAX__];
};

int main()
{   
     static volatile char cust_buffer[sizeof(struct A)] =
            {"custom buffer initializing"};
}

```
## Compilation Command
```bash
clang++ -x c++ repro.cpp
```

## The main stack trace
```
==3443639==ERROR: AddressSanitizer: memcpy-param-overlap: memory ranges
[0x7f128e662f5c,0x7f138e662f5b) and [0x7f128e6698b4, 0x7f138e6698b3) overlap
    #0 0x7f1295b5016d in memcpy
../../../../src/libsanitizer/sanitizer_common/sanitizer_common_interceptors_memintrinsics.inc:115
    #1 0x7aa329b in build_string(unsigned int, char const*)
/workspace/install/gcc/src/gcc/gcc/tree.cc:2626
    #2 0x28df19d in digest_init_r
/workspace/install/gcc/src/gcc/gcc/cp/typeck2.cc:1388
    #3 0x28e2919 in digest_init_flags(tree_node*, tree_node*, int, int)
/workspace/install/gcc/src/gcc/gcc/cp/typeck2.cc:1539
    #4 0x28d6bf1 in store_init_value(tree_node*, tree_node*, vec<tree_node*,
va_gc, vl_embed>**, int) /workspace/install/gcc/src/gcc/gcc/cp/typeck2.cc:945
    #5 0x162b89b in check_initializer
/workspace/install/gcc/src/gcc/gcc/cp/decl.cc:8566
    #6 0x16538ba in cp_finish_decl(tree_node*, tree_node*, bool, tree_node*,
int, cp_decomp*) /workspace/install/gcc/src/gcc/gcc/cp/decl.cc:9777
    #7 0x1fa3828 in cp_parser_init_declarator
/workspace/install/gcc/src/gcc/gcc/cp/parser.cc:25038
    #8 0x1f4c26d in cp_parser_simple_declaration
/workspace/install/gcc/src/gcc/gcc/cp/parser.cc:17195
    #9 0x1f4adef in cp_parser_block_declaration
/workspace/install/gcc/src/gcc/gcc/cp/parser.cc:17014
    #10 0x1f3e239 in cp_parser_declaration_statement
/workspace/install/gcc/src/gcc/gcc/cp/parser.cc:16057
    #11 0x1f1a17d in cp_parser_statement
/workspace/install/gcc/src/gcc/gcc/cp/parser.cc:13628
    #12 0x1f214ff in cp_parser_statement_seq_opt
/workspace/install/gcc/src/gcc/gcc/cp/parser.cc:14209
    #13 0x1f1f5d9 in cp_parser_compound_statement
/workspace/install/gcc/src/gcc/gcc/cp/parser.cc:14056
    #14 0x1fc23fe in cp_parser_function_body
/workspace/install/gcc/src/gcc/gcc/cp/parser.cc:27456
    #15 0x1fc35bb in cp_parser_ctor_initializer_opt_and_function_body
/workspace/install/gcc/src/gcc/gcc/cp/parser.cc:27507
    #16 0x201a837 in cp_parser_function_definition_after_declarator
/workspace/install/gcc/src/gcc/gcc/cp/parser.cc:34528
    #17 0x20194f1 in
cp_parser_function_definition_from_specifiers_and_declarator
/workspace/install/gcc/src/gcc/gcc/cp/parser.cc:34443
    #18 0x1f9fb5d in cp_parser_init_declarator
/workspace/install/gcc/src/gcc/gcc/cp/parser.cc:24738
    #19 0x1f4c26d in cp_parser_simple_declaration
/workspace/install/gcc/src/gcc/gcc/cp/parser.cc:17195
    #20 0x1f4adef in cp_parser_block_declaration
/workspace/install/gcc/src/gcc/gcc/cp/parser.cc:17014
    #21 0x1f48b63 in cp_parser_declaration
/workspace/install/gcc/src/gcc/gcc/cp/parser.cc:16815
    #22 0x1f49112 in cp_parser_toplevel_declaration
/workspace/install/gcc/src/gcc/gcc/cp/parser.cc:16836
    #23 0x1ea444a in cp_parser_translation_unit
/workspace/install/gcc/src/gcc/gcc/cp/parser.cc:5506
    #24 0x2165694 in c_parse_file()
/workspace/install/gcc/src/gcc/gcc/cp/parser.cc:55310
    #25 0x2c8c374 in c_common_parse_file()
/workspace/install/gcc/src/gcc/gcc/c-family/c-opts.cc:1418
    #26 0x62b467f in compile_file
/workspace/install/gcc/src/gcc/gcc/toplev.cc:453
    #27 0x62cab9b in do_compile
/workspace/install/gcc/src/gcc/gcc/toplev.cc:2222
    #28 0x62cc42d in toplev::main(int, char**)
/workspace/install/gcc/src/gcc/gcc/toplev.cc:2385
    #29 0x11858e05 in main /workspace/install/gcc/src/gcc/gcc/main.cc:39
    #30 0x7f1294d8a1c9  (/lib/x86_64-linux-gnu/libc.so.6+0x2a1c9) (BuildId:
8e9fd827446c24067541ac5390e6f527fb5947bb)
    #31 0x7f1294d8a28a in __libc_start_main
(/lib/x86_64-linux-gnu/libc.so.6+0x2a28a) (BuildId:
8e9fd827446c24067541ac5390e6f527fb5947bb)
    #32 0xf74004 in _start
(/workspace/install/gcc/install_15.2.0/libexec/gcc/x86_64-pc-linux-gnu/16.0.0/cc1plus+0xf74004)
(BuildId: 47a2a0370315580a8ef4ce4dea19d167db59320e)

Address 0x7f128e662f5c is a wild pointer inside of access range of size
0x0000ffffffff.
Address 0x7f128e6698b4 is a wild pointer inside of access range of size
0x0000ffffffff.
SUMMARY: AddressSanitizer: memcpy-param-overlap
../../../../src/libsanitizer/sanitizer_common/sanitizer_common_interceptors_memintrinsics.inc:115
in memcpy
==3443639==ABORTING
```

## The gcc version:
```
gcc (GCC) 16.0.0 20251029 (experimental)
Copyright (C) 2025 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
```

Reply via email to