|
21 | 21 | #include "clang/AST/ExprCXX.h" |
22 | 22 | #include "clang/AST/ExprObjC.h" |
23 | 23 | #include "clang/AST/RecursiveASTVisitor.h" |
24 | | -#include "clang/Analysis/CallGraph.h" |
| 24 | +#include "clang/Analysis/AnalysisDeclContext.h" |
25 | 25 | #include "clang/Basic/IdentifierTable.h" |
26 | 26 | #include "clang/Basic/LLVM.h" // isa, dyn_cast |
27 | 27 | #include "clang/Basic/SourceLocation.h" |
|
32 | 32 | #include "clang/Sema/TemplateDeduction.h" |
33 | 33 |
|
34 | 34 | #include <algorithm> |
| 35 | +#include <memory> |
35 | 36 | #include <string> |
36 | 37 | #include <utility> |
37 | 38 |
|
@@ -273,9 +274,10 @@ DeclRefExpr* getArgFunction(CallExpr* call, Sema& SemaRef) { |
273 | 274 |
|
274 | 275 | DiffCollector::DiffCollector(DeclGroupRef DGR, DiffInterval& Interval, |
275 | 276 | clad::DynamicGraph<DiffRequest>& requestGraph, |
276 | | - clang::Sema& S, RequestOptions& opts) |
277 | | - : m_Interval(Interval), m_DiffRequestGraph(requestGraph), m_Sema(S), |
278 | | - m_Options(opts) { |
| 277 | + clang::Sema& S, RequestOptions& opts, |
| 278 | + OwnedAnalysisContexts& AllAnalysisDC) |
| 279 | + : m_Interval(Interval), m_DiffRequestGraph(requestGraph), |
| 280 | + m_AllAnalysisDC(AllAnalysisDC), m_Sema(S), m_Options(opts) { |
279 | 281 |
|
280 | 282 | if (Interval.empty()) |
281 | 283 | return; |
@@ -648,13 +650,11 @@ DeclRefExpr* getArgFunction(CallExpr* call, Sema& SemaRef) { |
648 | 650 | if (E->getType()->isPointerType()) |
649 | 651 | return true; |
650 | 652 |
|
651 | | - if (!m_TbrRunInfo.HasAnalysisRun && !isLambdaCallOperator(Function)) { |
| 653 | + if (!m_TbrRunInfo.HasAnalysisRun && !isLambdaCallOperator(Function) && |
| 654 | + Function->isDefined()) { |
652 | 655 | TimedAnalysisRegion R("TBR " + BaseFunctionName); |
653 | | - |
654 | | - TBRAnalyzer analyzer(Function->getASTContext(), |
655 | | - m_TbrRunInfo.ToBeRecorded); |
656 | | - analyzer.Analyze(Function); |
657 | | - m_TbrRunInfo.HasAnalysisRun = true; |
| 656 | + TBRAnalyzer analyzer(m_AnalysisDC, getToBeRecorded()); |
| 657 | + analyzer.Analyze(*this); |
658 | 658 | } |
659 | 659 | auto found = m_TbrRunInfo.ToBeRecorded.find(E->getBeginLoc()); |
660 | 660 | return found != m_TbrRunInfo.ToBeRecorded.end(); |
@@ -1214,22 +1214,27 @@ DeclRefExpr* getArgFunction(CallExpr* call, Sema& SemaRef) { |
1214 | 1214 | request.Function = request.Function->getDefinition(); |
1215 | 1215 |
|
1216 | 1216 | if (!LookupCustomDerivativeDecl(request)) { |
1217 | | - if (m_TopMostReq->EnableVariedAnalysis && |
1218 | | - m_TopMostReq->Mode == DiffMode::reverse) { |
| 1217 | + clang::CFG::BuildOptions Options; |
| 1218 | + std::unique_ptr<AnalysisDeclContext> AnalysisDC = |
| 1219 | + std::make_unique<AnalysisDeclContext>( |
| 1220 | + /*AnalysisDeclContextManager=*/nullptr, request.Function, |
| 1221 | + Options); |
| 1222 | + |
| 1223 | + if (m_TopMostReq->EnableVariedAnalysis) { |
1219 | 1224 | TimedAnalysisRegion R("VA " + request.BaseFunctionName); |
1220 | | - VariedAnalyzer analyzer(request.Function->getASTContext(), |
1221 | | - request.getVariedDecls()); |
| 1225 | + VariedAnalyzer analyzer(AnalysisDC.get(), request.getVariedDecls()); |
1222 | 1226 | analyzer.Analyze(request.Function); |
1223 | 1227 | } |
1224 | 1228 |
|
1225 | 1229 | if (m_TopMostReq->EnableUsefulAnalysis) { |
1226 | 1230 | TimedAnalysisRegion R("UA " + request.BaseFunctionName); |
1227 | | - |
1228 | | - UsefulAnalyzer analyzer(request.Function->getASTContext(), |
1229 | | - request.getUsefulDecls()); |
| 1231 | + UsefulAnalyzer analyzer(AnalysisDC.get(), request.getUsefulDecls()); |
1230 | 1232 | analyzer.Analyze(request.Function); |
1231 | 1233 | } |
1232 | 1234 |
|
| 1235 | + m_AllAnalysisDC.push_back(std::move(AnalysisDC)); |
| 1236 | + request.m_AnalysisDC = m_AllAnalysisDC.back().get(); |
| 1237 | + |
1233 | 1238 | // Recurse into call graph. |
1234 | 1239 | TraverseFunctionDeclOnce(request.Function); |
1235 | 1240 | } |
@@ -1313,9 +1318,19 @@ DeclRefExpr* getArgFunction(CallExpr* call, Sema& SemaRef) { |
1313 | 1318 | if (m_Sema.isStdInitializerList(recordTy, /*elemType=*/nullptr)) |
1314 | 1319 | return true; |
1315 | 1320 |
|
1316 | | - if (!LookupCustomDerivativeDecl(request)) |
| 1321 | + if (!LookupCustomDerivativeDecl(request)) { |
| 1322 | + clang::CFG::BuildOptions Options; |
| 1323 | + std::unique_ptr<AnalysisDeclContext> AnalysisDC = |
| 1324 | + std::make_unique<AnalysisDeclContext>( |
| 1325 | + /*AnalysisDeclContextManager=*/nullptr, request.Function, |
| 1326 | + Options); |
| 1327 | + // FIXME: Add proper support for objects in VA and UA. |
| 1328 | + m_AllAnalysisDC.push_back(std::move(AnalysisDC)); |
| 1329 | + request.m_AnalysisDC = m_AllAnalysisDC.back().get(); |
| 1330 | + |
1317 | 1331 | // Recurse into call graph. |
1318 | 1332 | TraverseFunctionDeclOnce(request.Function); |
| 1333 | + } |
1319 | 1334 | m_DiffRequestGraph.addNode(request, /*isSource=*/true); |
1320 | 1335 |
|
1321 | 1336 | return true; |
|
0 commit comments