]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fix ICE due to c_safe_arg_type_equiv_p not checking for error_mark node
authorAndrew Pinski <pinskia@gmail.com>
Sat, 14 Oct 2023 20:18:00 +0000 (13:18 -0700)
committerAndrew Pinski <pinskia@gmail.com>
Wed, 18 Oct 2023 22:11:38 +0000 (15:11 -0700)
This is a simple error recovery issue when c_safe_arg_type_equiv_p
was added in r8-5312-gc65e18d3331aa999. The issue is that after
an error, an argument type (of a function type) might turn
into an error mark node and c_safe_arg_type_equiv_p was not ready
for that. So this just adds a check for error operand for its
arguments before getting the main variant.

OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions.

PR c/101285

gcc/c/ChangeLog:

* c-typeck.cc (c_safe_arg_type_equiv_p): Return true for error
operands early.

gcc/testsuite/ChangeLog:

* gcc.dg/pr101285-1.c: New test.

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

index e55e887da14616e05c12d541ac50318705b51a6d..6e044b4afbc991eaa76036f9b303146161aca75d 100644 (file)
@@ -5960,6 +5960,9 @@ handle_warn_cast_qual (location_t loc, tree type, tree otype)
 static bool
 c_safe_arg_type_equiv_p (tree t1, tree t2)
 {
+  if (error_operand_p (t1) || error_operand_p (t2))
+    return true;
+
   t1 = TYPE_MAIN_VARIANT (t1);
   t2 = TYPE_MAIN_VARIANT (t2);
 
diff --git a/gcc/testsuite/gcc.dg/pr101285-1.c b/gcc/testsuite/gcc.dg/pr101285-1.c
new file mode 100644 (file)
index 0000000..831e35f
--- /dev/null
@@ -0,0 +1,10 @@
+/* { dg-do compile } */
+/* { dg-options "-W -Wall" } */
+const int b;
+typedef void (*ft1)(int[b++]); /* { dg-error "read-only variable" } */
+void bar(int * z);
+void baz()
+{
+    (ft1) bar; /* { dg-warning "statement with no effect" } */
+}
+