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,13 @@ 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.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,16 @@ // 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 +// 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: {{^ *"}}