From 7c67ff4a1b44996cea0a72d0d9ee585c59fe2934 Mon Sep 17 00:00:00 2001 From: Segher Boessenkool Date: Wed, 19 Dec 2018 17:22:47 +0100 Subject: [PATCH] c++, asm: Do not handle any asm-qualifiers in top-level asm Previously, "volatile" was allowed. Changing this simplifies the code, makes things more regular, and makes the C and C++ frontends handle this the same way. cp/ * parser.c (cp_parser_asm_definition): Do not allow any asm qualifiers on top-level asm. testsuite/ * g++.dg/asm-qual-3.C: New testcase. * gcc.dg/asm-qual-3.c: New testcase. From-SVN: r267280 --- gcc/cp/ChangeLog | 5 +++++ gcc/cp/parser.c | 7 ++----- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/g++.dg/asm-qual-3.C | 12 ++++++++++++ gcc/testsuite/gcc.dg/asm-qual-3.c | 9 +++++++++ 5 files changed, 33 insertions(+), 5 deletions(-) create mode 100644 gcc/testsuite/g++.dg/asm-qual-3.C create mode 100644 gcc/testsuite/gcc.dg/asm-qual-3.c diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 4f84686e411..01d2f576c22 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2018-12-19 Segher Boessenkool + + * parser.c (cp_parser_asm_definition): Do not allow any asm qualifiers + on top-level asm. + 2018-12-19 Segher Boessenkool * parser.c (cp_parser_asm_definition) : Give diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index c4b969c84b9..d6bac826581 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -19699,7 +19699,8 @@ cp_parser_asm_definition (cp_parser* parser) location_t volatile_loc = UNKNOWN_LOCATION; location_t inline_loc = UNKNOWN_LOCATION; location_t goto_loc = UNKNOWN_LOCATION; - if (cp_parser_allow_gnu_extensions_p (parser)) + + if (cp_parser_allow_gnu_extensions_p (parser) && parser->in_function_body) for (;;) { cp_token *token = cp_lexer_peek_token (parser->lexer); @@ -19718,8 +19719,6 @@ cp_parser_asm_definition (cp_parser* parser) continue; case RID_INLINE: - if (!parser->in_function_body) - break; if (inline_loc) { error_at (loc, "duplicate asm qualifier %qT", token->u.value); @@ -19731,8 +19730,6 @@ cp_parser_asm_definition (cp_parser* parser) continue; case RID_GOTO: - if (!parser->in_function_body) - break; if (goto_loc) { error_at (loc, "duplicate asm qualifier %qT", token->u.value); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index d5b99730899..d1ebfc7c346 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2018-12-19 Segher Boessenkool + + * g++.dg/asm-qual-3.C: New testcase. + * gcc.dg/asm-qual-3.c: New testcase. + 2018-12-19 Segher Boessenkool * g++.dg/asm-qual-1.C: New testcase. diff --git a/gcc/testsuite/g++.dg/asm-qual-3.C b/gcc/testsuite/g++.dg/asm-qual-3.C new file mode 100644 index 00000000000..95c9b570a5f --- /dev/null +++ b/gcc/testsuite/g++.dg/asm-qual-3.C @@ -0,0 +1,12 @@ +// Test that asm-qualifiers are not allowed on toplevel asm. +// { dg-do compile } +// { dg-options "-std=gnu++98" } + +asm const (""); // { dg-error {expected '\(' before 'const'} } +asm volatile (""); // { dg-error {expected '\(' before 'volatile'} } +asm restrict (""); // { dg-error {expected '\(' before 'restrict'} } +asm inline (""); // { dg-error {expected '\(' before 'inline'} } +asm goto (""); // { dg-error {expected '\(' before 'goto'} } + +// There are many other things wrong with this code, so: +// { dg-excess-errors "" } diff --git a/gcc/testsuite/gcc.dg/asm-qual-3.c b/gcc/testsuite/gcc.dg/asm-qual-3.c new file mode 100644 index 00000000000..f85d8bff898 --- /dev/null +++ b/gcc/testsuite/gcc.dg/asm-qual-3.c @@ -0,0 +1,9 @@ +/* Test that asm-qualifiers are not allowed on toplevel asm. */ +/* { dg-do compile } */ +/* { dg-options "-std=gnu99" } */ + +asm const (""); /* { dg-error {expected '\(' before 'const'} } */ +asm volatile (""); /* { dg-error {expected '\(' before 'volatile'} } */ +asm restrict (""); /* { dg-error {expected '\(' before 'restrict'} } */ +asm inline (""); /* { dg-error {expected '\(' before 'inline'} } */ +asm goto (""); /* { dg-error {expected '\(' before 'goto'} } */ -- 2.30.2