[PATCH] D101341: Initialize optional members of ELFYAML types.

Vyacheslav Zakharin via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed May 12 15:27:07 PDT 2021


vzakhari added a comment.

In D101341#2753240 <https://reviews.llvm.org/D101341#2753240>, @jhenderson wrote:

> @vzakhari, what's the motivation for doing this? These data structures are used within yaml2obj/obj2yaml, although I'm not particularly familiar with the plumbing to identify whether it matters. My suspicion is that it doesn't.

@jhenderson, there are two ways to create a YAML file using YAML mappings.  The first one is to create a YAML file from a string bufffer (see line 38 in `llvm/unittests/ObjectYAML/ELFYAMLTest.cpp`).  The second way is to populate the `ELFYAML::` data structures and stream them into `yaml::Output`.  Both ways are valid.  The second way is a little bit more convenient for programmatic ELF-YAML creation in my downstream application.  When I try to use `ELFYAML::` data structures, there is no convenient way to make sure that all optional members in them are initialized.  Neither default nor zero-initialization works.  This is why I made these changes to make sure that all optional members are initialized properly.  Note that the default values are not necessarily zeroes.  The default values for this particular case are defined by the mappings in `llvm/lib/ObjectYAML/ELFYAML.cpp`.  So I am not sure that adjusting `LLVM_YAML_STRONG_TYPEDEF` to use zero values always is the right approach.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D101341/new/

https://reviews.llvm.org/D101341



More information about the llvm-commits mailing list