c: Fix ICE for incorrect code in comptypes_verify [PR115696]

Message ID a33b07aef5efe693a4b20d84b7451d8f82764afe.camel@tugraz.at
State Committed
Commit 592a746533a278a5fd3e7b5dff004e1846ef26a4
Headers
Series c: Fix ICE for incorrect code in comptypes_verify [PR115696] |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gcc_build--master-arm success Build passed
linaro-tcwg-bot/tcwg_gcc_check--master-arm success Test passed
linaro-tcwg-bot/tcwg_gcc_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_gcc_check--master-aarch64 success Test passed

Commit Message

Martin Uecker June 29, 2024, 3:13 p.m. UTC
  This adds missing code for handling error marks.


Bootstrapped and regression tested on x86_64.



    c: Fix ICE for incorrect code in comptypes_verify [PR115696]
    
    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.
  

Comments

Joseph Myers July 9, 2024, 5:32 p.m. UTC | #1
On Sat, 29 Jun 2024, Martin Uecker wrote:

> This adds missing code for handling error marks.
> 
> 
> Bootstrapped and regression tested on x86_64.
> 
> 
> 
>     c: Fix ICE for incorrect code in comptypes_verify [PR115696]
>     
>     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.

OK.
  

Patch

diff --git a/gcc/c/c-typeck.cc b/gcc/c/c-typeck.cc
index ffcab7df4d3..e486ac04f9c 100644
--- a/gcc/c/c-typeck.cc
+++ b/gcc/c/c-typeck.cc
@@ -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
index 00000000000..a7c8d87cb06
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr115696.c
@@ -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" } */