From 267bbb6fd17860dd09e69493ae031cc3e977301d Mon Sep 17 00:00:00 2001 From: Marek Polacek Date: Wed, 13 Sep 2017 16:46:17 +0000 Subject: [PATCH] re PR c/82167 (Segmentation fault when dereferencing the address of an array argument) 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. From-SVN: r252372 --- gcc/c/ChangeLog | 6 ++++++ gcc/c/c-typeck.c | 2 +- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gcc.dg/pr82167.c | 14 ++++++++++++++ 4 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.dg/pr82167.c diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog index d55b5ac42e4..957daeb4fe9 100644 --- a/gcc/c/ChangeLog +++ b/gcc/c/ChangeLog @@ -1,3 +1,9 @@ +2017-09-13 Marek Polacek + + PR c/82167 + * c-typeck.c (c_expr_sizeof_expr): Use the type of expr.value rather + than expr.original_type. + 2017-09-12 Nathan Sidwell * c-decl.c (field_decl_cmp, resort_data, resort_field_decl_cmp, diff --git a/gcc/c/c-typeck.c b/gcc/c/c-typeck.c index 91996c95ed0..f45fd3cfbbf 100644 --- a/gcc/c/c-typeck.c +++ b/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, "% 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 a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 2091f98c11a..1280e90308b 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2017-09-13 Marek Polacek + + PR c/82167 + * gcc.dg/pr82167.c: New test. + 2017-09-13 Will Schmidt * gcc.target/powerpc/fold-vec-ld-char.c: New. diff --git a/gcc/testsuite/gcc.dg/pr82167.c b/gcc/testsuite/gcc.dg/pr82167.c new file mode 100644 index 00000000000..af3b3a5a1c9 --- /dev/null +++ b/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 \\*\\*." } */ +} -- 2.30.2