Index: include/clang/Basic/LangOptions.h =================================================================== --- include/clang/Basic/LangOptions.h +++ 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: include/clang/Basic/SanitizerBlacklist.h =================================================================== --- include/clang/Basic/SanitizerBlacklist.h +++ 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: include/clang/Driver/SanitizerArgs.h =================================================================== --- include/clang/Driver/SanitizerArgs.h +++ 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: lib/AST/ASTContext.cpp =================================================================== --- lib/AST/ASTContext.cpp +++ 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: lib/Basic/LangOptions.cpp =================================================================== --- lib/Basic/LangOptions.cpp +++ 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: lib/Basic/SanitizerBlacklist.cpp =================================================================== --- lib/Basic/SanitizerBlacklist.cpp +++ 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: lib/CodeGen/BackendUtil.cpp =================================================================== --- lib/CodeGen/BackendUtil.cpp +++ 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: lib/Driver/SanitizerArgs.cpp =================================================================== --- lib/Driver/SanitizerArgs.cpp +++ 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,36 @@ // -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)) { + for (const auto *BLArg : Args) { if (BLArg->getOption().matches(options::OPT_fsanitize_blacklist)) { + BLArg->claim(); 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 { + if (!llvm::sys::fs::exists(BLPath)) { D.Diag(clang::diag::err_drv_no_such_file) << BLPath; + continue; } + BlacklistFiles.push_back(BLPath); + } else if (BLArg->getOption().matches( + options::OPT_fno_sanitize_blacklist)) { + BLArg->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 +411,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: lib/Frontend/CompilerInvocation.cpp =================================================================== --- lib/Frontend/CompilerInvocation.cpp +++ lib/Frontend/CompilerInvocation.cpp @@ -1668,7 +1668,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: test/Driver/fsanitize-blacklist.c =================================================================== --- test/Driver/fsanitize-blacklist.c +++ test/Driver/fsanitize-blacklist.c @@ -22,5 +22,5 @@ // 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 +// RUN: %clang -fsanitize=address -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