[cfe-commits] r169124 - in /cfe/trunk: include/clang/Basic/DiagnosticDriverKinds.td include/clang/Basic/Sanitizers.def lib/CodeGen/BackendUtil.cpp lib/Driver/SanitizerArgs.h lib/Driver/Tools.cpp
Evgeniy Stepanov
eugeni.stepanov at gmail.com
Mon Dec 3 05:20:43 PST 2012
Author: eugenis
Date: Mon Dec 3 07:20:43 2012
New Revision: 169124
URL: http://llvm.org/viewvc/llvm-project?rev=169124&view=rev
Log:
Add -fsanitize=memory.
Modified:
cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td
cfe/trunk/include/clang/Basic/Sanitizers.def
cfe/trunk/lib/CodeGen/BackendUtil.cpp
cfe/trunk/lib/Driver/SanitizerArgs.h
cfe/trunk/lib/Driver/Tools.cpp
Modified: cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td?rev=169124&r1=169123&r2=169124&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td Mon Dec 3 07:20:43 2012
@@ -101,6 +101,8 @@
"option '-MG' requires '-M' or '-MM'">;
def err_drv_asan_android_requires_pie : Error<
"AddressSanitizer on Android requires '-pie'">;
+def err_drv_sanitizer_requires_pie : Error<
+ "%select{Thread|Memory}0Sanitizer requires '-pie'">;
def err_drv_unknown_objc_runtime : Error<
"unknown or ill-formed Objective-C runtime '%0'">;
Modified: cfe/trunk/include/clang/Basic/Sanitizers.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Sanitizers.def?rev=169124&r1=169123&r2=169124&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/Sanitizers.def (original)
+++ cfe/trunk/include/clang/Basic/Sanitizers.def Mon Dec 3 07:20:43 2012
@@ -48,6 +48,9 @@
SANITIZER_GROUP("address-full", AddressFull,
Address | InitOrder | UseAfterReturn | UseAfterScope)
+// MemorySanitizer
+SANITIZER("memory", Memory)
+
// ThreadSanitizer
SANITIZER("thread", Thread)
Modified: cfe/trunk/lib/CodeGen/BackendUtil.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/BackendUtil.cpp?rev=169124&r1=169123&r2=169124&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/BackendUtil.cpp (original)
+++ cfe/trunk/lib/CodeGen/BackendUtil.cpp Mon Dec 3 07:20:43 2012
@@ -179,6 +179,11 @@
PM.add(createAddressSanitizerModulePass(LangOpts.SanitizeInitOrder));
}
+static void addMemorySanitizerPass(const PassManagerBuilder &Builder,
+ PassManagerBase &PM) {
+ PM.add(createMemorySanitizerPass());
+}
+
static void addThreadSanitizerPass(const PassManagerBuilder &Builder,
PassManagerBase &PM) {
PM.add(createThreadSanitizerPass());
@@ -227,6 +232,13 @@
addAddressSanitizerPasses);
}
+ if (LangOpts.SanitizeMemory) {
+ PMBuilder.addExtension(PassManagerBuilder::EP_OptimizerLast,
+ addMemorySanitizerPass);
+ PMBuilder.addExtension(PassManagerBuilder::EP_EnabledOnOptLevel0,
+ addMemorySanitizerPass);
+ }
+
if (LangOpts.SanitizeThread) {
PMBuilder.addExtension(PassManagerBuilder::EP_OptimizerLast,
addThreadSanitizerPass);
Modified: cfe/trunk/lib/Driver/SanitizerArgs.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/SanitizerArgs.h?rev=169124&r1=169123&r2=169124&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/SanitizerArgs.h (original)
+++ cfe/trunk/lib/Driver/SanitizerArgs.h Mon Dec 3 07:20:43 2012
@@ -30,6 +30,7 @@
#include "clang/Basic/Sanitizers.def"
NeedsAsanRt = AddressFull,
NeedsTsanRt = Thread,
+ NeedsMsanRt = Memory,
NeedsUbsanRt = (Undefined & ~Bounds) | Integer
};
unsigned Kind;
@@ -41,6 +42,7 @@
bool needsAsanRt() const { return Kind & NeedsAsanRt; }
bool needsTsanRt() const { return Kind & NeedsTsanRt; }
+ bool needsMsanRt() const { return Kind & NeedsMsanRt; }
bool needsUbsanRt() const { return Kind & NeedsUbsanRt; }
bool sanitizesVptr() const { return Kind & Vptr; }
Modified: cfe/trunk/lib/Driver/Tools.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=169124&r1=169123&r2=169124&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/Tools.cpp (original)
+++ cfe/trunk/lib/Driver/Tools.cpp Mon Dec 3 07:20:43 2012
@@ -1524,6 +1524,9 @@
static void addTsanRTLinux(const ToolChain &TC, const ArgList &Args,
ArgStringList &CmdArgs) {
if (!Args.hasArg(options::OPT_shared)) {
+ if (!Args.hasArg(options::OPT_pie))
+ TC.getDriver().Diag(diag::err_drv_sanitizer_requires_pie) <<
+ /* Thread */ 0;
// LibTsan is "libclang_rt.tsan-<ArchName>.a" in the Linux library
// resource directory.
SmallString<128> LibTsan(TC.getDriver().ResourceDir);
@@ -1537,6 +1540,27 @@
}
}
+/// If MemorySanitizer is enabled, add appropriate linker flags (Linux).
+/// This needs to be called before we add the C run-time (malloc, etc).
+static void addMsanRTLinux(const ToolChain &TC, const ArgList &Args,
+ ArgStringList &CmdArgs) {
+ if (!Args.hasArg(options::OPT_shared)) {
+ if (!Args.hasArg(options::OPT_pie))
+ TC.getDriver().Diag(diag::err_drv_sanitizer_requires_pie) <<
+ /* Memory */ 1;
+ // LibMsan is "libclang_rt.msan-<ArchName>.a" in the Linux library
+ // resource directory.
+ SmallString<128> LibMsan(TC.getDriver().ResourceDir);
+ llvm::sys::path::append(LibMsan, "lib", "linux",
+ (Twine("libclang_rt.msan-") +
+ TC.getArchName() + ".a"));
+ CmdArgs.push_back(Args.MakeArgString(LibMsan));
+ CmdArgs.push_back("-lpthread");
+ CmdArgs.push_back("-ldl");
+ CmdArgs.push_back("-export-dynamic");
+ }
+}
+
/// If UndefinedBehaviorSanitizer is enabled, add appropriate linker flags
/// (Linux).
static void addUbsanRTLinux(const ToolChain &TC, const ArgList &Args,
@@ -5443,6 +5467,8 @@
addAsanRTLinux(getToolChain(), Args, CmdArgs);
if (Sanitize.needsTsanRt())
addTsanRTLinux(getToolChain(), Args, CmdArgs);
+ if (Sanitize.needsMsanRt())
+ addMsanRTLinux(getToolChain(), Args, CmdArgs);
if (D.CCCIsCXX &&
!Args.hasArg(options::OPT_nostdlib) &&
More information about the cfe-commits
mailing list