-
Notifications
You must be signed in to change notification settings - Fork 843
Allow DWARF and multivalue together #6570
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| ;; Test that we handle multivalue + DWARF correctly. When we need to preserve | ||
| ;; DWARF info, we don't do any local reordering and all newly added locals | ||
| ;; during parsing/writing are added at the end of the local list. | ||
|
|
||
| ;; Generated from this c file with the following command: | ||
| ;; $ emcc -g -Xclang -target-abi -Xclang experimental-mv dwarf-multivalue.c -o dwarf-multivalue.wasm | ||
| ;; | ||
| ;; struct MyStruct { | ||
| ;; int a; | ||
| ;; float b; | ||
| ;; }; | ||
| ;; | ||
| ;; struct MyStruct foo() { | ||
| ;; struct MyStruct ret = {.a = 3, .b = 3.5}; | ||
| ;; return ret; | ||
| ;; } | ||
| ;; | ||
| ;; void test() { | ||
| ;; struct MyStruct s = foo(); | ||
| ;; } | ||
| ;; | ||
| ;; int main() { | ||
| ;; test(); | ||
| ;; return 0; | ||
| ;; } | ||
|
|
||
| ;; The original wasm file's $test function's locals are as follows: | ||
| ;; (func $test | ||
| ;; (local $0 i32) | ||
| ;; (local $1 i32) | ||
| ;; (local $2 i32) | ||
| ;; (local $3 i32) | ||
| ;; (local $4 f32) | ||
| ;; (local $5 i32) | ||
| ;; (local $6 i32) | ||
| ;; (local $7 i32) | ||
| ;; (local $8 f32) | ||
| ;; (local $9 i32) | ||
| ;; (local $10 f32) | ||
|
|
||
| ;; If we parse this wasm file into Binaryen IR, two locals are added in the | ||
| ;; process. Here $11 is added for tuple parsing and $12 is added for stacky IR | ||
| ;; resolving during binary reading process. | ||
| ;; RUN: wasm-dis %s.wasm -o - | filecheck %s --check-prefix=ORIG | ||
| ;; ORIG: (func $test | ||
| ;; ORIG-NEXT: (local $0 i32) | ||
| ;; ORIG-NEXT: (local $1 i32) | ||
| ;; ORIG-NEXT: (local $2 i32) | ||
| ;; ORIG-NEXT: (local $3 i32) | ||
| ;; ORIG-NEXT: (local $4 f32) | ||
| ;; ORIG-NEXT: (local $5 i32) | ||
| ;; ORIG-NEXT: (local $6 i32) | ||
| ;; ORIG-NEXT: (local $7 i32) | ||
| ;; ORIG-NEXT: (local $8 f32) | ||
| ;; ORIG-NEXT: (local $9 i32) | ||
| ;; ORIG-NEXT: (local $10 f32) | ||
| ;; ORIG-NEXT: (local $11 (tuple i32 f32)) | ||
| ;; ORIG-NEXT: (local $12 i32) | ||
|
|
||
| ;; If we write this IR into binary, even if this cannot be displayed in the wast | ||
| ;; format, the local order of $test will look like this, because we don't | ||
| ;; reorder locals: | ||
| ;; (func $test | ||
| ;; (local $0 i32) | ||
| ;; (local $1 i32) | ||
| ;; (local $2 i32) | ||
| ;; (local $3 i32) | ||
| ;; (local $4 f32) | ||
| ;; (local $5 i32) | ||
| ;; (local $6 i32) | ||
| ;; (local $7 i32) | ||
| ;; (local $8 f32) | ||
| ;; (local $9 i32) | ||
| ;; (local $10 f32) | ||
| ;; (local $11 i32) ;; Previous (local $11 (tuple i32 f32))'s first element | ||
| ;; (local $12 f32) ;; Previous (local $11 (tuple i32 f32))'s second element | ||
| ;; (local $13 i32) ;; Previous (local $12 i32) | ||
| ;; (local $14 f32) ;; scratch local for f32 | ||
|
|
||
| ;; We parse this binary again into Binaryen IR, roundtripping the original | ||
| ;; binary. Here until (local $14) is the same with the previous list, and $15 is | ||
| ;; is added for tuple parsing and $16 is added for stacky IR resolving during | ||
| ;; binary reading process. | ||
| ;; RUN: wasm-opt -all -g --roundtrip %s.wasm -S -o - | filecheck %s --check-prefix=ROUNDTRIP | ||
| ;; ROUNDTRIP: (func $test | ||
| ;; ROUNDTRIP-NEXT: (local $0 i32) | ||
| ;; ROUNDTRIP-NEXT: (local $1 i32) | ||
| ;; ROUNDTRIP-NEXT: (local $2 i32) | ||
| ;; ROUNDTRIP-NEXT: (local $3 i32) | ||
| ;; ROUNDTRIP-NEXT: (local $4 f32) | ||
| ;; ROUNDTRIP-NEXT: (local $5 i32) | ||
| ;; ROUNDTRIP-NEXT: (local $6 i32) | ||
| ;; ROUNDTRIP-NEXT: (local $7 i32) | ||
| ;; ROUNDTRIP-NEXT: (local $8 f32) | ||
| ;; ROUNDTRIP-NEXT: (local $9 i32) | ||
| ;; ROUNDTRIP-NEXT: (local $10 f32) | ||
| ;; ROUNDTRIP-NEXT: (local $11 i32) | ||
| ;; ROUNDTRIP-NEXT: (local $12 f32) | ||
| ;; ROUNDTRIP-NEXT: (local $13 i32) | ||
| ;; ROUNDTRIP-NEXT: (local $14 f32) | ||
| ;; ROUNDTRIP-NEXT: (local $15 (tuple i32 f32)) | ||
| ;; ROUNDTRIP-NEXT: (local $16 i32) | ||
|
|
||
| ;; We can see that we don't reorder the locals during the process and the | ||
| ;; original list of locals, local $0~$10, is untouched, to NOT invalidate DWARF | ||
| ;; info. |
Binary file not shown.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe save
func->getLocalType(i).size()which is used twice to a localsize?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done