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

            Bug ID: 118290
           Summary: ICE: argc.1 from nested referenced in nested
           Product: gcc
           Version: 15.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: iamanonymous.cs at gmail dot com
  Target Milestone: ---
            Target: x86_64

*******************************************************************************
The compiler produces an internal error during walk_tree_1  when compiling the
provided code with the specified options. 
The issue can also be reproduced on Compiler Explorer.

*******************************************************************************
OS and Platform:
# uname -a
Linux ubuntu 4.15.0-213-generic #224-Ubuntu SMP Mon Jun 19 13:30:12 UTC 2023
x86_64 x86_64 x86_64 GNU/Linux
*******************************************************************************
# gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/root/gdbtest/gcc/gcc-241224/libexec/gcc/x86_64-pc-linux-gnu/15.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../gcc/configure --prefix=/root/gdbtest/gcc/gcc-241224
--enable-languages=c,c++ --disable-multilib --disable-bootstrap
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 15.0.0 20241224 (experimental) (GCC)
*******************************************************************************
Program:
#cat 16567.c

#include <stddef.h>

int
main(int argc, char **argv)
{
  struct s { int a; char b[argc]; }

int nested (struct s x) { return x.a + sizeof(x); }

int nested (struct s x) { return x.a + sizeof(x); }

int main(int argc, char **argv) { 
  struct s { char b[argc]; }

int nested (struct s x) { return 0; }

int nested (struct s x) { return x.a + sizeof(x); }


*******************************************************************************
Command Lines:
gcc 16567.c  -funroll-loops -flto  -Wall -Wextra  -fno-strict-aliasing  -fwrapv
-g -fsanitize=address  -c -o 16567.o



16567.c: In function ‘main’:
16567.c:10:1: error: expected ‘;’, identifier or ‘(’ before ‘int’
   10 | int nested (struct s x) { return x.a + sizeof(x); }
      | ^~~
16567.c:12:5: error: redefinition of ‘nested’
   12 | int nested (struct s x) { return x.a + sizeof(x); }
      |     ^~~~~~
16567.c:10:5: note: previous definition of ‘nested’ with type ‘int(struct s)’
   10 | int nested (struct s x) { return x.a + sizeof(x); }
      |     ^~~~~~
16567.c:14:5: warning: ‘main’ is normally a non-static function [-Wmain]
   14 | int main(int argc, char **argv) {
      |     ^~~~
16567.c: In function ‘main’:
16567.c:17:1: error: expected ‘;’, identifier or ‘(’ before ‘int’
   17 | int nested (struct s x) { return 0; }
      | ^~~
16567.c: In function ‘nested’:
16567.c:17:22: warning: unused parameter ‘x’ [-Wunused-parameter]
   17 | int nested (struct s x) { return 0; }
      |             ~~~~~~~~~^
16567.c: In function ‘main’:
16567.c:19:5: error: redefinition of ‘nested’
   19 | int nested (struct s x) { return x.a + sizeof(x); }
      |     ^~~~~~
16567.c:17:5: note: previous definition of ‘nested’ with type ‘int(struct s)’
   17 | int nested (struct s x) { return 0; }
      |     ^~~~~~
16567.c: In function ‘nested’:
16567.c:19:35: error: ‘struct s’ has no member named ‘a’
   19 | int nested (struct s x) { return x.a + sizeof(x); }
      |                                   ^
16567.c: In function ‘main’:
16567.c:19:20: error: expected declaration or statement at end of input
   19 | int nested (struct s x) { return x.a + sizeof(x); }
      |                    ^
16567.c:14:27: warning: unused parameter ‘argv’ [-Wunused-parameter]
   14 | int main(int argc, char **argv) {
      |                    ~~~~~~~^~~~
16567.c: In function ‘main’:
16567.c:19:20: error: expected declaration or statement at end of input
   19 | int nested (struct s x) { return x.a + sizeof(x); }
      |                    ^
16567.c:6:23: warning: unused parameter ‘argv’ [-Wunused-parameter]
    6 | main(int argc, char **argv)
      |                ~~~~~~~^~~~
16567.c:6:1: internal compiler error: argc.1 from nested referenced in nested
    6 | main(int argc, char **argv)
      | ^~~~
0x26e831f internal_error(char const*, ...)
        ../../gcc/gcc/diagnostic-global-context.cc:517
0x124d3f6 convert_nonlocal_reference_op
        ../../gcc/gcc/tree-nested.cc:1204
0x1532b0c walk_tree_1(tree_node**, tree_node* (*)(tree_node**, int*, void*),
void*, hash_set<tree_node*, false, default_hash_traits<tree_node*> >*,
tree_node* (*)(tree_node**, int*, tree_node* (*)(tree_node**, int*, void*),
void*, hash_set<tree_node*, false, default_hash_traits<tree_node*> >*))
        ../../gcc/gcc/tree.cc:11532
0xe0a405 walk_gimple_op(gimple*, tree_node* (*)(tree_node**, int*, void*),
walk_stmt_info*)
        ../../gcc/gcc/gimple-walk.cc:212
0xe0a713 walk_gimple_stmt(gimple_stmt_iterator*, tree_node*
(*)(gimple_stmt_iterator*, bool*, walk_stmt_info*), tree_node* (*)(tree_node**,
int*, void*), walk_stmt_info*)
        ../../gcc/gcc/gimple-walk.cc:636
0xe0a915 walk_gimple_seq_mod(gimple**, tree_node* (*)(gimple_stmt_iterator*,
bool*, walk_stmt_info*), tree_node* (*)(tree_node**, int*, void*),
walk_stmt_info*)
        ../../gcc/gcc/gimple-walk.cc:51
0xe0a7b1 walk_gimple_stmt(gimple_stmt_iterator*, tree_node*
(*)(gimple_stmt_iterator*, bool*, walk_stmt_info*), tree_node* (*)(tree_node**,
int*, void*), walk_stmt_info*)
        ../../gcc/gcc/gimple-walk.cc:736
0xe0a915 walk_gimple_seq_mod(gimple**, tree_node* (*)(gimple_stmt_iterator*,
bool*, walk_stmt_info*), tree_node* (*)(tree_node**, int*, void*),
walk_stmt_info*)
        ../../gcc/gcc/gimple-walk.cc:51
0x1249094 walk_body
        ../../gcc/gcc/tree-nested.cc:820
0x1249094 walk_function
        ../../gcc/gcc/tree-nested.cc:831
0x1249094 walk_all_functions
        ../../gcc/gcc/tree-nested.cc:896
0x1251b51 lower_nested_functions(tree_node*)
        ../../gcc/gcc/tree-nested.cc:3849
0xc3d132 cgraph_node::analyze()
        ../../gcc/gcc/cgraphunit.cc:693
0xc3ffc7 analyze_functions
        ../../gcc/gcc/cgraphunit.cc:1263
0xc40f2d symbol_table::finalize_compilation_unit()
        ../../gcc/gcc/cgraphunit.cc:2572
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.

*******************************************************************************

Also ICE on trunk, compiler explorer:https://godbolt.org/z/x9YjvEEnh

*******************************************************************************

Reply via email to