* c-typeck.c (do_case): If case label is not an INTEGER_CST, fold
it and pedwarn if this results in an INTEGER_CST.
testsuite:
* gcc.dg/case-const-1.c, gcc.dg/case-const-2.c,
gcc.dg/case-const-3.c: New tests.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@145793
138bc75d-0d04-0410-961f-
82ee72b054a4
+2009-04-09 Joseph Myers <joseph@codesourcery.com>
+
+ PR c/39613
+ * c-typeck.c (do_case): If case label is not an INTEGER_CST, fold
+ it and pedwarn if this results in an INTEGER_CST.
+
2009-04-08 Kaveh R. Ghazi <ghazi@caip.rutgers.edu>
* doc/install.texi: Update minimum GMP version. Remove obsolete
{
tree label = NULL_TREE;
+ if (low_value && TREE_CODE (low_value) != INTEGER_CST)
+ {
+ low_value = c_fully_fold (low_value, false, NULL);
+ if (TREE_CODE (low_value) == INTEGER_CST)
+ pedwarn (input_location, OPT_pedantic,
+ "case label is not an integer constant expression");
+ }
+
+ if (high_value && TREE_CODE (high_value) != INTEGER_CST)
+ {
+ high_value = c_fully_fold (high_value, false, NULL);
+ if (TREE_CODE (high_value) == INTEGER_CST)
+ pedwarn (input_location, OPT_pedantic,
+ "case label is not an integer constant expression");
+ }
+
if (c_switch_stack && !c_switch_stack->blocked_stmt_expr
&& !c_switch_stack->blocked_vm)
{
+2009-04-09 Joseph Myers <joseph@codesourcery.com>
+
+ PR c/39613
+ * gcc.dg/case-const-1.c, gcc.dg/case-const-2.c,
+ gcc.dg/case-const-3.c: New tests.
+
2009-04-08 Joseph Myers <joseph@codesourcery.com>
* gcc.dg/c99-stdint-1.c: Fix cut-and-paste mistakes in test.
--- /dev/null
+/* Test for case labels not integer constant expressions but folding
+ to integer constants (used in Linux kernel, PR 39613). */
+/* { dg-do compile } */
+/* { dg-options "" } */
+
+extern int i;
+void
+f (int c)
+{
+ switch (c)
+ {
+ case (1 ? 1 : i):
+ ;
+ }
+}
--- /dev/null
+/* Test for case labels not integer constant expressions but folding
+ to integer constants (used in Linux kernel, PR 39613). */
+/* { dg-do compile } */
+/* { dg-options "-pedantic" } */
+
+extern int i;
+void
+f (int c)
+{
+ switch (c)
+ {
+ case (1 ? 1 : i): /* { dg-warning "case label is not an integer constant expression" } */
+ ;
+ }
+}
--- /dev/null
+/* Test for case labels not integer constant expressions but folding
+ to integer constants (used in Linux kernel, PR 39613). */
+/* { dg-do compile } */
+/* { dg-options "-pedantic-errors" } */
+
+extern int i;
+void
+f (int c)
+{
+ switch (c)
+ {
+ case (1 ? 1 : i): /* { dg-error "case label is not an integer constant expression" } */
+ ;
+ }
+}