public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Fix another ubsan_encode_value related ICE (PR sanitizer/81209)
@ 2017-06-27  5:52 Jakub Jelinek
  2017-06-27  7:11 ` Richard Biener
  0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2017-06-27  5:52 UTC (permalink / raw)
  To: Richard Biener; +Cc: gcc-patches

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.

--- 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

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] Fix another ubsan_encode_value related ICE (PR sanitizer/81209)
  2017-06-27  5:52 [PATCH] Fix another ubsan_encode_value related ICE (PR sanitizer/81209) Jakub Jelinek
@ 2017-06-27  7:11 ` Richard Biener
  0 siblings, 0 replies; 2+ messages in thread
From: Richard Biener @ 2017-06-27  7:11 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: gcc-patches

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
> 
> 

-- 
Richard Biener <rguenther@suse.de>
SUSE LINUX GmbH, GF: Felix Imendoerffer, Jane Smithard, Graham Norton, HRB 21284 (AG Nuernberg)

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-06-27  7:11 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-06-27  5:52 [PATCH] Fix another ubsan_encode_value related ICE (PR sanitizer/81209) Jakub Jelinek
2017-06-27  7:11 ` Richard Biener

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).