diff options
Diffstat (limited to 'gcc-4.9/gcc/testsuite/c-c++-common/ubsan/shift-5.c')
-rw-r--r-- | gcc-4.9/gcc/testsuite/c-c++-common/ubsan/shift-5.c | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/gcc-4.9/gcc/testsuite/c-c++-common/ubsan/shift-5.c b/gcc-4.9/gcc/testsuite/c-c++-common/ubsan/shift-5.c new file mode 100644 index 000000000..6f9c52a72 --- /dev/null +++ b/gcc-4.9/gcc/testsuite/c-c++-common/ubsan/shift-5.c @@ -0,0 +1,33 @@ +/* { dg-do compile } */ +/* { dg-options "-fsanitize=shift -w" } */ +/* { dg-shouldfail "ubsan" } */ + +int x; +int +foo (void) +{ + /* None of the following should pass. */ + switch (x) + { + case 1 >> -1: +/* { dg-error "case label does not reduce to an integer constant" "" {target c } 12 } */ +/* { dg-error "is not a constant expression" "" { target c++ } 12 } */ + case -1 >> -1: +/* { dg-error "case label does not reduce to an integer constant" "" {target c } 15 } */ +/* { dg-error "is not a constant expression" "" { target c++ } 15 } */ + case 1 << -1: +/* { dg-error "case label does not reduce to an integer constant" "" {target c } 18 } */ +/* { dg-error "is not a constant expression" "" { target c++ } 18 } */ + case -1 << -1: +/* { dg-error "case label does not reduce to an integer constant" "" {target c } 21 } */ +/* { dg-error "is not a constant expression" "" { target c++ } 21 } */ + case -1 >> 200: +/* { dg-error "case label does not reduce to an integer constant" "" {target c } 24 } */ +/* { dg-error "is not a constant expression" "" { target c++ } 24 } */ + case 1 << 200: +/* { dg-error "case label does not reduce to an integer constant" "" {target c } 27 } */ +/* { dg-error "is not a constant expression" "" { target c++ } 27 } */ + return 1; + } + return 0; +} |