[clang] 193e900 - [OpenACC][NFC] Fix begin loc and split it from the directive location
via cfe-commits
cfe-commits at lists.llvm.org
Tue May 28 13:39:45 PDT 2024
Author: erichkeane
Date: 2024-05-28T13:39:40-07:00
New Revision: 193e9007ef0bef6c881ab26746221f22ec674447
URL: https://github.com/llvm/llvm-project/commit/193e9007ef0bef6c881ab26746221f22ec674447
DIFF: https://github.com/llvm/llvm-project/commit/193e9007ef0bef6c881ab26746221f22ec674447.diff
LOG: [OpenACC][NFC] Fix begin loc and split it from the directive location
I discovered while working on something else that we were using the
location of the directive name as the 'beginloc' which caused some
problems in a few places. This patch makes it so our beginloc is the
'#' as we originally designed, and then adds a DirectiveLoc concept to a
construct for use diagnosing the name.
Added:
Modified:
clang/include/clang/AST/StmtOpenACC.h
clang/include/clang/Parse/Parser.h
clang/include/clang/Sema/SemaOpenACC.h
clang/lib/AST/StmtOpenACC.cpp
clang/lib/Parse/ParseOpenACC.cpp
clang/lib/Sema/SemaOpenACC.cpp
clang/lib/Sema/TreeTransform.h
clang/lib/Serialization/ASTReaderStmt.cpp
clang/lib/Serialization/ASTWriterStmt.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/AST/StmtOpenACC.h b/clang/include/clang/AST/StmtOpenACC.h
index b706864798baa..04daf511f5871 100644
--- a/clang/include/clang/AST/StmtOpenACC.h
+++ b/clang/include/clang/AST/StmtOpenACC.h
@@ -31,6 +31,8 @@ class OpenACCConstructStmt : public Stmt {
/// The location of the directive statement, from the '#' to the last token of
/// the directive.
SourceRange Range;
+ /// The location of the directive name.
+ SourceLocation DirectiveLoc;
/// The list of clauses. This is stored here as an ArrayRef, as this is the
/// most convienient place to access the list, however the list itself should
@@ -39,8 +41,9 @@ class OpenACCConstructStmt : public Stmt {
protected:
OpenACCConstructStmt(StmtClass SC, OpenACCDirectiveKind K,
- SourceLocation Start, SourceLocation End)
- : Stmt(SC), Kind(K), Range(Start, End) {}
+ SourceLocation Start, SourceLocation DirectiveLoc,
+ SourceLocation End)
+ : Stmt(SC), Kind(K), Range(Start, End), DirectiveLoc(DirectiveLoc) {}
// Used only for initialization, the leaf class can initialize this to
// trailing storage.
@@ -59,6 +62,7 @@ class OpenACCConstructStmt : public Stmt {
SourceLocation getBeginLoc() const { return Range.getBegin(); }
SourceLocation getEndLoc() const { return Range.getEnd(); }
+ SourceLocation getDirectiveLoc() const { return DirectiveLoc; }
ArrayRef<const OpenACCClause *> clauses() const { return Clauses; }
child_range children() {
@@ -81,9 +85,11 @@ class OpenACCAssociatedStmtConstruct : public OpenACCConstructStmt {
protected:
OpenACCAssociatedStmtConstruct(StmtClass SC, OpenACCDirectiveKind K,
- SourceLocation Start, SourceLocation End,
- Stmt *AssocStmt)
- : OpenACCConstructStmt(SC, K, Start, End), AssociatedStmt(AssocStmt) {}
+ SourceLocation Start,
+ SourceLocation DirectiveLoc,
+ SourceLocation End, Stmt *AssocStmt)
+ : OpenACCConstructStmt(SC, K, Start, DirectiveLoc, End),
+ AssociatedStmt(AssocStmt) {}
void setAssociatedStmt(Stmt *S) { AssociatedStmt = S; }
Stmt *getAssociatedStmt() { return AssociatedStmt; }
@@ -126,10 +132,10 @@ class OpenACCComputeConstruct final
friend class ASTStmtReader;
friend class ASTContext;
OpenACCComputeConstruct(unsigned NumClauses)
- : OpenACCAssociatedStmtConstruct(OpenACCComputeConstructClass,
- OpenACCDirectiveKind::Invalid,
- SourceLocation{}, SourceLocation{},
- /*AssociatedStmt=*/nullptr) {
+ : OpenACCAssociatedStmtConstruct(
+ OpenACCComputeConstructClass, OpenACCDirectiveKind::Invalid,
+ SourceLocation{}, SourceLocation{}, SourceLocation{},
+ /*AssociatedStmt=*/nullptr) {
// We cannot send the TrailingObjects storage to the base class (which holds
// a reference to the data) until it is constructed, so we have to set it
// separately here.
@@ -141,11 +147,11 @@ class OpenACCComputeConstruct final
}
OpenACCComputeConstruct(OpenACCDirectiveKind K, SourceLocation Start,
- SourceLocation End,
+ SourceLocation DirectiveLoc, SourceLocation End,
ArrayRef<const OpenACCClause *> Clauses,
Stmt *StructuredBlock)
: OpenACCAssociatedStmtConstruct(OpenACCComputeConstructClass, K, Start,
- End, StructuredBlock) {
+ DirectiveLoc, End, StructuredBlock) {
assert(isOpenACCComputeDirectiveKind(K) &&
"Only parallel, serial, and kernels constructs should be "
"represented by this type");
@@ -169,8 +175,8 @@ class OpenACCComputeConstruct final
unsigned NumClauses);
static OpenACCComputeConstruct *
Create(const ASTContext &C, OpenACCDirectiveKind K, SourceLocation BeginLoc,
- SourceLocation EndLoc, ArrayRef<const OpenACCClause *> Clauses,
- Stmt *StructuredBlock);
+ SourceLocation DirectiveLoc, SourceLocation EndLoc,
+ ArrayRef<const OpenACCClause *> Clauses, Stmt *StructuredBlock);
Stmt *getStructuredBlock() { return getAssociatedStmt(); }
const Stmt *getStructuredBlock() const {
diff --git a/clang/include/clang/Parse/Parser.h b/clang/include/clang/Parse/Parser.h
index 00b475e5b4282..d054b8cf0d240 100644
--- a/clang/include/clang/Parse/Parser.h
+++ b/clang/include/clang/Parse/Parser.h
@@ -3659,6 +3659,7 @@ class Parser : public CodeCompletionHandler {
struct OpenACCDirectiveParseInfo {
OpenACCDirectiveKind DirKind;
SourceLocation StartLoc;
+ SourceLocation DirLoc;
SourceLocation EndLoc;
SmallVector<OpenACCClause *> Clauses;
// TODO OpenACC: As we implement support for the Atomic, Routine, Cache, and
diff --git a/clang/include/clang/Sema/SemaOpenACC.h b/clang/include/clang/Sema/SemaOpenACC.h
index 6f69fa08939b8..66144de4340a8 100644
--- a/clang/include/clang/Sema/SemaOpenACC.h
+++ b/clang/include/clang/Sema/SemaOpenACC.h
@@ -379,7 +379,7 @@ class SemaOpenACC : public SemaBase {
/// Called after the construct has been parsed, but clauses haven't been
/// parsed. This allows us to diagnose not-implemented, as well as set up any
/// state required for parsing the clauses.
- void ActOnConstruct(OpenACCDirectiveKind K, SourceLocation StartLoc);
+ void ActOnConstruct(OpenACCDirectiveKind K, SourceLocation DirLoc);
/// Called after the directive, including its clauses, have been parsed and
/// parsing has consumed the 'annot_pragma_openacc_end' token. This DOES
@@ -400,6 +400,7 @@ class SemaOpenACC : public SemaBase {
/// declaration group or associated statement.
StmtResult ActOnEndStmtDirective(OpenACCDirectiveKind K,
SourceLocation StartLoc,
+ SourceLocation DirLoc,
SourceLocation EndLoc,
ArrayRef<OpenACCClause *> Clauses,
StmtResult AssocStmt);
diff --git a/clang/lib/AST/StmtOpenACC.cpp b/clang/lib/AST/StmtOpenACC.cpp
index a381a8dd7b62c..47899b344c97a 100644
--- a/clang/lib/AST/StmtOpenACC.cpp
+++ b/clang/lib/AST/StmtOpenACC.cpp
@@ -23,15 +23,14 @@ OpenACCComputeConstruct::CreateEmpty(const ASTContext &C, unsigned NumClauses) {
return Inst;
}
-OpenACCComputeConstruct *
-OpenACCComputeConstruct::Create(const ASTContext &C, OpenACCDirectiveKind K,
- SourceLocation BeginLoc, SourceLocation EndLoc,
- ArrayRef<const OpenACCClause *> Clauses,
- Stmt *StructuredBlock) {
+OpenACCComputeConstruct *OpenACCComputeConstruct::Create(
+ const ASTContext &C, OpenACCDirectiveKind K, SourceLocation BeginLoc,
+ SourceLocation DirLoc, SourceLocation EndLoc,
+ ArrayRef<const OpenACCClause *> Clauses, Stmt *StructuredBlock) {
void *Mem = C.Allocate(
OpenACCComputeConstruct::totalSizeToAlloc<const OpenACCClause *>(
Clauses.size()));
- auto *Inst = new (Mem)
- OpenACCComputeConstruct(K, BeginLoc, EndLoc, Clauses, StructuredBlock);
+ auto *Inst = new (Mem) OpenACCComputeConstruct(K, BeginLoc, DirLoc, EndLoc,
+ Clauses, StructuredBlock);
return Inst;
}
diff --git a/clang/lib/Parse/ParseOpenACC.cpp b/clang/lib/Parse/ParseOpenACC.cpp
index e9c60f76165b6..63afc18783a1f 100644
--- a/clang/lib/Parse/ParseOpenACC.cpp
+++ b/clang/lib/Parse/ParseOpenACC.cpp
@@ -1347,11 +1347,13 @@ void Parser::ParseOpenACCCacheVarList() {
ParseOpenACCVarList(OpenACCClauseKind::Invalid);
}
-Parser::OpenACCDirectiveParseInfo Parser::ParseOpenACCDirective() {
- SourceLocation StartLoc = getCurToken().getLocation();
+Parser::OpenACCDirectiveParseInfo
+Parser::ParseOpenACCDirective() {
+ SourceLocation StartLoc = ConsumeAnnotationToken();
+ SourceLocation DirLoc = getCurToken().getLocation();
OpenACCDirectiveKind DirKind = ParseOpenACCDirectiveKind(*this);
- getActions().OpenACC().ActOnConstruct(DirKind, StartLoc);
+ getActions().OpenACC().ActOnConstruct(DirKind, DirLoc);
// Once we've parsed the construct/directive name, some have additional
// specifiers that need to be taken care of. Atomic has an 'atomic-clause'
@@ -1390,7 +1392,7 @@ Parser::OpenACCDirectiveParseInfo Parser::ParseOpenACCDirective() {
break;
case OpenACCDirectiveKind::Wait:
// OpenACC has an optional paren-wrapped 'wait-argument'.
- if (ParseOpenACCWaitArgument(StartLoc, /*IsDirective=*/true).Failed)
+ if (ParseOpenACCWaitArgument(DirLoc, /*IsDirective=*/true).Failed)
T.skipToEnd();
else
T.consumeClose();
@@ -1404,7 +1406,8 @@ Parser::OpenACCDirectiveParseInfo Parser::ParseOpenACCDirective() {
}
// Parses the list of clauses, if present, plus set up return value.
- OpenACCDirectiveParseInfo ParseInfo{DirKind, StartLoc, SourceLocation{},
+ OpenACCDirectiveParseInfo ParseInfo{DirKind, StartLoc, DirLoc,
+ SourceLocation{},
ParseOpenACCClauseList(DirKind)};
assert(Tok.is(tok::annot_pragma_openacc_end) &&
@@ -1421,7 +1424,6 @@ Parser::DeclGroupPtrTy Parser::ParseOpenACCDirectiveDecl() {
assert(Tok.is(tok::annot_pragma_openacc) && "expected OpenACC Start Token");
ParsingOpenACCDirectiveRAII DirScope(*this);
- ConsumeAnnotationToken();
OpenACCDirectiveParseInfo DirInfo = ParseOpenACCDirective();
@@ -1438,7 +1440,6 @@ StmtResult Parser::ParseOpenACCDirectiveStmt() {
assert(Tok.is(tok::annot_pragma_openacc) && "expected OpenACC Start Token");
ParsingOpenACCDirectiveRAII DirScope(*this);
- ConsumeAnnotationToken();
OpenACCDirectiveParseInfo DirInfo = ParseOpenACCDirective();
if (getActions().OpenACC().ActOnStartStmtDirective(DirInfo.DirKind,
@@ -1456,6 +1457,6 @@ StmtResult Parser::ParseOpenACCDirectiveStmt() {
}
return getActions().OpenACC().ActOnEndStmtDirective(
- DirInfo.DirKind, DirInfo.StartLoc, DirInfo.EndLoc, DirInfo.Clauses,
- AssocStmt);
+ DirInfo.DirKind, DirInfo.StartLoc, DirInfo.DirLoc, DirInfo.EndLoc,
+ DirInfo.Clauses, AssocStmt);
}
diff --git a/clang/lib/Sema/SemaOpenACC.cpp b/clang/lib/Sema/SemaOpenACC.cpp
index 09d91b31cfe5f..15239f4f35c39 100644
--- a/clang/lib/Sema/SemaOpenACC.cpp
+++ b/clang/lib/Sema/SemaOpenACC.cpp
@@ -844,7 +844,7 @@ ExprResult SemaOpenACC::CheckReductionVar(Expr *VarExpr) {
}
void SemaOpenACC::ActOnConstruct(OpenACCDirectiveKind K,
- SourceLocation StartLoc) {
+ SourceLocation DirLoc) {
switch (K) {
case OpenACCDirectiveKind::Invalid:
// Nothing to do here, an invalid kind has nothing we can check here. We
@@ -859,7 +859,7 @@ void SemaOpenACC::ActOnConstruct(OpenACCDirectiveKind K,
// here as these constructs do not take any arguments.
break;
default:
- Diag(StartLoc, diag::warn_acc_construct_unimplemented) << K;
+ Diag(DirLoc, diag::warn_acc_construct_unimplemented) << K;
break;
}
}
@@ -1265,6 +1265,7 @@ bool SemaOpenACC::ActOnStartStmtDirective(OpenACCDirectiveKind K,
StmtResult SemaOpenACC::ActOnEndStmtDirective(OpenACCDirectiveKind K,
SourceLocation StartLoc,
+ SourceLocation DirLoc,
SourceLocation EndLoc,
ArrayRef<OpenACCClause *> Clauses,
StmtResult AssocStmt) {
@@ -1278,7 +1279,7 @@ StmtResult SemaOpenACC::ActOnEndStmtDirective(OpenACCDirectiveKind K,
case OpenACCDirectiveKind::Kernels:
// TODO OpenACC: Add clauses to the construct here.
return OpenACCComputeConstruct::Create(
- getASTContext(), K, StartLoc, EndLoc, Clauses,
+ getASTContext(), K, StartLoc, DirLoc, EndLoc, Clauses,
AssocStmt.isUsable() ? AssocStmt.get() : nullptr);
}
llvm_unreachable("Unhandled case in directive handling?");
diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index dee335b526991..765e6177d202d 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -4033,11 +4033,12 @@ class TreeTransform {
StmtResult RebuildOpenACCComputeConstruct(OpenACCDirectiveKind K,
SourceLocation BeginLoc,
+ SourceLocation DirLoc,
SourceLocation EndLoc,
ArrayRef<OpenACCClause *> Clauses,
StmtResult StrBlock) {
- return getSema().OpenACC().ActOnEndStmtDirective(K, BeginLoc, EndLoc,
- Clauses, StrBlock);
+ return getSema().OpenACC().ActOnEndStmtDirective(K, BeginLoc, DirLoc,
+ EndLoc, Clauses, StrBlock);
}
private:
@@ -11559,8 +11560,8 @@ StmtResult TreeTransform<Derived>::TransformOpenACCComputeConstruct(
getSema().OpenACC().ActOnAssociatedStmt(C->getDirectiveKind(), StrBlock);
return getDerived().RebuildOpenACCComputeConstruct(
- C->getDirectiveKind(), C->getBeginLoc(), C->getEndLoc(),
- TransformedClauses, StrBlock);
+ C->getDirectiveKind(), C->getBeginLoc(), C->getDirectiveLoc(),
+ C->getEndLoc(), TransformedClauses, StrBlock);
}
//===----------------------------------------------------------------------===//
diff --git a/clang/lib/Serialization/ASTReaderStmt.cpp b/clang/lib/Serialization/ASTReaderStmt.cpp
index eac4faff28549..bea2b94989107 100644
--- a/clang/lib/Serialization/ASTReaderStmt.cpp
+++ b/clang/lib/Serialization/ASTReaderStmt.cpp
@@ -2797,6 +2797,7 @@ void ASTStmtReader::VisitOpenACCConstructStmt(OpenACCConstructStmt *S) {
(void)Record.readInt();
S->Kind = Record.readEnum<OpenACCDirectiveKind>();
S->Range = Record.readSourceRange();
+ S->DirectiveLoc = Record.readSourceLocation();
Record.readOpenACCClauseList(S->Clauses);
}
diff --git a/clang/lib/Serialization/ASTWriterStmt.cpp b/clang/lib/Serialization/ASTWriterStmt.cpp
index a44852af97bea..3c586b270fbf4 100644
--- a/clang/lib/Serialization/ASTWriterStmt.cpp
+++ b/clang/lib/Serialization/ASTWriterStmt.cpp
@@ -2847,6 +2847,7 @@ void ASTStmtWriter::VisitOpenACCConstructStmt(OpenACCConstructStmt *S) {
Record.push_back(S->clauses().size());
Record.writeEnum(S->Kind);
Record.AddSourceRange(S->Range);
+ Record.AddSourceLocation(S->DirectiveLoc);
Record.writeOpenACCClauseList(S->clauses());
}
More information about the cfe-commits
mailing list