[PATCH] D39908: Allow empty mappings for optional YAML input
Dave Lee via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Nov 10 09:54:04 PST 2017
kastiglione created this revision.
This change fixes a bug where `obj2yaml` can in some cases produce YAML that
causes `yaml2obj` to error.
The ELF YAML document structure has a `Sections` mapping, which contains three
mappings, all of which are optional: `Local`, `Global`, and `Weak.` Any one of
these can be missing, but if all three are missing, then `yaml2obj` errors. This
change allows YAML input for cases like this one.
This caused test failures while working on https://reviews.llvm.org/D39582, which introduces a
`DynamicaSymbols` mapping.
https://reviews.llvm.org/D39908
Files:
lib/Support/YAMLTraits.cpp
test/tools/yaml2obj/empty-symbols.yaml
Index: test/tools/yaml2obj/empty-symbols.yaml
===================================================================
--- /dev/null
+++ test/tools/yaml2obj/empty-symbols.yaml
@@ -0,0 +1,10 @@
+# Ensure yaml2obj doesn't error on empty optional mappings, such as Symbols
+# RUN: yaml2obj %s -o %t
+
+!ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_DYN
+ Machine: EM_X86_64
+Symbols:
Index: lib/Support/YAMLTraits.cpp
===================================================================
--- lib/Support/YAMLTraits.cpp
+++ lib/Support/YAMLTraits.cpp
@@ -160,7 +160,9 @@
MapHNode *MN = dyn_cast<MapHNode>(CurrentNode);
if (!MN) {
- setError(CurrentNode, "not a mapping");
+ bool OptionalNode = !Required && isa<EmptyHNode>(CurrentNode);
+ if (!OptionalNode)
+ setError(CurrentNode, "not a mapping");
return false;
}
MN->ValidKeys.push_back(Key);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D39908.122467.patch
Type: text/x-patch
Size: 934 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171110/5caf9284/attachment.bin>
More information about the llvm-commits
mailing list