Index: cfe/trunk/include/clang/Basic/LangOptions.h =================================================================== --- cfe/trunk/include/clang/Basic/LangOptions.h +++ cfe/trunk/include/clang/Basic/LangOptions.h @@ -21,6 +21,7 @@ #include "clang/Basic/Sanitizers.h" #include "clang/Basic/Visibility.h" #include +#include namespace clang { @@ -70,9 +71,9 @@ /// \brief Set of enabled sanitizers. SanitizerSet Sanitize; - /// \brief Path to blacklist file specifying which objects + /// \brief Paths to blacklist files specifying which objects /// (files, functions, variables) should not be instrumented. - std::string SanitizerBlacklistFile; + std::vector SanitizerBlacklistFiles; clang::ObjCRuntime ObjCRuntime; Index: cfe/trunk/include/clang/Basic/SanitizerBlacklist.h =================================================================== --- cfe/trunk/include/clang/Basic/SanitizerBlacklist.h +++ cfe/trunk/include/clang/Basic/SanitizerBlacklist.h @@ -28,7 +28,8 @@ SourceManager &SM; public: - SanitizerBlacklist(StringRef BlacklistPath, SourceManager &SM); + SanitizerBlacklist(const std::vector &BlacklistPaths, + SourceManager &SM); bool isBlacklistedGlobal(StringRef GlobalName, StringRef Category = StringRef()) const; bool isBlacklistedType(StringRef MangledTypeName, Index: cfe/trunk/include/clang/Driver/SanitizerArgs.h =================================================================== --- cfe/trunk/include/clang/Driver/SanitizerArgs.h +++ cfe/trunk/include/clang/Driver/SanitizerArgs.h @@ -13,6 +13,7 @@ #include "llvm/Option/Arg.h" #include "llvm/Option/ArgList.h" #include +#include namespace clang { namespace driver { @@ -24,7 +25,7 @@ SanitizerSet Sanitizers; SanitizerSet RecoverableSanitizers; - std::string BlacklistFile; + std::vector BlacklistFiles; int SanitizeCoverage; int MsanTrackOrigins; int AsanFieldPadding; Index: cfe/trunk/lib/AST/ASTContext.cpp =================================================================== --- cfe/trunk/lib/AST/ASTContext.cpp +++ cfe/trunk/lib/AST/ASTContext.cpp @@ -737,9 +737,8 @@ FILEDecl(nullptr), jmp_bufDecl(nullptr), sigjmp_bufDecl(nullptr), ucontext_tDecl(nullptr), BlockDescriptorType(nullptr), BlockDescriptorExtendedType(nullptr), cudaConfigureCallDecl(nullptr), - FirstLocalImport(), LastLocalImport(), - SourceMgr(SM), LangOpts(LOpts), - SanitizerBL(new SanitizerBlacklist(LangOpts.SanitizerBlacklistFile, SM)), + FirstLocalImport(), LastLocalImport(), SourceMgr(SM), LangOpts(LOpts), + SanitizerBL(new SanitizerBlacklist(LangOpts.SanitizerBlacklistFiles, SM)), AddrSpaceMap(nullptr), Target(nullptr), PrintingPolicy(LOpts), Idents(idents), Selectors(sels), BuiltinInfo(builtins), DeclarationNames(*this), ExternalSource(nullptr), Listener(nullptr), Index: cfe/trunk/lib/Basic/LangOptions.cpp =================================================================== --- cfe/trunk/lib/Basic/LangOptions.cpp +++ cfe/trunk/lib/Basic/LangOptions.cpp @@ -30,7 +30,7 @@ // FIXME: This should not be reset; modules can be different with different // sanitizer options (this affects __has_feature(address_sanitizer) etc). Sanitize.clear(); - SanitizerBlacklistFile.clear(); + SanitizerBlacklistFiles.clear(); CurrentModule.clear(); ImplementationOfModule.clear(); Index: cfe/trunk/lib/Basic/SanitizerBlacklist.cpp =================================================================== --- cfe/trunk/lib/Basic/SanitizerBlacklist.cpp +++ cfe/trunk/lib/Basic/SanitizerBlacklist.cpp @@ -15,9 +15,9 @@ using namespace clang; -SanitizerBlacklist::SanitizerBlacklist(StringRef BlacklistPath, - SourceManager &SM) - : SCL(llvm::SpecialCaseList::createOrDie(BlacklistPath)), SM(SM) {} +SanitizerBlacklist::SanitizerBlacklist( + const std::vector &BlacklistPaths, SourceManager &SM) + : SCL(llvm::SpecialCaseList::createOrDie(BlacklistPaths)), SM(SM) {} bool SanitizerBlacklist::isBlacklistedGlobal(StringRef GlobalName, StringRef Category) const { Index: cfe/trunk/lib/CodeGen/BackendUtil.cpp =================================================================== --- cfe/trunk/lib/CodeGen/BackendUtil.cpp +++ cfe/trunk/lib/CodeGen/BackendUtil.cpp @@ -232,7 +232,7 @@ const PassManagerBuilderWrapper &BuilderWrapper = static_cast(Builder); const LangOptions &LangOpts = BuilderWrapper.getLangOpts(); - PM.add(createDataFlowSanitizerPass(LangOpts.SanitizerBlacklistFile)); + PM.add(createDataFlowSanitizerPass(LangOpts.SanitizerBlacklistFiles)); } static TargetLibraryInfoImpl *createTLII(llvm::Triple &TargetTriple, Index: cfe/trunk/lib/Driver/SanitizerArgs.cpp =================================================================== --- cfe/trunk/lib/Driver/SanitizerArgs.cpp +++ cfe/trunk/lib/Driver/SanitizerArgs.cpp @@ -151,7 +151,7 @@ void SanitizerArgs::clear() { Sanitizers.clear(); RecoverableSanitizers.clear(); - BlacklistFile = ""; + BlacklistFiles.clear(); SanitizeCoverage = 0; MsanTrackOrigins = 0; AsanFieldPadding = 0; @@ -285,30 +285,34 @@ // -f(-no)sanitize=leak should change whether leak detection is enabled by // default in ASan? + // Setup blacklist files. + // Add default blacklist from resource directory. + { + std::string BLPath; + if (getDefaultBlacklist(D, BLPath) && llvm::sys::fs::exists(BLPath)) + BlacklistFiles.push_back(BLPath); + } // Parse -f(no-)sanitize-blacklist options. - if (Arg *BLArg = Args.getLastArg(options::OPT_fsanitize_blacklist, - options::OPT_fno_sanitize_blacklist)) { - if (BLArg->getOption().matches(options::OPT_fsanitize_blacklist)) { - std::string BLPath = BLArg->getValue(); - if (llvm::sys::fs::exists(BLPath)) { - // Validate the blacklist format. - std::string BLError; - std::unique_ptr SCL( - llvm::SpecialCaseList::create(BLPath, BLError)); - if (!SCL.get()) - D.Diag(clang::diag::err_drv_malformed_sanitizer_blacklist) << BLError; - else - BlacklistFile = BLPath; - } else { + for (const auto *Arg : Args) { + if (Arg->getOption().matches(options::OPT_fsanitize_blacklist)) { + Arg->claim(); + std::string BLPath = Arg->getValue(); + if (llvm::sys::fs::exists(BLPath)) + BlacklistFiles.push_back(BLPath); + else D.Diag(clang::diag::err_drv_no_such_file) << BLPath; - } + } else if (Arg->getOption().matches(options::OPT_fno_sanitize_blacklist)) { + Arg->claim(); + BlacklistFiles.clear(); } - } else { - // If no -fsanitize-blacklist option is specified, try to look up for - // blacklist in the resource directory. - std::string BLPath; - if (getDefaultBlacklist(D, BLPath) && llvm::sys::fs::exists(BLPath)) - BlacklistFile = BLPath; + } + // Validate blacklists format. + { + std::string BLError; + std::unique_ptr SCL( + llvm::SpecialCaseList::create(BlacklistFiles, BLError)); + if (!SCL.get()) + D.Diag(clang::diag::err_drv_malformed_sanitizer_blacklist) << BLError; } // Parse -f[no-]sanitize-memory-track-origins[=level] options. @@ -405,9 +409,9 @@ if (UbsanTrapOnError) CmdArgs.push_back("-fsanitize-undefined-trap-on-error"); - if (!BlacklistFile.empty()) { + for (const auto &BLPath : BlacklistFiles) { SmallString<64> BlacklistOpt("-fsanitize-blacklist="); - BlacklistOpt += BlacklistFile; + BlacklistOpt += BLPath; CmdArgs.push_back(Args.MakeArgString(BlacklistOpt)); } Index: cfe/trunk/lib/Frontend/CompilerInvocation.cpp =================================================================== --- cfe/trunk/lib/Frontend/CompilerInvocation.cpp +++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp @@ -1669,7 +1669,7 @@ // -fsanitize-address-field-padding=N has to be a LangOpt, parse it here. Opts.SanitizeAddressFieldPadding = getLastArgIntValue(Args, OPT_fsanitize_address_field_padding, 0, Diags); - Opts.SanitizerBlacklistFile = Args.getLastArgValue(OPT_fsanitize_blacklist); + Opts.SanitizerBlacklistFiles = Args.getAllArgValues(OPT_fsanitize_blacklist); } static void ParsePreprocessorArgs(PreprocessorOptions &Opts, ArgList &Args, Index: cfe/trunk/test/Driver/fsanitize-blacklist.c =================================================================== --- cfe/trunk/test/Driver/fsanitize-blacklist.c +++ cfe/trunk/test/Driver/fsanitize-blacklist.c @@ -4,10 +4,12 @@ // REQUIRES: clang-driver, shell // RUN: echo "fun:foo" > %t.good +// RUN: echo "fun:bar" > %t.second // RUN: echo "badline" > %t.bad -// RUN: %clang -fsanitize=address -fsanitize-blacklist=%t.good %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-BLACKLIST -// CHECK-BLACKLIST: -fsanitize-blacklist +// RUN: %clang -fsanitize=address -fsanitize-blacklist=%t.good -fsanitize-blacklist=%t.second %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-BLACKLIST +// CHECK-BLACKLIST: -fsanitize-blacklist={{.*}}.good +// CHECK-BLACKLIST: -fsanitize-blacklist={{.*}}.second // Ignore -fsanitize-blacklist flag if there is no -fsanitize flag. // RUN: %clang -fsanitize-blacklist=%t.good %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-NO-SANITIZE @@ -22,5 +24,11 @@ // CHECK-NO-SUCH-FILE: error: no such file or directory: 'unexisting.txt' // Driver properly reports malformed blacklist files. -// RUN: %clang -fsanitize=address -fsanitize-blacklist=%t.bad %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-BAD-BLACKLIST -// CHECK-BAD-BLACKLIST: error: malformed sanitizer blacklist +// RUN: %clang -fsanitize=address -fsanitize-blacklist=%t.second -fsanitize-blacklist=%t.bad -fsanitize-blacklist=%t.good %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-BAD-BLACKLIST +// CHECK-BAD-BLACKLIST: error: malformed sanitizer blacklist: 'error parsing file '{{.*}}.bad': malformed line 1: 'badline'' + +// -fno-sanitize-blacklist disables all blacklists specified earlier. +// RUN: %clang -fsanitize=address -fsanitize-blacklist=%t.good -fno-sanitize-blacklist -fsanitize-blacklist=%t.second %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-ONLY-FIRST-DISABLED +// CHECK-ONLY_FIRST-DISABLED-NOT: good +// CHECK-ONLY-FIRST-DISABLED: -fsanitize-blacklist={{.*}}.second +// CHECK-ONLY_FIRST-DISABLED-NOT: good