[PATCH] ignore --disable-free in clang when leak detection is enabled

Kostya Serebryany kcc at google.com
Thu Dec 26 02:39:47 PST 2013


Hi chandlerc, dblaikie,

Disobey --disable-free flag if LEAK_SANITIZER macro is defined, for PR18320.
This way the build for LeakSanitizer will need to use -DCMAKE_CXX_FLAGS=-DLEAK_SANITIZER

Alternatives:
1. use #if __has_feature(address_sanitizer). This will solve our immediate need
to make asan+lsan bootstrap clean, but will not allow to run lsan-only (w/o asan).

2. Check if we have lsan at run-time instead of build time.
This may actually be nicer, but the only good way to do that that I know of
is to use weak functions, which will require more ifdefs.

3. use getenv("CLANG_IS_RUNNING_UNDER_LEAK_DETECTOR").

4. probably various others, suggestions are welcome.

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

Files:
  lib/Frontend/CompilerInvocation.cpp

Index: lib/Frontend/CompilerInvocation.cpp
===================================================================
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -283,6 +283,16 @@
   return Success;
 }
 
+static bool LeakDetectionIsOn() {
+#ifdef LEAK_SANITIZER
+  // If we want to detect leaks with LeakSanitizer,
+  // -DLEAK_SANITIZER should be passed at compile time.
+  return 1;
+#else
+  return 0;
+#endif
+}
+
 static bool ParseMigratorArgs(MigratorOptions &Opts, ArgList &Args) {
   Opts.NoNSAllocReallocError = Args.hasArg(OPT_migrator_no_nsalloc_error);
   Opts.NoFinalizeRemoval = Args.hasArg(OPT_migrator_no_finalize_removal);
@@ -368,7 +378,8 @@
   Opts.CodeModel = Args.getLastArgValue(OPT_mcode_model);
   Opts.DebugPass = Args.getLastArgValue(OPT_mdebug_pass);
   Opts.DisableFPElim = Args.hasArg(OPT_mdisable_fp_elim);
-  Opts.DisableFree = Args.hasArg(OPT_disable_free);
+  Opts.DisableFree =
+      LeakDetectionIsOn() ? false : Args.hasArg(OPT_disable_free);
   Opts.DisableTailCalls = Args.hasArg(OPT_mdisable_tail_calls);
   Opts.FloatABI = Args.getLastArgValue(OPT_mfloat_abi);
   Opts.HiddenWeakVTables = Args.hasArg(OPT_fhidden_weak_vtables);
@@ -742,7 +753,8 @@
       Diags.Report(diag::err_drv_invalid_value)
         << A->getAsString(Args) << A->getValue();
   }
-  Opts.DisableFree = Args.hasArg(OPT_disable_free);
+  Opts.DisableFree =
+      LeakDetectionIsOn() ? false : Args.hasArg(OPT_disable_free);
 
   Opts.OutputFile = Args.getLastArgValue(OPT_o);
   Opts.Plugins = Args.getAllArgValues(OPT_load);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D2475.1.patch
Type: text/x-patch
Size: 1571 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20131226/2037b42a/attachment.bin>


More information about the cfe-commits mailing list