[gcc(refs/users/marxin/heads/marxin-gcc-benchmark-branch)] c++: Fix ICE on invalid alignas in a template [PR93530]

Martin Liska marxin@gcc.gnu.org
Mon Mar 30 10:43:10 GMT 2020


https://gcc.gnu.org/g:b817be038d94c987e02c26ed2d81b6f2ebb5f97a

commit b817be038d94c987e02c26ed2d81b6f2ebb5f97a
Author: Marek Polacek <polacek@redhat.com>
Date:   Fri Jan 31 19:28:10 2020 -0500

    c++: Fix ICE on invalid alignas in a template [PR93530]
    
    This fixes an ICE taking place in cp_default_conversion because we got
    a SCOPE_REF that doesn't have a type and so checking
    INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (TREE_TYPE (exp)) will crash.
    This happens since the recent Joseph's change in decl_attributes whereby
    we don't skip C++11 attributes on types.
    
    [dcl.align] is clear that alignas applied to a function is ill-formed.
    That should be fixed, and we have PR90847 for that.  But I think a more
    appropriate fix at this stage would be the following: in a template we
    want to splice dependent attributes and save them for later, and by
    doing so avoid this crash.
    
            PR c++/93530 - ICE on invalid alignas in a template.
            * decl.c (grokdeclarator): Call cplus_decl_attributes instead of
            decl_attributes.
    
            * g++.dg/cpp0x/alignas18.C: New test.

Diff:
---
 gcc/cp/ChangeLog                       | 6 ++++++
 gcc/cp/decl.c                          | 2 +-
 gcc/testsuite/ChangeLog                | 5 +++++
 gcc/testsuite/g++.dg/cpp0x/alignas18.C | 8 ++++++++
 4 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 999348d2e29..ed1c64f18fb 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,9 @@
+2020-02-02  Marek Polacek  <polacek@redhat.com>
+
+	PR c++/93530 - ICE on invalid alignas in a template.
+	* decl.c (grokdeclarator): Call cplus_decl_attributes instead of
+	decl_attributes.
+
 2020-01-31  Jason Merrill  <jason@redhat.com>
 
 	PR c++/86216
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index ef34f436fdf..859fd1bb931 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -12318,7 +12318,7 @@ grokdeclarator (const cp_declarator *declarator,
 
 		 The optional attribute-specifier-seq appertains to
 		 the function type.  */
-	      decl_attributes (&type, attrs, 0);
+	      cplus_decl_attributes (&type, attrs, 0);
 
 	    if (raises)
 	      type = build_exception_variant (type, raises);
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 05620402c8a..74cbead32fb 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2020-02-02  Marek Polacek  <polacek@redhat.com>
+
+	PR c++/93530 - ICE on invalid alignas in a template.
+	* g++.dg/cpp0x/alignas18.C: New test.
+
 2020-02-02  Iain Sandoe  <iain@sandoe.co.uk>
 
 	* gcc.target/powerpc/darwin-abi-12.c: Add '-fcommon' to the
diff --git a/gcc/testsuite/g++.dg/cpp0x/alignas18.C b/gcc/testsuite/g++.dg/cpp0x/alignas18.C
new file mode 100644
index 00000000000..820bdd2d7ca
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/alignas18.C
@@ -0,0 +1,8 @@
+// PR c++/93530 - ICE on invalid alignas in a template.
+// { dg-do compile { target c++11 } }
+
+template <typename T> struct S {
+  using U = S;
+  // FIXME: This is ill-formed; see PR90847.
+  void fn() alignas(U::X);
+};


More information about the Gcc-cvs mailing list