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

commit r15-8286-gd9e834958e82219f836577da4ef8176aca2c7c9f
Author: Martin Uecker <uec...@tugraz.at>
Date:   Sat Mar 1 17:21:25 2025 +0100

    c: Fix ICE in error recovery when checking struct compatibility [PR118061]
    
    Return early when comparing two structures for compatibility
    and the type of a member is erroneous.
    
            PR c/118061
    
    gcc/c/ChangeLog:
            * c-typeck.cc (tagged_types_tu_compatible_p): Handle
            errors in types of struct members.
    
    gcc/testsuite/ChangeLog:
            * gcc.dg/pr118061.c: New test.

Diff:
---
 gcc/c/c-typeck.cc               | 3 +++
 gcc/testsuite/gcc.dg/pr118061.c | 8 ++++++++
 2 files changed, 11 insertions(+)

diff --git a/gcc/c/c-typeck.cc b/gcc/c/c-typeck.cc
index 11fa98d86ee8..1a39cbb20090 100644
--- a/gcc/c/c-typeck.cc
+++ b/gcc/c/c-typeck.cc
@@ -1933,6 +1933,9 @@ tagged_types_tu_compatible_p (const_tree t1, const_tree 
t2,
                ft2 = DECL_BIT_FIELD_TYPE (s2);
              }
 
+           if (TREE_CODE (ft1) == ERROR_MARK || TREE_CODE (ft2) == ERROR_MARK)
+             return false;
+
            data->anon_field = !DECL_NAME (s1);
            data->pointedto = false;
 
diff --git a/gcc/testsuite/gcc.dg/pr118061.c b/gcc/testsuite/gcc.dg/pr118061.c
new file mode 100644
index 000000000000..6efc94d9e3b6
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr118061.c
@@ -0,0 +1,8 @@
+/* { dg-do "compile" } */
+/* { dg-options "-std=gnu23" } */
+
+int main()
+{
+    struct { int x[1++]; } x;  /* { dg-error "lvalue required as increment 
operand" } */
+    struct { int x[1++]; } y;  /* { dg-error "lvalue required as increment 
operand" } */
+}

Reply via email to