Bug 117724 - [15 regression] ICE when building libgit2 (error: ‘TYPE_CANONICAL’ is not compatible)
Summary: [15 regression] ICE when building libgit2 (error: ‘TYPE_CANONICAL’ is not com...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 15.0
: P1 normal
Target Milestone: 15.0
Assignee: uecker
URL:
Keywords: ice-checking, ice-on-valid-code, patch
Depends on:
Blocks:
 
Reported: 2024-11-21 08:33 UTC by Sam James
Modified: 2024-12-12 14:44 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work: 14.2.1
Known to fail: 15.0
Last reconfirmed: 2024-11-21 00:00:00


Attachments
smart_pkt.i.xz (90.34 KB, application/x-xz)
2024-11-21 08:33 UTC, Sam James
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Sam James 2024-11-21 08:33:17 UTC
Created attachment 59657 [details]
smart_pkt.i.xz

This built OK on the 17th, so it's not quite a dupe of the other TYPE_CANONICAL issues AFAIK.

```
$ gcc smart_pkt.i -c -g
In file included from libgit2/src/libgit2/transports/smart_pkt.c:10:
libgit2/src/libgit2/transports/smart.h:175:16: error: ‘TYPE_CANONICAL’ is not compatible
  175 |         git_staticstr_with_size(GIT_SMART_BUFFER_SIZE) buffer;
      |                ^
 <record_type 0x72e7e6d78690 asm_written includes-flexarray BLK
    size <integer_cst 0x72e7e7402f90 type <integer_type 0x72e7e74230a8 bitsizetype> constant 128>
    unit-size <integer_cst 0x72e7e7402fa8 type <integer_type 0x72e7e7423000 sizetype> constant 16>
    align:64 warn_if_not_align:0 symtab:-422098352 alias-set -1 canonical-type 0x72e7e6d78690
    fields <field_decl 0x72e7e6d71be0 len
        type <integer_type 0x72e7e75e5d20 size_t asm_written public unsigned DI
            size <integer_cst 0x72e7e7402f48 constant 64>
            unit-size <integer_cst 0x72e7e7402f60 constant 8>
            align:64 warn_if_not_align:0 symtab:-413218304 alias-set -1 canonical-type 0x72e7e74237e0 precision:64 min <integer_cst 0x72e7e7425228 0> max <integer_cst 0x72e7e74036a0 18446744073709551615>
            pointer_to_this <pointer_type 0x72e7e70db930>>
        unsigned DI libgit2/src/util/staticstr.h:14:9 size <integer_cst 0x72e7e7402f48 64> unit-size <integer_cst 0x72e7e7402f60 8>
        align:64 warn_if_not_align:0 offset_align 128 decl_not_flexarray: 1
        offset <integer_cst 0x72e7e7402f78 constant 0>
        bit-offset <integer_cst 0x72e7e7402fc0 constant 0> context <record_type 0x72e7e6d78690>
        chain <field_decl 0x72e7e6d71c78 size type <integer_type 0x72e7e75e5d20 size_t>
            unsigned DI libgit2/src/util/staticstr.h:17:9 size <integer_cst 0x72e7e7402f48 64> unit-size <integer_cst 0x72e7e7402f60 8>
            align:64 warn_if_not_align:0 offset_align 128 decl_not_flexarray: 1 offset <integer_cst 0x72e7e7402f78 0> bit-offset <integer_cst 0x72e7e7402f48 64> context <record_type 0x72e7e6d78690> chain <field_decl 0x72e7e6d71d10 data>>>
    chain <type_decl 0x72e7e6d71b48 D.12863>>
 <record_type 0x72e7e6d8af18 BLK
    size <integer_cst 0x72e7e6d79690 type <integer_type 0x72e7e74230a8 bitsizetype> constant 524416>
    unit-size <integer_cst 0x72e7e6d79660 type <integer_type 0x72e7e7423000 sizetype> constant 65552>
    align:64 warn_if_not_align:0 symtab:0 alias-set -1 canonical-type 0x72e7e6d78690
    fields <field_decl 0x72e7e6d91720 len
        type <integer_type 0x72e7e75e5d20 size_t asm_written public unsigned DI
            size <integer_cst 0x72e7e7402f48 constant 64>
            unit-size <integer_cst 0x72e7e7402f60 constant 8>
            align:64 warn_if_not_align:0 symtab:-413218304 alias-set -1 canonical-type 0x72e7e74237e0 precision:64 min <integer_cst 0x72e7e7425228 0> max <integer_cst 0x72e7e74036a0 18446744073709551615>
            pointer_to_this <pointer_type 0x72e7e70db930>>
        unsigned DI libgit2/src/libgit2/transports/smart.h:175:18 size <integer_cst 0x72e7e7402f48 64> unit-size <integer_cst 0x72e7e7402f60 8>
        align:64 warn_if_not_align:0 offset_align 128 decl_not_flexarray: 1
        offset <integer_cst 0x72e7e7402f78 constant 0>
        bit-offset <integer_cst 0x72e7e7402fc0 constant 0> context <record_type 0x72e7e6d8af18>
        chain <field_decl 0x72e7e6d917b8 size type <integer_type 0x72e7e75e5d20 size_t>
            unsigned DI libgit2/src/libgit2/transports/smart.h:175:30 size <integer_cst 0x72e7e7402f48 64> unit-size <integer_cst 0x72e7e7402f60 8>
            align:64 warn_if_not_align:0 offset_align 128 decl_not_flexarray: 1 offset <integer_cst 0x72e7e7402f78 0> bit-offset <integer_cst 0x72e7e7402f48 64> context <record_type 0x72e7e6d8af18> chain <field_decl 0x72e7e6d91850 data>>>
    chain <type_decl 0x72e7e6d91688 D.12981>>
libgit2/src/libgit2/transports/smart.h:175:16: internal compiler error: ‘verify_type’ failed
0x615648ef2999 internal_error(char const*, ...)
	/usr/src/debug/sys-devel/gcc-15.0.9999/gcc-15.0.9999/gcc/diagnostic-global-context.cc:518
0x6156476afd8e verify_type(tree_node const*)
	/usr/src/debug/sys-devel/gcc-15.0.9999/gcc-15.0.9999/gcc/tree.cc:14496
0x6156490f693a gen_type_die_with_usage
	/usr/src/debug/sys-devel/gcc-15.0.9999/gcc-15.0.9999/gcc/dwarf2out.cc:26351
0x6156490f668a gen_type_die
	/usr/src/debug/sys-devel/gcc-15.0.9999/gcc-15.0.9999/gcc/dwarf2out.cc:26582
0x6156490a178e gen_decl_die
	/usr/src/debug/sys-devel/gcc-15.0.9999/gcc-15.0.9999/gcc/dwarf2out.cc:27222
0x61564989e829 dwarf2out_decl
	/usr/src/debug/sys-devel/gcc-15.0.9999/gcc-15.0.9999/gcc/dwarf2out.cc:27780
0x615649072fdd dwarf2out_type_decl
	/usr/src/debug/sys-devel/gcc-15.0.9999/gcc-15.0.9999/gcc/dwarf2out.cc:27498
0x6156490e9c89 rest_of_type_compilation(tree_node*, int)
	/usr/src/debug/sys-devel/gcc-15.0.9999/gcc-15.0.9999/gcc/passes.cc:340
0x6156498eb4f2 finish_struct(unsigned int, tree_node*, tree_node*, tree_node*, c_struct_parse_info*, tree_node**)
	/usr/src/debug/sys-devel/gcc-15.0.9999/gcc-15.0.9999/gcc/c/c-decl.cc:9910
0x6156490bdd13 c_parser_struct_or_union_specifier
	/usr/src/debug/sys-devel/gcc-15.0.9999/gcc-15.0.9999/gcc/c/c-parser.cc:4145
0x6156490bdd13 c_parser_declspecs(c_parser*, c_declspecs*, bool, bool, bool, bool, bool, bool, bool, c_lookahead_kind)
	/usr/src/debug/sys-devel/gcc-15.0.9999/gcc-15.0.9999/gcc/c/c-parser.cc:3549
0x6156498de70f c_parser_struct_declaration
	/usr/src/debug/sys-devel/gcc-15.0.9999/gcc-15.0.9999/gcc/c/c-parser.cc:4241
0x6156490bdc3e c_parser_struct_or_union_specifier
	/usr/src/debug/sys-devel/gcc-15.0.9999/gcc-15.0.9999/gcc/c/c-parser.cc:4119
0x6156490bdc3e c_parser_declspecs(c_parser*, c_declspecs*, bool, bool, bool, bool, bool, bool, bool, c_lookahead_kind)
	/usr/src/debug/sys-devel/gcc-15.0.9999/gcc-15.0.9999/gcc/c/c-parser.cc:3549
0x6156498ba793 c_parser_declaration_or_fndef
	/usr/src/debug/sys-devel/gcc-15.0.9999/gcc-15.0.9999/gcc/c/c-parser.cc:2338
0x6156498ba5b1 c_parser_external_declaration
	/usr/src/debug/sys-devel/gcc-15.0.9999/gcc-15.0.9999/gcc/c/c-parser.cc:2065
0x6156498b657a c_parser_translation_unit
	/usr/src/debug/sys-devel/gcc-15.0.9999/gcc-15.0.9999/gcc/c/c-parser.cc:1919
0x6156498b657a c_parse_file()
	/usr/src/debug/sys-devel/gcc-15.0.9999/gcc-15.0.9999/gcc/c/c-parser.cc:28047
0x6156498aadf0 c_common_parse_file()
	/usr/src/debug/sys-devel/gcc-15.0.9999/gcc-15.0.9999/gcc/c-family/c-opts.cc:1375
Please submit a full bug report, with preprocessed source (by using -freport-bug).
Please include the complete backtrace with any bug report.
See <https://bugs.gentoo.org/> for instructions.
```

```

Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-pc-linux-gnu/15/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /var/tmp/portage/sys-devel/gcc-15.0.9999/work/gcc-15.0.9999/configure --host=x86_64-pc-linux-gnu --build=x86_64-pc-linux-gnu --prefix=/usr --bindir=/usr/x86_64-pc-linux-gnu/gcc-bin/15 --includedir=/usr/lib/gcc/x86_64-pc-linux-gnu/15/include --datadir=/usr/share/gcc-data/x86_64-pc-linux-gnu/15 --mandir=/usr/share/gcc-data/x86_64-pc-linux-gnu/15/man --infodir=/usr/share/gcc-data/x86_64-pc-linux-gnu/15/info --with-gxx-include-dir=/usr/lib/gcc/x86_64-pc-linux-gnu/15/include/g++-v15 --disable-silent-rules --disable-dependency-tracking --with-python-dir=/share/gcc-data/x86_64-pc-linux-gnu/15/python --enable-objc-gc --enable-languages=c,c++,d,go,objc,obj-c++,fortran,ada,m2,rust --enable-obsolete --enable-secureplt --disable-werror --with-system-zlib --enable-nls --without-included-gettext --disable-libunwind-exceptions --enable-checking=yes,extra,rtl --with-bugurl=https://bugs.gentoo.org/ --with-pkgversion='Gentoo Hardened 15.0.9999 p, commit aa56b526fa7d8766f57a7f24bedde612b00c197d' --with-gcc-major-version-only --enable-libstdcxx-time --enable-lto --disable-libstdcxx-pch --enable-shared --enable-threads=posix --enable-__cxa_atexit --enable-clocale=gnu --enable-multilib --with-multilib-list=m32,m64 --disable-fixed-point --enable-targets=all --enable-libgomp --disable-libssp --enable-libada --disable-cet --disable-systemtap --enable-valgrind-annotations --disable-vtable-verify --disable-libvtv --with-zstd --with-isl --disable-isl-version-check --enable-default-pie --enable-host-pie --enable-host-bind-now --enable-default-ssp --disable-fixincludes --with-build-config='bootstrap-O3 bootstrap-lto'
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 15.0.0 20241120 (experimental) 7c7da1036509a988b9ca3492eb856081132b14b2 (Gentoo Hardened 15.0.9999 p, commit aa56b526fa7d8766f57a7f24bedde612b00c197d)
```
Comment 1 Sam James 2024-11-21 08:33:47 UTC
The original source file is OK with -std=gnu17.
Comment 2 Sam James 2024-11-21 09:04:52 UTC
```
struct {
  unsigned long len;
  unsigned long size;
  char data[];
};
struct {
  struct {
    unsigned long len;
    unsigned long size;
    char data[6];
  }
};
```
Comment 4 uecker 2024-11-21 17:43:55 UTC
This seems to be the same underlying issue with FAMs now exposed by the fix to PR117490.
Comment 5 uecker 2024-11-22 17:28:37 UTC
Preliminary patch (but does not cover all similar cases):

diff --git a/gcc/tree.cc b/gcc/tree.cc
index 1da06c7d4e9..453b56cc37c 100644
--- a/gcc/tree.cc
+++ b/gcc/tree.cc
@@ -13977,6 +13977,9 @@ gimple_canonical_types_compatible_p (const_tree t1, const_tree t2,
              tree max1 = TYPE_MAX_VALUE (i1);
              tree max2 = TYPE_MAX_VALUE (i2);

+             if (!max1 || !max2)
+               return true;
+
              /* The minimum/maximum values have to be the same.  */
              if ((min1 == min2
                   || (min1 && min2
Comment 7 Sam James 2024-11-25 22:48:55 UTC
pr57773.c fails for me as well with just 'gcc pr57773.c -g'.
Comment 8 Andres Freund 2024-11-27 19:24:07 UTC
FWIW, a few of postgres' CI instances (which intentionally track a snapshot gcc) are hitting this (see e.g. [1]). I reproduced the failure locally, applied the patch from [2], after which the build succeeds.

[1] https://buildfarm.postgresql.org/cgi-bin/show_log.pl?nm=flaviventris&dt=2024-11-27%2018%3A57%3A47
[2] https://gcc.gnu.org/pipermail/gcc-patches/2024-November/669873.html
Comment 9 David Binderman 2024-11-28 09:30:59 UTC
Another test case:

struct {
  struct {
    int Reserved : 32
  }
};
struct {
  struct {
    int Reserved
  }
};

$ ~/gcc/results/bin/gcc -c -w -g bug1069.c
bug1069.c:10:1: error: ‘TYPE_CANONICAL’ is not compatible
   10 | };
      | ^
 <record_type 0x7ff259fde150 asm_written SI
    size <integer_cst 0x7ff259e24198 type <integer_type 0x7ff259e220a8 bitsizety
pe> constant 32>
...
Comment 10 Andrew Pinski 2024-11-28 09:43:23 UTC
(In reply to David Binderman from comment #9)
> Another test case:

That is a different issue unrelated to this issue here can you file it seperately?
Comment 11 David Binderman 2024-11-28 10:01:04 UTC
(In reply to Andrew Pinski from comment #10)
> That is a different issue unrelated to this issue here can you file it
> seperately?

Done:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117828
Comment 12 GCC Commits 2024-12-12 12:27:42 UTC
The master branch has been updated by Martin Uecker <uecker@gcc.gnu.org>:

https://gcc.gnu.org/g:d46c7f313b5a30ee04080f249e31e12987d50aa2

commit r15-6170-gd46c7f313b5a30ee04080f249e31e12987d50aa2
Author: Martin Uecker <uecker@tugraz.at>
Date:   Sat Nov 23 08:04:05 2024 +0100

    Fix type compatibility for types with flexible array member 2/2 [PR113688,PR114713,PR117724]
    
    For checking or computing TYPE_CANONICAL, ignore the array size when it is
    the last element of a structure or union.  To not get errors because of
    an inconsistent number of members, zero-sized arrays which are the last
    element are not ignored anymore when checking the fields of a struct.
    
            PR c/113688
            PR c/114014
            PR c/114713
            PR c/117724
    
    gcc/ChangeLog:
            * tree.cc (gimple_canonical_types_compatible_p): Add exception.
    
    gcc/lto/ChangeLog:
            * lto-common.cc (hash_canonical_type): Add exception.
    
    gcc/testsuite/ChangeLog:
            * gcc.dg/pr113688.c: New test.
            * gcc.dg/pr114014.c: New test.
            * gcc.dg/pr114713.c: New test.
            * gcc.dg/pr117724.c: New test.
Comment 13 uecker 2024-12-12 14:44:24 UTC
Fixed.