21 #include "llvm/ADT/STLExtras.h"
22 #include "llvm/Support/CrashRecoveryContext.h"
23 #include "llvm/Support/FileSystem.h"
26 using namespace clang;
41 void ModelInjector::onBodySynthesis(
const NamedDecl *D) {
45 if (Bodies.count(D->
getName()) != 0)
49 FileID mainFileID =
SM.getMainFileID();
52 llvm::StringRef modelPath = analyzerOpts->ModelPath;
56 if (!modelPath.empty())
58 llvm::StringRef(modelPath.str() +
"/" + D->
getName().str() +
".model");
60 fileName = llvm::StringRef(D->
getName().str() +
".model");
62 if (!llvm::sys::fs::exists(fileName.str())) {
67 auto Invocation = std::make_shared<CompilerInvocation>(CI.
getInvocation());
71 FrontendOpts.
Inputs.clear();
72 FrontendOpts.
Inputs.emplace_back(fileName, IK);
75 Invocation->getDiagnosticOpts().VerifyDiagnostics = 0;
80 Instance.setInvocation(std::move(Invocation));
81 Instance.createDiagnostics(
85 Instance.getDiagnostics().setSourceManager(&
SM);
90 Instance.setSourceManager(&
SM);
94 Instance.getPreprocessor().InitializeForModelFile();
96 ParseModelFileAction parseModelFile(Bodies);
98 llvm::CrashRecoveryContext CRC;
100 CRC.RunSafelyOnThread([&]() { Instance.ExecuteAction(parseModelFile); },
103 Instance.getPreprocessor().FinalizeForModelFile();
105 Instance.resetAndLeakSourceManager();
106 Instance.resetAndLeakFileManager();
107 Instance.resetAndLeakPreprocessor();
113 SM.setMainFileID(mainFileID);