https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81281
--- Comment #12 from Jakub Jelinek <jakub at gcc dot gnu.org> --- Author: jakub Date: Wed Dec 6 19:22:06 2017 New Revision: 255449 URL: https://gcc.gnu.org/viewcvs?rev=255449&root=gcc&view=rev Log: PR sanitizer/81281 * match.pd ((T)(P + A) - (T)P -> (T) A): Split into separate simplify for plus with :c added, and pointer_plus without that. ((T)P - (T)(P + A) -> -(T) A): Likewise. If type is integral with undefined overflow and the conversion is not widening, perform negation in utype and only convert to type afterwards. ((T)(P + A) - (T)(P + B) -> (T)A - (T)B): Split into separate simplify for plus with :c added, and pointer_plus without that. If type is integral with undefined overflow and the conversion is not widening, perform minus in utype and only convert to type afterwards. Move the last pointer_diff_expr simplify into the two outermost ifs. * gcc.c-torture/execute/pr81281.c: New test. * gcc.dg/pr81281-1.c: New test. * gcc.dg/pr81281-2.c: New test. * g++.dg/ubsan/pr81281.C: New test. * g++.dg/ubsan/pr81281-aux.cc: New test. Added: trunk/gcc/testsuite/g++.dg/ubsan/pr81281-aux.cc trunk/gcc/testsuite/g++.dg/ubsan/pr81281.C trunk/gcc/testsuite/gcc.c-torture/execute/pr81281.c trunk/gcc/testsuite/gcc.dg/pr81281-1.c trunk/gcc/testsuite/gcc.dg/pr81281-2.c Modified: trunk/gcc/ChangeLog trunk/gcc/match.pd trunk/gcc/testsuite/ChangeLog