[Bug middle-end/95810] Spurious UBSan warning when computing the opposite of the absolute value of INT_MIN

2020-09-16 Thread cvs-commit at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95810

--- Comment #4 from CVS Commits  ---
The releases/gcc-9 branch has been updated by Jakub Jelinek
:

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

commit r9-8901-g6ff6c02695c9b6ae6e840422080f6d10449577b8
Author: Jakub Jelinek 
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  

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)

[Bug middle-end/95810] Spurious UBSan warning when computing the opposite of the absolute value of INT_MIN

2020-06-24 Thread cvs-commit at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95810

--- Comment #3 from CVS Commits  ---
The master branch has been updated by Jakub Jelinek :

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

commit r11-1620-g01e10b0ee77e82cb331414c569e02dc7a2c4999e
Author: Jakub Jelinek 
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  

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.

[Bug middle-end/95810] Spurious UBSan warning when computing the opposite of the absolute value of INT_MIN

2020-06-22 Thread jakub at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95810

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

Untested fix.

[Bug middle-end/95810] Spurious UBSan warning when computing the opposite of the absolute value of INT_MIN

2020-06-22 Thread jakub at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95810

Jakub Jelinek  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

[Bug middle-end/95810] Spurious UBSan warning when computing the opposite of the absolute value of INT_MIN

2020-06-22 Thread pinskia at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95810

Andrew Pinski  changed:

   What|Removed |Added

  Component|tree-optimization   |middle-end

--- Comment #1 from Andrew Pinski  ---
It should have became uabs instead.