]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c: ICE with invalid sizeof [PR115642]
authorMarek Polacek <polacek@redhat.com>
Tue, 25 Jun 2024 18:55:08 +0000 (14:55 -0400)
committerMarek Polacek <polacek@redhat.com>
Wed, 10 Jul 2024 18:39:19 +0000 (14:39 -0400)
Here we ICE in c_expr_sizeof_expr on an erroneous expr.value.  The
code checks for expr.value == error_mark_node but here the e_m_n is
wrapped in a C_MAYBE_CONST_EXPR.  I don't think we should have created
such a tree, so let's return earlier in c_cast_expr.

PR c/115642

gcc/c/ChangeLog:

* c-typeck.cc (c_cast_expr): Return error_mark_node if build_c_cast
failed.

gcc/testsuite/ChangeLog:

* gcc.dg/noncompile/sizeof-1.c: New test.

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

index 455dc374b481c84f4cbab5d975b882b763757280..36f88fcd03de883a87fb96475c21abfedfe4389f 100644 (file)
@@ -6702,6 +6702,9 @@ c_cast_expr (location_t loc, struct c_type_name *type_name, tree expr)
     return error_mark_node;
 
   ret = build_c_cast (loc, type, expr);
+  if (ret == error_mark_node)
+    return error_mark_node;
+
   if (type_expr)
     {
       bool inner_expr_const = true;
diff --git a/gcc/testsuite/gcc.dg/noncompile/sizeof-1.c b/gcc/testsuite/gcc.dg/noncompile/sizeof-1.c
new file mode 100644 (file)
index 0000000..db7e204
--- /dev/null
@@ -0,0 +1,7 @@
+/* PR c/115642 */
+/* { dg-do compile } */
+
+void f (int N) {
+  int a[2][N];
+  sizeof ((int [2][N])a); /* { dg-error "cast specifies array type" } */
+}