Index: include/clang/Basic/DiagnosticDriverKinds.td =================================================================== --- include/clang/Basic/DiagnosticDriverKinds.td +++ include/clang/Basic/DiagnosticDriverKinds.td @@ -85,6 +85,8 @@ "invalid deployment target for -stdlib=libc++ (requires %0 or later)">; def err_drv_malformed_sanitizer_blacklist : Error< "malformed sanitizer blacklist: '%0'">; +def note_drv_address_sanitizer_debug_runtime : Note< + "AddressSanitizer doesn't support linking with debug runtime libraries yet">; def err_target_unsupported_arch : Error<"the target architecture '%0' is not supported by the target '%1'">; Index: lib/Driver/Tools.cpp =================================================================== --- lib/Driver/Tools.cpp +++ lib/Driver/Tools.cpp @@ -3584,6 +3584,21 @@ Args.AddLastArg(CmdArgs, options::OPT_fno_elide_type); const SanitizerArgs &Sanitize = getToolChain().getSanitizerArgs(); + if (Sanitize.needsAsanRt()) { + Arg *DebugRTArg = nullptr; + if (Args.hasArg(options::OPT__SLASH_MTd)) + DebugRTArg = Args.getLastArg(options::OPT__SLASH_MTd); + if (Args.hasArg(options::OPT__SLASH_MDd)) + DebugRTArg = Args.getLastArg(options::OPT__SLASH_MDd); + if (Args.hasArg(options::OPT__SLASH_LDd)) + DebugRTArg = Args.getLastArg(options::OPT__SLASH_LDd); + if (DebugRTArg) { + D.Diag(diag::err_drv_argument_not_allowed_with) + << DebugRTArg->getAsString(Args) + << Args.getLastArg(options::OPT_fsanitize_EQ)->getAsString(Args); + D.Diag(diag::note_drv_address_sanitizer_debug_runtime); + } + } Sanitize.addArgs(Args, CmdArgs); if (!Args.hasFlag(options::OPT_fsanitize_recover, Index: test/Driver/fsanitize.c =================================================================== --- test/Driver/fsanitize.c +++ test/Driver/fsanitize.c @@ -153,3 +153,17 @@ // RUN: %clang -target x86_64-apple-darwin10 -fsanitize=function -fsanitize=undefined %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-FSAN-UBSAN-DARWIN // CHECK-FSAN-UBSAN-DARWIN: unsupported option '-fsanitize=function' for target 'x86_64-apple-darwin10' + +// RUN: %clang_cl -fsanitize=address -c -MDd -### -- %s 2>&1 | FileCheck %s -check-prefix=CHECK-ASAN-DEBUGRTL +// RUN: %clang_cl -fsanitize=address -c -MTd -### -- %s 2>&1 | FileCheck %s -check-prefix=CHECK-ASAN-DEBUGRTL +// RUN: %clang_cl -fsanitize=address -c -LDd -### -- %s 2>&1 | FileCheck %s -check-prefix=CHECK-ASAN-DEBUGRTL +// CHECK-ASAN-DEBUGRTL: error: invalid argument +// CHECK-ASAN-DEBUGRTL: not allowed with '-fsanitize=address' +// CHECK-ASAN-DEBUGRTL: note: AddressSanitizer doesn't support linking with debug runtime libraries yet + +// RUN: %clang_cl -fsanitize=address -c -MT -### -- %s 2>&1 | FileCheck %s -check-prefix=CHECK-ASAN-RELEASERTL +// RUN: %clang_cl -fsanitize=address -c -MD -### -- %s 2>&1 | FileCheck %s -check-prefix=CHECK-ASAN-RELEASERTL +// RUN: %clang_cl -fsanitize=address -c -LD -### -- %s 2>&1 | FileCheck %s -check-prefix=CHECK-ASAN-RELEASERTL +// CHECK-ASAN-RELEASERTL-NOT: error: invalid argument +// CHECK-ASAN-RELEASERTL-NOT: not allowed with '-fsanitize=address' +// CHECK-ASAN-RELEASERTL-NOT: note: AddressSanitizer doesn't support linking with debug runtime libraries yet