From: Evgeniy Stepanov Date: Wed, 5 Dec 2012 13:37:12 +0000 (+0000) Subject: Reuse an existing diagnostic for tsan/msan needing -pie error. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=99469f732efbd6600dfd0a70e0a36116a717dd06;p=clang Reuse an existing diagnostic for tsan/msan needing -pie error. Add a diagnosting for -fsanitize=memory conflicting with other sanitizers. Extend tests. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@169380 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Basic/DiagnosticDriverKinds.td b/include/clang/Basic/DiagnosticDriverKinds.td index 4a37ea7837..4b43035175 100644 --- a/include/clang/Basic/DiagnosticDriverKinds.td +++ b/include/clang/Basic/DiagnosticDriverKinds.td @@ -101,8 +101,6 @@ def err_drv_mg_requires_m_or_mm : Error< "option '-MG' requires '-M' or '-MM'">; def err_drv_asan_android_requires_pie : Error< "AddressSanitizer on Android requires '-pie'">; -def err_drv_sanitizer_requires_pie : Error< - "%select{Thread|Memory}0Sanitizer requires '-pie'">; def err_drv_unknown_objc_runtime : Error< "unknown or ill-formed Objective-C runtime '%0'">; diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp index d5f191cf8a..911a9dc512 100644 --- a/lib/Driver/Tools.cpp +++ b/lib/Driver/Tools.cpp @@ -1472,10 +1472,19 @@ SanitizerArgs::SanitizerArgs(const Driver &D, const ArgList &Args) { // Only one runtime library can be used at once. bool NeedsAsan = needsAsanRt(); bool NeedsTsan = needsTsanRt(); + bool NeedsMsan = needsMsanRt(); if (NeedsAsan && NeedsTsan) D.Diag(diag::err_drv_argument_not_allowed_with) << lastArgumentForKind(D, Args, NeedsAsanRt) << lastArgumentForKind(D, Args, NeedsTsanRt); + if (NeedsAsan && NeedsMsan) + D.Diag(diag::err_drv_argument_not_allowed_with) + << lastArgumentForKind(D, Args, NeedsAsanRt) + << lastArgumentForKind(D, Args, NeedsMsanRt); + if (NeedsTsan && NeedsMsan) + D.Diag(diag::err_drv_argument_not_allowed_with) + << lastArgumentForKind(D, Args, NeedsTsanRt) + << lastArgumentForKind(D, Args, NeedsMsanRt); // If -fsanitize contains extra features of ASan, it should also // explicitly contain -fsanitize=address. @@ -1545,8 +1554,8 @@ static void addTsanRTLinux(const ToolChain &TC, const ArgList &Args, ArgStringList &CmdArgs) { if (!Args.hasArg(options::OPT_shared)) { if (!Args.hasArg(options::OPT_pie)) - TC.getDriver().Diag(diag::err_drv_sanitizer_requires_pie) << - /* Thread */ 0; + TC.getDriver().Diag(diag::err_drv_argument_only_allowed_with) << + "-fsanitize=thread" << "-pie"; // LibTsan is "libclang_rt.tsan-.a" in the Linux library // resource directory. SmallString<128> LibTsan(TC.getDriver().ResourceDir); @@ -1566,8 +1575,8 @@ static void addMsanRTLinux(const ToolChain &TC, const ArgList &Args, ArgStringList &CmdArgs) { if (!Args.hasArg(options::OPT_shared)) { if (!Args.hasArg(options::OPT_pie)) - TC.getDriver().Diag(diag::err_drv_sanitizer_requires_pie) << - /* Memory */ 1; + TC.getDriver().Diag(diag::err_drv_argument_only_allowed_with) << + "-fsanitize=memory" << "-pie"; // LibMsan is "libclang_rt.msan-.a" in the Linux library // resource directory. SmallString<128> LibMsan(TC.getDriver().ResourceDir); diff --git a/test/Driver/fsanitize.c b/test/Driver/fsanitize.c index 4e3760f25d..80c1768afd 100644 --- a/test/Driver/fsanitize.c +++ b/test/Driver/fsanitize.c @@ -20,6 +20,15 @@ // RUN: %clang -target x86_64-linux-gnu -fsanitize=address,thread -fno-rtti %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-SANA-SANT // CHECK-SANA-SANT: '-fsanitize=address' not allowed with '-fsanitize=thread' +// RUN: %clang -target x86_64-linux-gnu -fsanitize=address,memory -fno-rtti %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-SANA-SANM +// CHECK-SANA-SANM: '-fsanitize=address' not allowed with '-fsanitize=memory' + +// RUN: %clang -target x86_64-linux-gnu -fsanitize=thread,memory -fno-rtti %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-SANT-SANM +// CHECK-SANT-SANM: '-fsanitize=thread' not allowed with '-fsanitize=memory' + +// RUN: %clang -target x86_64-linux-gnu -fsanitize=memory,thread -fno-rtti %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-SANM-SANT +// CHECK-SANM-SANT: '-fsanitize=thread' not allowed with '-fsanitize=memory' + // RUN: %clang -target x86_64-linux-gnu -faddress-sanitizer -fthread-sanitizer -fno-rtti %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-ASAN-TSAN // CHECK-ASAN-TSAN: '-faddress-sanitizer' not allowed with '-fthread-sanitizer' @@ -39,3 +48,12 @@ // CHECK-DEPRECATED: argument '-faddress-sanitizer' is deprecated, use '-fsanitize=address' instead // CHECK-DEPRECATED: argument '-fno-address-sanitizer' is deprecated, use '-fno-sanitize=address' instead // CHECK-DEPRECATED: argument '-fbounds-checking' is deprecated, use '-fsanitize=bounds' instead + +// RUN: %clang -target x86_64-linux-gnu -fsanitize=thread %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-TSAN-NO-PIE +// CHECK-TSAN-NO-PIE: invalid argument '-fsanitize=thread' only allowed with '-pie' + +// RUN: %clang -target x86_64-linux-gnu -fsanitize=memory %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-MSAN-NO-PIE +// CHECK-MSAN-NO-PIE: invalid argument '-fsanitize=memory' only allowed with '-pie' + +// RUN: %clang -target arm-linux-androideabi -fsanitize=address %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-ANDROID-ASAN-NO-PIE +// CHECK-ANDROID-ASAN-NO-PIE: AddressSanitizer on Android requires '-pie'