llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-llvm-support @llvm/pr-subscribers-clang-driver Author: Vitaly Buka (vitalybuka) <details> <summary>Changes</summary> Clang often combines multiple sanitizers (such as ASan and UBSan) and reads multiple ignorelist files in the same compilation. Entries without a `[section]` header fall into the implicit `[*]` section and apply to all enabled sanitizers, so an unsectioned ASan or UBSan suppression unexpectedly disables checks in the other sanitizer as well. Add version 6 (`#!special-case-list-v6`), which disallows entries without a preceding section header and reports a parse error instead. Assisted-by: Gemini --- Full diff: https://github.com/llvm/llvm-project/pull/243258.diff 6 Files Affected: - (modified) clang/docs/ReleaseNotes.md (+5) - (modified) clang/docs/SanitizerSpecialCaseList.md (+23-14) - (modified) clang/test/Driver/fsanitize-ignorelist.c (+5) - (modified) llvm/include/llvm/Support/SpecialCaseList.h (+3-2) - (modified) llvm/lib/Support/SpecialCaseList.cpp (+16-5) - (modified) llvm/unittests/Support/SpecialCaseListTest.cpp (+49) ``````````diff diff --git a/clang/docs/ReleaseNotes.md b/clang/docs/ReleaseNotes.md index f2397bc8dcd59..055416fbd5737 100644 --- a/clang/docs/ReleaseNotes.md +++ b/clang/docs/ReleaseNotes.md @@ -1609,6 +1609,11 @@ The `alpha.cplusplus.UseAfterLifetimeEnd` checker was renamed to `alpha.core.Use ### Sanitizers +- Sanitizer Special Case Lists (`-fsanitize-ignorelist`) and warning + suppression mappings (`--warning-suppression-mappings`) now recognize version + 6 of the Special Case List format (indicated by `#!special-case-list-v6`), + which disallows entries without a preceding section header instead of placing + them in the implicit `[*]` section. - Added the `typefunchash` and `typefunchashpointersplit` token assignment modes for `-fsanitize=alloc-token`, selected with `-Xclang -falloc-token-mode=<mode>`. These modes derive token IDs from both diff --git a/clang/docs/SanitizerSpecialCaseList.md b/clang/docs/SanitizerSpecialCaseList.md index 881b65aae23b5..7e701b07c5cc0 100644 --- a/clang/docs/SanitizerSpecialCaseList.md +++ b/clang/docs/SanitizerSpecialCaseList.md @@ -219,17 +219,6 @@ fun:*BadASanFunc* fun:*BadCfiCall ``` -:::{note} -By default, `src` and `mainfile` are matched against the filename as seen -by LLVM. On Windows, this might involve a mix of forward and backslashes as -file separators, and writing patterns to match both variants can be -inconvenient. - -Starting with version 4 (indicated by `#!special-case-list-v4`), path matching -on Windows hosts is slash-agnostic: both forward slashes (`/`) and backslashes -(`\`) match either path separator in both patterns and paths. -::: - :::{note} By default, path matching (for `src` and `mainfile`) matches the query path as-is. For example, a query with `./foo.c` will not match a rule @@ -243,11 +232,31 @@ a rule like `src:./foo.c` will no longer match. Version 4 (indicated by `#!special-case-list-v4`) is a transition version that maintains backward compatibility by matching both canonicalized and non-canonicalized paths, but emits a warning if a match would be lost in -Version 5 (i.e., if it only matches because of the deprecated leading `./` +version 5 (i.e., if it only matches because of the deprecated leading `./` in the rule). -Version 5 (indicated by `#!special-case-list-v5`) drops backward -compatibility and behaves like Version 3. +Starting with version 5 (indicated by `#!special-case-list-v5`), backward +compatibility for leading `./` is dropped, matching version 3 behavior. +::: + +:::{note} +By default, `src` and `mainfile` are matched against the filename as seen +by LLVM. On Windows, this might involve a mix of forward and backslashes as +file separators, and writing patterns to match both variants can be +inconvenient. + +Starting with version 4 (indicated by `#!special-case-list-v4`), path matching +on Windows hosts is slash-agnostic: both forward slashes (`/`) and backslashes +(`\`) match either path separator in both patterns and paths. +::: + +:::{note} +By default, entries without a preceding section header are placed under the +implicit `[*]` section, matching all sections. + +Starting with version 6 (indicated by `#!special-case-list-v6`), entries +without a preceding section header are disallowed and result in a parse error. +Use an explicit section header such as `[address]` or `[*]` instead. ::: `mainfile` is similar to applying `-fno-sanitize=` to a set of files but diff --git a/clang/test/Driver/fsanitize-ignorelist.c b/clang/test/Driver/fsanitize-ignorelist.c index 33645955d548e..943991e174920 100644 --- a/clang/test/Driver/fsanitize-ignorelist.c +++ b/clang/test/Driver/fsanitize-ignorelist.c @@ -53,6 +53,11 @@ // RUN: not %clang --target=x86_64-linux-gnu -fsanitize=address -fsanitize-ignorelist=%t.second -fsanitize-ignorelist=%t.bad -fsanitize-ignorelist=%t.good %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-BAD-IGNORELIST // CHECK-BAD-IGNORELIST: error: malformed sanitizer ignorelist: 'error parsing file '{{.*}}.bad': malformed line 1: 'badline'' +// Version 6 disallows entries without an explicit section header. +// RUN: printf "#!special-case-list-v6\nfun:foo\n" > %t.v6_implicit +// RUN: not %clang --target=x86_64-linux-gnu -fsanitize=address -fsanitize-ignorelist=%t.v6_implicit %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-V6-IMPLICIT +// CHECK-V6-IMPLICIT: error: malformed sanitizer ignorelist: 'error parsing file '{{.*}}.v6_implicit': entry without section header on line 2: 'fun:foo'' + // -fno-sanitize-ignorelist disables all ignorelists specified earlier. // RUN: %clang --target=x86_64-linux-gnu -fsanitize=address -fsanitize-ignorelist=%t.good -fno-sanitize-ignorelist -fsanitize-ignorelist=%t.second %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-ONLY-FIRST-DISABLED --implicit-check-not=-fsanitize-ignorelist= // CHECK-ONLY_FIRST-DISABLED-NOT: good diff --git a/llvm/include/llvm/Support/SpecialCaseList.h b/llvm/include/llvm/Support/SpecialCaseList.h index 3366ee078ebc7..83c85f184e1e2 100644 --- a/llvm/include/llvm/Support/SpecialCaseList.h +++ b/llvm/include/llvm/Support/SpecialCaseList.h @@ -31,9 +31,10 @@ class StringRef; /// /// Empty lines and lines starting with "#" are ignored. Sections are defined /// using a '[section_name]' header and can be used to specify sanitizers the -/// entries below it apply to. Section names are globs, and +/// entries below it apply to. Section names are globs. Before version 6, /// entries without a section header match all sections (e.g. an '[*]' header -/// is assumed.) +/// is assumed). Starting with version 6, entries without a section header are +/// an error. /// The remaining lines should have the form: /// prefix:glob_pattern[=category] /// If category is not specified, it is assumed to be empty string. diff --git a/llvm/lib/Support/SpecialCaseList.cpp b/llvm/lib/Support/SpecialCaseList.cpp index fe12039719059..d6f7bbaa8b0c6 100644 --- a/llvm/lib/Support/SpecialCaseList.cpp +++ b/llvm/lib/Support/SpecialCaseList.cpp @@ -424,13 +424,17 @@ bool SpecialCaseList::parse(unsigned FileIdx, const MemoryBuffer *MB, // preprocess the Glob pattern to use different escape sequences. bool SlashAgnostic = MinVersion(4) && llvm::sys::path::is_style_windows( llvm::sys::path::Style::native); + bool AllowImplicitSection = !MinVersion(6); - auto ErrOrSection = addSection("*", FileIdx, 1, true); - if (auto Err = ErrOrSection.takeError()) { - Error = toString(std::move(Err)); - return false; + Section::SectionImpl *CurrentImpl = nullptr; + if (AllowImplicitSection) { + auto ErrOrSection = addSection("*", FileIdx, 1, true); + if (auto Err = ErrOrSection.takeError()) { + Error = toString(std::move(Err)); + return false; + } + CurrentImpl = ErrOrSection.get()->Impl.get(); } - Section::SectionImpl *CurrentImpl = ErrOrSection.get()->Impl.get(); // This is the current list of prefixes for all existing users matching file // path. We may need parametrization in constructor in future. @@ -470,6 +474,13 @@ bool SpecialCaseList::parse(unsigned FileIdx, const MemoryBuffer *MB, return false; } + if (!CurrentImpl) { + Error = ("entry without section header on line " + Twine(LineNo) + ": '" + + Line + "'") + .str(); + return false; + } + QueryOptions QOpts; QOpts.UseGlobs = UseGlobs; if (llvm::is_contained(PathPrefixes, Prefix)) { diff --git a/llvm/unittests/Support/SpecialCaseListTest.cpp b/llvm/unittests/Support/SpecialCaseListTest.cpp index d4d47c37993f2..a44dc4944a2b6 100644 --- a/llvm/unittests/Support/SpecialCaseListTest.cpp +++ b/llvm/unittests/Support/SpecialCaseListTest.cpp @@ -484,4 +484,53 @@ TEST_F(SpecialCaseListTest, SlashAgnosticPathsOnWindows) { #endif +TEST_F(SpecialCaseListTest, Version6RequireExplicitSection) { + std::string Error; + EXPECT_EQ(nullptr, makeSpecialCaseList("src:foo\n", Error, /*Version=*/6)); + EXPECT_EQ("entry without section header on line 2: 'src:foo'", Error); + + EXPECT_EQ(nullptr, + makeSpecialCaseList("# comment\n\nsrc:foo\n[sect1]\nsrc:bar\n", + Error, /*Version=*/6)); + EXPECT_EQ("entry without section header on line 4: 'src:foo'", Error); + + EXPECT_EQ(nullptr, makeSpecialCaseList("badline\n", Error, /*Version=*/6)); + EXPECT_EQ("malformed line 2: 'badline'", Error); + + // Version 5 still allows implicit default section. + std::unique_ptr<SpecialCaseList> SCL5 = + makeSpecialCaseList("src:foo\n", /*Version=*/5); + EXPECT_TRUE(SCL5->inSection("arbitrary", "src", "foo")); + + // Empty or comments-only files are valid in version 6. + std::unique_ptr<SpecialCaseList> EmptySCL = + makeSpecialCaseList("# comment\n\n", /*Version=*/6); + EXPECT_FALSE(EmptySCL->inSection("arbitrary", "src", "foo")); + + // Explicit [*] and named sections work in version 6. + std::unique_ptr<SpecialCaseList> ExplicitStar = + makeSpecialCaseList("[*]\nsrc:foo\n", /*Version=*/6); + EXPECT_TRUE(ExplicitStar->inSection("arbitrary", "src", "foo")); + + std::unique_ptr<SpecialCaseList> Named = + makeSpecialCaseList("[sect1]\nsrc:foo\n", /*Version=*/6); + EXPECT_TRUE(Named->inSection("sect1", "src", "foo")); + EXPECT_FALSE(Named->inSection("sect2", "src", "foo")); +} + +TEST_F(SpecialCaseListTest, Version6DotSlash) { + StringRef IgnoreList = "[dot]\n" + "src:./bar\n" + "[not]\n" + "src:bar\n"; + std::unique_ptr<SpecialCaseList> SCL6 = + makeSpecialCaseList(IgnoreList, /*Version=*/6); + + testing::internal::CaptureStderr(); + EXPECT_FALSE(SCL6->inSection("dot", "src", "./bar")); + EXPECT_TRUE(SCL6->inSection("not", "src", "./bar")); + EXPECT_TRUE(SCL6->inSection("not", "src", "bar")); + EXPECT_TRUE(testing::internal::GetCapturedStderr().empty()); +} + } // namespace `````````` </details> https://github.com/llvm/llvm-project/pull/243258 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
