]> granicus.if.org Git - clang/commitdiff
Append -fno-assume-sane-operator-new in ASan builds.
authorSergey Matveev <earthdok@google.com>
Tue, 17 Feb 2015 15:09:33 +0000 (15:09 +0000)
committerSergey Matveev <earthdok@google.com>
Tue, 17 Feb 2015 15:09:33 +0000 (15:09 +0000)
This should help LSan detect leaks where operator new would otherwise be
optimized out.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@229498 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Driver/SanitizerArgs.cpp
test/Driver/fsanitize.c

index 037fff29ab18ef94b5bfc9591943b707278e9c58..310f5e81f951e5548257189d61e8ca363dd59ec7 100644 (file)
@@ -424,8 +424,13 @@ void SanitizerArgs::addArgs(const llvm::opt::ArgList &Args,
   if (SanitizeCoverage)
     CmdArgs.push_back(Args.MakeArgString("-fsanitize-coverage=" +
                                          llvm::utostr(SanitizeCoverage)));
-  // Workaround for PR16386.
-  if (Sanitizers.has(SanitizerKind::Memory))
+  // MSan: Workaround for PR16386.
+  // ASan: This is mainly to help LSan with cases such as
+  // https://code.google.com/p/address-sanitizer/issues/detail?id=373
+  // We can't make this conditional on -fsanitize=leak, as that flag shouldn't
+  // affect compilation.
+  if (Sanitizers.has(SanitizerKind::Memory) ||
+      Sanitizers.has(SanitizerKind::Address))
     CmdArgs.push_back(Args.MakeArgString("-fno-assume-sane-operator-new"));
 }
 
index 1988503f677cef012ae534e27418faa17a00e77d..a5eea446149f32e041cd8beaf759e22fc8ca5208 100644 (file)
 
 // RUN: %clang -target x86_64-linux-gnu -fsanitize=memory %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-MSAN
 // CHECK-MSAN: "-fno-assume-sane-operator-new"
+// RUN: %clang -target x86_64-linux-gnu -fsanitize=address %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-ASAN
+// CHECK-ASAN: "-fno-assume-sane-operator-new"
 
 // RUN: %clang -target x86_64-linux-gnu -fsanitize=zzz %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-DIAG1
 // CHECK-DIAG1: unsupported argument 'zzz' to option 'fsanitize='