Skip to content

Commit 8d2ab2a

Browse files
committed
[OpenACC][NFC] Fix EndLoc behavior of optional clause params
It was discovered while writing the 'wait' clause ast tests that the 'endloc' wasn't set correctly when there was no arguments. This patch ensures we set it right, and adds an assert to prevent us from messing it up in the future.
1 parent 6f1013a commit 8d2ab2a

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

clang/include/clang/AST/OpenACCClause.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ class OpenACCClause {
2626
protected:
2727
OpenACCClause(OpenACCClauseKind K, SourceLocation BeginLoc,
2828
SourceLocation EndLoc)
29-
: Kind(K), Location(BeginLoc, EndLoc) {}
29+
: Kind(K), Location(BeginLoc, EndLoc) {
30+
assert(!BeginLoc.isInvalid() && !EndLoc.isInvalid() &&
31+
"Begin and end location must be valid for OpenACCClause");
32+
}
3033

3134
public:
3235
OpenACCClauseKind getClauseKind() const { return Kind; }

clang/lib/Parse/ParseOpenACC.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1112,6 +1112,10 @@ Parser::OpenACCClauseParseResult Parser::ParseOpenACCClauseParams(
11121112
ParsedClause.setEndLoc(getCurToken().getLocation());
11131113
if (Parens.consumeClose())
11141114
return OpenACCCannotContinue();
1115+
} else {
1116+
// If we have optional parens, make sure we set the end-location to the
1117+
// clause, as we are a 'single token' clause.
1118+
ParsedClause.setEndLoc(ClauseLoc);
11151119
}
11161120
}
11171121
return OpenACCSuccess(

0 commit comments

Comments
 (0)