This is an archive of the discontinued LLVM Phabricator instance.

[WebAssembly] Handle block-like structures consistently in type checker
ClosedPublic

Authored by aheejin on Apr 8 2023, 7:17 AM.

Details

Summary

We disable type check in unreachable code, but when the unreachable code
is enclosed within a block-like structure, the block as a whole has a
valid type and we should continue type checking after the block. But it
looks we currently only do that for blocks and not other block-like
structures (loops, trys, and ifs). Also unreachable code within
if's true body shouldn't disable type checking in else body, and
that in try body shouldn't disable type checking in catch/catch_all
body.

This also causes the values/types on the stack to be correctly checked
when encounterint catch, catch_all, and delegate.

Diff Detail

Event Timeline

aheejin created this revision.Apr 8 2023, 7:17 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 8 2023, 7:17 AM
Herald added subscribers: pmatos, asb, wingo and 4 others. · View Herald Transcript
aheejin requested review of this revision.Apr 8 2023, 7:17 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 8 2023, 7:17 AM
aheejin updated this revision to Diff 511889.Apr 8 2023, 7:25 AM

Add one more test

aheejin updated this revision to Diff 511890.Apr 8 2023, 7:26 AM

Test name change

aheejin edited the summary of this revision. (Show Details)Apr 8 2023, 11:07 PM
aheejin edited the summary of this revision. (Show Details)Apr 9 2023, 12:06 AM
aheejin updated this revision to Diff 511974.Apr 9 2023, 3:05 AM

delete newline

aheejin retitled this revision from [WebAssembly] Handle unreachable in block-like structure in type checker to [WebAssembly] Handle block-like structures consistently in type checker.Apr 9 2023, 3:06 AM
aheejin edited the summary of this revision. (Show Details)
aheejin added inline comments.
llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmTypeCheck.cpp
313–326

This code is just moved from below

aheejin updated this revision to Diff 511975.Apr 9 2023, 3:18 AM
aheejin edited the summary of this revision. (Show Details)

More

aheejin added inline comments.Apr 9 2023, 3:23 AM
llvm/test/MC/WebAssembly/type-checker-errors.s
277

This (and another FIXME end_if_type_mismatch_2) is not done even with this patch due to another bug, which I'm planning to fix in another CL.

I renamed these to tests to else_*** to end_if_*** so that else_*** means checking types when we encounter else, and end_if_*** means checking types when we encounter end_if.

aheejin updated this revision to Diff 511989.Apr 9 2023, 5:05 AM

Handle delegate too

aheejin edited the summary of this revision. (Show Details)Apr 9 2023, 5:06 AM
aheejin updated this revision to Diff 511990.Apr 9 2023, 5:08 AM

Add one more test

dschuff accepted this revision.Apr 10 2023, 5:34 PM

These are nice improvements!

This revision is now accepted and ready to land.Apr 10 2023, 5:34 PM