aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorSeongbae Park <seongbae.park@gmail.com>2007-03-12 18:31:39 +0000
committerSeongbae Park <spark@gcc.gnu.org>2007-03-12 18:31:39 +0000
commit50d50fc7eed9ef1ef9a941be3a73c3ecc3eed5b0 (patch)
treef58a0ea917a7250e26da70b4e2da5c2e6db2fd99 /gcc
parentae0698035be607578e73afab669c3255bf52a6e0 (diff)
downloadgcc-50d50fc7eed9ef1ef9a941be3a73c3ecc3eed5b0.zip
gcc-50d50fc7eed9ef1ef9a941be3a73c3ecc3eed5b0.tar.gz
gcc-50d50fc7eed9ef1ef9a941be3a73c3ecc3eed5b0.tar.bz2
invoke.texi (Wvla): New warning.
ChangeLog: 2007-03-12 Seongbae Park <seongbae.park@gmail.com> * gcc/doc/invoke.texi (Wvla): New warning. gcc/ChangeLog: 2007-03-12 Seongbae Park <seongbae.park@gmail.com> * c-decl.c (warn_variable_length_array): New function. Refactored from grokdeclarator to handle warn_vla and handle unnamed array case. (grokdeclarator): Refactored VLA warning case. * c.opt (Wvla): New flag. gcc/cp/ChangeLog: 2007-03-12 Seongbae Park <seongbae.park@gmail.com> * decl.c (compute_array_index_type): New warning flag warn_vla. gcc/testsuite/ChangeLog: 2007-03-12 Seongbae Park <seongbae.park@gmail.com> * gcc.dg/wvla-1.c: New test * gcc.dg/wvla-2.c: New test * gcc.dg/wvla-3.c: New test * gcc.dg/wvla-4.c: New test * gcc.dg/wvla-5.c: New test * gcc.dg/wvla-6.c: New test * gcc.dg/wvla-7.c: New test * g++.dg/warn/Wvla-1.C: New test * g++.dg/warn/Wvla-2.C: New test * g++.dg/warn/Wvla-3.C: New test From-SVN: r122851
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog8
-rw-r--r--gcc/c-decl.c67
-rw-r--r--gcc/c.opt4
-rw-r--r--gcc/cp/ChangeLog4
-rw-r--r--gcc/cp/decl.c15
-rw-r--r--gcc/doc/invoke.texi10
-rw-r--r--gcc/testsuite/ChangeLog13
-rw-r--r--gcc/testsuite/g++.dg/warn/Wvla-1.C7
-rw-r--r--gcc/testsuite/g++.dg/warn/Wvla-2.C7
-rw-r--r--gcc/testsuite/g++.dg/warn/Wvla-3.C7
-rw-r--r--gcc/testsuite/gcc.dg/wvla-1.c5
-rw-r--r--gcc/testsuite/gcc.dg/wvla-2.c5
-rw-r--r--gcc/testsuite/gcc.dg/wvla-3.c5
-rw-r--r--gcc/testsuite/gcc.dg/wvla-4.c5
-rw-r--r--gcc/testsuite/gcc.dg/wvla-5.c5
-rw-r--r--gcc/testsuite/gcc.dg/wvla-6.c5
-rw-r--r--gcc/testsuite/gcc.dg/wvla-7.c5
17 files changed, 162 insertions, 15 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 0ce2746..624f651 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,11 @@
+2007-03-12 Seongbae Park <seongbae.park@gmail.com>
+
+ * c-decl.c (warn_variable_length_array): New function.
+ Refactored from grokdeclarator to handle warn_vla
+ and handle unnamed array case.
+ (grokdeclarator): Refactored VLA warning case.
+ * c.opt (Wvla): New flag.
+
2007-03-12 Richard Henderson <rth@redhat.com>
* config/alpha/alpha.c (alpha_elf_section_type_flags): New.
diff --git a/gcc/c-decl.c b/gcc/c-decl.c
index fd5b065..eaef0a5 100644
--- a/gcc/c-decl.c
+++ b/gcc/c-decl.c
@@ -3891,6 +3891,61 @@ check_bitfield_type_and_width (tree *type, tree *width, const char *orig_name)
}
+
+/* Print warning about variable length array if necessary. */
+
+static void
+warn_variable_length_array (const char *name, tree size)
+{
+ int ped = !flag_isoc99 && pedantic && warn_vla != 0;
+ int const_size = TREE_CONSTANT (size);
+
+ if (ped)
+ {
+ if (const_size)
+ {
+ if (name)
+ pedwarn ("ISO C90 forbids array %qs whose size "
+ "can%'t be evaluated",
+ name);
+ else
+ pedwarn ("ISO C90 forbids array whose size "
+ "can%'t be evaluated");
+ }
+ else
+ {
+ if (name)
+ pedwarn ("ISO C90 forbids variable length array %qs",
+ name);
+ else
+ pedwarn ("ISO C90 forbids variable length array");
+ }
+ }
+ else if (warn_vla > 0)
+ {
+ if (const_size)
+ {
+ if (name)
+ warning (OPT_Wvla,
+ "the size of array %qs can"
+ "%'t be evaluated", name);
+ else
+ warning (OPT_Wvla,
+ "the size of array can %'t be evaluated");
+ }
+ else
+ {
+ if (name)
+ warning (OPT_Wvla,
+ "variable length array %qs is used",
+ name);
+ else
+ warning (OPT_Wvla,
+ "variable length array is used");
+ }
+ }
+}
+
/* Given declspecs and a declarator,
determine the name and type of the object declared
and construct a ..._DECL node for it.
@@ -4289,17 +4344,7 @@ grokdeclarator (const struct c_declarator *declarator,
nonconstant even if it is (eg) a const variable
with known value. */
size_varies = 1;
-
- if (!flag_isoc99 && pedantic)
- {
- if (TREE_CONSTANT (size))
- pedwarn ("ISO C90 forbids array %qs whose size "
- "can%'t be evaluated",
- name);
- else
- pedwarn ("ISO C90 forbids variable-size array %qs",
- name);
- }
+ warn_variable_length_array (orig_name, size);
}
if (integer_zerop (size))
diff --git a/gcc/c.opt b/gcc/c.opt
index 3fb3686..928e8b2 100644
--- a/gcc/c.opt
+++ b/gcc/c.opt
@@ -450,6 +450,10 @@ Wvariadic-macros
C ObjC C++ ObjC++ Warning
Do not warn about using variadic macros when -pedantic
+Wvla
+C ObjC C++ ObjC++ Var(warn_vla) Init(-1) Warning
+Warn if a variable length array is used
+
Wwrite-strings
C ObjC C++ ObjC++ Var(warn_write_strings) Warning
In C++, nonzero means warn about deprecated conversion from string literals to `char *'. In C, similar warning, except that the conversion is of course not deprecated by the ISO C standard.
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index ccbb842..752d86f 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,7 @@
+2007-03-12 Seongbae Park <seongbae.park@gmail.com>
+
+ * decl.c (compute_array_index_type): New warning flag warn_vla.
+
2007-03-12 Mark Mitchell <mark@codesourcery.com>
PR c++/30108
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 318085a..14d20ce 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -6632,12 +6632,21 @@ compute_array_index_type (tree name, tree size)
error ("size of array is not an integral constant-expression");
size = integer_one_node;
}
- else if (pedantic)
+ else if (pedantic && warn_vla != 0)
{
if (name)
- pedwarn ("ISO C++ forbids variable-size array %qD", name);
+ pedwarn ("ISO C++ forbids variable length array %qD", name);
else
- pedwarn ("ISO C++ forbids variable-size array");
+ pedwarn ("ISO C++ forbids variable length array");
+ }
+ else if (warn_vla > 0)
+ {
+ if (name)
+ warning (OPT_Wvla,
+ "variable length array %qD is used", name);
+ else
+ warning (OPT_Wvla,
+ "variable length array is used");
}
if (processing_template_decl && !TREE_CONSTANT (size))
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index 7bb9f38..dc5bc51 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -254,7 +254,8 @@ Objective-C and Objective-C++ Dialects}.
-Wsystem-headers -Wtrigraphs -Wundef -Wuninitialized @gol
-Wunknown-pragmas -Wno-pragmas -Wunreachable-code @gol
-Wunused -Wunused-function -Wunused-label -Wunused-parameter @gol
--Wunused-value -Wunused-variable -Wvariadic-macros @gol
+-Wunused-value -Wunused-variable @gol
+-Wvariadic-macros -Wvla @gol
-Wvolatile-register-var -Wwrite-strings}
@item C-only Warning Options
@@ -3733,6 +3734,13 @@ Warn if variadic macros are used in pedantic ISO C90 mode, or the GNU
alternate syntax when in pedantic ISO C99 mode. This is default.
To inhibit the warning messages, use @option{-Wno-variadic-macros}.
+@item -Wvla
+@opindex Wvla
+@opindex Wno-vla
+Warn if variable length array is used in the code.
+@option{-Wno-vla} will prevent the @option{-pedantic} warning of
+the variable length array.
+
@item -Wvolatile-register-var
@opindex Wvolatile-register-var
@opindex Wno-volatile-register-var
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 9d0a8df..3925c55 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,16 @@
+2007-03-12 Seongbae Park <seongbae.park@gmail.com>
+
+ * gcc.dg/wvla-1.c: New test
+ * gcc.dg/wvla-2.c: New test
+ * gcc.dg/wvla-3.c: New test
+ * gcc.dg/wvla-4.c: New test
+ * gcc.dg/wvla-5.c: New test
+ * gcc.dg/wvla-6.c: New test
+ * gcc.dg/wvla-7.c: New test
+ * g++.dg/warn/Wvla-1.C: New test
+ * g++.dg/warn/Wvla-2.C: New test
+ * g++.dg/warn/Wvla-3.C: New test
+
2007-03-12 Mark Mitchell <mark@codesourcery.com>
PR c++/30108
diff --git a/gcc/testsuite/g++.dg/warn/Wvla-1.C b/gcc/testsuite/g++.dg/warn/Wvla-1.C
new file mode 100644
index 0000000..ca3669a
--- /dev/null
+++ b/gcc/testsuite/g++.dg/warn/Wvla-1.C
@@ -0,0 +1,7 @@
+/* { dg-do compile } */
+/* { dg-options "-Wvla" } */
+
+void func (int i)
+{
+ int array[i]; /* { dg-warning "variable length array 'array' is used" } */
+}
diff --git a/gcc/testsuite/g++.dg/warn/Wvla-2.C b/gcc/testsuite/g++.dg/warn/Wvla-2.C
new file mode 100644
index 0000000..c611f07
--- /dev/null
+++ b/gcc/testsuite/g++.dg/warn/Wvla-2.C
@@ -0,0 +1,7 @@
+/* { dg-do compile } */
+/* { dg-options "-pedantic-errors -Wvla" } */
+
+void func (int i)
+{
+ int array[i]; /* { dg-error "error: ISO C.* forbids variable.* array 'array'" } */
+}
diff --git a/gcc/testsuite/g++.dg/warn/Wvla-3.C b/gcc/testsuite/g++.dg/warn/Wvla-3.C
new file mode 100644
index 0000000..259c576
--- /dev/null
+++ b/gcc/testsuite/g++.dg/warn/Wvla-3.C
@@ -0,0 +1,7 @@
+/* { dg-do compile } */
+/* { dg-options "-pedantic-errors -Wno-vla" } */
+
+void func (int i)
+{
+ int array[i];
+}
diff --git a/gcc/testsuite/gcc.dg/wvla-1.c b/gcc/testsuite/gcc.dg/wvla-1.c
new file mode 100644
index 0000000..c8f2107
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/wvla-1.c
@@ -0,0 +1,5 @@
+/* { dg-do compile } */
+/* { dg-options "-std=c89 -Wvla" } */
+
+extern void
+func (int i, int array[i]); /* { dg-warning "variable length array 'array' is used" } */
diff --git a/gcc/testsuite/gcc.dg/wvla-2.c b/gcc/testsuite/gcc.dg/wvla-2.c
new file mode 100644
index 0000000..d811a11
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/wvla-2.c
@@ -0,0 +1,5 @@
+/* { dg-do compile } */
+/* { dg-options "-std=c99 -Wvla" } */
+
+extern void
+func (int i, int array[i]); /* { dg-warning "variable length array 'array' is used" } */
diff --git a/gcc/testsuite/gcc.dg/wvla-3.c b/gcc/testsuite/gcc.dg/wvla-3.c
new file mode 100644
index 0000000..3d5d3aa
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/wvla-3.c
@@ -0,0 +1,5 @@
+/* { dg-do compile } */
+/* { dg-options "-pedantic-errors -std=c89 -Wvla" } */
+
+extern void
+func (int i, int array[i]); /* { dg-error "error: ISO C90 forbids variable.* array 'array'" } */
diff --git a/gcc/testsuite/gcc.dg/wvla-4.c b/gcc/testsuite/gcc.dg/wvla-4.c
new file mode 100644
index 0000000..8c15292
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/wvla-4.c
@@ -0,0 +1,5 @@
+/* { dg-do compile } */
+/* { dg-options "-pedantic-errors -std=c99 -Wvla" } */
+
+extern void
+func (int i, int array[i]); /* { dg-warning "variable length array 'array' is used" } */
diff --git a/gcc/testsuite/gcc.dg/wvla-5.c b/gcc/testsuite/gcc.dg/wvla-5.c
new file mode 100644
index 0000000..919b8dc
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/wvla-5.c
@@ -0,0 +1,5 @@
+/* { dg-do compile } */
+/* { dg-options "-pedantic-errors -std=c89 -Wno-vla" } */
+
+extern void
+func (int i, int array[i]);
diff --git a/gcc/testsuite/gcc.dg/wvla-6.c b/gcc/testsuite/gcc.dg/wvla-6.c
new file mode 100644
index 0000000..f21435b
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/wvla-6.c
@@ -0,0 +1,5 @@
+/* { dg-do compile } */
+/* { dg-options "-std=c89 -Wvla" } */
+
+extern void
+func (int i, int [i]); /* { dg-warning "variable length array is used" } */
diff --git a/gcc/testsuite/gcc.dg/wvla-7.c b/gcc/testsuite/gcc.dg/wvla-7.c
new file mode 100644
index 0000000..bc113bf
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/wvla-7.c
@@ -0,0 +1,5 @@
+/* { dg-do compile } */
+/* { dg-options "-pedantic-errors -std=c89 -Wvla" } */
+
+extern void
+func (int i, int [i]); /* { dg-error "error: ISO C90 forbids variable" } */