From: Jakub Jelinek Date: Wed, 11 Oct 2017 20:51:08 +0000 (+0200) Subject: re PR middle-end/80421 (Case dispatch is scrambled in switch-statement) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=ca38a07b0637440d40ac7f6f987a16c825f00aa4;p=gcc.git re PR middle-end/80421 (Case dispatch is scrambled in switch-statement) PR middle-end/80421 * gcc.c-torture/execute/pr80421.c: New test. From-SVN: r253662 --- diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 2135f48e5f8..7ea4bd22ac7 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,8 @@ 2017-10-11 Jakub Jelinek + PR middle-end/80421 + * gcc.c-torture/execute/pr80421.c: New test. + PR tree-optimization/78558 * gcc.dg/vect/pr78558.c: New test. diff --git a/gcc/testsuite/gcc.c-torture/execute/pr80421.c b/gcc/testsuite/gcc.c-torture/execute/pr80421.c new file mode 100644 index 00000000000..b13ab5fc121 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/pr80421.c @@ -0,0 +1,121 @@ +/* PR middle-end/80421 */ + +__attribute__ ((noinline, noclone)) void +baz (const char *t, ...) +{ + asm volatile (""::"r" (t):"memory"); + if (*t == 'T') + __builtin_abort (); +} + +unsigned int +foo (char x) +{ + baz ("x %c\n", x); + switch (x) + { + default: + baz ("case default\n"); + if (x == 'D' || x == 'I') + baz ("This should never be reached.\n"); + return 0; + case 'D': + baz ("case 'D'\n"); + return 0; + case 'I': + baz ("case 'I'\n"); + return 0; + } +} + +void +bar (void) +{ + int a = 2; + int b = 5; + char c[] = { + 2, 4, 1, 2, 5, 5, 2, 4, 4, 0, 0, 0, 0, 0, 0, 3, 4, 4, 2, 4, + 1, 2, 5, 5, 2, 4, 1, 0, 0, 0, 2, 4, 4, 3, 4, 3, 3, 5, 1, 3, + 5, 5, 2, 4, 4, 2, 4, 1, 3, 5, 3, 3, 5, 1, 3, 5, 1, 2, 4, 4, + 2, 4,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 3, 3, + 5, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 + }; + char *f = c + 390; + int i, j, e, g, h; + char k, l; + i = 26; + j = 25; + k = l = 'M'; + h = 2; + while (i > 0) + { + int x = i - a; + x = x > 0 ? x : 0; + x = j - x; + g = x * 3 + h; + switch (f[g]) + { + case 1: + --i; + --j; + h = 2; + f -= b * 3; + k = 'M'; + break; + case 2: + --i; + h = 0; + f -= b * 3; + k = 'I'; + break; + case 3: + --i; + h = 2; + f -= b * 3; + k = 'I'; + break; + case 4: + --j; + h = 1; + k = 'D'; + break; + case 5: + --j; + h = 2; + k = 'D'; + break; + } + if (k == l) + ++e; + else + { + foo (l); + l = k; + } + } +} + +int +main () +{ + char l = 'D'; + foo (l); + bar (); + return 0; +}