|
26 | 26 | using namespace llvm; |
27 | 27 | using namespace clang; |
28 | 28 |
|
| 29 | + |
| 30 | +// Check if the compound statement is a function body |
| 31 | +// Used in both visitors so abstracted to a function |
| 32 | +bool isTopLevel(ASTContext *Context, CompoundStmt *S) { |
| 33 | + const auto &Parents = Context->getParents(*S); |
| 34 | + if (Parents.empty()) { |
| 35 | + return false; |
| 36 | + } |
| 37 | + // Ensure that our parent is a functiondecl |
| 38 | + return Parents[0].get<FunctionDecl>() != nullptr; |
| 39 | +} |
| 40 | + |
29 | 41 | // CheckedRegionAdder |
30 | 42 |
|
31 | 43 | bool CheckedRegionAdder::VisitCompoundStmt(CompoundStmt *S) { |
@@ -93,13 +105,6 @@ CheckedRegionAdder::findParentCompound(const ast_type_traits::DynTypedNode &N, |
93 | 105 | } |
94 | 106 |
|
95 | 107 |
|
96 | | -bool isTopLevel(ASTContext *Context, CompoundStmt *S) { |
97 | | - const auto &Parents = Context->getParents(*S); |
98 | | - if (Parents.empty()) { |
99 | | - return false; |
100 | | - } |
101 | | - return Parents[0].get<FunctionDecl>(); |
102 | | -} |
103 | 108 |
|
104 | 109 | bool CheckedRegionAdder::isFunctionBody(CompoundStmt *S) { |
105 | 110 | return isTopLevel(Context, S); |
@@ -171,7 +176,7 @@ bool CheckedRegionFinder::VisitCompoundStmt(CompoundStmt *S) { |
171 | 176 | const auto &Parents = Context->getParents(*S); |
172 | 177 | assert(!Parents.empty()); |
173 | 178 | FunctionDecl* Parent = const_cast<FunctionDecl*>(Parents[0].get<FunctionDecl>()); |
174 | | - assert(Parent != NULL); |
| 179 | + assert(Parent != nullptr); |
175 | 180 | auto retType = Parent->getReturnType().getTypePtr(); |
176 | 181 | if (retType->isPointerType()) { |
177 | 182 | CVarOption CV = Info.getVariable(Parent, Context); |
|
0 commit comments