[PATCH] D24091: [Driver] Warn on -nodefaultlibs and -fsanitize

Chris Bieneman via cfe-commits cfe-commits at lists.llvm.org
Wed Aug 31 10:38:58 PDT 2016


beanz created this revision.
beanz added reviewers: bogner, zaks.anna, bruno, filcab.
beanz added a subscriber: cfe-commits.
Herald added a subscriber: emaste.

The FreeBSD and GNUTools drivers support -fsanitize arguments bypassing -nodefaultlibs. With https://reviews.llvm.org/D24048, Darwin will support that behavior as well.

To make this a little less magical and behind the curtain this warning will fire when -nodefaultlibs is used with sanitizer arguments.

https://reviews.llvm.org/D24091

Files:
  include/clang/Basic/DiagnosticDriverKinds.td
  lib/Driver/Driver.cpp
  test/Driver/nodefaultlib.c

Index: test/Driver/nodefaultlib.c
===================================================================
--- test/Driver/nodefaultlib.c
+++ test/Driver/nodefaultlib.c
@@ -8,3 +8,7 @@
 // RUN: %clang -target i686-pc-linux-gnu -stdlib=libc++ -nodefaultlibs -lstdc++ -### %s 2>&1 | FileCheck -check-prefix=TEST2 %s
 // TEST2-NOT: "-lc++"
 // TEST2: "-lstdc++"
+
+// RUN: %clang -target i686-pc-linux-gnu -nodefaultlibs -fsanitize=address -### %s 2>&1 | FileCheck -check-prefix=TEST3 %s
+// TEST3: warning: Passing -nodefaultlibs and -fsanitize may result in linking sanitizer runtimes.
+// TEST3: libclang_rt.asan-i686.a
Index: lib/Driver/Driver.cpp
===================================================================
--- lib/Driver/Driver.cpp
+++ lib/Driver/Driver.cpp
@@ -1546,8 +1546,12 @@
   Arg *FinalPhaseArg;
   phases::ID FinalPhase = getFinalPhase(Args, &FinalPhaseArg);
 
-  if (FinalPhase == phases::Link && Args.hasArg(options::OPT_emit_llvm)) {
-    Diag(clang::diag::err_drv_emit_llvm_link);
+  if (FinalPhase == phases::Link) {
+    if(Args.hasArg(options::OPT_emit_llvm))
+      Diag(clang::diag::err_drv_emit_llvm_link);
+    if (Args.hasArg(options::OPT_nodefaultlibs) &&
+        Args.hasArg(options::OPT_fsanitize_EQ))
+      Diag(clang::diag::warn_drv_sanitizers_and_nodefaultlibs);
   }
 
   // Reject -Z* at the top level, these options should never have been exposed
Index: include/clang/Basic/DiagnosticDriverKinds.td
===================================================================
--- include/clang/Basic/DiagnosticDriverKinds.td
+++ include/clang/Basic/DiagnosticDriverKinds.td
@@ -271,4 +271,7 @@
   InGroup<InvalidOrNonExistentDirectory>;
 
 def err_drv_unsupported_linker : Error<"unsupported value '%0' for -linker option">;
+
+def warn_drv_sanitizers_and_nodefaultlibs : Warning<
+  "Passing -nodefaultlibs and -fsanitize may result in linking sanitizer runtimes.">;
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D24091.69879.patch
Type: text/x-patch
Size: 1900 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160831/248c3af2/attachment.bin>


More information about the cfe-commits mailing list