Commit 24070fcb by Joseph Myers Committed by Joseph Myers

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
parent afdb7762
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
......
......@@ -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;
......
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.
......
/* 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 } */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment