This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH][C family] Fix PR86453
- From: Richard Biener <rguenther at suse dot de>
- To: gcc-patches at gcc dot gnu dot org
- Date: Wed, 11 Jul 2018 11:55:32 +0200 (CEST)
- Subject: [PATCH][C family] Fix PR86453
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.
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;