diff options
author | Joseph Myers <joseph@codesourcery.com> | 2009-04-09 01:20:08 +0100 |
---|---|---|
committer | Joseph Myers <jsm28@gcc.gnu.org> | 2009-04-09 01:20:08 +0100 |
commit | 17cede2e303aaba4e5a5b10509499ba02d3c68a4 (patch) | |
tree | b5b2a508e50ee656a2b499eeebe913843eff682f /gcc | |
parent | 74a6dc82c2408288afc9c44eaf53a22457d192d5 (diff) | |
download | gcc-17cede2e303aaba4e5a5b10509499ba02d3c68a4.tar.gz |
re PR c/39613 (gcc 20090331 produces an error at mce64.c in kernel 2.6.29)
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.
testsuite:
* gcc.dg/case-const-1.c, gcc.dg/case-const-2.c,
gcc.dg/case-const-3.c: New tests.
From-SVN: r145793
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/c-typeck.c | 16 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/case-const-1.c | 15 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/case-const-2.c | 15 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/case-const-3.c | 15 |
6 files changed, 73 insertions, 0 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index e997af5a70f..feedc5c4253 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +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 diff --git a/gcc/c-typeck.c b/gcc/c-typeck.c index b2bb74f6ac3..9c74bf39944 100644 --- a/gcc/c-typeck.c +++ b/gcc/c-typeck.c @@ -7851,6 +7851,22 @@ do_case (tree low_value, tree high_value) { 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) { diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 7808aa5724a..27343277a47 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +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. diff --git a/gcc/testsuite/gcc.dg/case-const-1.c b/gcc/testsuite/gcc.dg/case-const-1.c new file mode 100644 index 00000000000..ba39d09616b --- /dev/null +++ b/gcc/testsuite/gcc.dg/case-const-1.c @@ -0,0 +1,15 @@ +/* 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): + ; + } +} diff --git a/gcc/testsuite/gcc.dg/case-const-2.c b/gcc/testsuite/gcc.dg/case-const-2.c new file mode 100644 index 00000000000..9c119b04df5 --- /dev/null +++ b/gcc/testsuite/gcc.dg/case-const-2.c @@ -0,0 +1,15 @@ +/* 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" } */ + ; + } +} diff --git a/gcc/testsuite/gcc.dg/case-const-3.c b/gcc/testsuite/gcc.dg/case-const-3.c new file mode 100644 index 00000000000..7224cca47d7 --- /dev/null +++ b/gcc/testsuite/gcc.dg/case-const-3.c @@ -0,0 +1,15 @@ +/* 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" } */ + ; + } +} |