Skip to content

Commit 63d00b1

Browse files
committed
[OPENMP]Add support for analysis of if clauses.
Summary: Added support for analysis of if clauses in the OpenMP directives to be able to check for the use of uninitialized variables. Reviewers: NoQ Subscribers: guansong, jfb, jdoerfert, caomhin, kkwli0, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D64646 llvm-svn: 366068
1 parent 8d879c8 commit 63d00b1

27 files changed

+494
-239
lines changed

clang/include/clang/AST/OpenMPClause.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -501,11 +501,10 @@ class OMPIfClause : public OMPClause, public OMPClauseWithPreInit {
501501
return const_child_range(&Condition, &Condition + 1);
502502
}
503503

504-
child_range used_children() {
505-
return child_range(child_iterator(), child_iterator());
506-
}
504+
child_range used_children();
507505
const_child_range used_children() const {
508-
return const_child_range(const_child_iterator(), const_child_iterator());
506+
auto Children = const_cast<OMPIfClause *>(this)->used_children();
507+
return const_child_range(Children.begin(), Children.end());
509508
}
510509

511510
static bool classof(const OMPClause *T) {

clang/lib/AST/OpenMPClause.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,25 @@ const OMPClauseWithPostUpdate *OMPClauseWithPostUpdate::get(const OMPClause *C)
209209
return nullptr;
210210
}
211211

212+
/// Gets the address of the original, non-captured, expression used in the
213+
/// clause as the preinitializer.
214+
static Stmt **getAddrOfExprAsWritten(Stmt *S) {
215+
if (!S)
216+
return nullptr;
217+
if (auto *DS = dyn_cast<DeclStmt>(S)) {
218+
assert(DS->isSingleDecl() && "Only single expression must be captured.");
219+
if (auto *OED = dyn_cast<OMPCapturedExprDecl>(DS->getSingleDecl()))
220+
return OED->getInitAddress();
221+
}
222+
return nullptr;
223+
}
224+
225+
OMPClause::child_range OMPIfClause::used_children() {
226+
if (Stmt **C = getAddrOfExprAsWritten(getPreInitStmt()))
227+
return child_range(C, C + 1);
228+
return child_range(&Condition, &Condition + 1);
229+
}
230+
212231
OMPOrderedClause *OMPOrderedClause::Create(const ASTContext &C, Expr *Num,
213232
unsigned NumLoops,
214233
SourceLocation StartLoc,

0 commit comments

Comments
 (0)