Skip to content

[YAML] fix output incorrect format for block scalar string #132897

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Mar 26, 2025

Conversation

HerrCai0907
Copy link
Contributor

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.

@@ -3,4 +3,4 @@
     Just a block
     scalar doc
-scalar:          a
+  scalar:          a
 ...\n

@HerrCai0907
Copy link
Contributor Author

original #131694 closed due to miss-operation

@llvmbot
Copy link
Member

llvmbot commented Mar 25, 2025

@llvm/pr-subscribers-objectyaml
@llvm/pr-subscribers-llvm-globalisel
@llvm/pr-subscribers-backend-aarch64

@llvm/pr-subscribers-llvm-support

Author: Congcong Cai (HerrCai0907)

Changes

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.

@@ -3,4 +3,4 @@
     Just a block
     scalar doc
-scalar:          a
+  scalar:          a
 ...\n

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

2 Files Affected:

  • (modified) llvm/lib/Support/YAMLTraits.cpp (+2-2)
  • (modified) llvm/unittests/Support/YAMLIOTest.cpp (+1-1)
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/unittests/Support/YAMLIOTest.cpp b/llvm/unittests/Support/YAMLIOTest.cpp
index 3db1db57ad596..5a86555d08fb3 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
 ...
 )");
 }

@arsenm
Copy link
Contributor

arsenm commented Mar 25, 2025

original #131694 closed due to miss-operation

You can reopen pull requests

@arsenm
Copy link
Contributor

arsenm commented Mar 25, 2025

Test has merge conflict

@HerrCai0907
Copy link
Contributor Author

You can reopen pull requests

I try to reopen it but failed.

Test has merge conflict

I will reland previous PR and re-run the test

@arsenm
Copy link
Contributor

arsenm commented Mar 26, 2025

Test failures look real

@HerrCai0907 HerrCai0907 merged commit a80aad2 into llvm:main Mar 26, 2025
14 checks passed
@HerrCai0907 HerrCai0907 deleted the fix/yamlio branch March 26, 2025 18:16
delcypher added a commit to swiftlang/llvm-project that referenced this pull request Mar 31, 2025
This change:

```
commit a80aad2
Author: Congcong Cai <[email protected]>
Date:   Thu Mar 27 02:16:27 2025 +0800

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

caused emission of empty lines to removed in some cases. Which broke the
tests. This patch updates the test.

rdar://148048779
delcypher added a commit to swiftlang/llvm-project that referenced this pull request Mar 31, 2025
This change:

```
commit a80aad2
Author: Congcong Cai <[email protected]>
Date:   Thu Mar 27 02:16:27 2025 +0800

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

caused emission of empty lines to removed in some cases. Which broke the
tests. This patch updates the test.

rdar://148048779
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants