[clang] 8d2ab2a - [OpenACC][NFC] Fix EndLoc behavior of optional clause params
via cfe-commits
cfe-commits at lists.llvm.org
Thu May 9 06:44:18 PDT 2024
Author: erichkeane
Date: 2024-05-09T06:44:11-07:00
New Revision: 8d2ab2a0ec168673696930ba3e3c403656cdfe55
URL: https://github.com/llvm/llvm-project/commit/8d2ab2a0ec168673696930ba3e3c403656cdfe55
DIFF: https://github.com/llvm/llvm-project/commit/8d2ab2a0ec168673696930ba3e3c403656cdfe55.diff
LOG: [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.
Added:
Modified:
clang/include/clang/AST/OpenACCClause.h
clang/lib/Parse/ParseOpenACC.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/AST/OpenACCClause.h b/clang/include/clang/AST/OpenACCClause.h
index e7b0b411b654f..125c2af793308 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 8c8330a5fad75..727854db9be1f 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(
More information about the cfe-commits
mailing list