[llvm] 79b44a4 - [YAMLTraits] Fix mapping <none> value that followed by comments.

Xing GUO via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 4 03:37:29 PDT 2020


Author: Xing GUO
Date: 2020-08-04T18:36:05+08:00
New Revision: 79b44a4d470041acf202027054ba86e935d86aa1

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

LOG: [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

Added: 
    

Modified: 
    llvm/include/llvm/Support/YAMLTraits.h
    llvm/test/tools/yaml2obj/ELF/none-value.yaml

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/Support/YAMLTraits.h b/llvm/include/llvm/Support/YAMLTraits.h
index e52bf7892d71..acb1d61cf569 100644
--- a/llvm/include/llvm/Support/YAMLTraits.h
+++ b/llvm/include/llvm/Support/YAMLTraits.h
@@ -1629,7 +1629,9 @@ void IO::processKeyWithDefault(const char *Key, Optional<T> &Val,
     bool IsNone = false;
     if (!outputting())
       if (auto *Node = dyn_cast<ScalarNode>(((Input *)this)->getCurrentNode()))
-        IsNone = Node->getRawValue() == "<none>";
+        // We use rtrim to ignore possible white spaces that might exist when a
+        // comment is present on the same line.
+        IsNone = Node->getRawValue().rtrim(' ') == "<none>";
 
     if (IsNone)
       Val = DefaultValue;

diff  --git a/llvm/test/tools/yaml2obj/ELF/none-value.yaml b/llvm/test/tools/yaml2obj/ELF/none-value.yaml
index 786a9b53aba7..7993e54c53cf 100644
--- a/llvm/test/tools/yaml2obj/ELF/none-value.yaml
+++ b/llvm/test/tools/yaml2obj/ELF/none-value.yaml
@@ -21,6 +21,7 @@ FileHeader:
 Sections:
   - Name:         .bar
     Type:         SHT_PROGBITS
+    Flags:        [[TEST=<none>]] ## Comment
     Offset:       [[TEST=<none>]]
     Address:      [[TEST=<none>]]
     Content:      [[TEST=<none>]]


        


More information about the llvm-commits mailing list