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

            Bug ID: 114389
           Summary: internal compiler error when compiling nested
                    structure in gdb
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libcc1
          Assignee: unassigned at gcc dot gnu.org
          Reporter: tsqurt at outlook dot com
  Target Milestone: ---

```
struct foo { int loc1; } bar;

int main()
{
    bar.loc1 = 0; // break here
    return 0;
}
```
Compile and start debugging with command gcc src.c -g && gdb a.out. 

```
(gdb) b 5
Breakpoint 1 at 0x40110a: file src.c, line 5.
(gdb) run
Starting program: a.out 

Breakpoint 1, main () at src.c:5
5           bar.loc1 = 0;
(gdb) expr bar.loc1
warning: variable has unknown type; assuming int
gdb command line:1:4: warning: statement with no effect [-Wunused-value]
*** WARNING *** there are active plugins, do not report this as a bug unless
you can reproduce it without enabling any plugins.
Event                            | Plugins
PLUGIN_PRE_GENERICIZE            | libcc1plugin
PLUGIN_GGC_MARKING               | libcc1plugin
PLUGIN_PRAGMAS                   | libcc1plugin
gdb command line:1:4: internal compiler error: tree check: expected field_decl,
have indirect_ref in component_ref_field_offset, at tree.cc:13095
0x866436 tree_check_failed(tree_node const*, char const*, int, char const*,
...)
        ../../gcc/gcc/tree.cc:8955
0x86ea64 tree_check(tree_node*, char const*, int, char const*, tree_code)
        ../../gcc/gcc/tree.h:3612
0x86ea64 component_ref_field_offset(tree_node*)
        ../../gcc/gcc/tree.cc:13095
0xd08225 gimplify_compound_lval
        ../../gcc/gcc/gimplify.cc:3483
0xcff389 gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*),
int)
        ../../gcc/gcc/gimplify.cc:17740
0xd01de6 gimplify_stmt(tree_node**, gimple**)
        ../../gcc/gcc/gimplify.cc:7485
0xd02ee6 gimplify_bind_expr
        ../../gcc/gcc/gimplify.cc:1619
0xcffad4 gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*),
int)
        ../../gcc/gcc/gimplify.cc:17992
0xd16e05 gimplify_stmt(tree_node**, gimple**)
        ../../gcc/gcc/gimplify.cc:7485
0xd16e05 gimplify_body(tree_node*, bool)
        ../../gcc/gcc/gimplify.cc:19058
0xd1724c gimplify_function_tree(tree_node*)
        ../../gcc/gcc/gimplify.cc:19257
0xb3abf7 cgraph_node::analyze()
        ../../gcc/gcc/cgraphunit.cc:687
0xb3d757 analyze_functions
        ../../gcc/gcc/cgraphunit.cc:1251
0xb3e6dd symbol_table::finalize_compilation_unit()
        ../../gcc/gcc/cgraphunit.cc:2558
Please submit a full bug report, with preprocessed source (by using
-freport-bug).
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.
Compilation failed.
```

Platform: x86-64, Ubuntu 20.04
Affected GCC: gcc-trunk, gcc-13.2.0, gcc-9.4.0.
Affected GDB: gdb-trunk, gdb-12.1, gdb-9.1.

Note: Version gcc-13.2.0 and below will trigger a segmentation fault, rather
than internal compiler error.
In this case, the member name text "loc1" is a must to trigger internal
compiler error.
Note: Alternative text "buf" for gdb-9.1, and "once" for gdb-12.1. 


A similar test case when handling the same name of "bar" twice:

```
struct foo { int bar; } * bar;

int main()
{
  struct foo x;
  x.bar = 0; // break here
  return 0;
}
```

```
(gdb) b 6
Breakpoint 1 at 0x40110a: file src2.c, line 6.
(gdb) run
Starting program: /home/asahi/emd/bugs/b/a.out 

Breakpoint 1, main () at src2.c:6
6         x.bar = 0;
(gdb) expr x.bar
gdb command line:1:2: warning: statement with no effect [-Wunused-value]
*** WARNING *** there are active plugins, do not report this as a bug unless
you can reproduce it without enabling any plugins.
Event                            | Plugins
PLUGIN_PRE_GENERICIZE            | libcc1plugin
PLUGIN_GGC_MARKING               | libcc1plugin
PLUGIN_PRAGMAS                   | libcc1plugin
gdb command line:1:2: internal compiler error: tree check: expected field_decl,
have indirect_ref in component_ref_field_offset, at tree.cc:13095
0x866436 tree_check_failed(tree_node const*, char const*, int, char const*,
...)
        ../../gcc/gcc/tree.cc:8955
0x86ea64 tree_check(tree_node*, char const*, int, char const*, tree_code)
        ../../gcc/gcc/tree.h:3612
0x86ea64 component_ref_field_offset(tree_node*)
        ../../gcc/gcc/tree.cc:13095
0xd08225 gimplify_compound_lval
        ../../gcc/gcc/gimplify.cc:3483
0xcff389 gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*),
int)
        ../../gcc/gcc/gimplify.cc:17740
0xd01de6 gimplify_stmt(tree_node**, gimple**)
        ../../gcc/gcc/gimplify.cc:7485
0xd0089b gimplify_statement_list
        ../../gcc/gcc/gimplify.cc:2227
0xd0089b gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*),
int)
        ../../gcc/gcc/gimplify.cc:18236
0xd01de6 gimplify_stmt(tree_node**, gimple**)
        ../../gcc/gcc/gimplify.cc:7485
0xd02ee6 gimplify_bind_expr
        ../../gcc/gcc/gimplify.cc:1619
0xcffad4 gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*),
int)
        ../../gcc/gcc/gimplify.cc:17992
0xd16e05 gimplify_stmt(tree_node**, gimple**)
        ../../gcc/gcc/gimplify.cc:7485
0xd16e05 gimplify_body(tree_node*, bool)
        ../../gcc/gcc/gimplify.cc:19058
0xd1724c gimplify_function_tree(tree_node*)
        ../../gcc/gcc/gimplify.cc:19257
0xb3abf7 cgraph_node::analyze()
        ../../gcc/gcc/cgraphunit.cc:687
0xb3d757 analyze_functions
        ../../gcc/gcc/cgraphunit.cc:1251
0xb3e6dd symbol_table::finalize_compilation_unit()
        ../../gcc/gcc/cgraphunit.cc:2558
Please submit a full bug report, with preprocessed source (by using
-freport-bug).
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.
Compilation failed.
```

Reply via email to