aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoseph Myers <joseph@codesourcery.com>2009-04-01 15:41:06 +0100
committerJoseph Myers <jsm28@gcc.gnu.org>2009-04-01 15:41:06 +0100
commit6ccb2a4a4bbd43dfbcf9ac56f0f0f7e614874f0c (patch)
tree1b594cd6ac30f778bcb2ffce2d24267f82199988
parent299b87f8a21c1ae2611434529c8c4dfc4c291d95 (diff)
downloadgcc-6ccb2a4a4bbd43dfbcf9ac56f0f0f7e614874f0c.zip
gcc-6ccb2a4a4bbd43dfbcf9ac56f0f0f7e614874f0c.tar.gz
gcc-6ccb2a4a4bbd43dfbcf9ac56f0f0f7e614874f0c.tar.bz2
re PR c/39605 ("error: variable-size type declared outside of any function" is issued twice)
PR c/39605 * c-decl.c (grokdeclarator): Pedwarn for file-scope array declarator whose size is not an integer constant expression but folds to an integer constant, then treat it as a constant subsequently. testsuite: * gcc.dg/vla-17.c, gcc.dg/vla-18.c: New tests. * gcc.dg/pr25682.c: Update expected diagnostics. From-SVN: r145405
-rw-r--r--gcc/ChangeLog8
-rw-r--r--gcc/c-decl.c12
-rw-r--r--gcc/testsuite/ChangeLog6
-rw-r--r--gcc/testsuite/gcc.dg/pr25682.c8
-rw-r--r--gcc/testsuite/gcc.dg/vla-17.c9
-rw-r--r--gcc/testsuite/gcc.dg/vla-18.c9
6 files changed, 47 insertions, 5 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index f4b1e56..1eebf64 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,11 @@
+2009-04-01 Joseph Myers <joseph@codesourcery.com>
+
+ PR c/39605
+ * c-decl.c (grokdeclarator): Pedwarn for file-scope array
+ declarator whose size is not an integer constant expression but
+ folds to an integer constant, then treat it as a constant
+ subsequently.
+
2009-04-01 Richard Guenther <rguenther@suse.de>
* fold-const.c (fold_plusminus_mult_expr): Do not fold
diff --git a/gcc/c-decl.c b/gcc/c-decl.c
index 3c1c277..9202feb 100644
--- a/gcc/c-decl.c
+++ b/gcc/c-decl.c
@@ -4408,7 +4408,17 @@ grokdeclarator (const struct c_declarator *declarator,
not an integer constant expression. */
if (!size_int_const)
{
- this_size_varies = size_varies = 1;
+ /* If this is a file scope declaration of an
+ ordinary identifier, this is invalid code;
+ diagnosing it here and not subsequently
+ treating the type as variable-length avoids
+ more confusing diagnostics later. */
+ if ((decl_context == NORMAL || decl_context == FIELD)
+ && current_scope == file_scope)
+ pedwarn (input_location, 0,
+ "variably modified %qs at file scope", name);
+ else
+ this_size_varies = size_varies = 1;
warn_variable_length_array (orig_name, size);
}
}
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 5462bea..16d9340 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,9 @@
+2009-04-01 Joseph Myers <joseph@codesourcery.com>
+
+ PR c/39605
+ * gcc.dg/vla-17.c, gcc.dg/vla-18.c: New tests.
+ * gcc.dg/pr25682.c: Update expected diagnostics.
+
2009-04-01 Richard Guenther <rguenther@suse.de>
* gcc.dg/fold-plusmult-2.c: New testcase.
diff --git a/gcc/testsuite/gcc.dg/pr25682.c b/gcc/testsuite/gcc.dg/pr25682.c
index c99b891..8c51d82 100644
--- a/gcc/testsuite/gcc.dg/pr25682.c
+++ b/gcc/testsuite/gcc.dg/pr25682.c
@@ -10,10 +10,10 @@ struct S
int b;
};
-char c[(char *) &((struct S *) 0)->b - (char *) 0]; /* { dg-error "variable-size" } */
-char d[(__SIZE_TYPE__) &((struct S *) 8)->b]; /* { dg-error "variable-size" } */
-char e[sizeof (c) == __builtin_offsetof (struct S, b) ? 1 : -1]; /* { dg-error "variably modified" } */
-char f[sizeof (d) == __builtin_offsetof (struct S, b) + 8 ? 1 : -1]; /* { dg-error "variably modified" } */
+char c[(char *) &((struct S *) 0)->b - (char *) 0]; /* { dg-warning "variably modified" } */
+char d[(__SIZE_TYPE__) &((struct S *) 8)->b]; /* { dg-warning "variably modified" } */
+char e[sizeof (c) == __builtin_offsetof (struct S, b) ? 1 : -1];
+char f[sizeof (d) == __builtin_offsetof (struct S, b) + 8 ? 1 : -1];
extern void bar (char *, char *);
diff --git a/gcc/testsuite/gcc.dg/vla-17.c b/gcc/testsuite/gcc.dg/vla-17.c
new file mode 100644
index 0000000..07d3930
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/vla-17.c
@@ -0,0 +1,9 @@
+/* Test diagnostics for VLA whose size folds to an integer constant at
+ file scope. PR 39605. */
+/* { dg-do compile } */
+/* { dg-options "" } */
+
+#define FIRST ((void*)0x80)
+#define LAST ((void*)0x86)
+
+static int b[LAST-FIRST]; /* { dg-warning "variably modified 'b' at file scope" } */
diff --git a/gcc/testsuite/gcc.dg/vla-18.c b/gcc/testsuite/gcc.dg/vla-18.c
new file mode 100644
index 0000000..c60069c
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/vla-18.c
@@ -0,0 +1,9 @@
+/* Test diagnostics for VLA whose size folds to an integer constant at
+ file scope; the diagnostic should be a pedwarn. PR 39605. */
+/* { dg-do compile } */
+/* { dg-options "-std=c99 -pedantic-errors" } */
+
+#define FIRST ((char*)0x80)
+#define LAST ((char*)0x86)
+
+static int b[LAST-FIRST]; /* { dg-error "variably modified 'b' at file scope" } */