public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/95810] New: Spurious UBSan warning when computing the opposite of the absolute value of INT_MIN
@ 2020-06-22  7:52 felix.von.s at posteo dot de
  2020-06-22  8:51 ` [Bug middle-end/95810] " pinskia at gcc dot gnu.org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: felix.von.s at posteo dot de @ 2020-06-22  7:52 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95810

            Bug ID: 95810
           Summary: Spurious UBSan warning when computing the opposite of
                    the absolute value of INT_MIN
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: felix.von.s at posteo dot de
  Target Milestone: ---

When the expression (x <= 0 ? x : -x) with x having type int is compiled with
-fsanitize=undefined -O3, setting (x = INT_MIN) triggers a spurious UBSan
warning about INT_MIN being negated.

Not sure if I should file this against tree-ssa or the frontend(s), because the
expression apparently becomes (-ABS_EXPR <x>) very early, even at -O0. I
checked this with C, C++ and D frontends.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug middle-end/95810] Spurious UBSan warning when computing the opposite of the absolute value of INT_MIN
  2020-06-22  7:52 [Bug tree-optimization/95810] New: Spurious UBSan warning when computing the opposite of the absolute value of INT_MIN felix.von.s at posteo dot de
@ 2020-06-22  8:51 ` pinskia at gcc dot gnu.org
  2020-06-22  9:36 ` jakub at gcc dot gnu.org
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2020-06-22  8:51 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95810

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|tree-optimization           |middle-end

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
It should have became uabs instead.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug middle-end/95810] Spurious UBSan warning when computing the opposite of the absolute value of INT_MIN
  2020-06-22  7:52 [Bug tree-optimization/95810] New: Spurious UBSan warning when computing the opposite of the absolute value of INT_MIN felix.von.s at posteo dot de
  2020-06-22  8:51 ` [Bug middle-end/95810] " pinskia at gcc dot gnu.org
@ 2020-06-22  9:36 ` jakub at gcc dot gnu.org
  2020-06-22  9:53 ` jakub at gcc dot gnu.org
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: jakub at gcc dot gnu.org @ 2020-06-22  9:36 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95810

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
           Assignee|unassigned at gcc dot gnu.org      |jakub at gcc dot gnu.org
   Last reconfirmed|                            |2020-06-22
                 CC|                            |jakub at gcc dot gnu.org
             Status|UNCONFIRMED                 |ASSIGNED

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug middle-end/95810] Spurious UBSan warning when computing the opposite of the absolute value of INT_MIN
  2020-06-22  7:52 [Bug tree-optimization/95810] New: Spurious UBSan warning when computing the opposite of the absolute value of INT_MIN felix.von.s at posteo dot de
  2020-06-22  8:51 ` [Bug middle-end/95810] " pinskia at gcc dot gnu.org
  2020-06-22  9:36 ` jakub at gcc dot gnu.org
@ 2020-06-22  9:53 ` jakub at gcc dot gnu.org
  2020-06-24  8:41 ` cvs-commit at gcc dot gnu.org
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: jakub at gcc dot gnu.org @ 2020-06-22  9:53 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95810

--- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Created attachment 48769
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=48769&action=edit
gcc11-pr95810.patch

Untested fix.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug middle-end/95810] Spurious UBSan warning when computing the opposite of the absolute value of INT_MIN
  2020-06-22  7:52 [Bug tree-optimization/95810] New: Spurious UBSan warning when computing the opposite of the absolute value of INT_MIN felix.von.s at posteo dot de
                   ` (2 preceding siblings ...)
  2020-06-22  9:53 ` jakub at gcc dot gnu.org
@ 2020-06-24  8:41 ` cvs-commit at gcc dot gnu.org
  2020-09-16 19:22 ` cvs-commit at gcc dot gnu.org
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2020-06-24  8:41 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95810

--- Comment #3 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jakub Jelinek <jakub@gcc.gnu.org>:

https://gcc.gnu.org/g:01e10b0ee77e82cb331414c569e02dc7a2c4999e

commit r11-1620-g01e10b0ee77e82cb331414c569e02dc7a2c4999e
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Wed Jun 24 10:40:02 2020 +0200

    fold-const: Fix A <= 0 ? A : -A folding [PR95810]

    We folded A <= 0 ? A : -A into -ABS (A), which is for signed integral types
    incorrect - can invoke on INT_MIN UB twice, once on ABS and once on its
    negation.

    The following patch fixes it by instead folding it to (type)-ABSU (A).

    2020-06-24  Jakub Jelinek  <jakub@redhat.com>

            PR middle-end/95810
            * fold-const.c (fold_cond_expr_with_comparison): Optimize
            A <= 0 ? A : -A into (type)-absu(A) rather than -abs(A).

            * gcc.dg/ubsan/pr95810.c: New test.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug middle-end/95810] Spurious UBSan warning when computing the opposite of the absolute value of INT_MIN
  2020-06-22  7:52 [Bug tree-optimization/95810] New: Spurious UBSan warning when computing the opposite of the absolute value of INT_MIN felix.von.s at posteo dot de
                   ` (3 preceding siblings ...)
  2020-06-24  8:41 ` cvs-commit at gcc dot gnu.org
@ 2020-09-16 19:22 ` cvs-commit at gcc dot gnu.org
  2021-04-28 17:56 ` [Bug middle-end/95810] [8 only] " pinskia at gcc dot gnu.org
  2021-05-14 14:02 ` jakub at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2020-09-16 19:22 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95810

--- Comment #4 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-9 branch has been updated by Jakub Jelinek
<jakub@gcc.gnu.org>:

https://gcc.gnu.org/g:6ff6c02695c9b6ae6e840422080f6d10449577b8

commit r9-8901-g6ff6c02695c9b6ae6e840422080f6d10449577b8
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Wed Jun 24 10:40:02 2020 +0200

    fold-const: Fix A <= 0 ? A : -A folding [PR95810]

    We folded A <= 0 ? A : -A into -ABS (A), which is for signed integral types
    incorrect - can invoke on INT_MIN UB twice, once on ABS and once on its
    negation.

    The following patch fixes it by instead folding it to (type)-ABSU (A).

    2020-06-24  Jakub Jelinek  <jakub@redhat.com>

            PR middle-end/95810
            * fold-const.c (fold_cond_expr_with_comparison): Optimize
            A <= 0 ? A : -A into (type)-absu(A) rather than -abs(A).

            * gcc.dg/ubsan/pr95810.c: New test.

    (cherry picked from commit 01e10b0ee77e82cb331414c569e02dc7a2c4999e)

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug middle-end/95810] [8 only] Spurious UBSan warning when computing the opposite of the absolute value of INT_MIN
  2020-06-22  7:52 [Bug tree-optimization/95810] New: Spurious UBSan warning when computing the opposite of the absolute value of INT_MIN felix.von.s at posteo dot de
                   ` (4 preceding siblings ...)
  2020-09-16 19:22 ` cvs-commit at gcc dot gnu.org
@ 2021-04-28 17:56 ` pinskia at gcc dot gnu.org
  2021-05-14 14:02 ` jakub at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-04-28 17:56 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95810

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |8.5
            Summary|Spurious UBSan warning when |[8 only] Spurious UBSan
                   |computing the opposite of   |warning when computing the
                   |the absolute value of       |opposite of the absolute
                   |INT_MIN                     |value of INT_MIN

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug middle-end/95810] [8 only] Spurious UBSan warning when computing the opposite of the absolute value of INT_MIN
  2020-06-22  7:52 [Bug tree-optimization/95810] New: Spurious UBSan warning when computing the opposite of the absolute value of INT_MIN felix.von.s at posteo dot de
                   ` (5 preceding siblings ...)
  2021-04-28 17:56 ` [Bug middle-end/95810] [8 only] " pinskia at gcc dot gnu.org
@ 2021-05-14 14:02 ` jakub at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: jakub at gcc dot gnu.org @ 2021-05-14 14:02 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95810

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
             Status|ASSIGNED                    |RESOLVED
   Target Milestone|8.5                         |9.4

--- Comment #5 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
The GCC 8 branch is being closed, fixed in GCC 9.4.

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2021-05-14 14:02 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-22  7:52 [Bug tree-optimization/95810] New: Spurious UBSan warning when computing the opposite of the absolute value of INT_MIN felix.von.s at posteo dot de
2020-06-22  8:51 ` [Bug middle-end/95810] " pinskia at gcc dot gnu.org
2020-06-22  9:36 ` jakub at gcc dot gnu.org
2020-06-22  9:53 ` jakub at gcc dot gnu.org
2020-06-24  8:41 ` cvs-commit at gcc dot gnu.org
2020-09-16 19:22 ` cvs-commit at gcc dot gnu.org
2021-04-28 17:56 ` [Bug middle-end/95810] [8 only] " pinskia at gcc dot gnu.org
2021-05-14 14:02 ` jakub at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).