aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2014-11-24 09:15:30 +0000
committerDimitry Andric <dim@FreeBSD.org>2014-11-24 09:15:30 +0000
commit9f4dbff6669c8037f3b036bcf580d14f1a4f12a5 (patch)
tree47df2c12b57214af6c31e47404b005675b8b7ffc /examples
parentf73d5f23a889b93d89ddef61ac0995df40286bb8 (diff)
Notes
Diffstat (limited to 'examples')
-rw-r--r--examples/CMakeLists.txt3
-rw-r--r--examples/PrintFunctionNames/CMakeLists.txt41
-rw-r--r--examples/PrintFunctionNames/Makefile2
-rw-r--r--examples/PrintFunctionNames/PrintFunctionNames.cpp6
-rw-r--r--examples/PrintFunctionNames/PrintFunctionNames.exports1
-rw-r--r--examples/analyzer-plugin/CMakeLists.txt31
-rw-r--r--examples/analyzer-plugin/MainCallChecker.cpp4
-rw-r--r--examples/clang-interpreter/CMakeLists.txt33
-rw-r--r--examples/clang-interpreter/Makefile4
-rw-r--r--examples/clang-interpreter/main.cpp17
10 files changed, 56 insertions, 86 deletions
diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt
index 84a5d2cecbe4e..5d4b5fcdb0f6c 100644
--- a/examples/CMakeLists.txt
+++ b/examples/CMakeLists.txt
@@ -1,7 +1,10 @@
if(NOT CLANG_BUILD_EXAMPLES)
set_property(DIRECTORY PROPERTY EXCLUDE_FROM_ALL ON)
+ set(EXCLUDE_FROM_ALL ON)
endif()
+if(CLANG_ENABLE_STATIC_ANALYZER)
add_subdirectory(analyzer-plugin)
+endif()
add_subdirectory(clang-interpreter)
add_subdirectory(PrintFunctionNames)
diff --git a/examples/PrintFunctionNames/CMakeLists.txt b/examples/PrintFunctionNames/CMakeLists.txt
index ba6a350cd9540..e700281ab4899 100644
--- a/examples/PrintFunctionNames/CMakeLists.txt
+++ b/examples/PrintFunctionNames/CMakeLists.txt
@@ -1,24 +1,21 @@
-set(MODULE TRUE)
+# If we don't need RTTI or EH, there's no reason to export anything
+# from the plugin.
+if( NOT MSVC ) # MSVC mangles symbols differently, and
+ # PrintFunctionNames.export contains C++ symbols.
+ if( NOT LLVM_REQUIRES_RTTI )
+ if( NOT LLVM_REQUIRES_EH )
+ set(LLVM_EXPORTED_SYMBOL_FILE ${CMAKE_CURRENT_SOURCE_DIR}/PrintFunctionNames.exports)
+ endif()
+ endif()
+endif()
-set( LLVM_LINK_COMPONENTS support mc)
+add_llvm_loadable_module(PrintFunctionNames PrintFunctionNames.cpp)
-add_clang_library(PrintFunctionNames PrintFunctionNames.cpp)
-
-add_dependencies(PrintFunctionNames
- ClangAttrClasses
- ClangAttrList
- ClangCommentNodes
- ClangDeclNodes
- ClangDiagnosticCommon
- ClangStmtNodes
- )
-
-target_link_libraries(PrintFunctionNames
- clangFrontend
- clangAST
- )
-
-set_target_properties(PrintFunctionNames
- PROPERTIES
- LINKER_LANGUAGE CXX
- PREFIX "")
+if(LLVM_ENABLE_PLUGINS AND (WIN32 OR CYGWIN))
+ target_link_libraries(PrintFunctionNames ${cmake_2_8_12_PRIVATE}
+ clangAST
+ clangBasic
+ clangFrontend
+ LLVMSupport
+ )
+endif()
diff --git a/examples/PrintFunctionNames/Makefile b/examples/PrintFunctionNames/Makefile
index 23a53054019d1..5865098bd305d 100644
--- a/examples/PrintFunctionNames/Makefile
+++ b/examples/PrintFunctionNames/Makefile
@@ -19,7 +19,7 @@ endif
endif
LINK_LIBS_IN_SHARED = 0
-SHARED_LIBRARY = 1
+LOADABLE_MODULE = 1
include $(CLANG_LEVEL)/Makefile
diff --git a/examples/PrintFunctionNames/PrintFunctionNames.cpp b/examples/PrintFunctionNames/PrintFunctionNames.cpp
index f6e75cc2d3a02..3f18cd45e5646 100644
--- a/examples/PrintFunctionNames/PrintFunctionNames.cpp
+++ b/examples/PrintFunctionNames/PrintFunctionNames.cpp
@@ -48,9 +48,9 @@ protected:
// Example error handling.
if (args[i] == "-an-error") {
DiagnosticsEngine &D = CI.getDiagnostics();
- unsigned DiagID = D.getCustomDiagID(
- DiagnosticsEngine::Error, "invalid argument '" + args[i] + "'");
- D.Report(DiagID);
+ unsigned DiagID = D.getCustomDiagID(DiagnosticsEngine::Error,
+ "invalid argument '%0'");
+ D.Report(DiagID) << args[i];
return false;
}
}
diff --git a/examples/PrintFunctionNames/PrintFunctionNames.exports b/examples/PrintFunctionNames/PrintFunctionNames.exports
index 0ff590d30d7bb..e69de29bb2d1d 100644
--- a/examples/PrintFunctionNames/PrintFunctionNames.exports
+++ b/examples/PrintFunctionNames/PrintFunctionNames.exports
@@ -1 +0,0 @@
-_ZN4llvm8Registry*
diff --git a/examples/analyzer-plugin/CMakeLists.txt b/examples/analyzer-plugin/CMakeLists.txt
index ba73030cc37b6..1788d6c5cac96 100644
--- a/examples/analyzer-plugin/CMakeLists.txt
+++ b/examples/analyzer-plugin/CMakeLists.txt
@@ -1,23 +1,10 @@
-set(MODULE TRUE)
+add_llvm_loadable_module(SampleAnalyzerPlugin MainCallChecker.cpp)
-set( LLVM_LINK_COMPONENTS support mc)
-
-add_clang_library(SampleAnalyzerPlugin MainCallChecker.cpp)
-
-add_dependencies(SampleAnalyzerPlugin
- ClangAttrClasses
- ClangAttrList
- ClangCommentNodes
- ClangDeclNodes
- ClangDiagnosticCommon
- ClangStmtNodes
- )
-
-target_link_libraries(SampleAnalyzerPlugin
- clangStaticAnalyzerCore
- )
-
-set_target_properties(SampleAnalyzerPlugin
- PROPERTIES
- LINKER_LANGUAGE CXX
- PREFIX "")
+if(LLVM_ENABLE_PLUGINS AND (WIN32 OR CYGWIN))
+ target_link_libraries(SampleAnalyzerPlugin ${cmake_2_8_12_PRIVATE}
+ clangAnalysis
+ clangAST
+ clangStaticAnalyzerCore
+ LLVMSupport
+ )
+endif()
diff --git a/examples/analyzer-plugin/MainCallChecker.cpp b/examples/analyzer-plugin/MainCallChecker.cpp
index 8801f9a158fa8..2ad8c8416a5eb 100644
--- a/examples/analyzer-plugin/MainCallChecker.cpp
+++ b/examples/analyzer-plugin/MainCallChecker.cpp
@@ -8,7 +8,7 @@ using namespace ento;
namespace {
class MainCallChecker : public Checker < check::PreStmt<CallExpr> > {
- mutable OwningPtr<BugType> BT;
+ mutable std::unique_ptr<BugType> BT;
public:
void checkPreStmt(const CallExpr *CE, CheckerContext &C) const;
@@ -35,7 +35,7 @@ void MainCallChecker::checkPreStmt(const CallExpr *CE, CheckerContext &C) const
return;
if (!BT)
- BT.reset(new BugType("call to main", "example analyzer plugin"));
+ BT.reset(new BugType(this, "call to main", "example analyzer plugin"));
BugReport *report = new BugReport(*BT, BT->getName(), N);
report->addRange(Callee->getSourceRange());
diff --git a/examples/clang-interpreter/CMakeLists.txt b/examples/clang-interpreter/CMakeLists.txt
index 451b4b8672224..3c66881d026b0 100644
--- a/examples/clang-interpreter/CMakeLists.txt
+++ b/examples/clang-interpreter/CMakeLists.txt
@@ -1,15 +1,9 @@
set(LLVM_LINK_COMPONENTS
- jit
- interpreter
- nativecodegen
- asmparser
- bitreader
- bitwriter
- irreader
- codegen
- ipo
- linker
- selectiondag
+ Core
+ ExecutionEngine
+ JIT
+ Support
+ native
)
add_clang_executable(clang-interpreter
@@ -21,19 +15,8 @@ add_dependencies(clang-interpreter
)
target_link_libraries(clang-interpreter
- clangFrontend
- clangSerialization
- clangDriver
- clangCodeGen
- clangSema
- clangStaticAnalyzerFrontend
- clangStaticAnalyzerCheckers
- clangStaticAnalyzerCore
- clangAnalysis
- clangRewriteCore
- clangRewriteFrontend
- clangAST
- clangParse
- clangLex
clangBasic
+ clangCodeGen
+ clangDriver
+ clangFrontend
)
diff --git a/examples/clang-interpreter/Makefile b/examples/clang-interpreter/Makefile
index 55a8e6fb0f48c..d571337735ea7 100644
--- a/examples/clang-interpreter/Makefile
+++ b/examples/clang-interpreter/Makefile
@@ -16,11 +16,11 @@ NO_INSTALL = 1
TOOL_NO_EXPORTS = 1
LINK_COMPONENTS := jit interpreter nativecodegen bitreader bitwriter irreader \
- ipo linker selectiondag asmparser instrumentation option
+ ipo linker selectiondag asmparser instrumentation objcarcopts option
USEDLIBS = clangFrontend.a clangSerialization.a clangDriver.a clangCodeGen.a \
clangParse.a clangSema.a clangStaticAnalyzerFrontend.a \
clangStaticAnalyzerCheckers.a clangStaticAnalyzerCore.a \
- clangAnalysis.a clangRewriteCore.a clangRewriteFrontend.a \
+ clangAnalysis.a clangRewrite.a clangRewriteFrontend.a \
clangEdit.a clangAST.a clangLex.a clangBasic.a
include $(CLANG_LEVEL)/Makefile
diff --git a/examples/clang-interpreter/main.cpp b/examples/clang-interpreter/main.cpp
index e00583d1a1ab5..8b8ccfdf70a08 100644
--- a/examples/clang-interpreter/main.cpp
+++ b/examples/clang-interpreter/main.cpp
@@ -16,7 +16,6 @@
#include "clang/Frontend/CompilerInvocation.h"
#include "clang/Frontend/FrontendDiagnostic.h"
#include "clang/Frontend/TextDiagnosticPrinter.h"
-#include "llvm/ADT/OwningPtr.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ExecutionEngine/ExecutionEngine.h"
#include "llvm/ExecutionEngine/JIT.h"
@@ -27,6 +26,7 @@
#include "llvm/Support/Path.h"
#include "llvm/Support/TargetSelect.h"
#include "llvm/Support/raw_ostream.h"
+#include <memory>
using namespace clang;
using namespace clang::driver;
@@ -46,8 +46,8 @@ static int Execute(llvm::Module *Mod, char * const *envp) {
llvm::InitializeNativeTarget();
std::string Error;
- OwningPtr<llvm::ExecutionEngine> EE(
- llvm::ExecutionEngine::createJIT(Mod, &Error));
+ std::unique_ptr<llvm::ExecutionEngine> EE(
+ llvm::ExecutionEngine::create(Mod, /*ForceInterpreter*/ false, &Error));
if (!EE) {
llvm::errs() << "unable to make execution engine: " << Error << "\n";
return 255;
@@ -75,15 +75,16 @@ int main(int argc, const char **argv, char * const *envp) {
IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs());
DiagnosticsEngine Diags(DiagID, &*DiagOpts, DiagClient);
- Driver TheDriver(Path, llvm::sys::getProcessTriple(), "a.out", Diags);
+ Driver TheDriver(Path, llvm::sys::getProcessTriple(), Diags);
TheDriver.setTitle("clang interpreter");
+ TheDriver.setCheckInputsExist(false);
// FIXME: This is a hack to try to force the driver to do something we can
// recognize. We need to extend the driver library to support this use model
// (basically, exactly one input, and the operation mode is hard wired).
SmallVector<const char *, 16> Args(argv, argv + argc);
Args.push_back("-fsyntax-only");
- OwningPtr<Compilation> C(TheDriver.BuildCompilation(Args));
+ std::unique_ptr<Compilation> C(TheDriver.BuildCompilation(Args));
if (!C)
return 0;
@@ -108,7 +109,7 @@ int main(int argc, const char **argv, char * const *envp) {
// Initialize a compiler invocation object from the clang (-cc1) arguments.
const driver::ArgStringList &CCArgs = Cmd->getArguments();
- OwningPtr<CompilerInvocation> CI(new CompilerInvocation);
+ std::unique_ptr<CompilerInvocation> CI(new CompilerInvocation);
CompilerInvocation::CreateFromArgs(*CI,
const_cast<const char **>(CCArgs.data()),
const_cast<const char **>(CCArgs.data()) +
@@ -126,7 +127,7 @@ int main(int argc, const char **argv, char * const *envp) {
// Create a compiler instance to handle the actual work.
CompilerInstance Clang;
- Clang.setInvocation(CI.take());
+ Clang.setInvocation(CI.release());
// Create the compilers actual diagnostics engine.
Clang.createDiagnostics();
@@ -140,7 +141,7 @@ int main(int argc, const char **argv, char * const *envp) {
CompilerInvocation::GetResourcesPath(argv[0], MainAddr);
// Create and execute the frontend to generate an LLVM bitcode module.
- OwningPtr<CodeGenAction> Act(new EmitLLVMOnlyAction());
+ std::unique_ptr<CodeGenAction> Act(new EmitLLVMOnlyAction());
if (!Clang.ExecuteAction(*Act))
return 1;