[llvm-branch-commits] [clang] 7e153f5 - [clang-format] Fix an assertion failure on comment-only config files (#163111)
Cullen Rhodes via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Mon Oct 20 02:53:08 PDT 2025
Author: owenca
Date: 2025-10-20T09:53:00Z
New Revision: 7e153f5372edb8f53b8576932cf5969187bf0484
URL: https://github.com/llvm/llvm-project/commit/7e153f5372edb8f53b8576932cf5969187bf0484
DIFF: https://github.com/llvm/llvm-project/commit/7e153f5372edb8f53b8576932cf5969187bf0484.diff
LOG: [clang-format] Fix an assertion failure on comment-only config files (#163111)
(cherry picked from commit 059f2df74898ff7f394dc8e60f746323499ae32b)
Added:
Modified:
clang/lib/Format/Format.cpp
clang/unittests/Format/ConfigParseTest.cpp
Removed:
################################################################################
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index d4e3a1989cd71..5bdb810a3925b 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -2132,8 +2132,9 @@ std::error_code parseConfiguration(llvm::MemoryBufferRef Config,
Input >> Styles;
if (Input.error())
return Input.error();
+ if (Styles.empty())
+ return make_error_code(ParseError::Success);
- assert(!Styles.empty());
const auto StyleCount = Styles.size();
// Start from the second style as (only) the first one may be the default.
diff --git a/clang/unittests/Format/ConfigParseTest.cpp b/clang/unittests/Format/ConfigParseTest.cpp
index bbe1923e19ee1..ff42f09b90cf3 100644
--- a/clang/unittests/Format/ConfigParseTest.cpp
+++ b/clang/unittests/Format/ConfigParseTest.cpp
@@ -1249,6 +1249,13 @@ TEST(ConfigParseTest, ParsesConfigurationWithLanguages) {
IndentWidth, 56u);
}
+TEST(ConfigParseTest, AllowCommentOnlyConfigFile) {
+ FormatStyle Style = {};
+ Style.Language = FormatStyle::LK_Cpp;
+ EXPECT_EQ(parseConfiguration("#Language: C", &Style), ParseError::Success);
+ EXPECT_EQ(Style.Language, FormatStyle::LK_Cpp);
+}
+
TEST(ConfigParseTest, AllowCppForC) {
FormatStyle Style = {};
Style.Language = FormatStyle::LK_C;
More information about the llvm-branch-commits
mailing list