Index: clang/include/clang/Driver/Options.td =================================================================== --- clang/include/clang/Driver/Options.td +++ clang/include/clang/Driver/Options.td @@ -1013,6 +1013,9 @@ def fno_sanitize_blacklist : Flag<["-"], "fno-sanitize-blacklist">, Group, HelpText<"Don't use blacklist file for sanitizers">; +def fno_system_sanitize_blacklist : Flag<["-"], "fno-system-sanitize-blacklist">, + Group, + HelpText<"Don't use system blacklist file for sanitizers">; def fsanitize_coverage : CommaJoined<["-"], "fsanitize-coverage=">, Group, Index: clang/lib/Driver/SanitizerArgs.cpp =================================================================== --- clang/lib/Driver/SanitizerArgs.cpp +++ clang/lib/Driver/SanitizerArgs.cpp @@ -117,6 +117,19 @@ /// Sanitizers set. static std::string toString(const clang::SanitizerSet &Sanitizers); +static void validateSpecialCaseListFormat(const Driver &D, + std::vector &SCLFiles, + unsigned MalformedSCLErrorDiagID) { + if (SCLFiles.empty()) + return; + + std::string BLError; + std::unique_ptr SCL( + llvm::SpecialCaseList::create(SCLFiles, D.getVFS(), BLError)); + if (!SCL.get()) + D.Diag(MalformedSCLErrorDiagID) << BLError; +} + static void addDefaultBlacklists(const Driver &D, SanitizerMask Kinds, std::vector &BlacklistFiles) { struct Blacklist { @@ -147,6 +160,8 @@ // should fail. D.Diag(clang::diag::err_drv_no_such_file) << Path; } + validateSpecialCaseListFormat( + D, BlacklistFiles, clang::diag::err_drv_malformed_sanitizer_blacklist); } /// Parse -f(no-)?sanitize-(coverage-)?(white|black)list argument's values, @@ -173,14 +188,7 @@ SCLFiles.clear(); } } - // Validate special case list format. - { - std::string BLError; - std::unique_ptr SCL( - llvm::SpecialCaseList::create(SCLFiles, D.getVFS(), BLError)); - if (!SCL.get()) - D.Diag(MalformedSCLErrorDiagID) << BLError; - } + validateSpecialCaseListFormat(D, SCLFiles, MalformedSCLErrorDiagID); } /// Sets group bits for every group that has at least one representative already @@ -566,16 +574,14 @@ RecoverableKinds &= ~TrappingKinds; // Setup blacklist files. - // Add default blacklist from resource directory. - addDefaultBlacklists(D, Kinds, SystemBlacklistFiles); + // Add default blacklist from resource directory for activated sanitizers, and + // validate special case lists format. + if (!Args.hasArg(options::OPT_fno_system_sanitize_blacklist) && + !Args.hasArgNoClaim(options::OPT_fno_sanitize_blacklist)) + addDefaultBlacklists(D, Kinds, SystemBlacklistFiles); // Parse -f(no-)?sanitize-blacklist options. // This also validates special case lists format. - // Here, OptSpecifier() acts as a never-matching command-line argument. - // So, there is no way to append to system blacklist but it can be cleared. - parseSpecialCaseListArg(D, Args, SystemBlacklistFiles, OptSpecifier(), - options::OPT_fno_sanitize_blacklist, - clang::diag::err_drv_malformed_sanitizer_blacklist); parseSpecialCaseListArg(D, Args, UserBlacklistFiles, options::OPT_fsanitize_blacklist, options::OPT_fno_sanitize_blacklist, Index: clang/test/Driver/fsanitize-blacklist.c =================================================================== --- clang/test/Driver/fsanitize-blacklist.c +++ clang/test/Driver/fsanitize-blacklist.c @@ -59,8 +59,18 @@ // CHECK-ONLY-FIRST-DISABLED: -fsanitize-blacklist={{.*}}.second // CHECK-ONLY_FIRST-DISABLED-NOT: good +// -fno-sanitize-blacklist disables the system blacklists. +// RUN: %clang -target x86_64-linux-gnu -fsanitize=address -fno-sanitize-blacklist %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-DISABLED-SYSTEM --check-prefix=DELIMITERS +// -fno-system-sanitize-blacklist disables the system blacklists. +// RUN: %clang -target x86_64-linux-gnu -fsanitize=address -fno-system-sanitize-blacklist %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-DISABLED-SYSTEM --check-prefix=DELIMITERS +// CHECK-DISABLED-SYSTEM-NOT: -fsanitize-system-blacklist + // If cfi_blacklist.txt cannot be found in the resource dir, driver should fail. -// RUN: %clang -target x86_64-linux-gnu -fsanitize=cfi -resource-dir=/dev/null %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-MISSING-CFI-BLACKLIST +// RUN: %clang -target x86_64-linux-gnu -fsanitize=cfi -flto -fvisibility=default -resource-dir=/dev/null %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-MISSING-CFI-BLACKLIST // CHECK-MISSING-CFI-BLACKLIST: error: no such file or directory: '{{.*}}cfi_blacklist.txt' +// -fno-sanitize-blacklist disables checking for cfi_blacklist.txt in the resource dir. +// RUN: %clang -target x86_64-linux-gnu -fsanitize=cfi -flto -fvisibility=default -fno-sanitize-blacklist -resource-dir=/dev/null %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-MISSING-CFI-NO-BLACKLIST +// CHECK-MISSING-CFI-NO-BLACKLIST-NOT: error: no such file or directory: '{{.*}}cfi_blacklist.txt' + // DELIMITERS: {{^ *"}}