diff options
author | Segher Boessenkool <segher@kernel.crashing.org> | 2018-12-06 18:47:52 +0100 |
---|---|---|
committer | Segher Boessenkool <segher@gcc.gnu.org> | 2018-12-06 18:47:52 +0100 |
commit | 30bd42b979140de02d343bb1014e9aece2e683c1 (patch) | |
tree | 9425afdd3c7769016beca989282d7389695f48ac /gcc/cp/parser.c | |
parent | 415937b37d77d7a8ec11273060d45a04b1f3ca62 (diff) | |
download | gcc-30bd42b979140de02d343bb1014e9aece2e683c1.zip gcc-30bd42b979140de02d343bb1014e9aece2e683c1.tar.gz gcc-30bd42b979140de02d343bb1014e9aece2e683c1.tar.bz2 |
asm qualifiers (PR55681)
PR55681 observes that currently only one qualifier is allowed for
inline asm, so that e.g. "volatile asm" is allowed, "const asm" is also
okay (with a warning), but "const volatile asm" gives an error. Also
"goto" has to be last.
This patch changes things so that only "asm-qualifiers" are allowed,
that is "volatile" and "goto", in any combination, in any order, but
without repetitions.
PR inline-asm/55681
* doc/extend.texi (Basic Asm): Update grammar.
(Extended Asm): Update grammar.
gcc/c/
PR inline-asm/55681
* c-parser.c (c_parser_asm_statement): Update grammar. Allow any
combination of volatile and goto, in any order, without repetitions.
gcc/cp/
PR inline-asm/55681
* parser.c (cp_parser_asm_definition): Update grammar. Allow any
combination of volatile and goto, in any order, without repetitions.
gcc/testsuite/
PR inline-asm/55681
* gcc.dg/asm-qual-1.c: Test that "const" and "restrict" are refused.
* gcc.dg/asm-qual-2.c: New test, test that asm-qualifiers are allowed
in any order, but that duplicates are not allowed.
From-SVN: r266859
Diffstat (limited to 'gcc/cp/parser.c')
-rw-r--r-- | gcc/cp/parser.c | 77 |
1 files changed, 51 insertions, 26 deletions
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index ac19cb4..ac953d0 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -19590,22 +19590,34 @@ cp_parser_using_directive (cp_parser* parser) /* Parse an asm-definition. + asm-qualifier: + volatile + goto + + asm-qualifier-list: + asm-qualifier + asm-qualifier-list asm-qualifier + asm-definition: asm ( string-literal ) ; GNU Extension: asm-definition: - asm volatile [opt] ( string-literal ) ; - asm volatile [opt] ( string-literal : asm-operand-list [opt] ) ; - asm volatile [opt] ( string-literal : asm-operand-list [opt] - : asm-operand-list [opt] ) ; - asm volatile [opt] ( string-literal : asm-operand-list [opt] - : asm-operand-list [opt] + asm asm-qualifier-list [opt] ( string-literal ) ; + asm asm-qualifier-list [opt] ( string-literal : asm-operand-list [opt] ) ; + asm asm-qualifier-list [opt] ( string-literal : asm-operand-list [opt] + : asm-operand-list [opt] ) ; + asm asm-qualifier-list [opt] ( string-literal : asm-operand-list [opt] + : asm-operand-list [opt] : asm-clobber-list [opt] ) ; - asm volatile [opt] goto ( string-literal : : asm-operand-list [opt] - : asm-clobber-list [opt] - : asm-goto-list ) ; */ + asm asm-qualifier-list [opt] ( string-literal : : asm-operand-list [opt] + : asm-clobber-list [opt] + : asm-goto-list ) ; + + The form with asm-goto-list is valid if and only if the asm-qualifier-list + contains goto, and is the only allowed form in that case. No duplicates are + allowed in an asm-qualifier-list. */ static void cp_parser_asm_definition (cp_parser* parser) @@ -19634,23 +19646,36 @@ cp_parser_asm_definition (cp_parser* parser) } /* See if the next token is `volatile'. */ - if (cp_parser_allow_gnu_extensions_p (parser) - && cp_lexer_next_token_is_keyword (parser->lexer, RID_VOLATILE)) - { - /* Remember that we saw the `volatile' keyword. */ - volatile_p = true; - /* Consume the token. */ - cp_lexer_consume_token (parser->lexer); - } - if (cp_parser_allow_gnu_extensions_p (parser) - && parser->in_function_body - && cp_lexer_next_token_is_keyword (parser->lexer, RID_GOTO)) - { - /* Remember that we saw the `goto' keyword. */ - goto_p = true; - /* Consume the token. */ - cp_lexer_consume_token (parser->lexer); - } + if (cp_parser_allow_gnu_extensions_p (parser)) + for (bool done = false; !done ; ) + switch (cp_lexer_peek_token (parser->lexer)->keyword) + { + case RID_VOLATILE: + if (!volatile_p) + { + /* Remember that we saw the `volatile' keyword. */ + volatile_p = true; + /* Consume the token. */ + cp_lexer_consume_token (parser->lexer); + } + else + done = true; + break; + case RID_GOTO: + if (!goto_p && parser->in_function_body) + { + /* Remember that we saw the `goto' keyword. */ + goto_p = true; + /* Consume the token. */ + cp_lexer_consume_token (parser->lexer); + } + else + done = true; + break; + default: + done = true; + } + /* Look for the opening `('. */ if (!cp_parser_require (parser, CPP_OPEN_PAREN, RT_OPEN_PAREN)) return; |