+2009-04-25 Joseph Myers <joseph@codesourcery.com>
+
+ 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.
+
2009-04-25 Uros Bizjak <ubizjak@gmail.com>
PR target/39897
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;
2009-04-25 Joseph Myers <joseph@codesourcery.com>
+ PR c/39582
+ * gcc.dg/vla-20.c: New test.
+
+2009-04-25 Joseph Myers <joseph@codesourcery.com>
+
PR c/39564
* gcc.dg/vla-19.c: New test.
--- /dev/null
+/* Test use of sizeof with [*] in type name: should not refer to
+ zero-size array. PR 39582. */
+/* { dg-do compile } */
+/* { dg-options "-std=c99 -pedantic-errors" } */
+
+void foo11d(int x[sizeof(int *[*])]); /* { dg-warning "not in a declaration" } */
+
+/* Although the size is not constant, it may nevertheless appear in a
+ constant expression if not evaluated. */
+
+void foo11e(int x[1 ? 0 : sizeof(int *[*])]); /* { dg-warning "not in a declaration" } */
+/* { dg-error "zero-size array" "correct zero size" { target *-*-* } 11 } */