diff mbox

Fix another ubsan_encode_value related ICE (PR sanitizer/81209)

Message ID 20170627055137.GO2123@tucnak
State New
Headers show

Commit Message

Jakub Jelinek June 27, 2017, 5:51 a.m. UTC
Hi!

Apparently the pr81125.C testcase ICEs on Darwin, but not on Linux,
the difference is that on Darwin ctors/dtors aren't deduplicated due to
lack of flexibility of the object format.  I've managed to reproduce
also on Linux with a virtual base and -fno-declone-ctor-dtor.
The problem was that because the temp var didn't have DECL_CONTEXT
set, during cloning that var wasn't remapped and thus was shared by
both complete and base ctor.

Fixed thusly, bootstrapped/regtested on x86_64-linux, ok for trunk?

2017-06-27  Jakub Jelinek  <jakub@redhat.com>

	PR sanitizer/81209
	* ubsan.c (ubsan_encode_value): Initialize DECL_CONTEXT on var.

	* g++.dg/ubsan/pr81209.C: New test.


	Jakub

Comments

Richard Biener June 27, 2017, 7:11 a.m. UTC | #1
On Tue, 27 Jun 2017, Jakub Jelinek wrote:

> Hi!
> 
> Apparently the pr81125.C testcase ICEs on Darwin, but not on Linux,
> the difference is that on Darwin ctors/dtors aren't deduplicated due to
> lack of flexibility of the object format.  I've managed to reproduce
> also on Linux with a virtual base and -fno-declone-ctor-dtor.
> The problem was that because the temp var didn't have DECL_CONTEXT
> set, during cloning that var wasn't remapped and thus was shared by
> both complete and base ctor.
> 
> Fixed thusly, bootstrapped/regtested on x86_64-linux, ok for trunk?

Ok.

> 2017-06-27  Jakub Jelinek  <jakub@redhat.com>
> 
> 	PR sanitizer/81209
> 	* ubsan.c (ubsan_encode_value): Initialize DECL_CONTEXT on var.
> 
> 	* g++.dg/ubsan/pr81209.C: New test.
> 
> --- gcc/ubsan.c.jj	2017-06-19 17:28:13.000000000 +0200
> +++ gcc/ubsan.c	2017-06-26 21:04:45.602012192 +0200
> @@ -153,6 +153,7 @@ ubsan_encode_value (tree t, enum ubsan_e
>  	    {
>  	      var = create_tmp_var_raw (type);
>  	      TREE_ADDRESSABLE (var) = 1;
> +	      DECL_CONTEXT (var) = current_function_decl;
>  	    }
>  	  if (phase == UBSAN_ENCODE_VALUE_RTL)
>  	    {
> --- gcc/testsuite/g++.dg/ubsan/pr81209.C.jj	2017-06-26 21:07:47.018875009 +0200
> +++ gcc/testsuite/g++.dg/ubsan/pr81209.C	2017-06-26 21:08:08.273624617 +0200
> @@ -0,0 +1,21 @@
> +// PR sanitizer/81209
> +// { dg-do compile }
> +// { dg-options "-fsanitize=undefined -fno-declone-ctor-dtor" }
> +
> +#ifdef __SIZEOF_INT128__
> +typedef __int128 T;
> +#else
> +typedef long long int T;
> +#endif
> +
> +struct B {};
> +struct A : virtual public B
> +{
> +  A (long);
> +  T a;
> +};
> +
> +A::A (long c)
> +{
> +  long b = a % c;
> +}
> 
> 	Jakub
> 
>
diff mbox

Patch

--- gcc/ubsan.c.jj	2017-06-19 17:28:13.000000000 +0200
+++ gcc/ubsan.c	2017-06-26 21:04:45.602012192 +0200
@@ -153,6 +153,7 @@  ubsan_encode_value (tree t, enum ubsan_e
 	    {
 	      var = create_tmp_var_raw (type);
 	      TREE_ADDRESSABLE (var) = 1;
+	      DECL_CONTEXT (var) = current_function_decl;
 	    }
 	  if (phase == UBSAN_ENCODE_VALUE_RTL)
 	    {
--- gcc/testsuite/g++.dg/ubsan/pr81209.C.jj	2017-06-26 21:07:47.018875009 +0200
+++ gcc/testsuite/g++.dg/ubsan/pr81209.C	2017-06-26 21:08:08.273624617 +0200
@@ -0,0 +1,21 @@ 
+// PR sanitizer/81209
+// { dg-do compile }
+// { dg-options "-fsanitize=undefined -fno-declone-ctor-dtor" }
+
+#ifdef __SIZEOF_INT128__
+typedef __int128 T;
+#else
+typedef long long int T;
+#endif
+
+struct B {};
+struct A : virtual public B
+{
+  A (long);
+  T a;
+};
+
+A::A (long c)
+{
+  long b = a % c;
+}