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

            Bug ID: 117652
           Summary: ICE: tree check: expected class ‘type’, have
                    ‘exceptional’ (error_mark) in
                    tagged_types_tu_compatible_p, at c/c-typeck.cc:1919
           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: ---

*******************************************************************************
The compiler produces an internal error during tree_class_check_failed 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-241118/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-241118
--enable-languages=c,c++ --disable-multilib --disable-bootstrap
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 15.0.0 20241118 (experimental) (GCC) 
*******************************************************************************
Program:
# cat bug.c


struct foo {
  ...
  int counter;
  ...
  struct bar array[] __attribute__((counted_by(counter)));
} *p;

#define alloc(P, FAM, COUNT) ({ \
  size_t __size = sizeof(*P) + sizeof(*P->FAM) * COUNT; \
  kmalloc(__size, GFP); \
})

p = alloc(p, array, how_many);
p->counter = how_many;

#define alloc(P, FAM, COUNT) ({ \
  typeof(P) __p; \
  size_t __size = sizeof(*P) + sizeof(*P->FAM) * COUNT; \
  __p = kmalloc(__size, GFP); \
  __builtin_set_counted_by(__p->FAM, COUNT); \
  __p; \
})

void __builtin_set_counted_by (ptr->FAM, const_exp_with_int_type)

void __builtin_set_counted_by (FAM_exp, count_exp)

void __builtin_set_counted_by (void *, size_t)

void __builtin_set_counted_by (ptr, type expr)

struct foo1 {
  int counter1;
  struct bar1 array[] __attribute__((counted_by(counter)));
} *p;

struct foo2 {
  int other;
  struct bar2 array[];
} *q;

__builtin_set_counted_by (p->array, COUNT)

__builtin_set_counted_by (q->array, COUNT)

struct foo1 {
  int counter1;
  struct bar1 array[] __attribute__((counted_by(counter)));
} *p;

struct foo2 {
  int other;
  struct bar2 array[];
} *q;

__builtin_set_counted_by (p->array, COUNT)

__builtin_set_counted_by (q->array, COUNT)

void __builtin_set_counted_by (ptr, type expr)

void __builtin_set_counted_by (ptr, type expr)

struct foo {
  int counter;
  struct bar1 array[] __attribute__((counted_by(counter)));
} *p;

__builtin_set_counted_by (p->array, COUNT)

struct foo2 {
  int other;
  struct bar2 array[];
} *q;

__builtin_set_counted_by (q->array, COUNT)

#define alloc(P, FAM, COUNT) ({ \
  typeof(P) __p; \
  size_t __size = sizeof(*P) + sizeof(*P->FAM) * COUNT; \
  __p = kmalloc(__size, GFP); \
  if (__p && __builtin_get_counted_by(__p->FAM)) \
    *__builtin_get_counted_by(__p->FAM) = COUNT; \
  __p; \
})

struct foo {
  int counter;
  struct bar array[] __attribute__((counted_by(counter)));
} *p;

__builtin_set_counted_by (p->array, COUNT)


*******************************************************************************
Command Lines:
# gcc bugreport.c -funroll-loops -flto -Ofast -Wall -Wextra
-fno-strict-aliasing -fwrapv -g -fsanitize=address  -c -o bug.o
/root/gdbtest/gcctest/gcc_llvm/gcc/log3/NoAttachment/fixed/116016/bugreport_0_1.o

<source>:2:3: error: expected specifier-qualifier-list before '...' token
    2 |   ...
      |   ^~~
<source>:13:1: warning: data definition has no type or storage class
   13 | p = alloc(p, array, how_many);
      | ^
<source>:13:1: error: type defaults to 'int' in declaration of 'p'
[-Wimplicit-int]
<source>:13:1: error: conflicting types for 'p'; have 'int'
<source>:6:4: note: previous declaration of 'p' with type 'struct foo *'
    6 | } *p;
      |    ^
<source>:8:30: error: braced-group within expression allowed only inside a
function
    8 | #define alloc(P, FAM, COUNT) ({ \
      |                              ^
<source>:13:5: note: in expansion of macro 'alloc'
   13 | p = alloc(p, array, how_many);
      |     ^~~~~
<source>:14:2: error: expected '=', ',', ';', 'asm' or '__attribute__' before
'->' token
   14 | p->counter = how_many;
      |  ^~
<source>:16:9: warning: 'alloc' redefined
   16 | #define alloc(P, FAM, COUNT) ({ \
      |         ^~~~~
<source>:8:9: note: this is the location of the previous definition
    8 | #define alloc(P, FAM, COUNT) ({ \
      |         ^~~~~
<source>:24:35: error: expected ')' before '->' token
   24 | void __builtin_set_counted_by (ptr->FAM, const_exp_with_int_type)
      |                                   ^~
      |                                   )
<source>:35:3: warning: data definition has no type or storage class
   35 | } *p;
      |   ^
<source>:35:4: error: type defaults to 'int' in declaration of 'p'
[-Wimplicit-int]
   35 | } *p;
      |    ^
<source>:39:15: error: array type has incomplete element type 'struct bar2'
   39 |   struct bar2 array[];
      |               ^~~~~
<source>:42:28: error: expected ')' before '->' token
   42 | __builtin_set_counted_by (p->array, COUNT)
      |                            ^~
      |                            )
<source>:49:3: warning: data definition has no type or storage class
   49 | } *p;
      |   ^
<source>:49:4: error: type defaults to 'int' in declaration of 'p'
[-Wimplicit-int]
   49 | } *p;
      |    ^
<source>:53:15: error: array type has incomplete element type 'struct bar2'
   53 |   struct bar2 array[];
      |               ^~~~~
<source>:54:1: internal compiler error: tree check: expected class 'type', have
'exceptional' (error_mark) in tagged_types_tu_compatible_p, at
c/c-typeck.cc:1919
   54 | } *q;
      | ^
0x259f775 diagnostic_context::diagnostic_impl(rich_location*,
diagnostic_metadata const*, diagnostic_option_id, char const*, __va_list_tag
(*) [1], diagnostic_t)
        ???:0
0x25b6165 internal_error(char const*, ...)
        ???:0
0x8beab5 tree_class_check_failed(tree_node const*, tree_code_class, char
const*, int, char const*)
        ???:0
0xa03af2 comptypes_same_p(tree_node*, tree_node*)
        ???:0
0x9f3f21 finish_struct(unsigned int, tree_node*, tree_node*, tree_node*,
c_struct_parse_info*, tree_node**)
        ???:0
0xa563b4 c_parser_declspecs(c_parser*, c_declspecs*, bool, bool, bool, bool,
bool, bool, bool, c_lookahead_kind)
        ???:0
0xa71e2b c_parse_file()
        ???:0
0xaee499 c_common_parse_file()
        ???:0
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.
Compiler returned: 1
*******************************************************************************

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

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

Reply via email to