diff mbox series

[C,family] Fix PR86453

Message ID alpine.LSU.2.20.1807111153100.16707@zhemvz.fhfr.qr
State New
Headers show
Series [C,family] Fix PR86453 | expand

Commit Message

Richard Biener July 11, 2018, 9:55 a.m. UTC
This fixes handle_packed_attribute creating a type variant which differs
in TYPE_PACKED.  This cannot be generally allowed since TYPE_PACKED
affects layout and layout is shared between variants.

For the testcase in question the attribute itself is later ignored
but TYPE_PACKED is still applied which eventually leads to an ICE
in type verification (that isn't applied very reliably).

Bootstrapped and tested on x86_64-unknown-linux-gnu, OK?

Thanks,
Richard.

2018-07-11  Richard Biener  <rguenther@suse.de>

	PR c/86453
	* c-attribs.c (handle_packed_attribute): Do not build a variant
	type with TYPE_PACKED, instead ignore the attribute if we may
	not apply to the original type.

	* g++.dg/warn/pr86453.C: New testcase.

Comments

Marek Polacek July 11, 2018, 2:02 p.m. UTC | #1
On Wed, Jul 11, 2018 at 11:55:32AM +0200, Richard Biener wrote:
> 
> This fixes handle_packed_attribute creating a type variant which differs
> in TYPE_PACKED.  This cannot be generally allowed since TYPE_PACKED
> affects layout and layout is shared between variants.
> 
> For the testcase in question the attribute itself is later ignored
> but TYPE_PACKED is still applied which eventually leads to an ICE
> in type verification (that isn't applied very reliably).
> 
> Bootstrapped and tested on x86_64-unknown-linux-gnu, OK?

Ok.

Marek
diff mbox series

Patch

diff --git a/gcc/c-family/c-attribs.c b/gcc/c-family/c-attribs.c
index f91add488bb..8cb87eb8154 100644
--- a/gcc/c-family/c-attribs.c
+++ b/gcc/c-family/c-attribs.c
@@ -502,8 +502,13 @@  handle_packed_attribute (tree *node, tree name, tree ARG_UNUSED (args),
   if (TYPE_P (*node))
     {
       if (!(flags & (int) ATTR_FLAG_TYPE_IN_PLACE))
-	*node = build_variant_type_copy (*node);
-      TYPE_PACKED (*node) = 1;
+	{
+	  warning (OPT_Wattributes,
+		   "%qE attribute ignored for type %qT", name, *node);
+	  *no_add_attrs = true;
+	}
+      else
+	TYPE_PACKED (*node) = 1;
     }
   else if (TREE_CODE (*node) == FIELD_DECL)
     {
Index: gcc/testsuite/g++.dg/warn/pr86453.C
===================================================================
--- gcc/testsuite/g++.dg/warn/pr86453.C	(nonexistent)
+++ gcc/testsuite/g++.dg/warn/pr86453.C	(working copy)
@@ -0,0 +1,5 @@ 
+// { dg-do compile }
+// { dg-additional-options "-flto" { target lto } }
+struct X {
+  int *__attribute__((aligned(2), packed)) a; // { dg-warning "attribute ignored" }
+} b;