diff mbox

Add signed integer overflow checking to ubsan

Message ID 20131122135552.GC892@tucnak.redhat.com
State New
Headers show

Commit Message

Jakub Jelinek Nov. 22, 2013, 1:55 p.m. UTC
On Fri, Nov 22, 2013 at 10:54:16AM +0100, Marek Polacek wrote:
> 1) currently, we seem to miscompile some code with -Os.  That's why
>    I skipped -Os in some of the test.

The following (untested) incremental fix should hopefully fix it.

Perhaps the calls before expand_normal aren't needed, dunno if we can end up
with any pending stack adjustments in between gimple stmts.
But the ones after expand_normal (fn); certainly are needed, if we the
calls change sp, we need to return back to the previous state of sp
before the CODE_LABEL that can be jumped to to bypass the call.

2013-11-22  Jakub Jelinek  <jakub@redhat.com>

	* internal-fn.c (ubsan_expand_si_overflow_addsub_check,
	ubsan_expand_si_overflow_neg_check,
	ubsan_expand_si_overflow_mul_check): Call do_pending_stack_adjust.



	Jakub
diff mbox

Patch

--- gcc/internal-fn.c.jj	2013-11-22 14:25:30.000000000 +0100
+++ gcc/internal-fn.c	2013-11-22 14:50:20.065688055 +0100
@@ -167,6 +167,7 @@  ubsan_expand_si_overflow_addsub_check (t
   do_error = gen_label_rtx ();
   fn = ubsan_build_overflow_builtin (code, gimple_location (stmt),
 				     TREE_TYPE (arg0), arg0, arg1);
+  do_pending_stack_adjust ();
   op0 = expand_normal (arg0);
   op1 = expand_normal (arg1);
 
@@ -233,6 +234,7 @@  ubsan_expand_si_overflow_addsub_check (t
    emit_label (do_error);
    /* Expand the ubsan builtin call.  */
    expand_normal (fn);
+   do_pending_stack_adjust ();
 
    /* We're done.  */
    emit_label (done_label);
@@ -257,6 +259,7 @@  ubsan_expand_si_overflow_neg_check (gimp
   fn = ubsan_build_overflow_builtin (NEGATE_EXPR, gimple_location (stmt),
 				     TREE_TYPE (arg1), arg1, NULL_TREE);
 
+  do_pending_stack_adjust ();
   op1 = expand_normal (arg1);
 
   enum machine_mode mode = TYPE_MODE (TREE_TYPE (arg1));
@@ -306,6 +309,7 @@  ubsan_expand_si_overflow_neg_check (gimp
   emit_label (do_error);
   /* Expand the ubsan builtin call.  */
   expand_normal (fn);
+  do_pending_stack_adjust ();
 
   /* We're done.  */
   emit_label (done_label);
@@ -331,6 +335,7 @@  ubsan_expand_si_overflow_mul_check (gimp
   fn = ubsan_build_overflow_builtin (MULT_EXPR, gimple_location (stmt),
 				     TREE_TYPE (arg0), arg0, arg1);
 
+  do_pending_stack_adjust ();
   op0 = expand_normal (arg0);
   op1 = expand_normal (arg1);
 
@@ -409,6 +414,7 @@  ubsan_expand_si_overflow_mul_check (gimp
   emit_label (do_error);
   /* Expand the ubsan builtin call.  */
   expand_normal (fn);
+  do_pending_stack_adjust ();
 
   /* We're done.  */
   emit_label (done_label);