Skip to content

Commit 731361c

Browse files
committed
[OpenACC] Fix bug with directive name being a 'special token'
If the 'directive name' is a special token instead of an identifier, we end up asserting. This fixes that.
1 parent 965fe35 commit 731361c

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

clang/lib/Parse/ParseOpenACC.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ OpenACCDirectiveKind ParseOpenACCDirectiveKind(Parser &P) {
206206

207207
// Just #pragma acc can get us immediately to the end, make sure we don't
208208
// introspect on the spelling before then.
209-
if (FirstTok.isAnnotation()) {
209+
if (FirstTok.isNot(tok::identifier)) {
210210
P.Diag(FirstTok, diag::err_acc_missing_directive);
211211
return OpenACCDirectiveKind::Invalid;
212212
}
@@ -224,11 +224,8 @@ OpenACCDirectiveKind ParseOpenACCDirectiveKind(Parser &P) {
224224
if (ExDirKind >= OpenACCDirectiveKindEx::Invalid) {
225225
switch (ExDirKind) {
226226
case OpenACCDirectiveKindEx::Invalid: {
227-
if (!FirstTok.is(tok::identifier))
228-
P.Diag(FirstTok, diag::err_expected) << tok::identifier;
229-
else
230-
P.Diag(FirstTok, diag::err_acc_invalid_directive)
231-
<< 0 << FirstTok.getIdentifierInfo();
227+
P.Diag(FirstTok, diag::err_acc_invalid_directive)
228+
<< 0 << FirstTok.getIdentifierInfo();
232229
return OpenACCDirectiveKind::Invalid;
233230
}
234231
case OpenACCDirectiveKindEx::Enter:

clang/test/ParserOpenACC/parse-constructs.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,17 @@ void func() {
77
#pragma acc
88
for(;;){}
99

10+
// expected-error@+4{{expected OpenACC directive}}
11+
// expected-error@+3{{expected clause-list or newline in OpenACC directive}}
12+
// expected-warning@+2{{OpenACC clause parsing not yet implemented}}
13+
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
14+
#pragma acc(whatever) routine
15+
16+
// expected-error@+3{{expected OpenACC directive}}
17+
// expected-warning@+2{{OpenACC clause parsing not yet implemented}}
18+
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
19+
#pragma acc) routine
20+
1021
// expected-error@+2{{invalid OpenACC directive 'invalid'}}
1122
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
1223
#pragma acc invalid

0 commit comments

Comments
 (0)