diff options
author | Jakub Jelinek <jakub@redhat.com> | 2014-03-22 17:25:50 +0100 |
---|---|---|
committer | Jakub Jelinek <jakub@gcc.gnu.org> | 2014-03-22 17:25:50 +0100 |
commit | f451d3a836fff435bc4bc0ed121cdc5f6e6c14d6 (patch) | |
tree | 99eaf3733d043efe30616738f13338abe2c28621 /gcc/internal-fn.c | |
parent | 3db31fd1cc7acf87e092c0bbeba37d234c77b83b (diff) | |
download | gcc-f451d3a836fff435bc4bc0ed121cdc5f6e6c14d6.zip gcc-f451d3a836fff435bc4bc0ed121cdc5f6e6c14d6.tar.gz gcc-f451d3a836fff435bc4bc0ed121cdc5f6e6c14d6.tar.bz2 |
re PR sanitizer/60613 (Invalid signed subtraction ubsan diagnostics)
PR sanitizer/60613
* internal-fn.c (ubsan_expand_si_overflow_addsub_check): For
code == MINUS_EXPR, never swap op0 with op1.
* c-c++-common/ubsan/pr60613-1.c: New test.
* c-c++-common/ubsan/pr60613-2.c: New test.
From-SVN: r208766
Diffstat (limited to 'gcc/internal-fn.c')
-rw-r--r-- | gcc/internal-fn.c | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/gcc/internal-fn.c b/gcc/internal-fn.c index 9926ec2..1062ea8 100644 --- a/gcc/internal-fn.c +++ b/gcc/internal-fn.c @@ -221,14 +221,15 @@ ubsan_expand_si_overflow_addsub_check (tree_code code, gimple stmt) res = expand_binop (mode, code == PLUS_EXPR ? add_optab : sub_optab, op0, op1, NULL_RTX, false, OPTAB_LIB_WIDEN); - /* If we can prove one of the arguments is always non-negative - or always negative, we can do just one comparison and - conditional jump instead of 2 at runtime, 3 present in the + /* If we can prove one of the arguments (for MINUS_EXPR only + the second operand, as subtraction is not commutative) is always + non-negative or always negative, we can do just one comparison + and conditional jump instead of 2 at runtime, 3 present in the emitted code. If one of the arguments is CONST_INT, all we need is to make sure it is op1, then the first emit_cmp_and_jump_insns will be just folded. Otherwise try to use range info if available. */ - if (CONST_INT_P (op0)) + if (code == PLUS_EXPR && CONST_INT_P (op0)) { rtx tem = op0; op0 = op1; @@ -236,7 +237,7 @@ ubsan_expand_si_overflow_addsub_check (tree_code code, gimple stmt) } else if (CONST_INT_P (op1)) ; - else if (TREE_CODE (arg0) == SSA_NAME) + else if (code == PLUS_EXPR && TREE_CODE (arg0) == SSA_NAME) { double_int arg0_min, arg0_max; if (get_range_info (arg0, &arg0_min, &arg0_max) == VR_RANGE) |