This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
C PATCH to fix ICE with -Wsizeof-array-argument (PR c/82167)
- From: Marek Polacek <polacek at redhat dot com>
- To: GCC Patches <gcc-patches at gcc dot gnu dot org>, Joseph Myers <joseph at codesourcery dot com>
- Date: Wed, 13 Sep 2017 13:00:33 +0200
- Subject: C PATCH to fix ICE with -Wsizeof-array-argument (PR c/82167)
- Authentication-results: sourceware.org; auth=none
- Authentication-results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com
- Authentication-results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=polacek at redhat dot com
- Dmarc-filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 74ADEC04B952
This fixes a segv, where -Wsizeof-array-argument crashed because
expr.original_type was null. It was null because for sizeof (*&a)
we go to c_parser_unary_expression's case CPP_AND: and case CPP_MULT:,
and that removes the original_type. But we don't need the original
type, we can just use TREE_TYPE of expr.value.
Bootstrapped/regtested on x86_64-linux, ok for trunk?
2017-09-13 Marek Polacek <polacek@redhat.com>
PR c/82167
* c-typeck.c (c_expr_sizeof_expr): Use the type of expr.value rather
than expr.original_type.
* gcc.dg/pr82167.c: New test.
diff --git gcc/c/c-typeck.c gcc/c/c-typeck.c
index 91996c95ed0..f45fd3cfbbf 100644
--- gcc/c/c-typeck.c
+++ gcc/c/c-typeck.c
@@ -2909,7 +2909,7 @@ c_expr_sizeof_expr (location_t loc, struct c_expr expr)
if (warning_at (loc, OPT_Wsizeof_array_argument,
"%<sizeof%> on array function parameter %qE will "
"return size of %qT", expr.value,
- expr.original_type))
+ TREE_TYPE (expr.value)))
inform (DECL_SOURCE_LOCATION (expr.value), "declared here");
}
tree folded_expr = c_fully_fold (expr.value, require_constant_value,
diff --git gcc/testsuite/gcc.dg/pr82167.c gcc/testsuite/gcc.dg/pr82167.c
index e69de29bb2d..af3b3a5a1c9 100644
--- gcc/testsuite/gcc.dg/pr82167.c
+++ gcc/testsuite/gcc.dg/pr82167.c
@@ -0,0 +1,14 @@
+/* PR c/82167 */
+/* { dg-do compile } */
+
+void
+fn1 (int a[])
+{
+ __builtin_printf ("%zu\n", sizeof (*&a)); /* { dg-warning ".sizeof. on array function parameter .a. will return size of .int \\*." } */
+}
+
+void
+fn2 (int *a[])
+{
+ __builtin_printf ("%zu\n", sizeof (*&a)); /* { dg-warning ".sizeof. on array function parameter .a. will return size of .int \\*\\*." } */
+}
Marek