diff --git a/clang/include/clang/AST/OpenACCClause.h b/clang/include/clang/AST/OpenACCClause.h index e7b0b411b654fd..125c2af7933080 100644 --- a/clang/include/clang/AST/OpenACCClause.h +++ b/clang/include/clang/AST/OpenACCClause.h @@ -26,7 +26,10 @@ class OpenACCClause { protected: OpenACCClause(OpenACCClauseKind K, SourceLocation BeginLoc, SourceLocation EndLoc) - : Kind(K), Location(BeginLoc, EndLoc) {} + : Kind(K), Location(BeginLoc, EndLoc) { + assert(!BeginLoc.isInvalid() && !EndLoc.isInvalid() && + "Begin and end location must be valid for OpenACCClause"); + } public: OpenACCClauseKind getClauseKind() const { return Kind; } diff --git a/clang/lib/Parse/ParseOpenACC.cpp b/clang/lib/Parse/ParseOpenACC.cpp index 8c8330a5fad75a..727854db9be1f7 100644 --- a/clang/lib/Parse/ParseOpenACC.cpp +++ b/clang/lib/Parse/ParseOpenACC.cpp @@ -1112,6 +1112,10 @@ Parser::OpenACCClauseParseResult Parser::ParseOpenACCClauseParams( ParsedClause.setEndLoc(getCurToken().getLocation()); if (Parens.consumeClose()) return OpenACCCannotContinue(); + } else { + // If we have optional parens, make sure we set the end-location to the + // clause, as we are a 'single token' clause. + ParsedClause.setEndLoc(ClauseLoc); } } return OpenACCSuccess(