Bug 117828 - [15 Regression] -g and error: ‘TYPE_CANONICAL’ is not compatible since r15-5470
Summary: [15 Regression] -g and error: ‘TYPE_CANONICAL’ is not compatible since r15-5470
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 15.0
: P1 normal
Target Milestone: 15.0
Assignee: Not yet assigned to anyone
URL:
Keywords: ice-checking, patch
Depends on:
Blocks:
 
Reported: 2024-11-28 09:59 UTC by David Binderman
Modified: 2024-12-03 22:14 UTC (History)
3 users (show)

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


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description David Binderman 2024-11-28 09:59:37 UTC
For this much reduced C source code:

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

seems to go wrong with recent gcc trunk:

cvise $ ~/gcc/results/bin/gcc -c -w -g bug1069.c
bug1069.c:10:1: error: ‘TYPE_CANONICAL’ is not compatible
   10 | };
      | ^
 <record_type 0x7f4dd55de150 asm_written SI
    size <integer_cst 0x7f4dd5424198 type <integer_type 0x7f4dd54220a8 bitsizetype> constant 32>
...

It's ok without the -g debug flag:

cvise $ ~/gcc/results/bin/gcc -c -w bug1069.c
cvise $ 

The bug first seems to occur sometime between g:fff5cfa4353e0c45
and g:6350e956d1a74963, which is 52 commits.
Comment 1 Jakub Jelinek 2024-11-28 10:06:03 UTC
Fixed up testcase:

struct {
  struct {
    int Reserved : 32;
  } u;
} v;
struct {
  struct {
    int Reserved;
  } u;
} w;

Started with r15-5470-g8b02cc9a4f2b8db48da
Comment 2 Richard Biener 2024-11-28 10:37:43 UTC
note -g only triggers type verfication
Comment 3 uecker 2024-11-28 11:37:08 UTC
A check is needed in tagged_tu_types_compatible_p. 

In C23 the following needs to be rejected:

struct foo {
  struct {
    int Reserved : 32;
  }
};
struct foo {
  struct {
    int Reserved;
  }
};
Comment 5 GCC Commits 2024-11-29 13:15:52 UTC
The master branch has been updated by Martin Uecker <uecker@gcc.gnu.org>:

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

commit r15-5792-gb6a513909793a87b62ca52da85ff3baa44f6b4b6
Author: Martin Uecker <uecker@tugraz.at>
Date:   Thu Nov 28 20:06:16 2024 +0100

    c: Correct type compatibility for bit-fields [PR117828]
    
    Add missing test for consistency of bit-fields when comparing tagged
    types for compatibility.
    
            PR c/117828
    
    gcc/c/ChangeLog:
            * c-typeck.cc (tagged_types_tu_compatible_p): Add check.
    
    gcc/testsuite/ChangeLog:
            * gcc.dg/c23-tag-bitfields-1.c: New test.
            * gcc.dg/pr117828.c: New test.
Comment 6 uecker 2024-11-29 13:41:10 UTC
Fixed.
Comment 7 GCC Commits 2024-12-03 22:14:02 UTC
The master branch has been updated by Georg-Johann Lay <gjl@gcc.gnu.org>:

https://gcc.gnu.org/g:846c0b397b5c1b4ff6c68d83af99aff2aa80a162

commit r15-5913-g846c0b397b5c1b4ff6c68d83af99aff2aa80a162
Author: Georg-Johann Lay <avr@gjlay.de>
Date:   Tue Dec 3 11:32:30 2024 +0100

    Rectify some test cases.
    
            PR testsuite/52641
            PR testsuite/109123
            PR testsuite/114661
            PR testsuite/117828
            PR testsuite/116481
            PR testsuite/91069
    gcc/testsuite/
            * gcc.dg/Wuse-after-free-pr109123.c: Use size_t
            instead of long unsigned int.
            * gcc.dg/c23-tag-bitfields-1.c: Requires int32plus.
            * gcc.dg/pr114661.c: Same.
            * gcc.dg/pr117828.c: Same.
            * gcc.dg/flex-array-counted-by-2.c: Use uintptr_t
            instead of unsigned long.
            * gcc.dg/pr116481.c: Same.
            * gcc.dg/lto/tag-1_0.c: Use int32_t instead of int.
            * gcc.dg/lto/tag-1_1.c: Use int16_t instead of short.
            * gcc.dg/pr91069.c: Require double64.
            * gcc.dg/type-convert-var.c: Require double64plus.