19 #include "llvm/ADT/STLExtras.h" 20 #include "llvm/Support/CrashRecoveryContext.h" 21 #include "llvm/Support/FileSystem.h" 24 using namespace clang;
39 void ModelInjector::onBodySynthesis(
const NamedDecl *D) {
43 if (Bodies.count(D->
getName()) != 0)
50 llvm::StringRef modelPath = analyzerOpts->Config[
"model-path"];
54 if (!modelPath.empty())
56 llvm::StringRef(modelPath.str() +
"/" + D->
getName().str() +
".model");
58 fileName = llvm::StringRef(D->
getName().str() +
".model");
60 if (!llvm::sys::fs::exists(fileName.str())) {
65 auto Invocation = std::make_shared<CompilerInvocation>(CI.
getInvocation());
69 FrontendOpts.Inputs.clear();
70 FrontendOpts.Inputs.emplace_back(fileName, IK);
71 FrontendOpts.DisableFree =
true;
73 Invocation->getDiagnosticOpts().VerifyDiagnostics = 0;
79 Instance.createDiagnostics(
83 Instance.getDiagnostics().setSourceManager(&SM);
90 Instance.setSourceManager(&SM);
94 Instance.getPreprocessor().InitializeForModelFile();
98 const unsigned ThreadStackSize = 8 << 20;
99 llvm::CrashRecoveryContext CRC;
101 CRC.RunSafelyOnThread([&]() { Instance.ExecuteAction(parseModelFile); },
104 Instance.getPreprocessor().FinalizeForModelFile();
106 Instance.resetAndLeakSourceManager();
107 Instance.resetAndLeakFileManager();
108 Instance.resetAndLeakPreprocessor();
An instance of this class is created to represent a function declaration or definition.
CompilerInvocation & getInvocation()
Stmt - This represents one statement.
std::shared_ptr< PCHContainerOperations > getPCHContainerOperations() const
ASTContext & getASTContext() const
ObjCMethodDecl - Represents an instance or class method declaration.
void setMainFileID(FileID FID)
Set the file ID for the main source file.
std::shared_ptr< Preprocessor > getPreprocessorPtr()
AnalyzerOptionsRef getAnalyzerOpts()
Frontend action to parse model files.
Stmt * getBody(const FunctionDecl *D) override
Defines the clang::Preprocessor interface.
This file defines the clang::ento::ModelInjector class which implements the clang::CodeInjector inter...
Defines the clang::IdentifierInfo, clang::IdentifierTable, and clang::Selector interfaces.
CompilerInstance - Helper class for managing a single instance of the Clang compiler.
Diagnostic consumer that forwards diagnostics along to an existing, already-initialized diagnostic co...
An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...
Dataflow Directional Tag Classes.
FileManager & getFileManager() const
Return the current file manager to the caller.
FileID getMainFileID() const
Returns the FileID of the main source file.
vfs::FileSystem & getVirtualFileSystem() const
SourceManager & getSourceManager() const
Return the current source manager.
FrontendOptions - Options for controlling the behavior of the frontend.
void setInvocation(std::shared_ptr< CompilerInvocation > Value)
setInvocation - Replace the current invocation.
DiagnosticConsumer & getDiagnosticClient() const
StringRef getName() const
getName - Get the name of identifier for this declaration as a StringRef.
Defines the clang::FrontendAction interface and various convenience abstract classes (clang::ASTFront...
NamedDecl - This represents a decl with a name.
This class handles loading and caching of source files into memory.
ModelInjector(CompilerInstance &CI)