public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] gimple-fold: Fix another __builtin_clear_padding ICE
@ 2020-11-26 15:03 Jakub Jelinek
  2020-11-26 15:10 ` Richard Biener
  0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2020-11-26 15:03 UTC (permalink / raw)
  To: Jason Merrill, Richard Biener; +Cc: gcc-patches

Hi!

When playing with __builtin_bit_cast, I have noticed __builtin_clear_padding
ICE on the G class below.  The artificial field with D type has offset 0
and size 8 bytes, but the following artificial field with E type has offset
0 and size 0, so it triggers the asserts that we don't move current position
backwards.  Fixed by ignoring is_empty_type (TREE_TYPE (field)) fields, all
of their bits are padding which is what is added when skipping over to next
field anyway.

Ok for trunk if it passes bootstrap/regtest?  So far passed all
builtin-clear-padding* tests, so everything that uses these functions ATM
in the GCC tree.

2020-11-26  Jakub Jelinek  <jakub@redhat.com>

	PR libstdc++/88101
	* gimple-fold.c (clear_padding_type): Ignore fields with is_empty_type
	types.

	* g++.dg/torture/builtin-clear-padding-3.C: New test.

--- gcc/gimple-fold.c.jj	2020-11-26 14:05:07.393268700 +0100
+++ gcc/gimple-fold.c	2020-11-26 14:18:10.826532574 +0100
@@ -4533,6 +4533,8 @@ clear_padding_type (clear_padding_struct
 				    "well defined padding bits for %qs",
 			  field, "__builtin_clear_padding");
 	      }
+	    else if (is_empty_type (TREE_TYPE (field)))
+	      continue;
 	    else
 	      {
 		HOST_WIDE_INT pos = int_byte_position (field);
--- gcc/testsuite/g++.dg/torture/builtin-clear-padding-3.C.jj	2020-11-26 14:26:40.532848182 +0100
+++ gcc/testsuite/g++.dg/torture/builtin-clear-padding-3.C	2020-11-26 14:27:51.995051122 +0100
@@ -0,0 +1,24 @@
+/* PR libstdc++/88101 */
+
+struct D { int a; int : 24; int b : 8; };
+struct E {};
+struct F { char c, d, e; };
+struct G : public D, E, F { int f; } g1, g2;
+
+__attribute__((noipa)) void
+foo (G *g)
+{
+  g->a = -1; g->b = -1; g->c = -1; g->d = -1; g->e = -1; g->f = -1;
+}
+
+int
+main ()
+{
+  __builtin_memset (&g2, -1, sizeof (g2));
+  foo (&g1);
+  foo (&g2);
+  __builtin_clear_padding (&g2);
+  if (__builtin_memcmp (&g1, &g2, sizeof (g1)))
+    __builtin_abort ();
+  return 0;
+}

	Jakub


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

* Re: [PATCH] gimple-fold: Fix another __builtin_clear_padding ICE
  2020-11-26 15:03 [PATCH] gimple-fold: Fix another __builtin_clear_padding ICE Jakub Jelinek
@ 2020-11-26 15:10 ` Richard Biener
  0 siblings, 0 replies; 2+ messages in thread
From: Richard Biener @ 2020-11-26 15:10 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: Jason Merrill, gcc-patches

On Thu, 26 Nov 2020, Jakub Jelinek wrote:

> Hi!
> 
> When playing with __builtin_bit_cast, I have noticed __builtin_clear_padding
> ICE on the G class below.  The artificial field with D type has offset 0
> and size 8 bytes, but the following artificial field with E type has offset
> 0 and size 0, so it triggers the asserts that we don't move current position
> backwards.  Fixed by ignoring is_empty_type (TREE_TYPE (field)) fields, all
> of their bits are padding which is what is added when skipping over to next
> field anyway.
> 
> Ok for trunk if it passes bootstrap/regtest?  So far passed all
> builtin-clear-padding* tests, so everything that uses these functions ATM
> in the GCC tree.

OK.

Richard.

> 2020-11-26  Jakub Jelinek  <jakub@redhat.com>
> 
> 	PR libstdc++/88101
> 	* gimple-fold.c (clear_padding_type): Ignore fields with is_empty_type
> 	types.
> 
> 	* g++.dg/torture/builtin-clear-padding-3.C: New test.
> 
> --- gcc/gimple-fold.c.jj	2020-11-26 14:05:07.393268700 +0100
> +++ gcc/gimple-fold.c	2020-11-26 14:18:10.826532574 +0100
> @@ -4533,6 +4533,8 @@ clear_padding_type (clear_padding_struct
>  				    "well defined padding bits for %qs",
>  			  field, "__builtin_clear_padding");
>  	      }
> +	    else if (is_empty_type (TREE_TYPE (field)))
> +	      continue;
>  	    else
>  	      {
>  		HOST_WIDE_INT pos = int_byte_position (field);
> --- gcc/testsuite/g++.dg/torture/builtin-clear-padding-3.C.jj	2020-11-26 14:26:40.532848182 +0100
> +++ gcc/testsuite/g++.dg/torture/builtin-clear-padding-3.C	2020-11-26 14:27:51.995051122 +0100
> @@ -0,0 +1,24 @@
> +/* PR libstdc++/88101 */
> +
> +struct D { int a; int : 24; int b : 8; };
> +struct E {};
> +struct F { char c, d, e; };
> +struct G : public D, E, F { int f; } g1, g2;
> +
> +__attribute__((noipa)) void
> +foo (G *g)
> +{
> +  g->a = -1; g->b = -1; g->c = -1; g->d = -1; g->e = -1; g->f = -1;
> +}
> +
> +int
> +main ()
> +{
> +  __builtin_memset (&g2, -1, sizeof (g2));
> +  foo (&g1);
> +  foo (&g2);
> +  __builtin_clear_padding (&g2);
> +  if (__builtin_memcmp (&g1, &g2, sizeof (g1)))
> +    __builtin_abort ();
> +  return 0;
> +}
> 
> 	Jakub
> 
> 

-- 
Richard Biener <rguenther@suse.de>
SUSE Software Solutions Germany GmbH, Maxfeldstrasse 5, 90409 Nuernberg,
Germany; GF: Felix Imend

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

end of thread, other threads:[~2020-11-26 15:11 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-26 15:03 [PATCH] gimple-fold: Fix another __builtin_clear_padding ICE Jakub Jelinek
2020-11-26 15:10 ` 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).