Message ID | 000601d8321b$716d1670$54474350$@nextmovesoftware.com |
---|---|
State | New |
Headers | show |
Series | [C++] PR c++/96329: ICE-on-invalid-code error recovery. | expand |
On 3/7/22 08:04, Roger Sayle wrote: > > This patch fixes PR c++/96329 which is an ICE-on-invalid-code regression > affecting mainline. > > This patch has been tested on x86_64-pc-linux-gnu, enabling languages > c and c++, with make bootstrap and make -k check with no new failures. > Ok for mainline? > > 2022-03-07 Roger Sayle <roger@nextmovesoftware.com> > > gcc/cp/ChangeLog > PR c++/96329 > * parser.cc (cp_parser_linkage_specification): Treat the case where > linkage is error_mark_node as "invalid linkage-specification". > > gcc/testsuite/ChangeLog > PR c++/96329 > * g++.dg/pr96329.C: New test case. > +/* { dg-options "-O2" } */ Is this necessary for the failure? That would be surprising for a parser issue. And this should probably go in g++.dg/template. OK with those adjustments. Jason
diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc index 03d99ab..d2993c7 100644 --- a/gcc/cp/parser.cc +++ b/gcc/cp/parser.cc @@ -16148,8 +16148,9 @@ cp_parser_linkage_specification (cp_parser* parser, tree prefix_attr) /* Transform the literal into an identifier. If the literal is a wide-character string, or contains embedded NULs, then we can't handle it as the user wants. */ - if (strlen (TREE_STRING_POINTER (linkage)) - != (size_t) (TREE_STRING_LENGTH (linkage) - 1)) + if (linkage == error_mark_node + || strlen (TREE_STRING_POINTER (linkage)) + != (size_t) (TREE_STRING_LENGTH (linkage) - 1)) { cp_parser_error (parser, "invalid linkage-specification"); /* Assume C++ linkage. */ diff --git a/gcc/testsuite/g++.dg/pr96329.C b/gcc/testsuite/g++.dg/pr96329.C new file mode 100644 index 0000000..c9f44b7 --- /dev/null +++ b/gcc/testsuite/g++.dg/pr96329.C @@ -0,0 +1,5 @@ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ +/* { dg-excess-errors "" } */ + +extern "C" ""a