From 773ec47fe60d07116c11f2eda13ef3cf25fae65a Mon Sep 17 00:00:00 2001 From: Marek Polacek Date: Sun, 6 Jul 2014 19:00:10 +0000 Subject: re PR c/6940 (taking sizeof array parameter should trigger a warning) PR c/6940 * doc/invoke.texi: Document -Wsizeof-array-argument. c-family/ * c.opt (Wsizeof-array-argument): New option. c/ * c-decl.c (grokdeclarator): Set C_ARRAY_PARAMETER. * c-tree.h (C_ARRAY_PARAMETER): Define. * c-typeck.c (c_expr_sizeof_expr): Warn when using sizeof on an array function parameter. cp/ * cp-tree.h (DECL_ARRAY_PARAMETER_P): Define. * decl.c (grokdeclarator): Set DECL_ARRAY_PARAMETER_P. * typeck.c (cxx_sizeof_expr): Warn when using sizeof on an array function parameter. testsuite/ * c-c++-common/Wsizeof-pointer-memaccess1.c: Use -Wno-sizeof-array-argument. * c-c++-common/Wsizeof-pointer-memaccess2.c: Likewise. * g++.dg/warn/Wsizeof-pointer-memaccess-1.C: Likewise. * gcc.dg/Wsizeof-pointer-memaccess1.c: Likewise. * g++.dg/torture/Wsizeof-pointer-memaccess1.C: Likewise. * g++.dg/torture/Wsizeof-pointer-memaccess2.C: Likewise. * gcc.dg/torture/Wsizeof-pointer-memaccess1.c: Likewise. * c-c++-common/sizeof-array-argument.c: New test. * gcc.dg/vla-5.c: Add dg-warnings. ../libgomp/ * testsuite/libgomp.c/appendix-a/a.29.1.c (f): Add dg-warnings. From-SVN: r212312 --- gcc/c/c-decl.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'gcc/c/c-decl.c') diff --git a/gcc/c/c-decl.c b/gcc/c/c-decl.c index 3dec90b..0ca2e0d 100644 --- a/gcc/c/c-decl.c +++ b/gcc/c/c-decl.c @@ -6103,6 +6103,7 @@ grokdeclarator (const struct c_declarator *declarator, if (decl_context == PARM) { tree promoted_type; + bool array_parameter_p = false; /* A parameter declared as an array of T is really a pointer to T. One declared as a function is really a pointer to a function. */ @@ -6124,6 +6125,7 @@ grokdeclarator (const struct c_declarator *declarator, "attributes in parameter array declarator ignored"); size_varies = false; + array_parameter_p = true; } else if (TREE_CODE (type) == FUNCTION_TYPE) { @@ -6148,6 +6150,7 @@ grokdeclarator (const struct c_declarator *declarator, PARM_DECL, declarator->u.id, type); if (size_varies) C_DECL_VARIABLE_SIZE (decl) = 1; + C_ARRAY_PARAMETER (decl) = array_parameter_p; /* Compute the type actually passed in the parmlist, for the case where there is no prototype. -- cgit v1.1