diff options
author | mpolacek <mpolacek@138bc75d-0d04-0410-961f-82ee72b054a4> | 2014-11-14 11:57:05 +0000 |
---|---|---|
committer | mpolacek <mpolacek@138bc75d-0d04-0410-961f-82ee72b054a4> | 2014-11-14 11:57:05 +0000 |
commit | 1043013c91c08e3d8cd665b3f960f658918d69fe (patch) | |
tree | e658bdd67d7d906e29048429d363eaa3f48eaab0 /gcc/fold-const.c | |
parent | f6b540af02190c7c3e07a26eb5864f9a24fe7274 (diff) | |
download | gcc-1043013c91c08e3d8cd665b3f960f658918d69fe.tar.gz |
* fold-const.c (fold_negate_expr): Don't fold INTEGER_CST if
that overflows when SANITIZE_SI_OVERFLOW is on. Guard -(-A)
folding with TYPE_OVERFLOW_SANITIZED.
* c-c++-common/ubsan/overflow-negate-3.c: New test.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@217556 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/fold-const.c')
-rw-r--r-- | gcc/fold-const.c | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/gcc/fold-const.c b/gcc/fold-const.c index 0170b88daef..7dbbadd859b 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -554,7 +554,8 @@ fold_negate_expr (location_t loc, tree t) case INTEGER_CST: tem = fold_negate_const (t, type); if (TREE_OVERFLOW (tem) == TREE_OVERFLOW (t) - || !TYPE_OVERFLOW_TRAPS (type)) + || (!TYPE_OVERFLOW_TRAPS (type) + && (flag_sanitize & SANITIZE_SI_OVERFLOW) == 0)) return tem; break; @@ -611,7 +612,9 @@ fold_negate_expr (location_t loc, tree t) break; case NEGATE_EXPR: - return TREE_OPERAND (t, 0); + if (!TYPE_OVERFLOW_SANITIZED (type)) + return TREE_OPERAND (t, 0); + break; case PLUS_EXPR: if (!HONOR_SIGN_DEPENDENT_ROUNDING (TYPE_MODE (type)) |