diff options
author | Segher Boessenkool <segher@kernel.crashing.org> | 2018-12-19 17:16:05 +0100 |
---|---|---|
committer | Segher Boessenkool <segher@gcc.gnu.org> | 2018-12-19 17:16:05 +0100 |
commit | 1edf88662b51da93460b6139344edb5f9b943b0e (patch) | |
tree | 4074dd0bc5bdd8115294b76ba0ef8f2f85e76a2a /gcc | |
parent | db4fd626ee2bb431adadddf5eca5fba104cea5ca (diff) | |
download | gcc-1edf88662b51da93460b6139344edb5f9b943b0e.zip gcc-1edf88662b51da93460b6139344edb5f9b943b0e.tar.gz gcc-1edf88662b51da93460b6139344edb5f9b943b0e.tar.bz2 |
c/c++, asm: Use nicer error for const and restrict
Not all qualifiers are asm qualifiers. We can talk about that in a
nicer way than just giving a generic parser error.
This also adds two testcases for C++, that previously were for C only.
c/
* c-parser.c (c_parser_asm_statement) <RID_CONST, RID_RESTRICT>: Give
a more specific error message (instead of just falling through).
cp/
* parser.c (cp_parser_asm_definition) <RID_CONST, RID_RESTRICT>: Give
a more specific error message (instead of just falling through).
testsuite/
* g++.dg/asm-qual-1.C: New testcase.
* g++.dg/asm-qual-2.C: New testcase.
* gcc.dg/asm-qual-1.c: Update.
From-SVN: r267279
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/c/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/c/c-parser.c | 6 | ||||
-rw-r--r-- | gcc/cp/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/cp/parser.c | 6 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/asm-qual-1.C | 13 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/asm-qual-2.C | 46 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/asm-qual-1.c | 6 |
8 files changed, 89 insertions, 4 deletions
diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog index 52b2c65..6e12dda 100644 --- a/gcc/c/ChangeLog +++ b/gcc/c/ChangeLog @@ -1,5 +1,10 @@ 2018-12-19 Segher Boessenkool <segher@kernel.crashing.org> + * c-parser.c (c_parser_asm_statement) <RID_CONST, RID_RESTRICT>: Give + a more specific error message (instead of just falling through). + +2018-12-19 Segher Boessenkool <segher@kernel.crashing.org> + * c-parser.c (c_parser_asm_statement): Keep track of the location each asm qualifier is first seen; use that to give nicer "duplicate asm qualifier" messages. Delete 'quals" variable, instead pass the diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c index 652e53c..0def497 100644 --- a/gcc/c/c-parser.c +++ b/gcc/c/c-parser.c @@ -6411,6 +6411,12 @@ c_parser_asm_statement (c_parser *parser) c_parser_consume_token (parser); continue; + case RID_CONST: + case RID_RESTRICT: + error_at (loc, "%qE is not an asm qualifier", token->value); + c_parser_consume_token (parser); + continue; + default: break; } diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index eb54a52..4f84686 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,10 @@ 2018-12-19 Segher Boessenkool <segher@kernel.crashing.org> + * parser.c (cp_parser_asm_definition) <RID_CONST, RID_RESTRICT>: Give + a more specific error message (instead of just falling through). + +2018-12-19 Segher Boessenkool <segher@kernel.crashing.org> + * parser.c (cp_parser_asm_definition): Rewrite the loop to work without "done" boolean variable. * parser.c (cp_parser_asm_definition): Keep track of the location each diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index b860fc4..c4b969c 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -19743,6 +19743,12 @@ cp_parser_asm_definition (cp_parser* parser) cp_lexer_consume_token (parser->lexer); continue; + case RID_CONST: + case RID_RESTRICT: + error_at (loc, "%qT is not an asm qualifier", token->u.value); + cp_lexer_consume_token (parser->lexer); + continue; + default: break; } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index b996242..d5b9973 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2018-12-19 Segher Boessenkool <segher@kernel.crashing.org> + + * g++.dg/asm-qual-1.C: New testcase. + * g++.dg/asm-qual-2.C: New testcase. + * gcc.dg/asm-qual-1.c: Update. + 2018-12-19 David Malcolm <dmalcolm@redhat.com> PR c++/88375 diff --git a/gcc/testsuite/g++.dg/asm-qual-1.C b/gcc/testsuite/g++.dg/asm-qual-1.C new file mode 100644 index 0000000..3fba592 --- /dev/null +++ b/gcc/testsuite/g++.dg/asm-qual-1.C @@ -0,0 +1,13 @@ +// Test that qualifiers other than volatile are disallowed on asm. +// { dg-do compile } +// { dg-options "-std=gnu++98" } + +void +f () +{ + asm volatile (""); + + asm const (""); // { dg-error {'const' is not an asm qualifier} } + + asm __restrict (""); // { dg-error {'__restrict' is not an asm qualifier} } +} diff --git a/gcc/testsuite/g++.dg/asm-qual-2.C b/gcc/testsuite/g++.dg/asm-qual-2.C new file mode 100644 index 0000000..52968bd --- /dev/null +++ b/gcc/testsuite/g++.dg/asm-qual-2.C @@ -0,0 +1,46 @@ +// Test that qualifiers on asm are allowed in any order. +// { dg-do compile } +// { dg-options "-std=c++98" } + +void +f () +{ + asm volatile goto ("" :::: lab); + asm volatile inline ("" :::); + asm inline volatile ("" :::); + asm inline goto ("" :::: lab); + asm goto volatile ("" :::: lab); + asm goto inline ("" :::: lab); + + asm volatile inline goto ("" :::: lab); + asm volatile goto inline ("" :::: lab); + asm inline volatile goto ("" :::: lab); + asm inline goto volatile ("" :::: lab); + asm goto volatile inline ("" :::: lab); + asm goto inline volatile ("" :::: lab); + + /* Duplicates are not allowed. */ + asm goto volatile volatile ("" :::: lab); /* { dg-error "" } */ + asm volatile goto volatile ("" :::: lab); /* { dg-error "" } */ + asm volatile volatile goto ("" :::: lab); /* { dg-error "" } */ + asm goto goto volatile ("" :::: lab); /* { dg-error "" } */ + asm goto volatile goto ("" :::: lab); /* { dg-error "" } */ + asm volatile goto goto ("" :::: lab); /* { dg-error "" } */ + + asm inline volatile volatile ("" :::); /* { dg-error "" } */ + asm volatile inline volatile ("" :::); /* { dg-error "" } */ + asm volatile volatile inline ("" :::); /* { dg-error "" } */ + asm inline inline volatile ("" :::); /* { dg-error "" } */ + asm inline volatile inline ("" :::); /* { dg-error "" } */ + asm volatile inline inline ("" :::); /* { dg-error "" } */ + + asm goto inline inline ("" :::: lab); /* { dg-error "" } */ + asm inline goto inline ("" :::: lab); /* { dg-error "" } */ + asm inline inline goto ("" :::: lab); /* { dg-error "" } */ + asm goto goto inline ("" :::: lab); /* { dg-error "" } */ + asm goto inline goto ("" :::: lab); /* { dg-error "" } */ + asm inline goto goto ("" :::: lab); /* { dg-error "" } */ + +lab: + ; +} diff --git a/gcc/testsuite/gcc.dg/asm-qual-1.c b/gcc/testsuite/gcc.dg/asm-qual-1.c index cb37283..eff6b45 100644 --- a/gcc/testsuite/gcc.dg/asm-qual-1.c +++ b/gcc/testsuite/gcc.dg/asm-qual-1.c @@ -8,9 +8,7 @@ f (void) { asm volatile (""); - asm const (""); /* { dg-error {expected '\(' before 'const'} } */ - /* { dg-error {expected identifier} {} {target *-*-*} .-1 } */ + asm const (""); /* { dg-error {'const' is not an asm qualifier} } */ - asm restrict (""); /* { dg-error {expected '\(' before 'restrict'} } */ - /* { dg-error {expected identifier} {} {target *-*-*} .-1 } */ + asm restrict (""); /* { dg-error {'restrict' is not an asm qualifier} } */ } |