Skip to content

Commit ccbba2c

Browse files
committed
[OpenACC] Fix assert when parsing 'bind' clause
I'd misunderstood how the ParseStringLiteralExpression function worked, so I assumed it would catch non-string literals, however it instead asserted. This patch now checks for that case and diagnoses. Fixes: llvm#139346
1 parent 939bb4e commit ccbba2c

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

clang/include/clang/Basic/DiagnosticParseKinds.td

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1469,7 +1469,8 @@ def err_acc_expected_reduction_operator
14691469
def err_acc_invalid_reduction_operator
14701470
: Error<"invalid reduction operator, expected '+', '*', 'max', 'min', "
14711471
"'&', '|', '^', '&&', or '||'">;
1472-
def err_acc_incorrect_bind_arg : Error<"expected identifier or string literal">;
1472+
def err_acc_incorrect_bind_arg
1473+
: Error<"expected identifier or string literal in OpenACC 'bind' clause">;
14731474
def err_acc_modifier
14741475
: Error<"%enum_select<ACCModifier>{%Unknown{unknown}|%Duplicate{duplicate}}"
14751476
"0 modifier %1 in OpenACC modifier-list on '%2' clause">;

clang/lib/Parse/ParseOpenACC.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1429,6 +1429,11 @@ Parser::ParseOpenACCBindClauseArgument() {
14291429
return II;
14301430
}
14311431

1432+
if (!tok::isStringLiteral(getCurToken().getKind())) {
1433+
Diag(getCurToken(), diag::err_acc_incorrect_bind_arg);
1434+
return std::monostate{};
1435+
}
1436+
14321437
ExprResult Res =
14331438
getActions().CorrectDelayedTyposInExpr(ParseStringLiteralExpression(
14341439
/*AllowUserDefinedLiteral=*/false, /*Unevaluated=*/true));

clang/test/ParserOpenACC/parse-clauses.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1345,9 +1345,15 @@ void bar();
13451345
#pragma acc routine seq bind
13461346
void BCP1();
13471347

1348-
// expected-error@+1{{expected identifier or string literal}}
1348+
// expected-error@+1{{expected identifier or string literal in OpenACC 'bind' clause}}
13491349
#pragma acc routine(BCP1) seq bind()
13501350

1351+
// expected-error@+1{{expected identifier or string literal in OpenACC 'bind' clause}}
1352+
#pragma acc routine(BCP1) seq bind(1)
1353+
1354+
// expected-error@+1{{expected identifier or string literal in OpenACC 'bind' clause}}
1355+
#pragma acc routine(BCP1) gang bind(0xF)
1356+
13511357
// expected-error@+1{{expected function or lambda declaration for 'routine' construct}}
13521358
#pragma acc routine seq bind("ReductionClauseParsing")
13531359

0 commit comments

Comments
 (0)