Hi rnk,

This exposes the command-line option and adds the runtime library to the link 
command.

http://llvm-reviews.chandlerc.com/D1526

Files:
  include/clang/Driver/Options.td
  lib/Driver/Tools.cpp
  test/Driver/cl-link.c

Index: include/clang/Driver/Options.td
===================================================================
--- include/clang/Driver/Options.td
+++ include/clang/Driver/Options.td
@@ -448,7 +448,7 @@
 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)">;
Index: lib/Driver/Tools.cpp
===================================================================
--- lib/Driver/Tools.cpp
+++ lib/Driver/Tools.cpp
@@ -6560,6 +6560,14 @@
 
   CmdArgs.push_back("-nologo");
 
+  if (getToolChain().getDriver().getOrParseSanitizerArgs(Args).needsAsanRt()) {
+    SmallString<128> LibSanitizer(getToolChain().getDriver().ResourceDir);
+    // FIXME: Handle 64-bit.
+    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);
 
Index: test/Driver/cl-link.c
===================================================================
--- test/Driver/cl-link.c
+++ test/Driver/cl-link.c
@@ -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"
Index: include/clang/Driver/Options.td
===================================================================
--- include/clang/Driver/Options.td
+++ include/clang/Driver/Options.td
@@ -448,7 +448,7 @@
 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)">;
Index: lib/Driver/Tools.cpp
===================================================================
--- lib/Driver/Tools.cpp
+++ lib/Driver/Tools.cpp
@@ -6560,6 +6560,14 @@
 
   CmdArgs.push_back("-nologo");
 
+  if (getToolChain().getDriver().getOrParseSanitizerArgs(Args).needsAsanRt()) {
+    SmallString<128> LibSanitizer(getToolChain().getDriver().ResourceDir);
+    // FIXME: Handle 64-bit.
+    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);
 
Index: test/Driver/cl-link.c
===================================================================
--- test/Driver/cl-link.c
+++ test/Driver/cl-link.c
@@ -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"
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to