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

2016-09-01 Thread Chris Bieneman via cfe-commits
If we do add a warning, we probably need to make the warning more generic than 
this because it also applies to the Code coverage flags.

-Chris

> On Sep 1, 2016, at 11:29 AM, Bruno Cardoso Lopes  
> wrote:
> 
> On Wed, Aug 31, 2016 at 11:00 PM, Justin Bogner  > wrote:
>> Chris Bieneman  writes:
>>> 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.
>> 
>> I don't think this makes any sense. If it's a legitimate use case to
>> pass these flags together, then anyone who does will have to manually
>> disable this warning - if it's invalid to pass the flags together, we
>> should just disallow it instead of warning. The warning either hurts
>> usability or doesn't do enough.
> 
> I disagree. Assuming that we go for allowing the behavior: I can see
> the fact that the warning may be annoying, but I still think it's
> better for the user to know what's happening and then disable the
> warning, instead of relying on implicit assumptions. Maybe not
> allowing the behavior and better modeling how these things
> interoperate is a better solution, but I'll leave this topic for the
> other thread.
> 
> -- 
> Bruno Cardoso Lopes
> http://www.brunocardoso.cc 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2016-09-01 Thread Bruno Cardoso Lopes via cfe-commits
On Wed, Aug 31, 2016 at 11:00 PM, Justin Bogner  wrote:
> Chris Bieneman  writes:
>> 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.
>
> I don't think this makes any sense. If it's a legitimate use case to
> pass these flags together, then anyone who does will have to manually
> disable this warning - if it's invalid to pass the flags together, we
> should just disallow it instead of warning. The warning either hurts
> usability or doesn't do enough.

I disagree. Assuming that we go for allowing the behavior: I can see
the fact that the warning may be annoying, but I still think it's
better for the user to know what's happening and then disable the
warning, instead of relying on implicit assumptions. Maybe not
allowing the behavior and better modeling how these things
interoperate is a better solution, but I'll leave this topic for the
other thread.

-- 
Bruno Cardoso Lopes
http://www.brunocardoso.cc
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2016-08-31 Thread Justin Bogner via cfe-commits
Chris Bieneman  writes:
> 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.

I don't think this makes any sense. If it's a legitimate use case to
pass these flags together, then anyone who does will have to manually
disable this warning - if it's invalid to pass the flags together, we
should just disallow it instead of warning. The warning either hurts
usability or doesn't do enough.

> 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;
>  
>  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.">;
>  }
>
>
> 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;
>  
>  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.">;
>  }
___
cfe-commits mailing list
c

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

2016-08-31 Thread Chris Bieneman via cfe-commits
beanz updated this revision to Diff 69926.
beanz added a comment.

- Changed warning text based on feedback from bruno
- Made the warning apply to -nostdlib as well as -nodefaultlibs based on 
offline discussion with Anna


https://reviews.llvm.org/D24091

Files:
  include/clang/Basic/DiagnosticDriverKinds.td
  include/clang/Driver/SanitizerArgs.h
  lib/Driver/Driver.cpp
  lib/Driver/ToolChains.cpp
  lib/Driver/Tools.cpp
  test/Driver/nodefaultlib.c
  test/Driver/nostdlib.c

Index: test/Driver/nostdlib.c
===
--- test/Driver/nostdlib.c
+++ test/Driver/nostdlib.c
@@ -29,3 +29,12 @@
 // CHECK-LINUX-NOSTDLIB: "{{(.*[^.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
 // CHECK-LINUX-NOSTDLIB-NOT: "{{.*}}/Inputs/resource_dir{{/|}}lib{{/|}}linux{{/|}}libclang_rt.builtins-i686.a"
 // CHECK-MSVC-NOSTDLIB: warning: argument unused during compilation: '--rtlib=compiler-rt'
+
+// RUN: %clang -target i686-pc-linux-gnu -nostdlib -fsanitize=address -### %s 2>&1 | FileCheck -check-prefix=TEST3 %s
+// RUN: %clang -target i686-unknown-freebsd -nodefaultlibs -fsanitize=address -### %s 2>&1 | FileCheck -check-prefix=TEST3 %s
+// TEST3: warning: -nodefaultlibs and -nostdlib do not skip sanitizer runtime libs when used with -fsanitize.
+// TEST3: libclang_rt.asan-i686.a
+
+// RUN: %clang -target i686-apple-darwin -nostdlib -fsanitize=address -### %s 2>&1 | FileCheck -check-prefix=TEST4 %s
+// TEST4: warning: -nodefaultlibs and -nostdlib do not skip sanitizer runtime libs when used with -fsanitize.
+// TEST4: libclang_rt.asan_osx_dynamic.dylib
Index: test/Driver/nodefaultlib.c
===
--- test/Driver/nodefaultlib.c
+++ test/Driver/nodefaultlib.c
@@ -8,3 +8,12 @@
 // 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
+// RUN: %clang -target i686-unknown-freebsd -nodefaultlibs -fsanitize=address -### %s 2>&1 | FileCheck -check-prefix=TEST3 %s
+// TEST3: warning: -nodefaultlibs and -nostdlib do not skip sanitizer runtime libs when used with -fsanitize.
+// TEST3: libclang_rt.asan-i686.a
+
+// RUN: %clang -target i686-apple-darwin -nodefaultlibs -fsanitize=address -### %s 2>&1 | FileCheck -check-prefix=TEST4 %s
+// TEST4: warning: -nodefaultlibs and -nostdlib do not skip sanitizer runtime libs when used with -fsanitize.
+// TEST4: libclang_rt.asan_osx_dynamic.dylib
Index: lib/Driver/Tools.cpp
===
--- lib/Driver/Tools.cpp
+++ lib/Driver/Tools.cpp
@@ -8768,6 +8768,10 @@
 AddGoldPlugin(ToolChain, Args, CmdArgs, D.getLTOMode() == LTOK_Thin);
 
   bool NeedsSanitizerDeps = addSanitizerRuntimes(ToolChain, Args, CmdArgs);
+
+  if (NeedsSanitizerDeps &&
+  Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs))
+D.Diag(clang::diag::warn_drv_sanitizers_and_nodefaultlibs);
   AddLinkerInputs(ToolChain, Inputs, Args, CmdArgs);
 
   if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) {
@@ -9604,6 +9608,11 @@
 CmdArgs.push_back("--no-demangle");
 
   bool NeedsSanitizerDeps = addSanitizerRuntimes(ToolChain, Args, CmdArgs);
+
+  if (NeedsSanitizerDeps &&
+  Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs))
+D.Diag(clang::diag::warn_drv_sanitizers_and_nodefaultlibs);
+
   bool NeedsXRayDeps = addXRayRuntime(ToolChain, Args, CmdArgs);
   AddLinkerInputs(ToolChain, Inputs, Args, CmdArgs);
   // The profile runtime also needs access to system libraries.
Index: lib/Driver/ToolChains.cpp
===
--- lib/Driver/ToolChains.cpp
+++ lib/Driver/ToolChains.cpp
@@ -321,6 +321,8 @@
 CmdArgs.push_back("-rpath");
 CmdArgs.push_back(Args.MakeArgString(Dir));
   }
+  if (Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs))
+getDriver().Diag(clang::diag::warn_drv_sanitizers_and_nodefaultlibs);
 }
 
 StringRef Darwin::getPlatformFamily() const {
Index: lib/Driver/Driver.cpp
===
--- lib/Driver/Driver.cpp
+++ lib/Driver/Driver.cpp
@@ -1546,9 +1546,8 @@
   Arg *FinalPhaseArg;
   phases::ID FinalPhase = getFinalPhase(Args, &FinalPhaseArg);
 
-  if (FinalPhase == phases::Link && Args.hasArg(options::OPT_emit_llvm)) {
+  if (FinalPhase == phases::Link && Args.hasArg(options::OPT_emit_llvm))
 Diag(clang::diag::err_drv_emit_llvm_link);
-  }
 
   // Reject -Z* at the top level, these options should never have been exposed
   // by gcc.
Index: include/clang/Driver/SanitizerArgs.h
===
--- include/clang/Driver/SanitizerArgs.h
+++ include/clang/Driver/SanitizerArgs.h
@@ -63,6 +63,8 @@
   

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

2016-08-31 Thread Bruno Cardoso Lopes via cfe-commits
bruno added inline comments.


Comment at: include/clang/Basic/DiagnosticDriverKinds.td:276
@@ +275,3 @@
+def warn_drv_sanitizers_and_nodefaultlibs : Warning<
+  "Passing -nodefaultlibs and -fsanitize has resulted in linking sanitizer 
runtimes.">,
+  InGroup>;

What about something like: "-nodefaultlibs does not skip sanitizer runtime libs 
when used with -fsanitize." ?


https://reviews.llvm.org/D24091



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2016-08-31 Thread Chris Bieneman via cfe-commits
beanz updated this revision to Diff 69910.
beanz added a comment.

Updates based on bruno's feedback.


https://reviews.llvm.org/D24091

Files:
  include/clang/Basic/DiagnosticDriverKinds.td
  include/clang/Driver/SanitizerArgs.h
  lib/Driver/Driver.cpp
  lib/Driver/ToolChains.cpp
  lib/Driver/Tools.cpp
  test/Driver/nodefaultlib.c

Index: test/Driver/nodefaultlib.c
===
--- test/Driver/nodefaultlib.c
+++ test/Driver/nodefaultlib.c
@@ -8,3 +8,12 @@
 // 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
+// RUN: %clang -target i686-unknown-freebsd -nodefaultlibs -fsanitize=address 
-### %s 2>&1 | FileCheck -check-prefix=TEST3 %s
+// TEST3: warning: Passing -nodefaultlibs and -fsanitize has resulted in 
linking sanitizer runtimes.
+// TEST3: libclang_rt.asan-i686.a
+
+// RUN: %clang -target i686-apple-darwin -nodefaultlibs -fsanitize=address 
-### %s 2>&1 | FileCheck -check-prefix=TEST4 %s
+// TEST4: warning: Passing -nodefaultlibs and -fsanitize has resulted in 
linking sanitizer runtimes.
+// TEST4: libclang_rt.asan_osx_dynamic.dylib
Index: lib/Driver/Tools.cpp
===
--- lib/Driver/Tools.cpp
+++ lib/Driver/Tools.cpp
@@ -8768,6 +8768,9 @@
 AddGoldPlugin(ToolChain, Args, CmdArgs, D.getLTOMode() == LTOK_Thin);
 
   bool NeedsSanitizerDeps = addSanitizerRuntimes(ToolChain, Args, CmdArgs);
+
+  if (NeedsSanitizerDeps && Args.hasArg(options::OPT_nodefaultlibs))
+D.Diag(clang::diag::warn_drv_sanitizers_and_nodefaultlibs);
   AddLinkerInputs(ToolChain, Inputs, Args, CmdArgs);
 
   if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) {
@@ -9604,6 +9607,10 @@
 CmdArgs.push_back("--no-demangle");
 
   bool NeedsSanitizerDeps = addSanitizerRuntimes(ToolChain, Args, CmdArgs);
+  
+  if (NeedsSanitizerDeps && Args.hasArg(options::OPT_nodefaultlibs))
+D.Diag(clang::diag::warn_drv_sanitizers_and_nodefaultlibs);
+
   bool NeedsXRayDeps = addXRayRuntime(ToolChain, Args, CmdArgs);
   AddLinkerInputs(ToolChain, Inputs, Args, CmdArgs);
   // The profile runtime also needs access to system libraries.
Index: lib/Driver/ToolChains.cpp
===
--- lib/Driver/ToolChains.cpp
+++ lib/Driver/ToolChains.cpp
@@ -321,6 +321,8 @@
 CmdArgs.push_back("-rpath");
 CmdArgs.push_back(Args.MakeArgString(Dir));
   }
+  if (Args.hasArg(options::OPT_nodefaultlibs))
+getDriver().Diag(clang::diag::warn_drv_sanitizers_and_nodefaultlibs);
 }
 
 StringRef Darwin::getPlatformFamily() const {
Index: lib/Driver/Driver.cpp
===
--- lib/Driver/Driver.cpp
+++ lib/Driver/Driver.cpp
@@ -1546,9 +1546,8 @@
   Arg *FinalPhaseArg;
   phases::ID FinalPhase = getFinalPhase(Args, &FinalPhaseArg);
 
-  if (FinalPhase == phases::Link && Args.hasArg(options::OPT_emit_llvm)) {
+  if (FinalPhase == phases::Link && Args.hasArg(options::OPT_emit_llvm))
 Diag(clang::diag::err_drv_emit_llvm_link);
-  }
 
   // Reject -Z* at the top level, these options should never have been exposed
   // by gcc.
Index: include/clang/Driver/SanitizerArgs.h
===
--- include/clang/Driver/SanitizerArgs.h
+++ include/clang/Driver/SanitizerArgs.h
@@ -63,6 +63,8 @@
 return Sanitizers.hasOneOf(SanitizerKind::Efficiency);
   }
 
+  bool hasSanitizers() const { return !Sanitizers.empty(); }
+
   bool requiresPIE() const;
   bool needsUnwindTables() const;
   bool linkCXXRuntimes() const { return LinkCXXRuntimes; }
Index: include/clang/Basic/DiagnosticDriverKinds.td
===
--- include/clang/Basic/DiagnosticDriverKinds.td
+++ include/clang/Basic/DiagnosticDriverKinds.td
@@ -271,4 +271,8 @@
   InGroup;
 
 def err_drv_unsupported_linker : Error<"unsupported value '%0' for -linker 
option">;
+
+def warn_drv_sanitizers_and_nodefaultlibs : Warning<
+  "Passing -nodefaultlibs and -fsanitize has resulted in linking sanitizer 
runtimes.">,
+  InGroup>;
 }


Index: test/Driver/nodefaultlib.c
===
--- test/Driver/nodefaultlib.c
+++ test/Driver/nodefaultlib.c
@@ -8,3 +8,12 @@
 // 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
+// RUN: %clang -target i686-unknown-freebsd -nodefaultlibs -fsanitize=address -### %s 2>&1 | FileCheck -check-prefix=TEST3 %s

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

2016-08-31 Thread Chris Bieneman via cfe-commits
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;
 
 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.">;
 }


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;
 
 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.">;
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2016-08-31 Thread Chris Bieneman via cfe-commits
beanz added a comment.

I can change the implementation, but that quickly falls into target specific 
driver code. It results in adding the warning in one place for Darwin, another 
for FreeBSD, and a third for GNUTools.

If that is the preferred way I can work up that patch.


https://reviews.llvm.org/D24091



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2016-08-31 Thread Bruno Cardoso Lopes via cfe-commits
bruno added a comment.

Hi Chris,

Thanks for doing this.



Comment at: lib/Driver/Driver.cpp:1554
@@ -1551,1 +1553,3 @@
+Args.hasArg(options::OPT_fsanitize_EQ))
+  Diag(clang::diag::warn_drv_sanitizers_and_nodefaultlibs);
   }

How hard is to fire the warning only when the target assumes this behavior? It 
seems misleading (and noisy) to warn when -nodefaultlibs isn't bypassed.


https://reviews.llvm.org/D24091



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits