aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJoseph Myers <joseph@codesourcery.com>2009-04-25 22:19:09 +0100
committerJoseph Myers <jsm28@gcc.gnu.org>2009-04-25 22:19:09 +0100
commit24070fcb42eca4e9df8129f9c3ffb3cf71379fa5 (patch)
tree8c910c03d4c980b208b9616acc0764a504105241 /gcc
parentafdb7762cb3eb4f2e14a0fd3a774008f684210e8 (diff)
downloadgcc-24070fcb42eca4e9df8129f9c3ffb3cf71379fa5.zip
gcc-24070fcb42eca4e9df8129f9c3ffb3cf71379fa5.tar.gz
gcc-24070fcb42eca4e9df8129f9c3ffb3cf71379fa5.tar.bz2
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
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog7
-rw-r--r--gcc/c-typeck.c14
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/gcc.dg/vla-20.c12
4 files changed, 36 insertions, 2 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 113cf11..b454cb6 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -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
diff --git a/gcc/c-typeck.c b/gcc/c-typeck.c
index 1cfab1f..dc7d731 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;
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index c9cfd92..44c8c1a 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,5 +1,10 @@
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.
diff --git a/gcc/testsuite/gcc.dg/vla-20.c b/gcc/testsuite/gcc.dg/vla-20.c
new file mode 100644
index 0000000..04d9ee7
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/vla-20.c
@@ -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 } */