Author: Zeyi Xu Date: 2026-11-19T09:47:31+08:00 New Revision: 86448028d584e0d5f546205cc75cad8cf34c58d8
URL: https://github.com/llvm/llvm-project/commit/86448028d584e0d5f546205cc75cad8cf34c58d8 DIFF: https://github.com/llvm/llvm-project/commit/86448028d584e0d5f546205cc75cad8cf34c58d8.diff LOG: [clang-tidy] Fix crash in misc-include-cleaner on invalid config (#243739) Found by CTIT on HarfBuzz Added: clang-tools-extra/test/clang-tidy/checkers/misc/include-cleaner-invalid-format.cpp Modified: clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.cpp clang-tools-extra/docs/ReleaseNotes.md Removed: ################################################################################ diff --git a/clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.cpp b/clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.cpp index fc13b8aef2d8b2..329a369658cf82 100644 --- a/clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.cpp +++ b/clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.cpp @@ -203,10 +203,10 @@ void IncludeCleanerCheck::check(const MatchFinder::MatchResult &Result) { } const StringRef Code = SM->getBufferData(SM->getMainFileID()); - auto FileStyle = + auto FileStyle = llvm::expectedToOptional( format::getStyle(format::DefaultFormatStyle, getCurrentMainFile(), format::DefaultFallbackStyle, Code, - &SM->getFileManager().getVirtualFileSystem()); + &SM->getFileManager().getVirtualFileSystem())); if (!FileStyle) FileStyle = format::getLLVMStyle(); diff --git a/clang-tools-extra/docs/ReleaseNotes.md b/clang-tools-extra/docs/ReleaseNotes.md index 2566c24544d706..98a385feaa5898 100644 --- a/clang-tools-extra/docs/ReleaseNotes.md +++ b/clang-tools-extra/docs/ReleaseNotes.md @@ -298,9 +298,13 @@ infrastructure are described first, followed by tool-specific sections. instantiations with real move semantics. - Improved {doc}`misc-include-cleaner - <clang-tidy/checks/misc/include-cleaner>` check by matching - {option}`IgnoreHeaders` patterns containing `/` against header paths on - Windows. + <clang-tidy/checks/misc/include-cleaner>` check: + + - Match {option}`IgnoreHeaders` patterns containing `/` against header paths + on Windows. + + - Fix a crash when a `.clang-format` file contains invalid configuration, such + as duplicate keys. - Fixed an infinite loop in {doc}`misc-multiple-inheritance <clang-tidy/checks/misc/multiple-inheritance>` when checking a class that diff --git a/clang-tools-extra/test/clang-tidy/checkers/misc/include-cleaner-invalid-format.cpp b/clang-tools-extra/test/clang-tidy/checkers/misc/include-cleaner-invalid-format.cpp new file mode 100644 index 00000000000000..ef19dce29f809a --- /dev/null +++ b/clang-tools-extra/test/clang-tidy/checkers/misc/include-cleaner-invalid-format.cpp @@ -0,0 +1,6 @@ +// RUN: mkdir -p %t.dir +// RUN: echo 'IndentWidth: 2' > %t.dir/.clang-format +// RUN: echo 'IndentWidth: 4' >> %t.dir/.clang-format +// RUN: %check_clang_tidy %s misc-include-cleaner %t.dir/repro + +// CHECK-MESSAGES: error: duplicated mapping key 'IndentWidth' _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
