__attribute__((noinline, noclone)) int foo (int x) { if (x == '(' - 256 || x == '|' - 256 || x == '&' - 256 || x == 'n' - 256) return 1; return 0; } int main () { if (foo ('n' - 256) != 1 || foo ('(' - 256) != 1 || foo ('|' - 256) != 1 || foo ('&' - 256) != 1 || foo ('q' - 256) != 0) __builtin_abort (); return 0; } is miscompiled at -O2 starting with r216393.
Created attachment 35028 [details] gcc5-pr65418.patch Untested fix.
Author: jakub Date: Sat Mar 14 09:55:41 2015 New Revision: 221434 URL: https://gcc.gnu.org/viewcvs?rev=221434&root=gcc&view=rev Log: PR tree-optimization/65418 * tree-ssa-reassoc.c (extract_bit_test_mask): If there are casts in the first PLUS_EXPR operand, ensure tbias and *totallowp are in the inner type. * gcc.c-torture/execute/pr65418-1.c: New test. * gcc.c-torture/execute/pr65418-2.c: New test. Added: trunk/gcc/testsuite/gcc.c-torture/execute/pr65418-1.c trunk/gcc/testsuite/gcc.c-torture/execute/pr65418-2.c Modified: trunk/gcc/ChangeLog trunk/gcc/testsuite/ChangeLog trunk/gcc/tree-ssa-reassoc.c
Fixed.