[llvm] r318428 - Allow empty mappings for optional YAML input

Dave Lee via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 16 09:46:11 PST 2017


Author: kastiglione
Date: Thu Nov 16 09:46:11 2017
New Revision: 318428

URL: http://llvm.org/viewvc/llvm-project?rev=318428&view=rev
Log:
Allow empty mappings for optional YAML input

Summary:
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.

I have tested this with check-llvm and check-lld, and all tests passed.

This change is the result of test failures while working on D39582, which
introduces a `DynamicSymbols` mapping, which will be empty at times.

Reviewers: compnerd, jakehehrlich, silvas, kledzik, mehdi_amini, pcc

Reviewed By: compnerd

Subscribers: silvas, llvm-commits

Differential Revision: https://reviews.llvm.org/D39908

Added:
    llvm/trunk/test/tools/yaml2obj/empty-symbols.yaml
Modified:
    llvm/trunk/lib/Support/YAMLTraits.cpp

Modified: llvm/trunk/lib/Support/YAMLTraits.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/YAMLTraits.cpp?rev=318428&r1=318427&r2=318428&view=diff
==============================================================================
--- llvm/trunk/lib/Support/YAMLTraits.cpp (original)
+++ llvm/trunk/lib/Support/YAMLTraits.cpp Thu Nov 16 09:46:11 2017
@@ -160,7 +160,8 @@ bool Input::preflightKey(const char *Key
 
   MapHNode *MN = dyn_cast<MapHNode>(CurrentNode);
   if (!MN) {
-    setError(CurrentNode, "not a mapping");
+    if (Required || !isa<EmptyHNode>(CurrentNode))
+      setError(CurrentNode, "not a mapping");
     return false;
   }
   MN->ValidKeys.push_back(Key);

Added: llvm/trunk/test/tools/yaml2obj/empty-symbols.yaml
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/yaml2obj/empty-symbols.yaml?rev=318428&view=auto
==============================================================================
--- llvm/trunk/test/tools/yaml2obj/empty-symbols.yaml (added)
+++ llvm/trunk/test/tools/yaml2obj/empty-symbols.yaml Thu Nov 16 09:46:11 2017
@@ -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:




More information about the llvm-commits mailing list