* [PATCH] c++: ICE with attribute on enumerator [PR104667]
@ 2022-02-25 21:59 Marek Polacek
2022-02-28 16:16 ` Jason Merrill
0 siblings, 1 reply; 4+ messages in thread
From: Marek Polacek @ 2022-02-25 21:59 UTC (permalink / raw)
To: GCC Patches, Jason Merrill
When processing a template, the enumerators we build don't have a type
yet. But is_late_template_attribute is not prepared to see a _DECL
without a type, so we crash on
enum tree_code code = TREE_CODE (type);
(I found that we don't give the "is deprecated" warning for the enumerator
'f' in the test. Reported as PR104682.)
Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk/11?
PR c++/104667
gcc/cp/ChangeLog:
* decl2.cc (is_late_template_attribute): Cope with a decl without
a type.
gcc/testsuite/ChangeLog:
* g++.dg/ext/attrib64.C: New test.
---
gcc/cp/decl2.cc | 2 +-
gcc/testsuite/g++.dg/ext/attrib64.C | 11 +++++++++++
2 files changed, 12 insertions(+), 1 deletion(-)
create mode 100644 gcc/testsuite/g++.dg/ext/attrib64.C
diff --git a/gcc/cp/decl2.cc b/gcc/cp/decl2.cc
index 2e58419ea51..dc7710660d0 100644
--- a/gcc/cp/decl2.cc
+++ b/gcc/cp/decl2.cc
@@ -1300,7 +1300,7 @@ is_late_template_attribute (tree attr, tree decl)
/* We can't apply any attributes to a completely unknown type until
instantiation time. */
- enum tree_code code = TREE_CODE (type);
+ enum tree_code code = type ? TREE_CODE (type) : ERROR_MARK;
if (code == TEMPLATE_TYPE_PARM
|| code == BOUND_TEMPLATE_TEMPLATE_PARM
|| code == TYPENAME_TYPE)
diff --git a/gcc/testsuite/g++.dg/ext/attrib64.C b/gcc/testsuite/g++.dg/ext/attrib64.C
new file mode 100644
index 00000000000..4a4505fc4b2
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ext/attrib64.C
@@ -0,0 +1,11 @@
+// PR c++/104667
+// { dg-do compile }
+
+template<typename> struct A {
+ enum E { // { dg-warning "only applies to function types" }
+ e __attribute__ ((access(read_only))),
+ f __attribute__ ((deprecated))
+ };
+};
+
+A<int> a;
base-commit: ae3c4e521dd0b66db712639298cd08331d62f315
--
2.35.1
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] c++: ICE with attribute on enumerator [PR104667]
2022-02-25 21:59 [PATCH] c++: ICE with attribute on enumerator [PR104667] Marek Polacek
@ 2022-02-28 16:16 ` Jason Merrill
2022-02-28 16:22 ` Marek Polacek
0 siblings, 1 reply; 4+ messages in thread
From: Jason Merrill @ 2022-02-28 16:16 UTC (permalink / raw)
To: Marek Polacek, GCC Patches
On 2/25/22 17:59, Marek Polacek wrote:
> When processing a template, the enumerators we build don't have a type
> yet. But is_late_template_attribute is not prepared to see a _DECL
> without a type, so we crash on
>
> enum tree_code code = TREE_CODE (type);
>
> (I found that we don't give the "is deprecated" warning for the enumerator
> 'f' in the test. Reported as PR104682.)
>
> Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk/11?
>
> PR c++/104667
>
> gcc/cp/ChangeLog:
>
> * decl2.cc (is_late_template_attribute): Cope with a decl without
> a type.
>
> gcc/testsuite/ChangeLog:
>
> * g++.dg/ext/attrib64.C: New test.
> ---
> gcc/cp/decl2.cc | 2 +-
> gcc/testsuite/g++.dg/ext/attrib64.C | 11 +++++++++++
> 2 files changed, 12 insertions(+), 1 deletion(-)
> create mode 100644 gcc/testsuite/g++.dg/ext/attrib64.C
>
> diff --git a/gcc/cp/decl2.cc b/gcc/cp/decl2.cc
> index 2e58419ea51..dc7710660d0 100644
> --- a/gcc/cp/decl2.cc
> +++ b/gcc/cp/decl2.cc
> @@ -1300,7 +1300,7 @@ is_late_template_attribute (tree attr, tree decl)
>
> /* We can't apply any attributes to a completely unknown type until
> instantiation time. */
> - enum tree_code code = TREE_CODE (type);
> + enum tree_code code = type ? TREE_CODE (type) : ERROR_MARK;
Maybe return true for null type before looking at the code? OK with
that change.
> if (code == TEMPLATE_TYPE_PARM
> || code == BOUND_TEMPLATE_TEMPLATE_PARM
> || code == TYPENAME_TYPE)
> diff --git a/gcc/testsuite/g++.dg/ext/attrib64.C b/gcc/testsuite/g++.dg/ext/attrib64.C
> new file mode 100644
> index 00000000000..4a4505fc4b2
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/ext/attrib64.C
> @@ -0,0 +1,11 @@
> +// PR c++/104667
> +// { dg-do compile }
> +
> +template<typename> struct A {
> + enum E { // { dg-warning "only applies to function types" }
> + e __attribute__ ((access(read_only))),
> + f __attribute__ ((deprecated))
> + };
> +};
> +
> +A<int> a;
>
> base-commit: ae3c4e521dd0b66db712639298cd08331d62f315
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] c++: ICE with attribute on enumerator [PR104667]
2022-02-28 16:16 ` Jason Merrill
@ 2022-02-28 16:22 ` Marek Polacek
2022-02-28 16:25 ` Jason Merrill
0 siblings, 1 reply; 4+ messages in thread
From: Marek Polacek @ 2022-02-28 16:22 UTC (permalink / raw)
To: Jason Merrill; +Cc: GCC Patches
On Mon, Feb 28, 2022 at 12:16:47PM -0400, Jason Merrill wrote:
> On 2/25/22 17:59, Marek Polacek wrote:
> > When processing a template, the enumerators we build don't have a type
> > yet. But is_late_template_attribute is not prepared to see a _DECL
> > without a type, so we crash on
> >
> > enum tree_code code = TREE_CODE (type);
> >
> > (I found that we don't give the "is deprecated" warning for the enumerator
> > 'f' in the test. Reported as PR104682.)
> >
> > Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk/11?
> >
> > PR c++/104667
> >
> > gcc/cp/ChangeLog:
> >
> > * decl2.cc (is_late_template_attribute): Cope with a decl without
> > a type.
> >
> > gcc/testsuite/ChangeLog:
> >
> > * g++.dg/ext/attrib64.C: New test.
> > ---
> > gcc/cp/decl2.cc | 2 +-
> > gcc/testsuite/g++.dg/ext/attrib64.C | 11 +++++++++++
> > 2 files changed, 12 insertions(+), 1 deletion(-)
> > create mode 100644 gcc/testsuite/g++.dg/ext/attrib64.C
> >
> > diff --git a/gcc/cp/decl2.cc b/gcc/cp/decl2.cc
> > index 2e58419ea51..dc7710660d0 100644
> > --- a/gcc/cp/decl2.cc
> > +++ b/gcc/cp/decl2.cc
> > @@ -1300,7 +1300,7 @@ is_late_template_attribute (tree attr, tree decl)
> > /* We can't apply any attributes to a completely unknown type until
> > instantiation time. */
> > - enum tree_code code = TREE_CODE (type);
> > + enum tree_code code = type ? TREE_CODE (type) : ERROR_MARK;
>
> Maybe return true for null type before looking at the code? OK with that
> change.
I didn't do that because I thought it'd be better to go on and reach
1310 else if (dependent_type_p (type)
1311 /* But some attributes specifically apply to templates. */
1312 && !is_attribute_p ("abi_tag", name)
1313 && !is_attribute_p ("deprecated", name)
1314 && !is_attribute_p ("visibility", name))
null type means dependent, but the attribute can still be one of the
"special" ones.
Do you still want me to make that
if (!type)
return true;
change?
Marek
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] c++: ICE with attribute on enumerator [PR104667]
2022-02-28 16:22 ` Marek Polacek
@ 2022-02-28 16:25 ` Jason Merrill
0 siblings, 0 replies; 4+ messages in thread
From: Jason Merrill @ 2022-02-28 16:25 UTC (permalink / raw)
To: Marek Polacek; +Cc: GCC Patches
On 2/28/22 12:22, Marek Polacek wrote:
> On Mon, Feb 28, 2022 at 12:16:47PM -0400, Jason Merrill wrote:
>> On 2/25/22 17:59, Marek Polacek wrote:
>>> When processing a template, the enumerators we build don't have a type
>>> yet. But is_late_template_attribute is not prepared to see a _DECL
>>> without a type, so we crash on
>>>
>>> enum tree_code code = TREE_CODE (type);
>>>
>>> (I found that we don't give the "is deprecated" warning for the enumerator
>>> 'f' in the test. Reported as PR104682.)
>>>
>>> Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk/11?
>>>
>>> PR c++/104667
>>>
>>> gcc/cp/ChangeLog:
>>>
>>> * decl2.cc (is_late_template_attribute): Cope with a decl without
>>> a type.
>>>
>>> gcc/testsuite/ChangeLog:
>>>
>>> * g++.dg/ext/attrib64.C: New test.
>>> ---
>>> gcc/cp/decl2.cc | 2 +-
>>> gcc/testsuite/g++.dg/ext/attrib64.C | 11 +++++++++++
>>> 2 files changed, 12 insertions(+), 1 deletion(-)
>>> create mode 100644 gcc/testsuite/g++.dg/ext/attrib64.C
>>>
>>> diff --git a/gcc/cp/decl2.cc b/gcc/cp/decl2.cc
>>> index 2e58419ea51..dc7710660d0 100644
>>> --- a/gcc/cp/decl2.cc
>>> +++ b/gcc/cp/decl2.cc
>>> @@ -1300,7 +1300,7 @@ is_late_template_attribute (tree attr, tree decl)
>>> /* We can't apply any attributes to a completely unknown type until
>>> instantiation time. */
>>> - enum tree_code code = TREE_CODE (type);
>>> + enum tree_code code = type ? TREE_CODE (type) : ERROR_MARK;
>>
>> Maybe return true for null type before looking at the code? OK with that
>> change.
>
> I didn't do that because I thought it'd be better to go on and reach
>
> 1310 else if (dependent_type_p (type)
> 1311 /* But some attributes specifically apply to templates. */
> 1312 && !is_attribute_p ("abi_tag", name)
> 1313 && !is_attribute_p ("deprecated", name)
> 1314 && !is_attribute_p ("visibility", name))
>
> null type means dependent, but the attribute can still be one of the
> "special" ones.
>
> Do you still want me to make that
>
> if (!type)
> return true;
>
> change?
Please. The comment above 'code' applies even more to null type: we
can't apply any attributes to it.
Jason
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-02-28 16:25 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-25 21:59 [PATCH] c++: ICE with attribute on enumerator [PR104667] Marek Polacek
2022-02-28 16:16 ` Jason Merrill
2022-02-28 16:22 ` Marek Polacek
2022-02-28 16:25 ` 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).