summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authordim <dim@FreeBSD.org>2011-10-20 21:14:49 +0000
committerdim <dim@FreeBSD.org>2011-10-20 21:14:49 +0000
commit3963a48221351c61c17fb3f382341ab04809a3d3 (patch)
treeee2483e98b09cac943dc93a6969d83ca737ff139 /examples
parent611ba3ea3300b71eb95dc4e45f20eee5dddd32e1 (diff)
downloadFreeBSD-src-3963a48221351c61c17fb3f382341ab04809a3d3.zip
FreeBSD-src-3963a48221351c61c17fb3f382341ab04809a3d3.tar.gz
Vendor import of clang release_30 branch r142614:
http://llvm.org/svn/llvm-project/cfe/branches/release_30@142614
Diffstat (limited to 'examples')
-rw-r--r--examples/PrintFunctionNames/PrintFunctionNames.cpp4
-rw-r--r--examples/analyzer-plugin/CMakeLists.txt14
-rw-r--r--examples/analyzer-plugin/MainCallChecker.cpp52
-rw-r--r--examples/analyzer-plugin/Makefile20
-rw-r--r--examples/clang-interpreter/main.cpp8
5 files changed, 92 insertions, 6 deletions
diff --git a/examples/PrintFunctionNames/PrintFunctionNames.cpp b/examples/PrintFunctionNames/PrintFunctionNames.cpp
index cc138f5..fde6095 100644
--- a/examples/PrintFunctionNames/PrintFunctionNames.cpp
+++ b/examples/PrintFunctionNames/PrintFunctionNames.cpp
@@ -45,9 +45,9 @@ protected:
// Example error handling.
if (args[i] == "-an-error") {
- Diagnostic &D = CI.getDiagnostics();
+ DiagnosticsEngine &D = CI.getDiagnostics();
unsigned DiagID = D.getCustomDiagID(
- Diagnostic::Error, "invalid argument '" + args[i] + "'");
+ DiagnosticsEngine::Error, "invalid argument '" + args[i] + "'");
D.Report(DiagID);
return false;
}
diff --git a/examples/analyzer-plugin/CMakeLists.txt b/examples/analyzer-plugin/CMakeLists.txt
new file mode 100644
index 0000000..8654226
--- /dev/null
+++ b/examples/analyzer-plugin/CMakeLists.txt
@@ -0,0 +1,14 @@
+set(MODULE TRUE)
+
+set( LLVM_USED_LIBS
+ clangStaticAnalyzerCore
+ )
+
+set( LLVM_LINK_COMPONENTS support mc)
+
+add_clang_library(SampleAnalyzerPlugin SampleAnalyzerPlugin)
+
+set_target_properties(SampleAnalyzerPlugin
+ PROPERTIES
+ LINKER_LANGUAGE CXX
+ PREFIX "")
diff --git a/examples/analyzer-plugin/MainCallChecker.cpp b/examples/analyzer-plugin/MainCallChecker.cpp
new file mode 100644
index 0000000..85f7754
--- /dev/null
+++ b/examples/analyzer-plugin/MainCallChecker.cpp
@@ -0,0 +1,52 @@
+#include "clang/StaticAnalyzer/Core/Checker.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
+#include "clang/StaticAnalyzer/Core/CheckerRegistry.h"
+#include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
+
+using namespace clang;
+using namespace ento;
+
+namespace {
+class MainCallChecker : public Checker < check::PreStmt<CallExpr> > {
+ mutable llvm::OwningPtr<BugType> BT;
+
+public:
+ void checkPreStmt(const CallExpr *CE, CheckerContext &C) const;
+};
+} // end anonymous namespace
+
+void MainCallChecker::checkPreStmt(const CallExpr *CE, CheckerContext &C) const {
+ const ProgramState *state = C.getState();
+ const Expr *Callee = CE->getCallee();
+ const FunctionDecl *FD = state->getSVal(Callee).getAsFunctionDecl();
+
+ if (!FD)
+ return;
+
+ // Get the name of the callee.
+ IdentifierInfo *II = FD->getIdentifier();
+ if (!II) // if no identifier, not a simple C function
+ return;
+
+ if (II->isStr("main")) {
+ ExplodedNode *N = C.generateSink();
+ if (!N)
+ return;
+
+ if (!BT)
+ BT.reset(new BugType("call to main", "example analyzer plugin"));
+
+ BugReport *report = new BugReport(*BT, BT->getName(), N);
+ report->addRange(Callee->getSourceRange());
+ C.EmitReport(report);
+ }
+}
+
+// Register plugin!
+extern "C"
+void clang_registerCheckers (CheckerRegistry &registry) {
+ registry.addChecker<MainCallChecker>("example.MainCallChecker", "Disallows calls to functions called main");
+}
+
+extern "C"
+const char clang_analyzerAPIVersionString[] = CLANG_ANALYZER_API_VERSION_STRING;
diff --git a/examples/analyzer-plugin/Makefile b/examples/analyzer-plugin/Makefile
new file mode 100644
index 0000000..5537ee0
--- /dev/null
+++ b/examples/analyzer-plugin/Makefile
@@ -0,0 +1,20 @@
+##===- examples/analyzer-plugin/Makefile -------------------*- Makefile -*-===##
+#
+# The LLVM Compiler Infrastructure
+#
+# This file is distributed under the University of Illinois Open Source
+# License. See LICENSE.TXT for details.
+#
+##===----------------------------------------------------------------------===##
+
+CLANG_LEVEL := ../..
+LIBRARYNAME = SampleAnalyzerPlugin
+
+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/clang-interpreter/main.cpp b/examples/clang-interpreter/main.cpp
index 16f4dab..c9734e5 100644
--- a/examples/clang-interpreter/main.cpp
+++ b/examples/clang-interpreter/main.cpp
@@ -22,12 +22,13 @@
#include "llvm/ADT/OwningPtr.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/Config/config.h"
+#include "llvm/ExecutionEngine/JIT.h"
#include "llvm/ExecutionEngine/ExecutionEngine.h"
#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Support/Host.h"
#include "llvm/Support/Path.h"
-#include "llvm/Target/TargetSelect.h"
+#include "llvm/Support/TargetSelect.h"
using namespace clang;
using namespace clang::driver;
@@ -74,10 +75,9 @@ int main(int argc, const char **argv, char * const *envp) {
new TextDiagnosticPrinter(llvm::errs(), DiagnosticOptions());
llvm::IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs());
- Diagnostic Diags(DiagID, DiagClient);
+ DiagnosticsEngine Diags(DiagID, DiagClient);
Driver TheDriver(Path.str(), llvm::sys::getHostTriple(),
- "a.out", /*IsProduction=*/false, /*CXXIsProduction=*/false,
- Diags);
+ "a.out", /*IsProduction=*/false, Diags);
TheDriver.setTitle("clang interpreter");
// FIXME: This is a hack to try to force the driver to do something we can
OpenPOWER on IntegriCloud