This is an archive of the discontinued LLVM Phabricator instance.

[yaml2obj] - Add a support for "<none>" value for all optional fields.
ClosedPublic

Authored by grimar on Jul 24 2020, 6:36 AM.

Details

Summary

It implements an approach suggested in the D84398 thread.

With it the following:

Sections:
  - Name:   .bar
    Type:   SHT_PROGBITS
    Offset: [[MACRO=<none>]]

works just like the Offset key was not specified.
It is useful for tests that want to have a default value for a field and to
have a way to override it at the same time.

Diff Detail

Event Timeline

grimar created this revision.Jul 24 2020, 6:36 AM
Herald added a project: Restricted Project. · View Herald Transcript
Herald added a subscriber: emaste. · View Herald Transcript
grimar updated this revision to Diff 280444.Jul 24 2020, 6:39 AM
  • Move the comment line.

What about the alternative syntax mentioned in https://reviews.llvm.org/D84398#2169623 ?

grimar added a comment.EditedJul 27 2020, 11:43 PM

What about the alternative syntax mentioned in https://reviews.llvm.org/D84398#2169623 ?

Other syntactic forms include ShOffset?: [[TEST]].

IMO "Offset: [[MACRO=<none>]]" looks/works better. Since we have default values, e.g. [[MACRO=0x5]], the <none> looks consistent.
Seems "?:" is only meaningful with marcos, so personally I'd try to avoid introducing one more syntax for them.

At the worst, we can use [[TEST=ShOffset: 0]]

It is seems to be not an option, because we might do not know the default ShOffset. The idea of the change is to avoid specifying it explicitly.
(e.g. you often do not know the value of ShName, for example, so ShName=<none> - works, but any other default value - usually doesn't).

Upd:
Oh, I seems misunderstood the last one. So you suggest to have something like:

Sections:
  - Type:   SHT_NULL
    [[NAME=ShName: 0xX]]
    [[OFF=ShOffset: 0xY]]

And then just disable lines, i.e do -DNAME="" -DOFF=""?
But this doesn't work well too:

  1. What to specify as 0xX, 0xY? We often can't know valid default values, so will it be values that works for the first sub-test? It shouldn't work good for other sub-tests I think

(and probably reads harder than "=<none>")

  1. When there are more than one marco, disabling other ones, which should be unused, might look too verbose.

What's the motivation for testing every Optional<T> type? It seems to me like this code is a common piece of code where a single example would be sufficient. In fact, this test doesn't include coverage for the DWARF tag, for example (see @Higuoxing's recent work), which has many optional fields.

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

Perhaps change "value was not set" to "field was not specified"? I think it avoids ambiguity of the term "value", which might be the thing on the right of the colon.

11

It is exist -> It exists

183

You can probably get rid of the notes from the second YAML. The initial comment saying it is a duplicate, barring the missing fields, is sufficient to convey that, I think.

What's the motivation for testing every Optional<T> type? It seems to me like this code is a common piece of code where a single example would be sufficient.

OK, probably you're right. What about having a full set for a section instead?
E.g I'll compare:

- Name:         .bar
  Type:         SHT_PROGBITS
  Offset:       [[TEST=<none>]]
  Address:      [[TEST=<none>]]
  Content:      [[TEST=<none>]]
  Size:         [[TEST=<none>]]
  ContentArray: [[TEST=<none>]]
  Info:         [[TEST=<none>]]
  EntSize:      [[TEST=<none>]]
  ShName:       [[TEST=<none>]]
  ShOffset:     [[TEST=<none>]]
  ShSize:       [[TEST=<none>]]
  ShFlags:      [[TEST=<none>]]

vs

- Name:         .bar
  Type:         SHT_PROGBITS

The first set contains some possible interactions between Content, Size, ContentArray and ShSize,
between Name and ShName, Offset and ShOffset etc. I.e. probably demonstrates
the having =<none> really does nothing.

What's the motivation for testing every Optional<T> type? It seems to me like this code is a common piece of code where a single example would be sufficient.

OK, probably you're right. What about having a full set for a section instead?
E.g I'll compare:

- Name:         .bar
  Type:         SHT_PROGBITS
  Offset:       [[TEST=<none>]]
  Address:      [[TEST=<none>]]
  Content:      [[TEST=<none>]]
  Size:         [[TEST=<none>]]
  ContentArray: [[TEST=<none>]]
  Info:         [[TEST=<none>]]
  EntSize:      [[TEST=<none>]]
  ShName:       [[TEST=<none>]]
  ShOffset:     [[TEST=<none>]]
  ShSize:       [[TEST=<none>]]
  ShFlags:      [[TEST=<none>]]

vs

- Name:         .bar
  Type:         SHT_PROGBITS

The first set contains some possible interactions between Content, Size, ContentArray and ShSize,
between Name and ShName, Offset and ShOffset etc. I.e. probably demonstrates
the having =<none> really does nothing.

Yeah, that seems reasonable to me.

grimar updated this revision to Diff 281212.Jul 28 2020, 6:39 AM
grimar marked 2 inline comments as done.
  • Addressed review comments.
jhenderson accepted this revision.Jul 29 2020, 4:23 AM

LGTM, with a couple of nits. I'm also happy with other strings/syntax etc, as long as it's fairly readable.

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

all of -> all

8

a resonable choice -> reasonable

This revision is now accepted and ready to land.Jul 29 2020, 4:23 AM
MaskRay added a subscriber: labath.