Fixes: #57427
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
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.
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.
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