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)
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);
73 FrontendOpts.DisableFree =
true;
75 Invocation->getDiagnosticOpts().VerifyDiagnostics = 0;
81 Instance.createDiagnostics(
85 Instance.getDiagnostics().setSourceManager(&SM);
90 Instance.setSourceManager(&SM);
94 Instance.getPreprocessor().InitializeForModelFile();
98 llvm::CrashRecoveryContext CRC;
100 CRC.RunSafelyOnThread([&]() { Instance.ExecuteAction(parseModelFile); },
103 Instance.getPreprocessor().FinalizeForModelFile();
105 Instance.resetAndLeakSourceManager();
106 Instance.resetAndLeakFileManager();
107 Instance.resetAndLeakPreprocessor();
Represents 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.
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...
constexpr size_t DesiredStackSize
The amount of stack space that Clang would like to be provided with.
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.
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
Get the name of identifier for this declaration as a StringRef.
Defines the clang::FrontendAction interface and various convenience abstract classes (clang::ASTFront...
Defines utilities for dealing with stack allocation and stack space.
Stmt * getBody(const FunctionDecl *D) override
This represents a decl that may have a name.
This class handles loading and caching of source files into memory.
ModelInjector(CompilerInstance &CI)