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
This commit is contained in:
Marek Polacek 2017-09-13 16:46:17 +00:00 committed by Marek Polacek
parent 72ace300a2
commit 267bbb6fd1
4 changed files with 26 additions and 1 deletions

View File

@ -1,3 +1,9 @@
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.
2017-09-12 Nathan Sidwell <nathan@acm.org>
* c-decl.c (field_decl_cmp, resort_data, resort_field_decl_cmp,

View File

@ -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,

View File

@ -1,3 +1,8 @@
2017-09-13 Marek Polacek <polacek@redhat.com>
PR c/82167
* gcc.dg/pr82167.c: New test.
2017-09-13 Will Schmidt <will_schmidt@vnet.ibm.com>
* gcc.target/powerpc/fold-vec-ld-char.c: New.

View File

@ -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 \\*\\*." } */
}