]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c: Fix ICE for incorrect code in comptypes_verify [PR115696]
authorMartin Uecker <uecker@tugraz.at>
Sat, 29 Jun 2024 13:36:18 +0000 (15:36 +0200)
committerMartin Uecker <uecker@gcc.gnu.org>
Tue, 9 Jul 2024 19:05:26 +0000 (21:05 +0200)
The new verification code produces an ICE for incorrect code.  Add the
same logic as already used in comptypes to to bail out under certain
conditions.

PR c/115696

gcc/c/
* c-typeck.cc (comptypes_verify): Bail out for
identical, empty, and erroneous input types.

gcc/testsuite/
* gcc.dg/pr115696.c: New test.

gcc/c/c-typeck.cc
gcc/testsuite/gcc.dg/pr115696.c [new file with mode: 0644]

index ffcab7df4d3b1f24f0a4eff41982436eaf502b59..e486ac04f9cf774307979942889dce4379454d64 100644 (file)
@@ -1175,6 +1175,10 @@ common_type (tree t1, tree t2)
 static bool
 comptypes_verify (tree type1, tree type2)
 {
+  if (type1 == type2 || !type1 || !type2
+      || TREE_CODE (type1) == ERROR_MARK || TREE_CODE (type2) == ERROR_MARK)
+    return true;
+
   if (TYPE_CANONICAL (type1) != TYPE_CANONICAL (type2)
       && !TYPE_STRUCTURAL_EQUALITY_P (type1)
       && !TYPE_STRUCTURAL_EQUALITY_P (type2))
diff --git a/gcc/testsuite/gcc.dg/pr115696.c b/gcc/testsuite/gcc.dg/pr115696.c
new file mode 100644 (file)
index 0000000..50b8ebc
--- /dev/null
@@ -0,0 +1,7 @@
+/* { dg-do compile } */
+/* { dg-options "-Wno-implicit-int" } */
+
+a();   /* { dg-warning "no type or storage" } */
+a;     /* { dg-error "redeclared" } */
+       /* { dg-warning "no type or storage" "" { target *-*-* } .-1 } */
+a();   /* { dg-warning "no type or storage" } */