gcc x86_64, top of the trunk with patch from 80349. This seems related, but different. > cat f.cpp unsigned foo() { unsigned a = unsigned(!(6044238 >> 0) >= (0 < 0)) % 0; unsigned b = unsigned(!(6044238 >> 0) >= (0 < 0)) / 0; return a+b; } > g++ -fsanitize=undefined -w -O0 -c f.cpp f.cpp: In function ‘unsigned int foo()’: f.cpp:1:10: error: type mismatch in binary expression unsigned foo() { ^~~ unsigned int int unsigned int a = 1 % 0; f.cpp:1:10: error: type mismatch in binary expression unsigned int int unsigned int b = 1 / 0; f.cpp:1:10: internal compiler error: verify_gimple failed
Created attachment 41183 [details] gcc7-pr80403.patch Untested fix.
Created attachment 41184 [details] gcc7-pr80403.patch The other two PRs are dups of this, added those testcases to this patch.
*** Bug 80404 has been marked as a duplicate of this bug. ***
*** Bug 80405 has been marked as a duplicate of this bug. ***
Author: jakub Date: Wed Apr 12 18:08:29 2017 New Revision: 246881 URL: https://gcc.gnu.org/viewcvs?rev=246881&root=gcc&view=rev Log: PR sanitizer/80403 PR sanitizer/80404 PR sanitizer/80405 * fold-const.c (fold_ternary_loc): Use op1 instead of arg1 as argument to fold_build2_loc. Convert TREE_OPERAND (tem, 0) to type. Use op0 instead of fold_convert_loc (loc, type, arg0). * g++.dg/ubsan/pr80403.C: New test. * g++.dg/ubsan/pr80404.C: New test. * g++.dg/ubsan/pr80405.C: New test. Added: trunk/gcc/testsuite/g++.dg/ubsan/pr80403.C trunk/gcc/testsuite/g++.dg/ubsan/pr80404.C trunk/gcc/testsuite/g++.dg/ubsan/pr80405.C Modified: trunk/gcc/ChangeLog trunk/gcc/fold-const.c trunk/gcc/testsuite/ChangeLog
Fixed.
80404 and 80405 seemed similar, but different to me, so I decided to report them separately. Anyway, after the latest fixes I still see 2 compile crashes. I'm reducing them and will report here.
Three errors in one test case. GCC r246882. > cat f.cpp extern const long long int var_7; extern unsigned long int var_59; int foo() { int a = (0 - 40U <= (0 == 8)) << !var_59 << (0 < var_7) == 0; int b = ((0 ^ 0) < long(1066066618772207110 <= 0)) / 0 << 0; return a+b; } > g++ -w -fsanitize=undefined -O0 -c f.cpp f.cpp: In function ‘int foo()’: f.cpp:3:5: error: mismatching comparison operand types int foo() { ^~~ unsigned int int _4 = D.2761 < 0; f.cpp:3:5: error: type mismatch in shift expression int unsigned int int _19 = D.2761 << _18; f.cpp:3:5: error: type mismatch in binary expression int long int int D.2772 = 0 / 0; f.cpp:3:5: internal compiler error: verify_gimple failed
Created attachment 41195 [details] gcc7-pr80403-2.patch Oops, thinko in the committed patch. COND_EXPR/VEC_COND_EXPR op0's type doesn't have to be the same as the result type (which needs to be equal to op1 and op2's type). Will test this and commit as obvious if it passes.
Author: jakub Date: Thu Apr 13 19:52:58 2017 New Revision: 246917 URL: https://gcc.gnu.org/viewcvs?rev=246917&root=gcc&view=rev Log: PR sanitizer/80403 * fold-const.c (fold_ternary_loc): Revert use op0 instead of fold_convert_loc (loc, type, arg0) part of 2017-04-12 change. * g++.dg/ubsan/pr80403-2.C: New test. Added: trunk/gcc/testsuite/g++.dg/ubsan/pr80403-2.C Modified: trunk/gcc/ChangeLog trunk/gcc/fold-const.c trunk/gcc/testsuite/ChangeLog
I confirm that the latest patch fixes all UBSAN compile time problems that I have. Thanks! Though correctness issues remain - PR80386.