llvmorg-github-actions[bot] wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang-tools-extra

Author: Zeyi Xu (zeyi2)

<details>
<summary>Changes</summary>

Found by CTIT on HarfBuzz

---
Full diff: https://github.com/llvm/llvm-project/pull/243739.diff


3 Files Affected:

- (modified) clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.cpp (+2-2) 
- (modified) clang-tools-extra/docs/ReleaseNotes.md (+4) 
- (added) 
clang-tools-extra/test/clang-tidy/checkers/misc/include-cleaner-invalid-format.cpp
 (+6) 


``````````diff
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..f203591b6fe626 100644
--- a/clang-tools-extra/docs/ReleaseNotes.md
+++ b/clang-tools-extra/docs/ReleaseNotes.md
@@ -302,6 +302,10 @@ infrastructure are described first, followed by 
tool-specific sections.
   {option}`IgnoreHeaders` patterns containing `/` against header paths on
   Windows.
 
+- Improved {doc}`misc-include-cleaner
+  <clang-tidy/checks/misc/include-cleaner>` check by fixing 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
   inherits from itself or has a circular inheritance graph.
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'

``````````

</details>


https://github.com/llvm/llvm-project/pull/243739
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to