[llvm] a80aad2 - [YAML] fix output incorrect format for block scalar string (#132897)

via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 26 11:16:31 PDT 2025


Author: Congcong Cai
Date: 2025-03-27T02:16:27+08:00
New Revision: a80aad28123101539134c277c6904905016754ca

URL: https://github.com/llvm/llvm-project/commit/a80aad28123101539134c277c6904905016754ca
DIFF: https://github.com/llvm/llvm-project/commit/a80aad28123101539134c277c6904905016754ca.diff

LOG: [YAML] fix output incorrect format for block scalar string (#132897)

After outputting block scalar string, the indent will be wrong.
This patch fixes Padding after block scalar string to ensure the correct
format of yaml.

The new added ut will fail in main.
```diff
@@ -3,4 +3,4 @@
     Just a block
     scalar doc
-scalar:          a
+  scalar:          a
 ...\n
```

Added: 
    

Modified: 
    llvm/lib/Support/YAMLTraits.cpp
    llvm/test/CodeGen/AArch64/GlobalISel/arm64-irtranslator.ll
    llvm/test/CodeGen/Generic/MIRStripDebug/no-metadata-present.mir
    llvm/test/CodeGen/MIR/AArch64/empty-MF.mir
    llvm/test/tools/obj2yaml/Minidump/basic.yaml
    llvm/unittests/Support/YAMLIOTest.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Support/YAMLTraits.cpp b/llvm/lib/Support/YAMLTraits.cpp
index 28642e004c4f4..035828b594e84 100644
--- a/llvm/lib/Support/YAMLTraits.cpp
+++ b/llvm/lib/Support/YAMLTraits.cpp
@@ -725,18 +725,18 @@ void Output::blockScalarString(StringRef &S) {
   if (!StateStack.empty())
     newLineCheck();
   output(" |");
-  outputNewLine();
 
   unsigned Indent = StateStack.empty() ? 1 : StateStack.size();
 
   auto Buffer = MemoryBuffer::getMemBuffer(S, "", false);
   for (line_iterator Lines(*Buffer, false); !Lines.is_at_end(); ++Lines) {
+    outputNewLine();
     for (unsigned I = 0; I < Indent; ++I) {
       output("  ");
     }
     output(*Lines);
-    outputNewLine();
   }
+  outputUpToEndOfLine("");
 }
 
 void Output::scalarTag(std::string &Tag) {

diff  --git a/llvm/test/CodeGen/AArch64/GlobalISel/arm64-irtranslator.ll b/llvm/test/CodeGen/AArch64/GlobalISel/arm64-irtranslator.ll
index 15ee5e48a88e6..d457418720f47 100644
--- a/llvm/test/CodeGen/AArch64/GlobalISel/arm64-irtranslator.ll
+++ b/llvm/test/CodeGen/AArch64/GlobalISel/arm64-irtranslator.ll
@@ -431,7 +431,6 @@ end:
 
 ; CHECK-LABEL: name: unreachable
 ; CHECK: G_ADD
-; CHECK-NEXT: {{^$}}
 ; CHECK-NEXT: ...
 define void @unreachable(i32 %a) {
   %sum = add i32 %a, %a

diff  --git a/llvm/test/CodeGen/Generic/MIRStripDebug/no-metadata-present.mir b/llvm/test/CodeGen/Generic/MIRStripDebug/no-metadata-present.mir
index 3df834845b404..00a2fd70919a8 100644
--- a/llvm/test/CodeGen/Generic/MIRStripDebug/no-metadata-present.mir
+++ b/llvm/test/CodeGen/Generic/MIRStripDebug/no-metadata-present.mir
@@ -3,7 +3,6 @@
 # CHECK: name: test
 # CHECK: body: |
 # CHECK-NEXT: bb.0:
-# CHECK-EMPTY:
 # CHECK-NEXT: ...
 
 ---

diff  --git a/llvm/test/CodeGen/MIR/AArch64/empty-MF.mir b/llvm/test/CodeGen/MIR/AArch64/empty-MF.mir
index 40b1bff06ff5a..38526b7f60d6d 100644
--- a/llvm/test/CodeGen/MIR/AArch64/empty-MF.mir
+++ b/llvm/test/CodeGen/MIR/AArch64/empty-MF.mir
@@ -3,7 +3,6 @@
 # CHECK-NEXT: ---
 # CHECK-NEXT: name:            foo
 # CHECK: body:             |
-# CHECK-EMPTY:
 # CHECK-NEXT: ...
 ---
 name: foo

diff  --git a/llvm/test/tools/obj2yaml/Minidump/basic.yaml b/llvm/test/tools/obj2yaml/Minidump/basic.yaml
index 3df4689d6761e..b1d8da3bb568f 100644
--- a/llvm/test/tools/obj2yaml/Minidump/basic.yaml
+++ b/llvm/test/tools/obj2yaml/Minidump/basic.yaml
@@ -114,7 +114,6 @@ Streams:
 # CHECK-NEXT:     Text:             |
 # CHECK-NEXT:       400d9000-400db000 r-xp 00000000 b3:04 227        /system/bin/app_process
 # CHECK-NEXT:       400db000-400dc000 r--p 00001000 b3:04 227        /system/bin/app_process
-# CHECK-EMPTY:
 # CHECK-NEXT:   - Type:            ModuleList
 # CHECK-NEXT:     Modules:
 # CHECK-NEXT:       - Base of Image:   0x1020304050607

diff  --git a/llvm/unittests/Support/YAMLIOTest.cpp b/llvm/unittests/Support/YAMLIOTest.cpp
index f03563cd5bc2e..080f2b9619d1a 100644
--- a/llvm/unittests/Support/YAMLIOTest.cpp
+++ b/llvm/unittests/Support/YAMLIOTest.cpp
@@ -1298,7 +1298,7 @@ TEST(YAMLIO, TestScalarAfterBlockScalar) {
 - block_scalac:     |
     AA
     BB
-scalar:          a
+  scalar:          a
 ...
 )");
 }


        


More information about the llvm-commits mailing list