gcc/testsuite/g++.dg/ubsan/pr120471.C
raw| 1 | // PR c++/120471 |
| 2 | // { dg-do run } |
| 3 | // { dg-options "-fsanitize=undefined" } |
| 4 | |
| 5 | volatile int b[1], a[1]; |
| 6 | |
| 7 | void |
| 8 | foo (int x) |
| 9 | { |
| 10 | volatile int c = 21; |
| 11 | volatile int v = (x % 2 ? b : a)[c % 3]; |
| 12 | if (v != 0) |
| 13 | __builtin_abort (); |
| 14 | } |
| 15 | |
| 16 | int |
| 17 | main () |
| 18 | { |
| 19 | foo (1); |
| 20 | foo (2); |
| 21 | } |