https://github.com/owenca updated 
https://github.com/llvm/llvm-project/pull/204565

>From d9997828c460931677dbb69eab12f5f44bcd2c7e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Damian=20H=C3=B6ster?= <[email protected]>
Date: Wed, 17 Jun 2026 14:43:28 +0200
Subject: [PATCH 1/2] [clang-format] Reset Line->IsModuleOrImportDecl in
 addUnwrappedLine

The `IsModuleOrImportDecl` flag was not reset in `addUnwrappedLine`. Since the 
parser recycles the `Line` object, this flag remained `true` for all subsequent 
lines in the file, which disabled wrapping (`CanBreakBefore` in 
`TokenAnnotator.cpp`) for expression-level constructs after any C++20 module or 
import statement.

This patch fixes the issue by resetting the flag to `false` in 
`addUnwrappedLine()`.
---
 clang/lib/Format/UnwrappedLineParser.cpp | 1 +
 1 file changed, 1 insertion(+)

diff --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index c83e82674dee1..b3f239a3ee801 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -4718,6 +4718,7 @@ void UnwrappedLineParser::addUnwrappedLine(LineLevel 
AdjustLevel) {
   Line->FirstStartColumn = 0;
   Line->IsContinuation = false;
   Line->SeenDecltypeAuto = false;
+  Line->IsModuleOrImportDecl = false;
 
   if (ClosesWhitesmithsBlock && AdjustLevel == LineLevel::Remove)
     --Line->Level;

>From d9a6ec4a5508b920c8b1f55323af446228664345 Mon Sep 17 00:00:00 2001
From: Owen Pan <[email protected]>
Date: Fri, 19 Jun 2026 20:47:18 -0700
Subject: [PATCH 2/2] Add a test case

---
 clang/lib/Format/UnwrappedLineParser.cpp | 1 -
 clang/lib/Format/UnwrappedLineParser.h   | 5 +++--
 clang/unittests/Format/FormatTest.cpp    | 9 +++++++++
 3 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index b3f239a3ee801..534b356175f82 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -108,7 +108,6 @@ class ScopedLineState {
     Parser.Line->PPLevel = PreBlockLine->PPLevel;
     Parser.Line->InPPDirective = PreBlockLine->InPPDirective;
     Parser.Line->InMacroBody = PreBlockLine->InMacroBody;
-    Parser.Line->IsModuleOrImportDecl = PreBlockLine->IsModuleOrImportDecl;
     Parser.Line->UnbracedBodyLevel = PreBlockLine->UnbracedBodyLevel;
   }
 
diff --git a/clang/lib/Format/UnwrappedLineParser.h 
b/clang/lib/Format/UnwrappedLineParser.h
index 5014fad7e6ef1..22803a837cc63 100644
--- a/clang/lib/Format/UnwrappedLineParser.h
+++ b/clang/lib/Format/UnwrappedLineParser.h
@@ -48,8 +48,6 @@ struct UnwrappedLine {
   bool InPragmaDirective = false;
   /// Whether it is part of a macro body.
   bool InMacroBody = false;
-  /// Whether it is a C++20 module/import declaration.
-  bool IsModuleOrImportDecl = false;
 
   /// Nesting level of unbraced body of a control statement.
   unsigned UnbracedBodyLevel = 0;
@@ -63,6 +61,9 @@ struct UnwrappedLine {
   /// addition to the normal indention level.
   bool IsContinuation = false;
 
+  /// Whether it is a C++20 module/import declaration.
+  bool IsModuleOrImportDecl = false;
+
   /// If this \c UnwrappedLine closes a block in a sequence of lines,
   /// \c MatchingOpeningBlockLineIndex stores the index of the corresponding
   /// opening line. Otherwise, \c MatchingOpeningBlockLineIndex must be
diff --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index acd584c811ae7..61697cf9d9b10 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -24906,6 +24906,15 @@ TEST_F(FormatTest, Cpp20ModulesSupport) {
   verifyFormat("import <Foo/Bar> /* comment */;", Style);
   verifyFormat("import <Foo/Bar>; // Trailing comment", Style);
 
+  Style.BreakStringLiterals = true;
+  Style.ColumnLimit = 20;
+  verifyFormat("export module foobar;\n"
+               "char *s = \"s1\"\n"
+               "          \"s2\";",
+               "export module foobar;\n"
+               "char *s = \"s1\" \"s2\";",
+               Style);
+
   // Somewhat gracefully handle import in pre-C++20 code.
   verifyFormat("import /* not keyword */ = val ? 2 : 1;");
   verifyFormat("_world->import<engine_module>();");

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

Reply via email to