diff options
Diffstat (limited to 'examples')
-rw-r--r-- | examples/PrintFunctionNames/CMakeLists.txt | 7 | ||||
-rw-r--r-- | examples/PrintFunctionNames/Makefile | 6 | ||||
-rw-r--r-- | examples/PrintFunctionNames/README.txt | 10 | ||||
-rw-r--r-- | examples/clang-interpreter/CMakeLists.txt | 6 | ||||
-rw-r--r-- | examples/clang-interpreter/Makefile | 2 | ||||
-rw-r--r-- | examples/clang-interpreter/main.cpp | 16 | ||||
-rw-r--r-- | examples/wpa/CMakeLists.txt | 6 | ||||
-rw-r--r-- | examples/wpa/Makefile | 2 | ||||
-rw-r--r-- | examples/wpa/clang-wpa.cpp | 60 |
9 files changed, 80 insertions, 35 deletions
diff --git a/examples/PrintFunctionNames/CMakeLists.txt b/examples/PrintFunctionNames/CMakeLists.txt index 5ea75db..86793ce 100644 --- a/examples/PrintFunctionNames/CMakeLists.txt +++ b/examples/PrintFunctionNames/CMakeLists.txt @@ -1,6 +1,11 @@ set(MODULE TRUE) -set(LLVM_NO_RTTI 1) +set( LLVM_USED_LIBS + clangFrontend + clangAST + ) + +set( LLVM_LINK_COMPONENTS support mc) add_clang_library(PrintFunctionNames PrintFunctionNames.cpp) diff --git a/examples/PrintFunctionNames/Makefile b/examples/PrintFunctionNames/Makefile index 125ac48..23a5305 100644 --- a/examples/PrintFunctionNames/Makefile +++ b/examples/PrintFunctionNames/Makefile @@ -18,7 +18,11 @@ EXPORTED_SYMBOL_FILE = $(PROJ_SRC_DIR)/PrintFunctionNames.exports endif endif -LINK_LIBS_IN_SHARED = 1 +LINK_LIBS_IN_SHARED = 0 SHARED_LIBRARY = 1 include $(CLANG_LEVEL)/Makefile + +ifeq ($(OS),Darwin) + LDFLAGS=-Wl,-undefined,dynamic_lookup +endif diff --git a/examples/PrintFunctionNames/README.txt b/examples/PrintFunctionNames/README.txt index 267865c..4c284cd 100644 --- a/examples/PrintFunctionNames/README.txt +++ b/examples/PrintFunctionNames/README.txt @@ -1,10 +1,12 @@ This is a simple example demonstrating how to use clang's facility for providing AST consumers using a plugin. -You will probably need to build clang so that it exports all symbols (disable -TOOL_NO_EXPORT in the tools/clang Makefile). +Build the plugin by running `make` in this directory. Once the plugin is built, you can run it using: -- -$ clang -cc1 -load path/to/PrintFunctionNames.so -plugin print-fns some-input-file.c --- +Linux: +$ clang -cc1 -load ../../Debug+Asserts/lib/libPrintFunctionNames.so -plugin print-fns some-input-file.c + +Mac: +$ clang -cc1 -load ../../Debug+Asserts/lib/libPrintFunctionNames.dylib -plugin print-fns some-input-file.c diff --git a/examples/clang-interpreter/CMakeLists.txt b/examples/clang-interpreter/CMakeLists.txt index 73f28bb..a747b92 100644 --- a/examples/clang-interpreter/CMakeLists.txt +++ b/examples/clang-interpreter/CMakeLists.txt @@ -1,12 +1,12 @@ -set(LLVM_NO_RTTI 1) - set(LLVM_USED_LIBS clangFrontend clangSerialization clangDriver clangCodeGen clangSema - clangChecker + clangStaticAnalyzerFrontend + clangStaticAnalyzerCheckers + clangStaticAnalyzerCore clangIndex clangAnalysis clangRewrite diff --git a/examples/clang-interpreter/Makefile b/examples/clang-interpreter/Makefile index 2f5e017..6e762da 100644 --- a/examples/clang-interpreter/Makefile +++ b/examples/clang-interpreter/Makefile @@ -18,7 +18,7 @@ TOOL_NO_EXPORTS = 1 LINK_COMPONENTS := jit interpreter nativecodegen bitreader bitwriter ipo \ selectiondag asmparser USEDLIBS = clangFrontend.a clangSerialization.a clangDriver.a clangCodeGen.a \ - clangSema.a clangChecker.a clangAnalysis.a clangRewrite.a \ + clangSema.a clangStaticAnalyzerFrontend.a clangStaticAnalyzerCheckers.a clangStaticAnalyzerCore.a clangAnalysis.a clangRewrite.a \ clangAST.a clangParse.a clangLex.a clangBasic.a include $(CLANG_LEVEL)/Makefile diff --git a/examples/clang-interpreter/main.cpp b/examples/clang-interpreter/main.cpp index 2ccba8b..a99766f 100644 --- a/examples/clang-interpreter/main.cpp +++ b/examples/clang-interpreter/main.cpp @@ -17,7 +17,6 @@ #include "clang/Frontend/FrontendDiagnostic.h" #include "clang/Frontend/TextDiagnosticPrinter.h" -#include "llvm/LLVMContext.h" #include "llvm/Module.h" #include "llvm/Config/config.h" #include "llvm/ADT/OwningPtr.h" @@ -26,12 +25,17 @@ #include "llvm/ExecutionEngine/ExecutionEngine.h" #include "llvm/Support/ManagedStatic.h" #include "llvm/Support/raw_ostream.h" -#include "llvm/System/Host.h" -#include "llvm/System/Path.h" +#include "llvm/Support/Host.h" +#include "llvm/Support/Path.h" #include "llvm/Target/TargetSelect.h" using namespace clang; using namespace clang::driver; +// This function isn't referenced outside its translation unit, but it +// can't use the "static" keyword because its address is used for +// GetMainExecutable (since some platforms don't support taking the +// address of main, and some platforms can't implement GetMainExecutable +// without being given the address of a function in the main executable). llvm::sys::Path GetExecutablePath(const char *Argv0) { // This just needs to be some symbol in the binary; C++ doesn't // allow taking the address of ::main however. @@ -39,7 +43,7 @@ llvm::sys::Path GetExecutablePath(const char *Argv0) { return llvm::sys::Path::GetMainExecutable(Argv0, MainAddr); } -int Execute(llvm::Module *Mod, char * const *envp) { +static int Execute(llvm::Module *Mod, char * const *envp) { llvm::InitializeNativeTarget(); std::string Error; @@ -69,7 +73,8 @@ int main(int argc, const char **argv, char * const *envp) { TextDiagnosticPrinter *DiagClient = new TextDiagnosticPrinter(llvm::errs(), DiagnosticOptions()); - Diagnostic Diags(DiagClient); + llvm::IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs()); + Diagnostic Diags(DiagID, DiagClient); Driver TheDriver(Path.str(), llvm::sys::getHostTriple(), "a.out", /*IsProduction=*/false, /*CXXIsProduction=*/false, Diags); @@ -124,7 +129,6 @@ int main(int argc, const char **argv, char * const *envp) { // Create a compiler instance to handle the actual work. CompilerInstance Clang; - Clang.setLLVMContext(new llvm::LLVMContext); Clang.setInvocation(CI.take()); // Create the compilers actual diagnostics engine. diff --git a/examples/wpa/CMakeLists.txt b/examples/wpa/CMakeLists.txt index 13e4298..ad1bb8e 100644 --- a/examples/wpa/CMakeLists.txt +++ b/examples/wpa/CMakeLists.txt @@ -1,5 +1,3 @@ -set(LLVM_NO_RTTI 1) - set(LLVM_USED_LIBS clangIndex clangFrontend @@ -7,7 +5,9 @@ set(LLVM_USED_LIBS clangSema clangAnalysis clangSerialization - clangChecker + clangStaticAnalyzerFrontend + clangStaticAnalyzerCheckers + clangStaticAnalyzerCore clangRewrite clangAST clangParse diff --git a/examples/wpa/Makefile b/examples/wpa/Makefile index 0a70ea6..2ce2040 100644 --- a/examples/wpa/Makefile +++ b/examples/wpa/Makefile @@ -16,7 +16,7 @@ NO_INSTALL = 1 TOOL_NO_EXPORTS = 1 LINK_COMPONENTS := asmparser bitreader mc core -USEDLIBS = clangChecker.a clangIndex.a clangFrontend.a clangDriver.a \ +USEDLIBS = clangStaticAnalyzerFrontend.a clangStaticAnalyzerCheckers.a clangStaticAnalyzerCore.a clangIndex.a clangFrontend.a clangDriver.a \ clangSema.a clangAnalysis.a clangSerialization.a \ clangAST.a clangParse.a clangLex.a clangBasic.a diff --git a/examples/wpa/clang-wpa.cpp b/examples/wpa/clang-wpa.cpp index 41dca0d..bbb9e14 100644 --- a/examples/wpa/clang-wpa.cpp +++ b/examples/wpa/clang-wpa.cpp @@ -14,10 +14,12 @@ #include "clang/Basic/FileManager.h" #include "clang/Basic/SourceManager.h" -#include "clang/Checker/PathSensitive/AnalysisManager.h" -#include "clang/Checker/PathSensitive/GRExprEngine.h" -#include "clang/Checker/PathSensitive/GRTransferFuncs.h" -#include "clang/Checker/Checkers/LocalCheckers.h" +#include "clang/StaticAnalyzer/Frontend/CheckerRegistration.h" +#include "clang/StaticAnalyzer/Core/PathSensitive/AnalysisManager.h" +#include "clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h" +#include "clang/StaticAnalyzer/Core/PathSensitive/TransferFuncs.h" +#include "clang/StaticAnalyzer/Core/CheckerManager.h" +#include "clang/StaticAnalyzer/Checkers/LocalCheckers.h" #include "clang/Frontend/ASTUnit.h" #include "clang/Frontend/CompilerInstance.h" #include "clang/Index/CallGraph.h" @@ -26,6 +28,7 @@ #include "clang/Index/DeclReferenceMap.h" #include "clang/Index/SelectorMap.h" #include "clang/Lex/Preprocessor.h" +#include "clang/Basic/TargetInfo.h" #include "llvm/ADT/IntrusiveRefCntPtr.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/raw_ostream.h" @@ -91,7 +94,9 @@ int main(int argc, char **argv) { = CompilerInstance::createDiagnostics(DiagOpts, argc, argv); for (unsigned i = 0, e = InputFilenames.size(); i != e; ++i) { const std::string &InFile = InputFilenames[i]; - llvm::OwningPtr<ASTUnit> AST(ASTUnit::LoadFromASTFile(InFile, Diags)); + llvm::OwningPtr<ASTUnit> AST(ASTUnit::LoadFromASTFile(InFile, Diags, + FileSystemOptions(), + false, 0, 0, true)); if (!AST) return 1; @@ -129,20 +134,45 @@ int main(int argc, char **argv) { // Create an analysis engine. Preprocessor &PP = TU->getPreprocessor(); - // Hard code options for now. + AnalyzerOptions Opts; + + // Hard code options and checkers for now. + + Opts.MaxNodes = 300000; + Opts.MaxLoop = 3; + Opts.InlineCall = true; + Opts.CFGAddImplicitDtors = true; + Opts.EagerlyTrimEGraph = true; + + Opts.CheckersControlList.push_back(std::make_pair("core", true)); + if (PP.getTargetInfo().getTriple().getOS() != llvm::Triple::Win32) + Opts.CheckersControlList.push_back(std::make_pair("unix", true)); + if (PP.getTargetInfo().getTriple().getVendor() == llvm::Triple::Apple) + Opts.CheckersControlList.push_back(std::make_pair("macosx", true)); + + // Checks to perform for Objective-C/Objective-C++. + if (PP.getLangOptions().ObjC1) + Opts.CheckersControlList.push_back(std::make_pair("cocoa", true)); + + llvm::OwningPtr<ento::CheckerManager> checkerMgr; + checkerMgr.reset(ento::registerCheckers(Opts, PP.getDiagnostics())); + + using namespace clang::ento; AnalysisManager AMgr(TU->getASTContext(), PP.getDiagnostics(), PP.getLangOptions(), /* PathDiagnostic */ 0, CreateRegionStoreManager, - CreateRangeConstraintManager, &Idxer, - /* MaxNodes */ 300000, /* MaxLoop */ 3, - /* VisualizeEG */ false, /* VisualizeEGUbi */ false, - /* PurgeDead */ true, /* EagerlyAssume */ false, - /* TrimGraph */ false, /* InlineCall */ true, - /* UseUnoptimizedCFG */ false); - - GRTransferFuncs* TF = MakeCFRefCountTF(AMgr.getASTContext(), /*GC*/false, + CreateRangeConstraintManager, checkerMgr.get(), &Idxer, + Opts.MaxNodes, Opts.MaxLoop, + Opts.VisualizeEGDot, Opts.VisualizeEGUbi, + Opts.PurgeDead, Opts.EagerlyAssume, + Opts.TrimGraph, Opts.InlineCall, + Opts.UnoptimizedCFG, Opts.CFGAddImplicitDtors, + Opts.CFGAddInitializers, + Opts.EagerlyTrimEGraph); + + TransferFuncs* TF = MakeCFRefCountTF(AMgr.getASTContext(), /*GC*/false, AMgr.getLangOptions()); - GRExprEngine Eng(AMgr, TF); + ExprEngine Eng(AMgr, TF); Eng.ExecuteWorkList(AMgr.getStackFrame(FD, TU), AMgr.getMaxNodes()); |