19 #include "llvm/ADT/STLExtras.h"
20 #include "llvm/Support/CrashRecoveryContext.h"
21 #include "llvm/Support/FileSystem.h"
25 using namespace clang;
40 void ModelInjector::onBodySynthesis(
const NamedDecl *D) {
44 if (Bodies.count(D->
getName()) != 0)
51 llvm::StringRef modelPath = analyzerOpts->Config[
"model-path"];
55 if (!modelPath.empty())
57 llvm::StringRef(modelPath.str() +
"/" + D->
getName().str() +
".model");
59 fileName = llvm::StringRef(D->
getName().str() +
".model");
61 if (!llvm::sys::fs::exists(fileName.str())) {
71 FrontendOpts.
Inputs.clear();
72 FrontendOpts.
Inputs.emplace_back(fileName, IK);
75 Invocation->getDiagnosticOpts().VerifyDiagnostics = 0;
81 Instance.createDiagnostics(
85 Instance.getDiagnostics().setSourceManager(&SM);
92 Instance.setSourceManager(&SM);
96 Instance.getPreprocessor().InitializeForModelFile();
100 const unsigned ThreadStackSize = 8 << 20;
101 llvm::CrashRecoveryContext CRC;
103 CRC.RunSafelyOnThread([&]() { Instance.ExecuteAction(parseModelFile); },
106 Instance.getPreprocessor().FinalizeForModelFile();
108 Instance.resetAndLeakSourceManager();
109 Instance.resetAndLeakFileManager();
110 Instance.resetAndLeakPreprocessor();
ASTContext & getASTContext() const
FunctionDecl - An instance of this class is created to represent a function declaration or definition...
CompilerInvocation & getInvocation()
StringRef getName() const
getName - Get the name of identifier for this declaration as a StringRef.
vfs::FileSystem & getVirtualFileSystem() const
SourceManager & getSourceManager() const
Return the current source manager.
ObjCMethodDecl - Represents an instance or class method declaration.
void setMainFileID(FileID FID)
Set the file ID for the main source file.
DiagnosticConsumer & getDiagnosticClient() const
Preprocessor & getPreprocessor() const
Return the current preprocessor.
AnalyzerOptionsRef getAnalyzerOpts()
Frontend action to parse model files.
Stmt * getBody(const FunctionDecl *D) override
void setInvocation(CompilerInvocation *Value)
setInvocation - Replace the current invocation.
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.
std::vector< FrontendInputFile > Inputs
The input files and their types.
Diagnostic consumer that forwards diagnostics along to an existing, already-initialized diagnostic co...
std::shared_ptr< PCHContainerOperations > getPCHContainerOperations() const
FileID getMainFileID() const
Returns the FileID of the main source file.
An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...
FileManager & getFileManager() const
Return the current file manager to the caller.
Helper class for holding the data necessary to invoke the compiler.
FrontendOptions - Options for controlling the behavior of the frontend.
unsigned DisableFree
Disable memory freeing on exit.
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)