]> gcc.gnu.org Git - gcc.git/commit
fold-const: Fix A <= 0 ? A : -A folding [PR95810]
authorJakub Jelinek <jakub@redhat.com>
Wed, 24 Jun 2020 08:40:02 +0000 (10:40 +0200)
committerJakub Jelinek <jakub@redhat.com>
Wed, 24 Jun 2020 08:41:04 +0000 (10:41 +0200)
commit01e10b0ee77e82cb331414c569e02dc7a2c4999e
tree4fd662b22fa60263df1fe1b0596242a88aa0655d
parentf0008858dec9b16da153b948834abb20b9f1ab32
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.
gcc/fold-const.c
gcc/testsuite/gcc.dg/ubsan/pr95810.c [new file with mode: 0644]
This page took 0.072947 seconds and 6 git commands to generate.