public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/109756] New: "internal compiler error: tree check" when using the [[assume]] attribute with pack expansion
@ 2023-05-06 10:33 ensadc at mailnesia dot com
2023-05-06 16:40 ` [Bug c++/109756] " pinskia at gcc dot gnu.org
` (9 more replies)
0 siblings, 10 replies; 11+ messages in thread
From: ensadc at mailnesia dot com @ 2023-05-06 10:33 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109756
Bug ID: 109756
Summary: "internal compiler error: tree check" when using the
[[assume]] attribute with pack expansion
Product: gcc
Version: 14.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: ensadc at mailnesia dot com
Target Milestone: ---
https://godbolt.org/z/WPn9aq8sr
====
bool f(auto... args) {
[[assume(args > 0)...]];
return ((args == 0) && ...);
}
bool g(int a, int b) {
return f(a, b);
}
====
<source>: In function 'bool f(auto:1 ...)':
<source>:2:28: internal compiler error: tree check: expected tree that contains
'common' structure, have 'expr_pack_expansion' in list_length, at tree.cc:3414
2 | [[assume(args > 0)...]];
| ^
0x235945e internal_error(char const*, ...)
???:0
0x96da3a tree_contains_struct_check_failed(tree_node const*,
tree_node_structure_enum, char const*, int, char const*)
???:0
0xb20632 process_stmt_assume_attribute(tree_node*, tree_node*, unsigned int)
???:0
0xc7212f c_parse_file()
???:0
0xdb0d99 c_common_parse_file()
???:0
Please submit a full bug report, with preprocessed source (by using
-freport-bug).
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.
Compiler returned: 1
====
I believe that [[assume(args > 0)...]] is a valid pack expansion. The standard
says ([temp.variadic]/5):
> Pack expansions can occur in the following contexts:
> (5.8) - In an attribute-list ([dcl.attr.grammar]); the pattern is an attribute.
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/109756] "internal compiler error: tree check" when using the [[assume]] attribute with pack expansion
2023-05-06 10:33 [Bug c++/109756] New: "internal compiler error: tree check" when using the [[assume]] attribute with pack expansion ensadc at mailnesia dot com
@ 2023-05-06 16:40 ` pinskia at gcc dot gnu.org
2023-05-06 16:54 ` jakub at gcc dot gnu.org
` (8 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-05-06 16:40 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109756
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Keywords|ice-on-valid-code |
Last reconfirmed| |2023-05-06
Ever confirmed|0 |1
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed.
clang rejects it:
<source>:2:26: error: attribute 'assume' cannot be used as an attribute pack
[[assume(args > 0)...]];
^
While MSVC accepts it.
I am not sure if it is this is valid or not but GCC should NOT be ICEing either
way.
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/109756] "internal compiler error: tree check" when using the [[assume]] attribute with pack expansion
2023-05-06 10:33 [Bug c++/109756] New: "internal compiler error: tree check" when using the [[assume]] attribute with pack expansion ensadc at mailnesia dot com
2023-05-06 16:40 ` [Bug c++/109756] " pinskia at gcc dot gnu.org
@ 2023-05-06 16:54 ` jakub at gcc dot gnu.org
2023-05-06 16:59 ` pinskia at gcc dot gnu.org
` (7 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: jakub at gcc dot gnu.org @ 2023-05-06 16:54 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109756
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |jakub at gcc dot gnu.org
--- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
The https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p1774r8.pdf
paper says in the introductory part:
We could therefore hypothetically permit the assume attribute to directly
support pack expansion:
template <int... args>
void f() {
[[assume(args >= 0)...]];
}
However, we do not propose this. It would require substantial additional work
for a very rare use
case. Note that this can instead be expressed with a fold expression, which is
equivalent to the
above and works out of the box without any extra effort:
template <int... args>
void f() {
[[assume(((args >= 0) && ...))]];
}
http://eel.is/c++draft/dcl.attr#grammar-4 says:
"In an attribute-list, an ellipsis may appear only if that attribute's
specification permits it."
And I don't see it being explicitly permitted for any of the standard attribute
(except for alignas which uses a different syntax).
So, I think this is invalid and we should reject it.
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/109756] "internal compiler error: tree check" when using the [[assume]] attribute with pack expansion
2023-05-06 10:33 [Bug c++/109756] New: "internal compiler error: tree check" when using the [[assume]] attribute with pack expansion ensadc at mailnesia dot com
2023-05-06 16:40 ` [Bug c++/109756] " pinskia at gcc dot gnu.org
2023-05-06 16:54 ` jakub at gcc dot gnu.org
@ 2023-05-06 16:59 ` pinskia at gcc dot gnu.org
2023-05-06 17:00 ` pinskia at gcc dot gnu.org
` (6 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-05-06 16:59 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109756
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |ice-checking,
| |ice-on-invalid-code
--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
We also correctly reject:
bool f(auto... args) {
[[assume(((args >= 0) ))]];
}
bool g(int a, int b) {
return f(a, b);
}
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/109756] "internal compiler error: tree check" when using the [[assume]] attribute with pack expansion
2023-05-06 10:33 [Bug c++/109756] New: "internal compiler error: tree check" when using the [[assume]] attribute with pack expansion ensadc at mailnesia dot com
` (2 preceding siblings ...)
2023-05-06 16:59 ` pinskia at gcc dot gnu.org
@ 2023-05-06 17:00 ` pinskia at gcc dot gnu.org
2023-05-07 19:02 ` jakub at gcc dot gnu.org
` (5 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-05-06 17:00 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109756
--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Andrew Pinski from comment #3)
> We also correctly reject:
I should say without an ICE.
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/109756] "internal compiler error: tree check" when using the [[assume]] attribute with pack expansion
2023-05-06 10:33 [Bug c++/109756] New: "internal compiler error: tree check" when using the [[assume]] attribute with pack expansion ensadc at mailnesia dot com
` (3 preceding siblings ...)
2023-05-06 17:00 ` pinskia at gcc dot gnu.org
@ 2023-05-07 19:02 ` jakub at gcc dot gnu.org
2023-05-08 10:56 ` jakub at gcc dot gnu.org
` (4 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: jakub at gcc dot gnu.org @ 2023-05-07 19:02 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109756
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |jason at gcc dot gnu.org,
| |ppalka at gcc dot gnu.org
--- Comment #5 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Trying other standard attributes, we accept
template <int ...args>
[[noreturn...]] [[deprecated...]] [[nodiscard...]]
int foo (int x)
{
switch (x)
{
case 1:
[[likely...]];
[[fallthrough...]];
case 2:
[[unlikely...]];
break;
default:
break;
}
struct T {};
struct S { [[no_unique_address...]] T t; };
for (;;)
;
}
int a = foo <1, 2, 3> (4);
and just emit the deprecated warning, while clang++ rejects all those.
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/109756] "internal compiler error: tree check" when using the [[assume]] attribute with pack expansion
2023-05-06 10:33 [Bug c++/109756] New: "internal compiler error: tree check" when using the [[assume]] attribute with pack expansion ensadc at mailnesia dot com
` (4 preceding siblings ...)
2023-05-07 19:02 ` jakub at gcc dot gnu.org
@ 2023-05-08 10:56 ` jakub at gcc dot gnu.org
2023-05-08 11:26 ` jakub at gcc dot gnu.org
` (3 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: jakub at gcc dot gnu.org @ 2023-05-08 10:56 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109756
--- Comment #6 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Created attachment 55019
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=55019&action=edit
gcc14-pr109756.patch
Untested patch to diagnose ellipsis after attributes with no arguments.
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/109756] "internal compiler error: tree check" when using the [[assume]] attribute with pack expansion
2023-05-06 10:33 [Bug c++/109756] New: "internal compiler error: tree check" when using the [[assume]] attribute with pack expansion ensadc at mailnesia dot com
` (5 preceding siblings ...)
2023-05-08 10:56 ` jakub at gcc dot gnu.org
@ 2023-05-08 11:26 ` jakub at gcc dot gnu.org
2023-05-09 14:07 ` cvs-commit at gcc dot gnu.org
` (2 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: jakub at gcc dot gnu.org @ 2023-05-08 11:26 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109756
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |ASSIGNED
Assignee|unassigned at gcc dot gnu.org |jakub at gcc dot gnu.org
--- Comment #7 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Created attachment 55020
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=55020&action=edit
gcc14-pr109756-2.patch
And untested patch to fix the actually reported problem.
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/109756] "internal compiler error: tree check" when using the [[assume]] attribute with pack expansion
2023-05-06 10:33 [Bug c++/109756] New: "internal compiler error: tree check" when using the [[assume]] attribute with pack expansion ensadc at mailnesia dot com
` (6 preceding siblings ...)
2023-05-08 11:26 ` jakub at gcc dot gnu.org
@ 2023-05-09 14:07 ` cvs-commit at gcc dot gnu.org
2023-05-09 14:10 ` cvs-commit at gcc dot gnu.org
2023-05-10 9:41 ` cvs-commit at gcc dot gnu.org
9 siblings, 0 replies; 11+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-05-09 14:07 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109756
--- Comment #8 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jakub Jelinek <jakub@gcc.gnu.org>:
https://gcc.gnu.org/g:2499540e9abb55079b5f7b7ccdac97fbc63d9ab4
commit r14-619-g2499540e9abb55079b5f7b7ccdac97fbc63d9ab4
Author: Jakub Jelinek <jakub@redhat.com>
Date: Tue May 9 16:05:22 2023 +0200
c++: Reject pack expansion of assume attribute [PR109756]
http://eel.is/c++draft/dcl.attr#grammar-4 says
"In an attribute-list, an ellipsis may appear only if that attribute's
specification permits it."
and doesn't explicitly permit it on any standard attribute.
The https://wg21.link/p1774r8 paper which introduced assume attribute says
"We could therefore hypothetically permit the assume attribute to directly
support pack expansion:
template <int... args>
void f() {
[[assume(args >= 0)...]];
}
However, we do not propose this. It would require substantial additional
work
for a very rare use case. Note that this can instead be expressed with a
fold
expression, which is equivalent to the above and works out of the box
without
any extra effort:
template <int... args>
void f() {
[[assume(((args >= 0) && ...))]];
}
", but as the testcase shows, GCC 13+ ICEs on assume attribute followed by
... if it contains packs.
The following patch rejects those instead of ICE and for C++17 or later
suggests using fold expressions instead (it doesn't make sense to suggest
it for C++14 and earlier when we'd error on the fold expressions).
2023-05-09 Jakub Jelinek <jakub@redhat.com>
PR c++/109756
* cp-gimplify.cc (process_stmt_assume_attribute): Diagnose pack
expansion of assume attribute.
* g++.dg/cpp23/attr-assume11.C: New test.
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/109756] "internal compiler error: tree check" when using the [[assume]] attribute with pack expansion
2023-05-06 10:33 [Bug c++/109756] New: "internal compiler error: tree check" when using the [[assume]] attribute with pack expansion ensadc at mailnesia dot com
` (7 preceding siblings ...)
2023-05-09 14:07 ` cvs-commit at gcc dot gnu.org
@ 2023-05-09 14:10 ` cvs-commit at gcc dot gnu.org
2023-05-10 9:41 ` cvs-commit at gcc dot gnu.org
9 siblings, 0 replies; 11+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-05-09 14:10 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109756
--- Comment #9 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-13 branch has been updated by Jakub Jelinek
<jakub@gcc.gnu.org>:
https://gcc.gnu.org/g:7bd9a34e9fce0fc307ec26d6db071fe0bc02cd37
commit r13-7312-g7bd9a34e9fce0fc307ec26d6db071fe0bc02cd37
Author: Jakub Jelinek <jakub@redhat.com>
Date: Tue May 9 16:05:22 2023 +0200
c++: Reject pack expansion of assume attribute [PR109756]
http://eel.is/c++draft/dcl.attr#grammar-4 says
"In an attribute-list, an ellipsis may appear only if that attribute's
specification permits it."
and doesn't explicitly permit it on any standard attribute.
The https://wg21.link/p1774r8 paper which introduced assume attribute says
"We could therefore hypothetically permit the assume attribute to directly
support pack expansion:
template <int... args>
void f() {
[[assume(args >= 0)...]];
}
However, we do not propose this. It would require substantial additional
work
for a very rare use case. Note that this can instead be expressed with a
fold
expression, which is equivalent to the above and works out of the box
without
any extra effort:
template <int... args>
void f() {
[[assume(((args >= 0) && ...))]];
}
", but as the testcase shows, GCC 13+ ICEs on assume attribute followed by
... if it contains packs.
The following patch rejects those instead of ICE and for C++17 or later
suggests using fold expressions instead (it doesn't make sense to suggest
it for C++14 and earlier when we'd error on the fold expressions).
2023-05-09 Jakub Jelinek <jakub@redhat.com>
PR c++/109756
* cp-gimplify.cc (process_stmt_assume_attribute): Diagnose pack
expansion of assume attribute.
* g++.dg/cpp23/attr-assume11.C: New test.
(cherry picked from commit 2499540e9abb55079b5f7b7ccdac97fbc63d9ab4)
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/109756] "internal compiler error: tree check" when using the [[assume]] attribute with pack expansion
2023-05-06 10:33 [Bug c++/109756] New: "internal compiler error: tree check" when using the [[assume]] attribute with pack expansion ensadc at mailnesia dot com
` (8 preceding siblings ...)
2023-05-09 14:10 ` cvs-commit at gcc dot gnu.org
@ 2023-05-10 9:41 ` cvs-commit at gcc dot gnu.org
9 siblings, 0 replies; 11+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-05-10 9:41 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109756
--- Comment #10 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jakub Jelinek <jakub@gcc.gnu.org>:
https://gcc.gnu.org/g:39d6d4256d16d676f8b9031c4d1d115ddf4ad76b
commit r14-650-g39d6d4256d16d676f8b9031c4d1d115ddf4ad76b
Author: Jakub Jelinek <jakub@redhat.com>
Date: Wed May 10 11:37:04 2023 +0200
c++: Reject attributes without arguments used as pack expansion [PR109756]
The following testcase shows we silently accept (and ignore) attributes
without
arguments used as pack expansions. This is because we call
make_pack_expansion and that starts with
if (!arg || arg == error_mark_node)
return arg;
Now, an attribute without arguments like [[noreturn...]] is IMHO always
invalid, in this case for 2 reasons; one is that as it has no arguments,
no pack can be present and second is that the standard says that
attributes need to specially permit uses of parameter pack and doesn't
explicitly permit it for any of the standard attributes (except for
alignas?
which has different syntax).
If an attribute has some arguments but doesn't contain packs in those
arguments, make_pack_expansion will already diagnose it.
The patch also changes cp_parser_std_attribute, such that for attributes
unknown
to the compiler (or perhaps registered just for -Wno-attributes=) we
differentiate
between the attribute having no arguments (in that case we want to diagnose
them
when followed by ellipsis even if they are unknown, as they can't contain a
pack
in that case) and the case where they do have arguments but we've just
skipped over
those arguments because we don't know how to parse them (except that they
are
a balanced token sequence) - in that case we really don't know if they
contain
packs or not.
2023-05-10 Jakub Jelinek <jakub@redhat.com>
PR c++/109756
* parser.cc (cp_parser_std_attribute): For unknown attributes with
arguments set TREE_VALUE (attribute) to error_mark_node after
skipping
the balanced tokens.
(cp_parser_std_attribute_list): If ... is used after attribute
without
arguments, diagnose it and return error_mark_node. If
TREE_VALUE (attribute) is error_mark_node, don't call
make_pack_expansion nor return early error_mark_node.
* g++.dg/cpp0x/gen-attrs-78.C: New test.
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2023-05-10 9:41 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-06 10:33 [Bug c++/109756] New: "internal compiler error: tree check" when using the [[assume]] attribute with pack expansion ensadc at mailnesia dot com
2023-05-06 16:40 ` [Bug c++/109756] " pinskia at gcc dot gnu.org
2023-05-06 16:54 ` jakub at gcc dot gnu.org
2023-05-06 16:59 ` pinskia at gcc dot gnu.org
2023-05-06 17:00 ` pinskia at gcc dot gnu.org
2023-05-07 19:02 ` jakub at gcc dot gnu.org
2023-05-08 10:56 ` jakub at gcc dot gnu.org
2023-05-08 11:26 ` jakub at gcc dot gnu.org
2023-05-09 14:07 ` cvs-commit at gcc dot gnu.org
2023-05-09 14:10 ` cvs-commit at gcc dot gnu.org
2023-05-10 9:41 ` cvs-commit at gcc dot gnu.org
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).