public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/105300] New: segfault from static_assert with user-defined string suffix argument
@ 2022-04-18 3:51 Jack at Applin dot US
2022-04-19 14:11 ` [Bug c++/105300] " marxin at gcc dot gnu.org
` (8 more replies)
0 siblings, 9 replies; 10+ messages in thread
From: Jack at Applin dot US @ 2022-04-18 3:51 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105300
Bug ID: 105300
Summary: segfault from static_assert with user-defined string
suffix argument
Product: gcc
Version: 11.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: Jack at Applin dot US
Target Milestone: ---
Created attachment 52824
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=52824&action=edit
preprocessed source to reproduce the error
$ cat bad.ii
void operator""_x(const char *, unsigned long);
static_assert(false, "foo"_x);
$ g++ bad.ii
bad.ii:2:15: internal compiler error: Segmentation fault
2 | static_assert(false, "foo"_x);
| ^~~~~
0xb0c67e crash_signal
../../src/gcc/toplev.c:327
0x7fb38e75951f ???
./signal/../sysdeps/unix/sysv/linux/x86_64/libc_sigaction.c:0
0x7dd197 finish_static_assert(tree_node*, tree_node*, unsigned int, bool, bool)
../../src/gcc/cp/semantics.c:10134
0x15089c8 cp_parser_static_assert
../../src/gcc/cp/parser.c:15464
0xf9ed91 cp_parser_declaration
../../src/gcc/cp/parser.c:14164
0x149bba3 cp_parser_toplevel_declaration
../../src/gcc/cp/parser.c:14193
0x149bba3 cp_parser_translation_unit
../../src/gcc/cp/parser.c:4942
0x149bba3 c_parse_file()
../../src/gcc/cp/parser.c:45326
0x1489a5e c_common_parse_file()
../../src/gcc/c-family/c-opts.c:1218
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <file:///usr/share/doc/gcc-11/README.Bugs> for instructions.
$ g++ --version
g++ (Ubuntu 11.2.0-7ubuntu2) 11.2.0
Copyright (C) 2021 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/105300] segfault from static_assert with user-defined string suffix argument
2022-04-18 3:51 [Bug c++/105300] New: segfault from static_assert with user-defined string suffix argument Jack at Applin dot US
@ 2022-04-19 14:11 ` marxin at gcc dot gnu.org
2022-04-19 17:17 ` marxin at gcc dot gnu.org
` (7 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: marxin at gcc dot gnu.org @ 2022-04-19 14:11 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105300
Martin Liška <marxin at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Ever confirmed|0 |1
CC| |marxin at gcc dot gnu.org
Last reconfirmed| |2022-04-19
Status|UNCONFIRMED |WAITING
--- Comment #1 from Martin Liška <marxin at gcc dot gnu.org> ---
Is it really a valid code since clang rejects it?
$ clang++ pr105300.C -c
pr105300.C:2:27: error: string literal with user-defined suffix cannot be used
here
static_assert(false, "foo"_x);
^
1 error generated.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/105300] segfault from static_assert with user-defined string suffix argument
2022-04-18 3:51 [Bug c++/105300] New: segfault from static_assert with user-defined string suffix argument Jack at Applin dot US
2022-04-19 14:11 ` [Bug c++/105300] " marxin at gcc dot gnu.org
@ 2022-04-19 17:17 ` marxin at gcc dot gnu.org
2022-11-03 0:21 ` [Bug c++/105300] [10/11/12/13 Regression] " pinskia at gcc dot gnu.org
` (6 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: marxin at gcc dot gnu.org @ 2022-04-19 17:17 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105300
Martin Liška <marxin at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|WAITING |NEW
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/105300] [10/11/12/13 Regression] segfault from static_assert with user-defined string suffix argument
2022-04-18 3:51 [Bug c++/105300] New: segfault from static_assert with user-defined string suffix argument Jack at Applin dot US
2022-04-19 14:11 ` [Bug c++/105300] " marxin at gcc dot gnu.org
2022-04-19 17:17 ` marxin at gcc dot gnu.org
@ 2022-11-03 0:21 ` pinskia at gcc dot gnu.org
2022-11-03 0:32 ` pinskia at gcc dot gnu.org
` (5 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-11-03 0:21 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105300
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|--- |10.5
Known to fail| |6.1.0
Summary|segfault from static_assert |[10/11/12/13 Regression]
|with user-defined string |segfault from static_assert
|suffix argument |with user-defined string
| |suffix argument
Keywords| |diagnostic
Known to work| |5.5.0
--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
MSVC produces a decent error message:
<source>(2): error C3690: expected a string literal, but found a user-defined
string literal instead
Note best definition of the operator is just:
void operator""_x(const char *, decltype(sizeof(0)));
static_assert(false, "foo"_x);
Oh we started to ICE between GCC 5 and 6. Most likely when we started to print
out the message too.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/105300] [10/11/12/13 Regression] segfault from static_assert with user-defined string suffix argument
2022-04-18 3:51 [Bug c++/105300] New: segfault from static_assert with user-defined string suffix argument Jack at Applin dot US
` (2 preceding siblings ...)
2022-11-03 0:21 ` [Bug c++/105300] [10/11/12/13 Regression] " pinskia at gcc dot gnu.org
@ 2022-11-03 0:32 ` pinskia at gcc dot gnu.org
2022-11-11 20:39 ` mpolacek at gcc dot gnu.org
` (4 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-11-03 0:32 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105300
--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Something like:
diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc
index 7c5f90b5127..185e0ac53f7 100644
--- a/gcc/cp/semantics.cc
+++ b/gcc/cp/semantics.cc
@@ -11203,6 +11203,13 @@ finish_static_assert (tree condition, tree message,
location_t location,
if (check_for_bare_parameter_packs (condition))
condition = error_mark_node;
+ if (TREE_CODE (message) != STRING_CST)
+ {
+ location_t mloc = cp_expr_loc_or_loc (message, location);
+ error_at (mloc, "user defined suffix not expected here");
+ return;
+ }
+
if (instantiation_dependent_expression_p (condition))
{
/* We're in a template; build a STATIC_ASSERT and put it in
Should fix this I think ....
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/105300] [10/11/12/13 Regression] segfault from static_assert with user-defined string suffix argument
2022-04-18 3:51 [Bug c++/105300] New: segfault from static_assert with user-defined string suffix argument Jack at Applin dot US
` (3 preceding siblings ...)
2022-11-03 0:32 ` pinskia at gcc dot gnu.org
@ 2022-11-11 20:39 ` mpolacek at gcc dot gnu.org
2022-12-20 13:39 ` rguenth at gcc dot gnu.org
` (3 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2022-11-11 20:39 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105300
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Assignee|unassigned at gcc dot gnu.org |mpolacek at gcc dot gnu.org
CC| |mpolacek at gcc dot gnu.org
Status|NEW |ASSIGNED
--- Comment #4 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
We also crash on
asm (""_x);
but not
extern ""_x { void g(); }
A more complete test:
// PR c++/105300
void operator""_x(const char *, decltype(sizeof(0)));
static_assert(false, "foo"_x);
extern ""_x { void g(); }
void
lol ()
{
asm (""_x);
}
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/105300] [10/11/12/13 Regression] segfault from static_assert with user-defined string suffix argument
2022-04-18 3:51 [Bug c++/105300] New: segfault from static_assert with user-defined string suffix argument Jack at Applin dot US
` (4 preceding siblings ...)
2022-11-11 20:39 ` mpolacek at gcc dot gnu.org
@ 2022-12-20 13:39 ` rguenth at gcc dot gnu.org
2023-01-26 15:08 ` cvs-commit at gcc dot gnu.org
` (2 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-12-20 13:39 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105300
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Priority|P3 |P2
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/105300] [10/11/12/13 Regression] segfault from static_assert with user-defined string suffix argument
2022-04-18 3:51 [Bug c++/105300] New: segfault from static_assert with user-defined string suffix argument Jack at Applin dot US
` (5 preceding siblings ...)
2022-12-20 13:39 ` rguenth at gcc dot gnu.org
@ 2023-01-26 15:08 ` cvs-commit at gcc dot gnu.org
2023-01-26 15:21 ` [Bug c++/105300] [10/11/12 " mpolacek at gcc dot gnu.org
2023-04-10 7:24 ` jakub at gcc dot gnu.org
8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-01-26 15:08 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105300
--- Comment #5 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The trunk branch has been updated by Marek Polacek <mpolacek@gcc.gnu.org>:
https://gcc.gnu.org/g:9f353b0c1dc9385ba8b8a64b65d66d5452383c11
commit r13-5390-g9f353b0c1dc9385ba8b8a64b65d66d5452383c11
Author: Marek Polacek <polacek@redhat.com>
Date: Fri Nov 11 17:59:30 2022 -0500
c++: Reject UDLs in certain contexts [PR105300]
In this PR, we are crashing because we've encountered a UDL where a
string-literal is expected. This patch makes the parser reject string
and character UDLs in all places where the grammar requires a
string-literal and not a user-defined-string-literal.
I've introduced two new wrappers; the existing cp_parser_string_literal
was renamed to cp_parser_string_literal_common and should not be called
directly. finish_userdef_string_literal is renamed from
cp_parser_userdef_string_literal.
PR c++/105300
gcc/c-family/ChangeLog:
* c-pragma.cc (handle_pragma_message): Warn for CPP_STRING_USERDEF.
gcc/cp/ChangeLog:
* parser.cc: Remove unnecessary forward declarations.
(cp_parser_string_literal): New wrapper.
(cp_parser_string_literal_common): Renamed from
cp_parser_string_literal. Add a bool parameter. Give an error
when
UDLs are not permitted.
(cp_parser_userdef_string_literal): New wrapper.
(finish_userdef_string_literal): Renamed from
cp_parser_userdef_string_literal.
(cp_parser_primary_expression): Call
cp_parser_userdef_string_literal
instead of cp_parser_string_literal.
(cp_parser_linkage_specification): Move a variable declaration
closer
to its first use.
(cp_parser_static_assert): Likewise.
(cp_parser_operator): Call cp_parser_userdef_string_literal instead
of
cp_parser_string_literal.
(cp_parser_asm_definition): Move a variable declaration closer to
its
first use.
(cp_parser_asm_specification_opt): Move variable declarations
closer to
their first use.
(cp_parser_asm_operand_list): Likewise.
(cp_parser_asm_clobber_list): Likewise.
gcc/testsuite/ChangeLog:
* g++.dg/cpp0x/udlit-error1.C: New test.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/105300] [10/11/12 Regression] segfault from static_assert with user-defined string suffix argument
2022-04-18 3:51 [Bug c++/105300] New: segfault from static_assert with user-defined string suffix argument Jack at Applin dot US
` (6 preceding siblings ...)
2023-01-26 15:08 ` cvs-commit at gcc dot gnu.org
@ 2023-01-26 15:21 ` mpolacek at gcc dot gnu.org
2023-04-10 7:24 ` jakub at gcc dot gnu.org
8 siblings, 0 replies; 10+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2023-01-26 15:21 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105300
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |FIXED
Status|ASSIGNED |RESOLVED
Summary|[10/11/12/13 Regression] |[10/11/12 Regression]
|segfault from static_assert |segfault from static_assert
|with user-defined string |with user-defined string
|suffix argument |suffix argument
--- Comment #6 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Fixed for GCC 13. I don't think I want to backport the patch.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/105300] [10/11/12 Regression] segfault from static_assert with user-defined string suffix argument
2022-04-18 3:51 [Bug c++/105300] New: segfault from static_assert with user-defined string suffix argument Jack at Applin dot US
` (7 preceding siblings ...)
2023-01-26 15:21 ` [Bug c++/105300] [10/11/12 " mpolacek at gcc dot gnu.org
@ 2023-04-10 7:24 ` jakub at gcc dot gnu.org
8 siblings, 0 replies; 10+ messages in thread
From: jakub at gcc dot gnu.org @ 2023-04-10 7:24 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105300
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |stevenxia990430 at gmail dot com
--- Comment #7 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
*** Bug 109459 has been marked as a duplicate of this bug. ***
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2023-04-10 7:24 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-18 3:51 [Bug c++/105300] New: segfault from static_assert with user-defined string suffix argument Jack at Applin dot US
2022-04-19 14:11 ` [Bug c++/105300] " marxin at gcc dot gnu.org
2022-04-19 17:17 ` marxin at gcc dot gnu.org
2022-11-03 0:21 ` [Bug c++/105300] [10/11/12/13 Regression] " pinskia at gcc dot gnu.org
2022-11-03 0:32 ` pinskia at gcc dot gnu.org
2022-11-11 20:39 ` mpolacek at gcc dot gnu.org
2022-12-20 13:39 ` rguenth at gcc dot gnu.org
2023-01-26 15:08 ` cvs-commit at gcc dot gnu.org
2023-01-26 15:21 ` [Bug c++/105300] [10/11/12 " mpolacek at gcc dot gnu.org
2023-04-10 7:24 ` jakub 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).