Skip to content

Commit 79b44a4

Browse files
committed
[YAMLTraits] Fix mapping <none> value that followed by comments.
When mapping an optional value, if the value is <none> and followed by comments, there will be a parsing error. This patch helps fix this issue. e.g., When mapping the following YAML, ``` Sections: - Name: blah Type: SHT_foo Flags: [[FLAGS=<none>]] ## some comments. ``` the raw value of `ScalarNode` is "<none> " rather than "<none>". We need to remove the spaces. Differential Revision: https://reviews.llvm.org/D85180
1 parent 4be13b1 commit 79b44a4

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

llvm/include/llvm/Support/YAMLTraits.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1629,7 +1629,9 @@ void IO::processKeyWithDefault(const char *Key, Optional<T> &Val,
16291629
bool IsNone = false;
16301630
if (!outputting())
16311631
if (auto *Node = dyn_cast<ScalarNode>(((Input *)this)->getCurrentNode()))
1632-
IsNone = Node->getRawValue() == "<none>";
1632+
// We use rtrim to ignore possible white spaces that might exist when a
1633+
// comment is present on the same line.
1634+
IsNone = Node->getRawValue().rtrim(' ') == "<none>";
16331635

16341636
if (IsNone)
16351637
Val = DefaultValue;

llvm/test/tools/yaml2obj/ELF/none-value.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ FileHeader:
2121
Sections:
2222
- Name: .bar
2323
Type: SHT_PROGBITS
24+
Flags: [[TEST=<none>]] ## Comment
2425
Offset: [[TEST=<none>]]
2526
Address: [[TEST=<none>]]
2627
Content: [[TEST=<none>]]

0 commit comments

Comments
 (0)