aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorMarek Polacek <polacek@redhat.com>2024-06-25 14:55:08 -0400
committerMarek Polacek <polacek@redhat.com>2024-07-10 14:39:19 -0400
commit0c27eade4754c13a54e265e4305182c95be1e441 (patch)
treefaeada5a1f6c91c8ceafc7b9fe4aa7a0b5b2dfd9 /gcc
parent4c7009735f73f59c9a635d79c048c8981310e331 (diff)
downloadgcc-0c27eade4754c13a54e265e4305182c95be1e441.zip
gcc-0c27eade4754c13a54e265e4305182c95be1e441.tar.gz
gcc-0c27eade4754c13a54e265e4305182c95be1e441.tar.bz2
c: ICE with invalid sizeof [PR115642]
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.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/c/c-typeck.cc3
-rw-r--r--gcc/testsuite/gcc.dg/noncompile/sizeof-1.c7
2 files changed, 10 insertions, 0 deletions
diff --git a/gcc/c/c-typeck.cc b/gcc/c/c-typeck.cc
index 455dc37..36f88fcd 100644
--- a/gcc/c/c-typeck.cc
+++ b/gcc/c/c-typeck.cc
@@ -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
index 0000000..db7e204
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/noncompile/sizeof-1.c
@@ -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" } */
+}