gcc rev248384, x86_64. > cat f.cpp void foo() { ~2147483647 * (0 / 0); } > g++ -fsanitize=undefined -w -c f.cpp f.cpp: In function ‘void foo()’: f.cpp:3:1: internal compiler error: tree check: expected class ‘constant’, have ‘unary’ (negate_expr) in fold_binary_loc, at fold-const.c:9817 } ^ 0x10384a7 tree_class_check_failed(tree_node const*, tree_code_class, char const*, int, char const*) ../../gcc_svn/gcc/tree.c:9909 <...>
Confirmed.
commit 0123775a88c6cf1035e4633fde7823a3e9889809 Author: rguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4> Date: Wed Oct 28 13:41:25 2015 +0000 2015-10-28 Richard Biener <rguenther@suse.de> * fold-const.c (negate_expr_p): Adjust the division case to properly avoid introducing undefined overflow. (fold_negate_expr): Likewise. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@229484 138bc75d-0d04-0410-961f-82ee72b054a4
I'll look.
9810 && negate_expr_p (op0) 9811 && (tem = negate_expr (op1)) != op1 should probaby use negate_expr_p (op1) to guard this.
(In reply to Richard Biener from comment #4) > 9810 && negate_expr_p (op0) > 9811 && (tem = negate_expr (op1)) != op1 > > should probaby use negate_expr_p (op1) to guard this. Yea, I sent a patch doing exactly that yesterday: https://gcc.gnu.org/ml/gcc-patches/2017-05/msg01971.html
Author: mpolacek Date: Fri May 26 09:31:36 2017 New Revision: 248485 URL: https://gcc.gnu.org/viewcvs?rev=248485&root=gcc&view=rev Log: PR sanitizer/80875 * fold-const.c (fold_binary_loc) <case MULT_EXPR>: Check if OP1 can be negated. * c-c++-common/ubsan/pr80875.c: New test. Added: trunk/gcc/testsuite/c-c++-common/ubsan/pr80875.c Modified: trunk/gcc/ChangeLog trunk/gcc/fold-const.c trunk/gcc/testsuite/ChangeLog
Fixed on trunk so far.
Author: mpolacek Date: Fri May 26 11:15:37 2017 New Revision: 248490 URL: https://gcc.gnu.org/viewcvs?rev=248490&root=gcc&view=rev Log: PR sanitizer/80875 * fold-const.c (fold_binary_loc) <case MULT_EXPR>: Check if OP1 can be negated. * c-c++-common/ubsan/pr80875.c: New test. Added: branches/gcc-7-branch/gcc/testsuite/c-c++-common/ubsan/pr80875.c Modified: branches/gcc-7-branch/gcc/ChangeLog branches/gcc-7-branch/gcc/fold-const.c branches/gcc-7-branch/gcc/testsuite/ChangeLog
Fixed.