summaryrefslogtreecommitdiffstats
path: root/gcc/c-typeck.c
diff options
context:
space:
mode:
authorjsm28 <jsm28@138bc75d-0d04-0410-961f-82ee72b054a4>2009-04-25 21:19:09 +0000
committerjsm28 <jsm28@138bc75d-0d04-0410-961f-82ee72b054a4>2009-04-25 21:19:09 +0000
commite807498288ab20ac58d32ac81072b70d09a0e1b1 (patch)
tree8c910c03d4c980b208b9616acc0764a504105241 /gcc/c-typeck.c
parent2094ad2fdac49c08bb16eceac1cb8edb5c10a294 (diff)
downloadppe42-gcc-e807498288ab20ac58d32ac81072b70d09a0e1b1.tar.gz
ppe42-gcc-e807498288ab20ac58d32ac81072b70d09a0e1b1.zip
PR c/39582
* c-typeck.c (c_expr_sizeof_type): Create a C_MAYBE_CONST_EXPR with non-null C_MAYBE_CONST_EXPR_PRE if size of a variable-length type is an integer constant. testsuite: * gcc.dg/vla-20.c: New test. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@146787 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/c-typeck.c')
-rw-r--r--gcc/c-typeck.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/gcc/c-typeck.c b/gcc/c-typeck.c
index 1cfab1f14f2..dc7d731ee02 100644
--- a/gcc/c-typeck.c
+++ b/gcc/c-typeck.c
@@ -2391,8 +2391,18 @@ c_expr_sizeof_type (struct c_type_name *t)
ret.value = c_sizeof (type);
ret.original_code = ERROR_MARK;
ret.original_type = NULL;
- if (type_expr && c_vla_type_p (type))
- {
+ if ((type_expr || TREE_CODE (ret.value) == INTEGER_CST)
+ && c_vla_type_p (type))
+ {
+ /* If the type is a [*] array, it is a VLA but is represented as
+ having a size of zero. In such a case we must ensure that
+ the result of sizeof does not get folded to a constant by
+ c_fully_fold, because if the size is evaluated the result is
+ not constant and so constraints on zero or negative size
+ arrays must not be applied when this sizeof call is inside
+ another array declarator. */
+ if (!type_expr)
+ type_expr = integer_zero_node;
ret.value = build2 (C_MAYBE_CONST_EXPR, TREE_TYPE (ret.value),
type_expr, ret.value);
C_MAYBE_CONST_EXPR_NON_CONST (ret.value) = !type_expr_const;
OpenPOWER on IntegriCloud