re PR c/39582 (bad errors for some uses of [*] arrays)

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.

From-SVN: r146787
This commit is contained in:
Joseph Myers 2009-04-25 22:19:09 +01:00 committed by Joseph Myers
parent afdb7762cb
commit 24070fcb42
4 changed files with 35 additions and 1 deletions

View File

@ -1,3 +1,10 @@
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

View File

@ -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;

View File

@ -1,3 +1,8 @@
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

View File

@ -0,0 +1,12 @@
/* 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 } */