r189389 - clang-cl: Support -fsanitize=address
Hans Wennborg
hans at hanshq.net
Tue Aug 27 11:10:21 PDT 2013
Author: hans
Date: Tue Aug 27 13:10:21 2013
New Revision: 189389
URL: http://llvm.org/viewvc/llvm-project?rev=189389&view=rev
Log:
clang-cl: Support -fsanitize=address
This exposes the -fsanitize=address option and adds the runtime library
to the link command.
Differential Revision: http://llvm-reviews.chandlerc.com/D1526
Modified:
cfe/trunk/include/clang/Driver/Options.td
cfe/trunk/lib/Driver/Tools.cpp
cfe/trunk/test/Driver/cl-link.c
Modified: cfe/trunk/include/clang/Driver/Options.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=189389&r1=189388&r2=189389&view=diff
==============================================================================
--- cfe/trunk/include/clang/Driver/Options.td (original)
+++ cfe/trunk/include/clang/Driver/Options.td Tue Aug 27 13:10:21 2013
@@ -448,7 +448,7 @@ def fbracket_depth_EQ : Joined<["-"], "f
def fsignaling_math : Flag<["-"], "fsignaling-math">, Group<f_Group>;
def fno_signaling_math : Flag<["-"], "fno-signaling-math">, Group<f_Group>;
def fsanitize_EQ : CommaJoined<["-"], "fsanitize=">, Group<f_clang_Group>,
- Flags<[CC1Option]>, MetaVarName<"<check>">,
+ Flags<[CC1Option, CoreOption]>, MetaVarName<"<check>">,
HelpText<"Enable runtime instrumentation for bug detection: "
"address (memory errors) | thread (race detection) | "
"undefined (miscellaneous undefined behavior)">;
Modified: cfe/trunk/lib/Driver/Tools.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=189389&r1=189388&r2=189389&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/Tools.cpp (original)
+++ cfe/trunk/lib/Driver/Tools.cpp Tue Aug 27 13:10:21 2013
@@ -6568,6 +6568,14 @@ void visualstudio::Link::ConstructJob(Co
CmdArgs.push_back("-nologo");
+ if (getToolChain().getDriver().getOrParseSanitizerArgs(Args).needsAsanRt()) {
+ SmallString<128> LibSanitizer(getToolChain().getDriver().ResourceDir);
+ // FIXME: Handle 64-bit. Use asan_dll_thunk.dll when building a DLL.
+ llvm::sys::path::append(
+ LibSanitizer, "lib", "windows", "clang_rt.asan-i386.lib");
+ CmdArgs.push_back(Args.MakeArgString(LibSanitizer));
+ }
+
Args.AddAllArgValues(CmdArgs, options::OPT_l);
Args.AddAllArgValues(CmdArgs, options::OPT__SLASH_link);
Modified: cfe/trunk/test/Driver/cl-link.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/cl-link.c?rev=189389&r1=189388&r2=189389&view=diff
==============================================================================
--- cfe/trunk/test/Driver/cl-link.c (original)
+++ cfe/trunk/test/Driver/cl-link.c Tue Aug 27 13:10:21 2013
@@ -5,8 +5,13 @@
// be interpreted as a command-line option, e.g. on Mac where %s is commonly
// under /Users.
-// RUN: %clang_cl /Tc%s -### /link foo bar baz 2>&1 | FileCheck %s
-// CHECK: link.exe
-// CHECK: "foo"
-// CHECK: "bar"
-// CHECK: "baz"
+// RUN: %clang_cl /Tc%s -### /link foo bar baz 2>&1 | FileCheck --check-prefix=LINK %s
+// LINK: link.exe
+// LINK: "foo"
+// LINK: "bar"
+// LINK: "baz"
+
+// RUN: %clang_cl /Tc%s -### -fsanitize=address 2>&1 | FileCheck --check-prefix=ASAN %s
+// ASAN: link.exe
+// ASAN: "{{.*}}clang_rt.asan-i386.lib"
+// ASAN: "{{.*}}cl-link{{.*}}.obj"
More information about the cfe-commits
mailing list