===================================================================
@@ -4630,6 +4630,8 @@ push_parm_decl (const struct c_parm *par
decl = grokdeclarator (parm->declarator, parm->specs, PARM, false, NULL,
&attrs, expr, NULL, DEPRECATED_NORMAL);
decl_attributes (&decl, attrs, 0);
+
+ C_ARRAY_PARM (decl) = parm->declarator->kind == cdk_array;
decl = pushdecl (decl);
===================================================================
@@ -66,6 +66,9 @@ along with GCC; see the file COPYING3.
/* For a FUNCTION_DECL, nonzero if it was an implicit declaration. */
#define C_DECL_IMPLICIT(EXP) DECL_LANG_FLAG_2 (EXP)
+/* For a PARM_DECL, nonzero if parameter was declared as array */
+#define C_ARRAY_PARM(NODE) DECL_LANG_FLAG_2 (NODE)
+
/* For FUNCTION_DECLs, evaluates true if the decl is built-in but has
been declared. */
#define C_DECL_DECLARED_BUILTIN(EXP) \
===================================================================
@@ -2730,6 +2730,13 @@ c_expr_sizeof_expr (location_t loc, stru
else
{
bool expr_const_operands = true;
+
+ if (warn_sizeof_array_argument && TREE_CODE (expr.value) == PARM_DECL && C_ARRAY_PARM (expr.value))
+ {
+ warning_at (loc, 0, "sizeof on array parameter %<%s%> shall return size of %qT",
+ IDENTIFIER_POINTER (DECL_NAME (expr.value)), expr.original_type);
+ inform (DECL_SOURCE_LOCATION (expr.value), "declared here");
+ }
tree folded_expr = c_fully_fold (expr.value, require_constant_value,
&expr_const_operands);
ret.value = c_sizeof (loc, TREE_TYPE (folded_expr));
===================================================================
@@ -509,6 +509,9 @@ Warn about missing fields in struct init
Wsizeof-pointer-memaccess
C ObjC C++ ObjC++ Var(warn_sizeof_pointer_memaccess) Warning LangEnabledBy(C ObjC C++ ObjC++,Wall)
+Wsizeof-array-argument
+C Var(warn_sizeof_array_argument) Warning LangEnabledBy(C,Wall)
+
Wsuggest-attribute=format
C ObjC C++ ObjC++ Var(warn_suggest_attribute_format) Warning
Warn about functions which might be candidates for format attributes
===================================================================
@@ -0,0 +1,17 @@
+/* { dg-do compile } */
+/* { dg-options "-Wsizeof-array-argument" } */
+
+int foo(int a[])
+{
+ return (int) sizeof (a); /* { dg-warning "sizeof on array parameter" } */
+}
+
+int bar(int x, int b[3])
+{
+ return x + (int) sizeof (b); /* { dg-warning "sizeof on array parameter" } */
+}
+
+int f(int *p)
+{
+ return (int) sizeof (*p);
+}