aboutsummaryrefslogtreecommitdiff
path: root/gcc/c
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/c')
-rw-r--r--gcc/c/ChangeLog8
-rw-r--r--gcc/c/c-decl.c3
-rw-r--r--gcc/c/c-tree.h3
-rw-r--r--gcc/c/c-typeck.c10
4 files changed, 24 insertions, 0 deletions
diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog
index 68abca4..80ad172 100644
--- a/gcc/c/ChangeLog
+++ b/gcc/c/ChangeLog
@@ -1,3 +1,11 @@
+2014-07-06 Marek Polacek <polacek@redhat.com>
+
+ PR c/6940
+ * 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.
+
2014-07-02 Jan Hubicka <hubicka@ucw.cz>
Chen Gang <gang.chen.5i5j@gmail.com>
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.
diff --git a/gcc/c/c-tree.h b/gcc/c/c-tree.h
index 133930f..f97d0d5 100644
--- a/gcc/c/c-tree.h
+++ b/gcc/c/c-tree.h
@@ -66,6 +66,9 @@ along with GCC; see the file COPYING3. If not see
/* 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 it was declared as an array. */
+#define C_ARRAY_PARAMETER(NODE) DECL_LANG_FLAG_0 (NODE)
+
/* For FUNCTION_DECLs, evaluates true if the decl is built-in but has
been declared. */
#define C_DECL_DECLARED_BUILTIN(EXP) \
diff --git a/gcc/c/c-typeck.c b/gcc/c/c-typeck.c
index 35bfd14..06fd565 100644
--- a/gcc/c/c-typeck.c
+++ b/gcc/c/c-typeck.c
@@ -2731,6 +2731,16 @@ c_expr_sizeof_expr (location_t loc, struct c_expr expr)
else
{
bool expr_const_operands = true;
+
+ if (TREE_CODE (expr.value) == PARM_DECL
+ && C_ARRAY_PARAMETER (expr.value))
+ {
+ if (warning_at (loc, OPT_Wsizeof_array_argument,
+ "%<sizeof%> on array function parameter %qE will "
+ "return size of %qT", 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));