public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] c++: Fix ICE on invalid alignas in a template [PR93530]
@ 2020-02-01  1:07 Marek Polacek
  2020-02-02 20:10 ` Jason Merrill
  0 siblings, 1 reply; 2+ messages in thread
From: Marek Polacek @ 2020-02-01  1:07 UTC (permalink / raw)
  To: GCC Patches, Jason Merrill

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.

Bootstrapped/regtested on x86_64-linux, ok for trunk?

	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.
---
 gcc/cp/decl.c                          | 2 +-
 gcc/testsuite/g++.dg/cpp0x/alignas18.C | 8 ++++++++
 2 files changed, 9 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/g++.dg/cpp0x/alignas18.C

diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 6ad558eef9e..576cbd8643a 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -12300,7 +12300,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/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);
+};

base-commit: 2a07345c4f8dabc286fc470e76c53473e5bc3eb7
-- 
Marek Polacek • Red Hat, Inc. • 300 A St, Boston, MA

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

* Re: [PATCH] c++: Fix ICE on invalid alignas in a template [PR93530]
  2020-02-01  1:07 [PATCH] c++: Fix ICE on invalid alignas in a template [PR93530] Marek Polacek
@ 2020-02-02 20:10 ` Jason Merrill
  0 siblings, 0 replies; 2+ messages in thread
From: Jason Merrill @ 2020-02-02 20:10 UTC (permalink / raw)
  To: Marek Polacek, GCC Patches

On 1/31/20 8:06 PM, Marek Polacek wrote:
> 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.
> 
> Bootstrapped/regtested on x86_64-linux, ok for trunk?

OK.

> 
> 	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.
> ---
>   gcc/cp/decl.c                          | 2 +-
>   gcc/testsuite/g++.dg/cpp0x/alignas18.C | 8 ++++++++
>   2 files changed, 9 insertions(+), 1 deletion(-)
>   create mode 100644 gcc/testsuite/g++.dg/cpp0x/alignas18.C
> 
> diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
> index 6ad558eef9e..576cbd8643a 100644
> --- a/gcc/cp/decl.c
> +++ b/gcc/cp/decl.c
> @@ -12300,7 +12300,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/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);
> +};
> 
> base-commit: 2a07345c4f8dabc286fc470e76c53473e5bc3eb7
> 

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

end of thread, other threads:[~2020-02-02 20:10 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-01  1:07 [PATCH] c++: Fix ICE on invalid alignas in a template [PR93530] Marek Polacek
2020-02-02 20:10 ` Jason Merrill

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