aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Sebor <msebor@redhat.com>2020-08-28 08:26:32 -0600
committerMartin Sebor <msebor@redhat.com>2020-08-28 08:26:32 -0600
commitba6373a39782139789f0eeba7c0e607ec6dfb477 (patch)
tree08e4bc7b94b6f94a7c0be13f89b223d569de5db7
parentcb3c3d63315ceb4dc262e5efb83b42c73c43387d (diff)
downloadgcc-ba6373a39782139789f0eeba7c0e607ec6dfb477.zip
gcc-ba6373a39782139789f0eeba7c0e607ec6dfb477.tar.gz
gcc-ba6373a39782139789f0eeba7c0e607ec6dfb477.tar.bz2
PR c/96596 - ICE in match_builtin_function_types on a declaration of a built-in with invalid array argument
gcc/c/ChangeLog: PR c/96596 * c-decl.c (match_builtin_function_types): Avoid dealing with erroneous argument type. gcc/testsuite/ChangeLog: PR c/96596 * gcc.dg/Wbuiltin-declaration-mismatch-16.c: New test.
-rw-r--r--gcc/c/c-decl.c5
-rw-r--r--gcc/testsuite/gcc.dg/Wbuiltin-declaration-mismatch-16.c12
2 files changed, 16 insertions, 1 deletions
diff --git a/gcc/c/c-decl.c b/gcc/c/c-decl.c
index 5d6b504..190c00b 100644
--- a/gcc/c/c-decl.c
+++ b/gcc/c/c-decl.c
@@ -1712,7 +1712,10 @@ match_builtin_function_types (tree newtype, tree oldtype,
return NULL_TREE;
tree oldtype = TYPE_MAIN_VARIANT (TREE_VALUE (oldargs));
- tree newtype = TYPE_MAIN_VARIANT (TREE_VALUE (newargs));
+ tree newtype = TREE_VALUE (newargs);
+ if (newtype == error_mark_node)
+ return NULL_TREE;
+ newtype = TYPE_MAIN_VARIANT (newtype);
if (!types_close_enough_to_match (oldtype, newtype))
return NULL_TREE;
diff --git a/gcc/testsuite/gcc.dg/Wbuiltin-declaration-mismatch-16.c b/gcc/testsuite/gcc.dg/Wbuiltin-declaration-mismatch-16.c
new file mode 100644
index 0000000..494fff9
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/Wbuiltin-declaration-mismatch-16.c
@@ -0,0 +1,12 @@
+/* PR c/96596 - ICE on a declaration of a built-in with invalid array
+ argument
+ { dg-do compile } */
+
+void __builtin_abort (int[foo]); /* { dg-error "'foo' undeclared" } */
+void __builtin_trap (int[__SIZE_MAX__]); /* { dg-error "size of unnamed array is too large" } */
+void __builtin_unreachable (int[][]); /* { dg-error "array type has incomplete element type" } */
+
+void __builtin_exit (int, int[+]); /* { dg-error "expected expression before" } */
+
+/* { dg-prune-output "\\\[-Wbuiltin-declaration-mismatch" } */
+