This is an archive of the discontinued LLVM Phabricator instance.

[WebAssembly][MC] Improve error handling on empty function declarations
Needs ReviewPublic

Authored by sbc100 on Aug 31 2022, 2:41 PM.

Details

Reviewers
dschuff
Summary

Fixes: #57427

Diff Detail

Event Timeline

sbc100 created this revision.Aug 31 2022, 2:41 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 31 2022, 2:41 PM
Herald added subscribers: pmatos, asb, wingo and 5 others. · View Herald Transcript
sbc100 requested review of this revision.Aug 31 2022, 2:41 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 31 2022, 2:41 PM

IIUC in other asm formats, you can just e.g. switch to the data section (in the middle of generating code for a function), emit a data constant, and then switch back and finish the function. In theory we could do that for wasm too, as long as we do actually switch back and finish the function. but I get that would make this error checking a lot more complicated, and I don't know of any cases where we would actually want to do that. do you?

IIUC in other asm formats, you can just e.g. switch to the data section (in the middle of generating code for a function), emit a data constant, and then switch back and finish the function. In theory we could do that for wasm too, as long as we do actually switch back and finish the function. but I get that would make this error checking a lot more complicated, and I don't know of any cases where we would actually want to do that. do you?

I can't think of any no.. but at the same time I didn't indent this change to change that behaviour. I will check if that is possible prior to this change.. if it is possible, we can reconsider.

sbc100 added a comment.Sep 1 2022, 6:19 AM

IIUC in other asm formats, you can just e.g. switch to the data section (in the middle of generating code for a function), emit a data constant, and then switch back and finish the function. In theory we could do that for wasm too, as long as we do actually switch back and finish the function. but I get that would make this error checking a lot more complicated, and I don't know of any cases where we would actually want to do that. do you?

I looked into this and I think we already can't support this type of thing in the general case due to the way to type checking works.

For example there is global state in the type checker that assumes that only one function is parsed at a time. If you could emit part of one function then part of another, then switch back to the original, that would break the type checker.

dschuff added a comment.EditedSep 1 2022, 2:21 PM

I was actually thinking about something like the following:

foo:
  .functype foo (i32) -> ()
  local.get 0

.section .data.bar,"",@
bar:
  .int32 7
  .size bar, 4

.section .text.foo,"",@
  drop
  end_function

It looks like that does actually work today. (if you delete the drop you'll even get the right type check failure.
But still, I'm not sure how valuable it is. I wonder how we'd find out.

BTW, do you have any idea how close we are to being able to round trip some clang test suite through asm rather than directly emitting objects? That would at least tell us whether clang ever does this.

edit: I had wondered whether clang used e.g. .pushsection/.popsection which would make this even easier to write. but it looks like we don't actually even support .pushsection

This comment was removed by dschuff.