Commit aa6b742f by Jakub Jelinek Committed by Jakub Jelinek

re PR sanitizer/60636 (ubsan doesn't instrument signed integer ABS_EXPR)

	PR sanitizer/60636
	* ubsan.c (instrument_si_overflow): Instrument ABS_EXPR.

	* c-c++-common/ubsan/pr60636.c: New test.

From-SVN: r208841
parent 368b454d
2014-03-26 Jakub Jelinek <jakub@redhat.com> 2014-03-26 Jakub Jelinek <jakub@redhat.com>
PR sanitizer/60636
* ubsan.c (instrument_si_overflow): Instrument ABS_EXPR.
* tree-vrp.c (simplify_internal_call_using_ranges): If only * tree-vrp.c (simplify_internal_call_using_ranges): If only
one range is range_int_cst_p, but not both, at least optimize one range is range_int_cst_p, but not both, at least optimize
addition/subtraction of 0 and multiplication by 0 or 1. addition/subtraction of 0 and multiplication by 0 or 1.
......
2014-03-26 Jakub Jelinek <jakub@redhat.com>
PR sanitizer/60636
* c-c++-common/ubsan/pr60636.c: New test.
2014-03-26 Andreas Schwab <schwab@suse.de> 2014-03-26 Andreas Schwab <schwab@suse.de>
* g++.dg/torture/pr60315.C: Remove duplication. * g++.dg/torture/pr60315.C: Remove duplication.
......
/* PR sanitizer/60636 */
/* { dg-do run } */
/* { dg-options "-fsanitize=undefined" } */
volatile long long int a;
int
main ()
{
long long int u = -__LONG_LONG_MAX__ - 1;
a = u > 0 ? u : -u;
return 0;
}
/* { dg-output "negation of -9223372036854775808 cannot be represented in type 'long long int'" } */
...@@ -737,6 +737,21 @@ instrument_si_overflow (gimple_stmt_iterator gsi) ...@@ -737,6 +737,21 @@ instrument_si_overflow (gimple_stmt_iterator gsi)
gimple_call_set_lhs (g, lhs); gimple_call_set_lhs (g, lhs);
gsi_replace (&gsi, g, false); gsi_replace (&gsi, g, false);
break; break;
case ABS_EXPR:
/* Transform i = ABS_EXPR<u>;
into
_N = UBSAN_CHECK_SUB (0, u);
i = ABS_EXPR<_N>; */
a = build_int_cst (lhstype, 0);
b = gimple_assign_rhs1 (stmt);
g = gimple_build_call_internal (IFN_UBSAN_CHECK_SUB, 2, a, b);
a = make_ssa_name (lhstype, NULL);
gimple_call_set_lhs (g, a);
gimple_set_location (g, gimple_location (stmt));
gsi_insert_before (&gsi, g, GSI_SAME_STMT);
gimple_assign_set_rhs1 (stmt, a);
update_stmt (stmt);
break;
default: default:
break; break;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment