Bug 106990 - Missing TYPE_OVERFLOW_SANITIZED checks in match.pd
Summary: Missing TYPE_OVERFLOW_SANITIZED checks in match.pd
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 13.0
: P3 normal
Target Milestone: ---
Assignee: Jakub Jelinek
URL:
Keywords: easyhack
Depends on:
Blocks:
 
Reported: 2022-09-20 23:34 UTC by Krister Walfridsson
Modified: 2022-10-19 09:31 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2022-09-21 00:00:00


Attachments
gcc13-pr106990.patch (860 bytes, patch)
2022-10-18 14:26 UTC, Jakub Jelinek
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Krister Walfridsson 2022-09-20 23:34:26 UTC
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;
}
Comment 1 Richard Biener 2022-09-21 08:12:25 UTC
Thanks for reporting.
Comment 2 Jakub Jelinek 2022-10-18 14:26:52 UTC
Created attachment 53723 [details]
gcc13-pr106990.patch

Untested fix.
Comment 3 GCC Commits 2022-10-19 09:29:18 UTC
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.
Comment 4 Jakub Jelinek 2022-10-19 09:31:13 UTC
Fixed for 13+.