When UBSan is used, match.pd disables simplifications that can remove UB. But two simplifications are missing TYPE_OVERFLOW_SANITIZED checks, making the two tests below fail to report UB when compiled with -fsanitize=undefined. /* (~X - ~Y) -> Y - X. */ int main(void) { volatile int x = -1956816001; volatile int y = 1999200512; return ~x - ~y; } /* -x & 1 -> x & 1. */ int main(void) { volatile int x = 0x80000000; return -x & 1; }
Thanks for reporting.
Created attachment 53723 [details] gcc13-pr106990.patch Untested fix.
The master branch has been updated by Jakub Jelinek <jakub@gcc.gnu.org>: https://gcc.gnu.org/g:07cc4c1da1046f0ffda241d59df796417c122ff5 commit r13-3373-g07cc4c1da1046f0ffda241d59df796417c122ff5 Author: Jakub Jelinek <jakub@redhat.com> Date: Wed Oct 19 11:28:42 2022 +0200 match.pd: Add 2 TYPE_OVERFLOW_SANITIZED checks [PR106990] As requested in the PR, this adds 2 TYPE_OVERFLOW_SANITIZED checks and corresponding testcase. 2022-10-19 Jakub Jelinek <jakub@redhat.com> PR tree-optimization/106990 * match.pd ((~X - ~Y) -> Y - X, -x & 1 -> x & 1): Guard with !TYPE_OVERFLOW_SANITIZED (type). * c-c++-common/ubsan/pr106990.c: New test.
Fixed for 13+.