Skip to content

Commit 11d48f2

Browse files
author
Simon Moll
committed
[sotoc][fix] decl may be null
1 parent a4513b1 commit 11d48f2

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

clang/tools/sotoc/src/Visitors.cpp

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,13 @@ llvm::Optional<std::string> getSystemHeaderForDecl(clang::Decl *D) {
8585
}
8686

8787
bool FindTargetCodeVisitor::TraverseDecl(clang::Decl *D) {
88-
if (auto *FD = llvm::dyn_cast<clang::FunctionDecl>(D)) {
88+
bool PushedDecl = false;
89+
if (auto *FD = llvm::dyn_cast_or_null<clang::FunctionDecl>(D)) {
8990
LastVisitedFuncDecl.push(FD);
91+
PushedDecl = true;
9092
}
9193
bool ret = clang::RecursiveASTVisitor<FindTargetCodeVisitor>::TraverseDecl(D);
92-
if (auto *FD = llvm::dyn_cast<clang::FunctionDecl>(D)) {
94+
if (PushedDecl) {
9395
LastVisitedFuncDecl.pop();
9496
}
9597
return ret;
@@ -134,9 +136,10 @@ bool FindTargetCodeVisitor::VisitStmt(clang::Stmt *S) {
134136
class CollectOMPClauseParamsVarsVisitor
135137
: public clang::RecursiveASTVisitor<CollectOMPClauseParamsVarsVisitor> {
136138
std::shared_ptr<TargetCodeRegion> TCR;
139+
137140
public:
138141
CollectOMPClauseParamsVarsVisitor(std::shared_ptr<TargetCodeRegion> &TCR)
139-
: TCR(TCR) {};
142+
: TCR(TCR){};
140143

141144
bool VisitStmt(clang::Stmt *S) {
142145
if (auto *DRE = llvm::dyn_cast<clang::DeclRefExpr>(S)) {
@@ -151,15 +154,16 @@ class CollectOMPClauseParamsVarsVisitor
151154
class CollectOMPClauseParamsVisitor
152155
: public clang::RecursiveASTVisitor<CollectOMPClauseParamsVisitor> {
153156

154-
CollectOMPClauseParamsVarsVisitor VarsVisitor;
157+
CollectOMPClauseParamsVarsVisitor VarsVisitor;
155158
bool InExplicitCast;
159+
156160
public:
157161
CollectOMPClauseParamsVisitor(std::shared_ptr<TargetCodeRegion> &TCR)
158-
: VarsVisitor(TCR), InExplicitCast(false) {};
162+
: VarsVisitor(TCR), InExplicitCast(false){};
159163
bool VisitStmt(clang::Stmt *S) {
160164
// This relies on the captured statement being the last child
161165
if (llvm::isa<clang::CapturedStmt>(S)) {
162-
return false;
166+
return false;
163167
}
164168

165169
if (llvm::isa<clang::ImplicitCastExpr>(S)) {
@@ -197,7 +201,8 @@ bool FindTargetCodeVisitor::processTargetRegion(
197201
// if the target region cannot be added we dont want to parse its args
198202
if (TargetCodeInfo.addCodeFragment(TCR)) {
199203

200-
FindArraySectionVisitor(TCR->CapturedLowerBounds).TraverseStmt(TargetDirective);
204+
FindArraySectionVisitor(TCR->CapturedLowerBounds)
205+
.TraverseStmt(TargetDirective);
201206

202207
for (auto C : TargetDirective->clauses()) {
203208
TCR->addOMPClause(C);
@@ -283,7 +288,6 @@ bool FindLoopStmtVisitor::VisitStmt(clang::Stmt *S) {
283288
return true;
284289
}
285290

286-
287291
bool FindDeclRefExprVisitor::VisitStmt(clang::Stmt *S) {
288292
if (auto DRE = llvm::dyn_cast<clang::DeclRefExpr>(S)) {
289293
if (auto DD = llvm::dyn_cast<clang::DeclaratorDecl>(DRE->getDecl())) {
@@ -407,7 +411,8 @@ bool FindPrivateVariablesVisitor::VisitExpr(clang::Expr *E) {
407411

408412
// If the variable is declared outside of the target region it may be a
409413
// private variable
410-
if (SM.isBeforeInTranslationUnit(VD->getLocation(), RegionTopSourceLocation)) {
414+
if (SM.isBeforeInTranslationUnit(VD->getLocation(),
415+
RegionTopSourceLocation)) {
411416
// Add the Variable to our set
412417
VarSet.insert(VD);
413418
}

0 commit comments

Comments
 (0)