From: Alexey Samsonov Date: Fri, 19 Dec 2014 18:41:43 +0000 (+0000) Subject: Allow to disable all sanitizers with "-fno-sanitize=all" option. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2c8f904f31ca2af9f0e6deb82e62daf983b71745;p=clang Allow to disable all sanitizers with "-fno-sanitize=all" option. Summary: This patch adds "all" sanitizer group. A shortcut "-fno-sanitize=all" can be used to disable all sanitizers for a given source file. "-fsanitize=all" option makes no sense, and will produce an error. This group can also be useful when we add "-fsanitize-recover=" options (patch in http://reviews.llvm.org/D6302), as it would allow to conveniently enable/disable recovery for all specified sanitizers. Test Plan: regression test suite Reviewers: kcc, rsmith Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D6733 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@224596 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Basic/Sanitizers.def b/include/clang/Basic/Sanitizers.def index adb9b04072..91a1ef4d19 100644 --- a/include/clang/Basic/Sanitizers.def +++ b/include/clang/Basic/Sanitizers.def @@ -102,5 +102,9 @@ SANITIZER_GROUP("integer", Integer, SANITIZER("local-bounds", LocalBounds) SANITIZER_GROUP("bounds", Bounds, ArrayBounds | LocalBounds) +// Magic group, containing all sanitizers. For example, "-fno-sanitize=all" +// can be used to disable all the sanitizers. +SANITIZER_GROUP("all", All, ~0) + #undef SANITIZER #undef SANITIZER_GROUP diff --git a/lib/Driver/SanitizerArgs.cpp b/lib/Driver/SanitizerArgs.cpp index 2692d77a49..adffad2daa 100644 --- a/lib/Driver/SanitizerArgs.cpp +++ b/lib/Driver/SanitizerArgs.cpp @@ -427,15 +427,24 @@ unsigned parseArgValues(const Driver &D, const llvm::opt::Arg *A, assert((A->getOption().matches(options::OPT_fsanitize_EQ) || A->getOption().matches(options::OPT_fno_sanitize_EQ)) && "Invalid argument in parseArgValues!"); - unsigned Kind = 0; + unsigned Kinds = 0; for (unsigned I = 0, N = A->getNumValues(); I != N; ++I) { - if (unsigned K = parseValue(A->getValue(I))) - Kind |= K; + const char *Value = A->getValue(I); + unsigned Kind; + // Special case: don't accept -fsanitize=all. + if (A->getOption().matches(options::OPT_fsanitize_EQ) && + 0 == strcmp("all", Value)) + Kind = 0; + else + Kind = parseValue(Value); + + if (Kind) + Kinds |= Kind; else if (DiagnoseErrors) D.Diag(clang::diag::err_drv_unsupported_option_argument) - << A->getOption().getName() << A->getValue(I); + << A->getOption().getName() << Value; } - return Kind; + return Kinds; } std::string lastArgumentForMask(const Driver &D, const llvm::opt::ArgList &Args, diff --git a/test/Driver/fsanitize.c b/test/Driver/fsanitize.c index 2d15b4d1f4..dbe3c61f50 100644 --- a/test/Driver/fsanitize.c +++ b/test/Driver/fsanitize.c @@ -15,6 +15,12 @@ // RUN: %clang -fsanitize=bounds -### -fsyntax-only %s 2>&1 | FileCheck %s --check-prefix=CHECK-BOUNDS // CHECK-BOUNDS: "-fsanitize={{((array-bounds|local-bounds),?){2}"}} +// RUN: %clang -target x86_64-linux-gnu -fsanitize=all %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-FSANITIZE-ALL +// CHECK-FSANITIZE-ALL: error: unsupported argument 'all' to option 'fsanitize=' + +// RUN: %clang -target x86_64-linux-gnu -fsanitize=address,undefined -fno-sanitize=all -fsanitize=thread %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-FNO-SANITIZE-ALL +// CHECK-FNO-SANITIZE-ALL: "-fsanitize=thread" + // RUN: %clang -target x86_64-linux-gnu -fsanitize=thread,undefined -fno-sanitize=thread -fno-sanitize=float-cast-overflow,vptr,bool,enum %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-PARTIAL-UNDEFINED // CHECK-PARTIAL-UNDEFINED: "-fsanitize={{((signed-integer-overflow|integer-divide-by-zero|float-divide-by-zero|function|shift|unreachable|return|vla-bound|alignment|null|object-size|array-bounds|returns-nonnull-attribute|nonnull-attribute),?){14}"}}