diff mbox

Don't segv in vtable verification with ubsan (PR sanitizer/59415)

Message ID 20131209142330.GJ11710@redhat.com
State New
Headers show

Commit Message

Marek Polacek Dec. 9, 2013, 2:23 p.m. UTC
We ICEd on the following testcase with -fsanitize=null and vtable
verification on, because gimple_call_fn returns NULL for UBSAN_*
internal functions.  Fixed by checking the result for NULL before
accessing its TREE_CODE.

Regtested/bootstrapped on x86_64-linux, ok for trunk?

2013-12-09  Marek Polacek  <polacek@redhat.com>

	PR sanitizer/59415
	* vtable-verify.c (verify_bb_vtables): Check the return value
	of gimple_call_fn.
testsuite/
	* g++.dg/ubsan/pr59415.C: New test.


	Marek

Comments

Jakub Jelinek Dec. 9, 2013, 2:29 p.m. UTC | #1
On Mon, Dec 09, 2013 at 03:23:30PM +0100, Marek Polacek wrote:
> We ICEd on the following testcase with -fsanitize=null and vtable
> verification on, because gimple_call_fn returns NULL for UBSAN_*
> internal functions.  Fixed by checking the result for NULL before
> accessing its TREE_CODE.
> 
> Regtested/bootstrapped on x86_64-linux, ok for trunk?

Ok.
> 2013-12-09  Marek Polacek  <polacek@redhat.com>
> 
> 	PR sanitizer/59415
> 	* vtable-verify.c (verify_bb_vtables): Check the return value
> 	of gimple_call_fn.
> testsuite/
> 	* g++.dg/ubsan/pr59415.C: New test.
> 
> --- gcc/vtable-verify.c.mp	2013-12-09 13:11:24.045759854 +0100
> +++ gcc/vtable-verify.c	2013-12-09 14:47:55.549415078 +0100
> @@ -589,7 +589,7 @@ verify_bb_vtables (basic_block bb)
>        if (gimple_code (stmt) == GIMPLE_CALL)

While you are at this, can you please change the above into
      if (is_gimple_call (stmt))
, please?  Thanks.

	Jakub
diff mbox

Patch

--- gcc/vtable-verify.c.mp	2013-12-09 13:11:24.045759854 +0100
+++ gcc/vtable-verify.c	2013-12-09 14:47:55.549415078 +0100
@@ -589,7 +589,7 @@  verify_bb_vtables (basic_block bb)
       if (gimple_code (stmt) == GIMPLE_CALL)
         {
           tree fncall = gimple_call_fn (stmt);
-          if (TREE_CODE (fncall) == OBJ_TYPE_REF)
+          if (fncall && TREE_CODE (fncall) == OBJ_TYPE_REF)
             total_num_virtual_calls++;
         }
 
--- gcc/testsuite/g++.dg/ubsan/pr59415.C.mp	2013-12-09 14:44:59.757670282 +0100
+++ gcc/testsuite/g++.dg/ubsan/pr59415.C	2013-12-09 14:45:45.918858550 +0100
@@ -0,0 +1,8 @@ 
+/* { dg-do compile } */
+/* { dg-options "-fsanitize=null -Wall -fvtable-verify=std" } */
+
+void
+foo (void)
+{
+  throw 0;
+}