Index: clang/include/clang/Driver/Options.td =================================================================== --- clang/include/clang/Driver/Options.td +++ clang/include/clang/Driver/Options.td @@ -851,6 +851,9 @@ def fsanitize_memory_use_after_dtor : Flag<["-"], "fsanitize-memory-use-after-dtor">, Group, HelpText<"Enable use-after-destroy detection in MemorySanitizer">; +def fno_sanitize_memory_use_after_dtor : Flag<["-"], "fno-sanitize-memory-use-after-dtor">, + Group, + HelpText<"Disable use-after-destroy detection in MemorySanitizer">; def fsanitize_address_field_padding : Joined<["-"], "fsanitize-address-field-padding=">, Group, HelpText<"Level of field padding for AddressSanitizer">; Index: clang/lib/Driver/SanitizerArgs.cpp =================================================================== --- clang/lib/Driver/SanitizerArgs.cpp +++ clang/lib/Driver/SanitizerArgs.cpp @@ -488,8 +488,14 @@ } } } - MsanUseAfterDtor = - Args.hasArg(options::OPT_fsanitize_memory_use_after_dtor); + if (Arg *A = + Args.getLastArg(options::OPT_fsanitize_memory_use_after_dtor, + options::OPT_fno_sanitize_memory_use_after_dtor)) { + MsanUseAfterDtor = A->getOption().matches( + options::OPT_fsanitize_memory_use_after_dtor); + } else { + MsanUseAfterDtor = true; + } NeedPIE |= !(TC.getTriple().isOSLinux() && TC.getTriple().getArch() == llvm::Triple::x86_64); } Index: clang/lib/Frontend/CompilerInvocation.cpp =================================================================== --- clang/lib/Frontend/CompilerInvocation.cpp +++ clang/lib/Frontend/CompilerInvocation.cpp @@ -828,6 +828,11 @@ Args.hasArg(OPT_fsanitize_coverage_stack_depth); Opts.SanitizeMemoryTrackOrigins = getLastArgIntValue(Args, OPT_fsanitize_memory_track_origins_EQ, 0, Diags); + if (Arg *A = Args.getLastArg(OPT_fsanitize_memory_use_after_dtor, + OPT_fno_sanitize_memory_use_after_dtor)) { + Opts.SanitizeMemoryUseAfterDtor = + A->getOption().matches(OPT_fsanitize_memory_use_after_dtor); + } Opts.SanitizeMemoryUseAfterDtor = Args.hasArg(OPT_fsanitize_memory_use_after_dtor); Opts.SanitizeMinimalRuntime = Args.hasArg(OPT_fsanitize_minimal_runtime); Index: clang/test/Driver/fsanitize.c =================================================================== --- clang/test/Driver/fsanitize.c +++ clang/test/Driver/fsanitize.c @@ -172,8 +172,14 @@ // RUN: %clang -target x86_64-linux-gnu -fsanitize=memory -fsanitize-memory-track-origins=3 -pie %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-TRACK-ORIGINS-3 // CHECK-TRACK-ORIGINS-3: error: invalid value '3' in '-fsanitize-memory-track-origins=3' -// RUN: %clang -target x86_64-linux-gnu -fsanitize=memory -fsanitize-memory-use-after-dtor -pie %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-MSAN-USE-AFTER-DTOR -// CHECK-MSAN-USE-AFTER-DTOR: -cc1{{.*}}-fsanitize-memory-use-after-dtor +// RUN: %clang -target x86_64-linux-gnu -fsanitize=memory -fsanitize-memory-use-after-dtor %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-USE-AFTER-DTOR +// RUN: %clang -target x86_64-linux-gnu -fsanitize=memory -fno-sanitize-memory-use-after-dtor -fsanitize-memory-use-after-dtor %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-USE-AFTER-DTOR +// RUN: %clang -target x86_64-linux-gnu -fsanitize=memory %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-USE-AFTER-DTOR +// CHECK-USE-AFTER-DTOR: -cc1{{.*}}-fsanitize-memory-use-after-dtor + +// RUN: %clang -target x86_64-linux-gnu -fsanitize=memory -fno-sanitize-memory-use-after-dtor %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-USE-AFTER-DTOR-OFF +// RUN: %clang -target x86_64-linux-gnu -fsanitize=memory -fsanitize-memory-use-after-dtor -fno-sanitize-memory-use-after-dtor %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-USE-AFTER-DTOR-OFF +// CHECK-USE-AFTER-DTOR-OFF-NOT: -cc1{{.*}}memory-use-after-dtor // RUN: %clang -target x86_64-linux-gnu -fsanitize=address -fsanitize-address-field-padding=0 %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-ASAN-FIELD-PADDING-0 // CHECK-ASAN-FIELD-PADDING-0-NOT: -fsanitize-address-field-padding Index: compiler-rt/test/msan/dtor-base-access.cc =================================================================== --- compiler-rt/test/msan/dtor-base-access.cc +++ compiler-rt/test/msan/dtor-base-access.cc @@ -1,8 +1,8 @@ -// RUN: %clangxx_msan %s -O0 -fsanitize=memory -fsanitize-memory-use-after-dtor -o %t && MSAN_OPTIONS=poison_in_dtor=1 %run %t >%t.out 2>&1 +// RUN: %clangxx_msan %s -O0 -o %t && MSAN_OPTIONS=poison_in_dtor=1 %run %t >%t.out 2>&1 -// RUN: %clangxx_msan %s -O1 -fsanitize=memory -fsanitize-memory-use-after-dtor -o %t && MSAN_OPTIONS=poison_in_dtor=1 %run %t >%t.out 2>&1 +// RUN: %clangxx_msan %s -O1 -o %t && MSAN_OPTIONS=poison_in_dtor=1 %run %t >%t.out 2>&1 -// RUN: %clangxx_msan %s -O2 -fsanitize=memory -fsanitize-memory-use-after-dtor -o %t && MSAN_OPTIONS=poison_in_dtor=1 %run %t >%t.out 2>&1 +// RUN: %clangxx_msan %s -O2 -o %t && MSAN_OPTIONS=poison_in_dtor=1 %run %t >%t.out 2>&1 #include #include Index: compiler-rt/test/msan/dtor-bit-fields.cc =================================================================== --- compiler-rt/test/msan/dtor-bit-fields.cc +++ compiler-rt/test/msan/dtor-bit-fields.cc @@ -1,8 +1,8 @@ -// RUN: %clangxx_msan %s -O0 -fsanitize=memory -fsanitize-memory-use-after-dtor -o %t && MSAN_OPTIONS=poison_in_dtor=1 %run %t +// RUN: %clangxx_msan %s -O0 -o %t && MSAN_OPTIONS=poison_in_dtor=1 %run %t -// RUN: %clangxx_msan %s -O1 -fsanitize=memory -fsanitize-memory-use-after-dtor -o %t && MSAN_OPTIONS=poison_in_dtor=1 %run %t +// RUN: %clangxx_msan %s -O1 -o %t && MSAN_OPTIONS=poison_in_dtor=1 %run %t -// RUN: %clangxx_msan %s -O2 -fsanitize=memory -fsanitize-memory-use-after-dtor -o %t && MSAN_OPTIONS=poison_in_dtor=1 %run %t +// RUN: %clangxx_msan %s -O2 -o %t && MSAN_OPTIONS=poison_in_dtor=1 %run %t #include #include Index: compiler-rt/test/msan/dtor-derived-class.cc =================================================================== --- compiler-rt/test/msan/dtor-derived-class.cc +++ compiler-rt/test/msan/dtor-derived-class.cc @@ -1,6 +1,6 @@ -// RUN: %clangxx_msan %s -O0 -fsanitize=memory -fsanitize-memory-use-after-dtor -o %t && MSAN_OPTIONS=poison_in_dtor=1 %run %t >%t.out 2>&1 -// RUN: %clangxx_msan %s -O1 -fsanitize=memory -fsanitize-memory-use-after-dtor -o %t && MSAN_OPTIONS=poison_in_dtor=1 %run %t >%t.out 2>&1 -// RUN: %clangxx_msan %s -O2 -fsanitize=memory -fsanitize-memory-use-after-dtor -o %t && MSAN_OPTIONS=poison_in_dtor=1 %run %t >%t.out 2>&1 +// RUN: %clangxx_msan %s -O0 -o %t && MSAN_OPTIONS=poison_in_dtor=1 %run %t >%t.out 2>&1 +// RUN: %clangxx_msan %s -O1 -o %t && MSAN_OPTIONS=poison_in_dtor=1 %run %t >%t.out 2>&1 +// RUN: %clangxx_msan %s -O2 -o %t && MSAN_OPTIONS=poison_in_dtor=1 %run %t >%t.out 2>&1 #include #include Index: compiler-rt/test/msan/dtor-member.cc =================================================================== --- compiler-rt/test/msan/dtor-member.cc +++ compiler-rt/test/msan/dtor-member.cc @@ -1,16 +1,16 @@ -// RUN: %clangxx_msan %s -fsanitize=memory -fsanitize-memory-use-after-dtor -o %t && MSAN_OPTIONS=poison_in_dtor=1 %run %t >%t.out 2>&1 +// RUN: %clangxx_msan %s -O0 -o %t && MSAN_OPTIONS=poison_in_dtor=1 %run %t >%t.out 2>&1 // RUN: FileCheck %s < %t.out -// RUN: %clangxx_msan %s -O1 -fsanitize=memory -fsanitize-memory-use-after-dtor -o %t && MSAN_OPTIONS=poison_in_dtor=1 %run %t >%t.out 2>&1 +// RUN: %clangxx_msan %s -O1 -o %t && MSAN_OPTIONS=poison_in_dtor=1 %run %t >%t.out 2>&1 // RUN: FileCheck %s < %t.out -// RUN: %clangxx_msan %s -O2 -fsanitize=memory -fsanitize-memory-use-after-dtor -o %t && MSAN_OPTIONS=poison_in_dtor=1 %run %t >%t.out 2>&1 +// RUN: %clangxx_msan %s -O2 -o %t && MSAN_OPTIONS=poison_in_dtor=1 %run %t >%t.out 2>&1 // RUN: FileCheck %s < %t.out -// RUN: %clangxx_msan %s -fsanitize=memory -o %t && MSAN_OPTIONS=poison_in_dtor=1 %run %t >%t.out 2>&1 +// RUN: %clangxx_msan %s -fno-sanitize-memory-use-after-dtor -o %t && MSAN_OPTIONS=poison_in_dtor=1 %run %t >%t.out 2>&1 // RUN: FileCheck %s --check-prefix=CHECK-NO-FLAG < %t.out -// RUN: %clangxx_msan -fsanitize=memory -fsanitize-memory-use-after-dtor %s -o %t && MSAN_OPTIONS=poison_in_dtor=0 %run %t >%t.out 2>&1 +// RUN: %clangxx_msan %s -o %t && MSAN_OPTIONS=poison_in_dtor=0 %run %t >%t.out 2>&1 // RUN: FileCheck %s --check-prefix=CHECK-NO-FLAG < %t.out #include Index: compiler-rt/test/msan/dtor-multiple-inheritance-nontrivial-class-members.cc =================================================================== --- compiler-rt/test/msan/dtor-multiple-inheritance-nontrivial-class-members.cc +++ compiler-rt/test/msan/dtor-multiple-inheritance-nontrivial-class-members.cc @@ -1,8 +1,8 @@ -// RUN: %clangxx_msan %s -O0 -fsanitize=memory -fsanitize-memory-use-after-dtor -o %t && MSAN_OPTIONS=poison_in_dtor=1 %run %t >%t.out 2>&1 +// RUN: %clangxx_msan %s -O0 -o %t && MSAN_OPTIONS=poison_in_dtor=1 %run %t >%t.out 2>&1 -// RUN: %clangxx_msan %s -O1 -fsanitize=memory -fsanitize-memory-use-after-dtor -o %t && MSAN_OPTIONS=poison_in_dtor=1 %run %t >%t.out 2>&1 +// RUN: %clangxx_msan %s -O1 -o %t && MSAN_OPTIONS=poison_in_dtor=1 %run %t >%t.out 2>&1 -// RUN: %clangxx_msan %s -O2 -fsanitize=memory -fsanitize-memory-use-after-dtor -o %t && MSAN_OPTIONS=poison_in_dtor=1 %run %t >%t.out 2>&1 +// RUN: %clangxx_msan %s -O2 -o %t && MSAN_OPTIONS=poison_in_dtor=1 %run %t >%t.out 2>&1 #include #include Index: compiler-rt/test/msan/dtor-multiple-inheritance.cc =================================================================== --- compiler-rt/test/msan/dtor-multiple-inheritance.cc +++ compiler-rt/test/msan/dtor-multiple-inheritance.cc @@ -5,11 +5,11 @@ // \ / // Derived -// RUN: %clangxx_msan %s -O0 -fsanitize=memory -fsanitize-memory-use-after-dtor -o %t && MSAN_OPTIONS=poison_in_dtor=1 %run %t >%t.out 2>&1 +// RUN: %clangxx_msan %s -O0 -o %t && MSAN_OPTIONS=poison_in_dtor=1 %run %t >%t.out 2>&1 -// RUN: %clangxx_msan %s -O1 -fsanitize=memory -fsanitize-memory-use-after-dtor -o %t && MSAN_OPTIONS=poison_in_dtor=1 %run %t >%t.out 2>&1 +// RUN: %clangxx_msan %s -O1 -o %t && MSAN_OPTIONS=poison_in_dtor=1 %run %t >%t.out 2>&1 -// RUN: %clangxx_msan %s -O2 -fsanitize=memory -fsanitize-memory-use-after-dtor -o %t && MSAN_OPTIONS=poison_in_dtor=1 %run %t >%t.out 2>&1 +// RUN: %clangxx_msan %s -O2 -o %t && MSAN_OPTIONS=poison_in_dtor=1 %run %t >%t.out 2>&1 #include #include Index: compiler-rt/test/msan/dtor-trivial-class-members.cc =================================================================== --- compiler-rt/test/msan/dtor-trivial-class-members.cc +++ compiler-rt/test/msan/dtor-trivial-class-members.cc @@ -1,8 +1,8 @@ -// RUN: %clangxx_msan %s -O0 -fsanitize=memory -fsanitize-memory-use-after-dtor -o %t && MSAN_OPTIONS=poison_in_dtor=1 %run %t >%t.out 2>&1 +// RUN: %clangxx_msan %s -O0 -o %t && MSAN_OPTIONS=poison_in_dtor=1 %run %t >%t.out 2>&1 -// RUN: %clangxx_msan %s -O1 -fsanitize=memory -fsanitize-memory-use-after-dtor -o %t && MSAN_OPTIONS=poison_in_dtor=1 %run %t >%t.out 2>&1 +// RUN: %clangxx_msan %s -O1 -o %t && MSAN_OPTIONS=poison_in_dtor=1 %run %t >%t.out 2>&1 -// RUN: %clangxx_msan %s -O2 -fsanitize=memory -fsanitize-memory-use-after-dtor -o %t && MSAN_OPTIONS=poison_in_dtor=1 %run %t >%t.out 2>&1 +// RUN: %clangxx_msan %s -O2 -o %t && MSAN_OPTIONS=poison_in_dtor=1 %run %t >%t.out 2>&1 #include #include Index: compiler-rt/test/msan/dtor-trivial.cpp =================================================================== --- compiler-rt/test/msan/dtor-trivial.cpp +++ compiler-rt/test/msan/dtor-trivial.cpp @@ -1,8 +1,8 @@ -// RUN: %clangxx_msan %s -O0 -fsanitize=memory -fsanitize-memory-use-after-dtor -o %t && MSAN_OPTIONS=poison_in_dtor=1 %run %t >%t.out 2>&1 +// RUN: %clangxx_msan %s -O0 -o %t && MSAN_OPTIONS=poison_in_dtor=1 %run %t >%t.out 2>&1 -// RUN: %clangxx_msan %s -O1 -fsanitize=memory -fsanitize-memory-use-after-dtor -o %t && MSAN_OPTIONS=poison_in_dtor=1 %run %t >%t.out 2>&1 +// RUN: %clangxx_msan %s -O1 -o %t && MSAN_OPTIONS=poison_in_dtor=1 %run %t >%t.out 2>&1 -// RUN: %clangxx_msan %s -O2 -fsanitize=memory -fsanitize-memory-use-after-dtor -o %t && MSAN_OPTIONS=poison_in_dtor=1 %run %t >%t.out 2>&1 +// RUN: %clangxx_msan %s -O2 -o %t && MSAN_OPTIONS=poison_in_dtor=1 %run %t >%t.out 2>&1 // TODO Success pending on resolution of // https://github.com/google/sanitizers/issues/596 Index: compiler-rt/test/msan/dtor-vtable-multiple-inheritance.cc =================================================================== --- compiler-rt/test/msan/dtor-vtable-multiple-inheritance.cc +++ compiler-rt/test/msan/dtor-vtable-multiple-inheritance.cc @@ -1,14 +1,14 @@ -// RUN: %clangxx_msan %s -O0 -fsanitize=memory -fsanitize-memory-use-after-dtor -o %t && MSAN_OPTIONS=poison_in_dtor=1 %run %t +// RUN: %clangxx_msan %s -O0 -o %t && MSAN_OPTIONS=poison_in_dtor=1 %run %t -// RUN: %clangxx_msan %s -O1 -fsanitize=memory -fsanitize-memory-use-after-dtor -o %t && MSAN_OPTIONS=poison_in_dtor=1 %run %t +// RUN: %clangxx_msan %s -O1 -o %t && MSAN_OPTIONS=poison_in_dtor=1 %run %t -// RUN: %clangxx_msan %s -O2 -fsanitize=memory -fsanitize-memory-use-after-dtor -o %t && MSAN_OPTIONS=poison_in_dtor=1 %run %t +// RUN: %clangxx_msan %s -O2 -o %t && MSAN_OPTIONS=poison_in_dtor=1 %run %t -// RUN: %clangxx_msan %s -DCVPTR=1 -O2 -fsanitize=memory -fsanitize-memory-use-after-dtor -o %t && MSAN_OPTIONS=poison_in_dtor=1 not %run %t +// RUN: %clangxx_msan %s -DCVPTR=1 -O2 -o %t && MSAN_OPTIONS=poison_in_dtor=1 not %run %t -// RUN: %clangxx_msan %s -DEAVPTR=1 -O2 -fsanitize=memory -fsanitize-memory-use-after-dtor -o %t && MSAN_OPTIONS=poison_in_dtor=1 not %run %t +// RUN: %clangxx_msan %s -DEAVPTR=1 -O2 -o %t && MSAN_OPTIONS=poison_in_dtor=1 not %run %t -// RUN: %clangxx_msan %s -DEDVPTR=1 -O2 -fsanitize=memory -fsanitize-memory-use-after-dtor -o %t && MSAN_OPTIONS=poison_in_dtor=1 not %run %t +// RUN: %clangxx_msan %s -DEDVPTR=1 -O2 -o %t && MSAN_OPTIONS=poison_in_dtor=1 not %run %t // Expected to quit due to invalid access when invoking // function using vtable. Index: compiler-rt/test/msan/dtor-vtable.cc =================================================================== --- compiler-rt/test/msan/dtor-vtable.cc +++ compiler-rt/test/msan/dtor-vtable.cc @@ -1,16 +1,16 @@ -// RUN: %clangxx_msan %s -O0 -fsanitize=memory -fsanitize-memory-use-after-dtor -o %t && MSAN_OPTIONS=poison_in_dtor=1 %run %t +// RUN: %clangxx_msan %s -O0 -o %t && MSAN_OPTIONS=poison_in_dtor=1 %run %t -// RUN: %clangxx_msan %s -O1 -fsanitize=memory -fsanitize-memory-use-after-dtor -o %t && MSAN_OPTIONS=poison_in_dtor=1 %run %t +// RUN: %clangxx_msan %s -O1 -o %t && MSAN_OPTIONS=poison_in_dtor=1 %run %t -// RUN: %clangxx_msan %s -O2 -fsanitize=memory -fsanitize-memory-use-after-dtor -o %t && MSAN_OPTIONS=poison_in_dtor=1 %run %t +// RUN: %clangxx_msan %s -O2 -o %t && MSAN_OPTIONS=poison_in_dtor=1 %run %t -// RUN: %clangxx_msan %s -DVPTRA=1 -O2 -fsanitize=memory -fsanitize-memory-use-after-dtor -o %t && MSAN_OPTIONS=poison_in_dtor=1 not %run %t +// RUN: %clangxx_msan %s -DVPTRA=1 -O2 -o %t && MSAN_OPTIONS=poison_in_dtor=1 not %run %t -// RUN: %clangxx_msan %s -DVPTRCA=1 -O2 -fsanitize=memory -fsanitize-memory-use-after-dtor -o %t && MSAN_OPTIONS=poison_in_dtor=1 not %run %t +// RUN: %clangxx_msan %s -DVPTRCA=1 -O2 -o %t && MSAN_OPTIONS=poison_in_dtor=1 not %run %t -// RUN: %clangxx_msan %s -DVPTRCB=1 -O2 -fsanitize=memory -fsanitize-memory-use-after-dtor -o %t && MSAN_OPTIONS=poison_in_dtor=1 not %run %t +// RUN: %clangxx_msan %s -DVPTRCB=1 -O2 -o %t && MSAN_OPTIONS=poison_in_dtor=1 not %run %t -// RUN: %clangxx_msan %s -DVPTRC=1 -O2 -fsanitize=memory -fsanitize-memory-use-after-dtor -o %t && MSAN_OPTIONS=poison_in_dtor=1 not %run %t +// RUN: %clangxx_msan %s -DVPTRC=1 -O2 -o %t && MSAN_OPTIONS=poison_in_dtor=1 not %run %t // Expected to quit due to invalid access when invoking // function using vtable. Index: compiler-rt/test/msan/use-after-dtor.cc =================================================================== --- compiler-rt/test/msan/use-after-dtor.cc +++ compiler-rt/test/msan/use-after-dtor.cc @@ -1,13 +1,13 @@ -// RUN: %clangxx_msan %s -fsanitize=memory -fsanitize-memory-use-after-dtor -o %t && MSAN_OPTIONS=poison_in_dtor=1 not %run %t >%t.out 2>&1 +// RUN: %clangxx_msan %s -O0 -o %t && MSAN_OPTIONS=poison_in_dtor=1 not %run %t >%t.out 2>&1 // RUN: FileCheck %s < %t.out -// RUN: %clangxx_msan %s -O1 -fsanitize=memory -fsanitize-memory-use-after-dtor -o %t && MSAN_OPTIONS=poison_in_dtor=1 not %run %t >%t.out 2>&1 +// RUN: %clangxx_msan %s -O1 -o %t && MSAN_OPTIONS=poison_in_dtor=1 not %run %t >%t.out 2>&1 // RUN: FileCheck %s < %t.out -// RUN: %clangxx_msan %s -O2 -fsanitize=memory -fsanitize-memory-use-after-dtor -o %t && MSAN_OPTIONS=poison_in_dtor=1 not %run %t >%t.out 2>&1 +// RUN: %clangxx_msan %s -O2 -o %t && MSAN_OPTIONS=poison_in_dtor=1 not %run %t >%t.out 2>&1 // RUN: FileCheck %s < %t.out -// RUN: %clangxx_msan %s -O1 -fsanitize=memory -fsanitize-memory-use-after-dtor -fsanitize-memory-track-origins -o %t && MSAN_OPTIONS=poison_in_dtor=1 not %run %t >%t.out 2>&1 +// RUN: %clangxx_msan %s -O1 -fsanitize-memory-track-origins -o %t && MSAN_OPTIONS=poison_in_dtor=1 not %run %t >%t.out 2>&1 // RUN: FileCheck %s --check-prefix=CHECK-ORIGINS < %t.out #include