-
-
Notifications
You must be signed in to change notification settings - Fork 667
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Compile incrementors in for loops within the initializer's flow (#2826)
It turns out that incrementors were compiled with the body's flow, which meant that the incrementor had access to local variables declared in the body. Now, incrementors no longer have access to such variables. Fixes #2825.
- Loading branch information
1 parent
9605c03
commit 9102c05
Showing
5 changed files
with
101 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 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,55 @@ | ||
(module | ||
(type $0 (func)) | ||
(type $1 (func (param i32 i32 i32 i32))) | ||
(type $2 (func (param i32) (result i32))) | ||
(import "env" "abort" (func $~lib/builtins/abort (param i32 i32 i32 i32))) | ||
(global $~lib/memory/__data_end i32 (i32.const 60)) | ||
(global $~lib/memory/__stack_pointer (mut i32) (i32.const 32828)) | ||
(global $~lib/memory/__heap_base i32 (i32.const 32828)) | ||
(memory $0 1) | ||
(data $0 (i32.const 12) ",\00\00\00\00\00\00\00\00\00\00\00\02\00\00\00\1c\00\00\00i\00s\00s\00u\00e\00s\00/\002\008\002\005\00.\00t\00s\00") | ||
(table $0 1 1 funcref) | ||
(elem $0 (i32.const 1)) | ||
(export "memory" (memory $0)) | ||
(start $~start) | ||
(func $issues/2825/increment (param $x i32) (result i32) | ||
local.get $x | ||
i32.const 1234 | ||
i32.ne | ||
i32.eqz | ||
if | ||
i32.const 0 | ||
i32.const 32 | ||
i32.const 2 | ||
i32.const 3 | ||
call $~lib/builtins/abort | ||
unreachable | ||
end | ||
local.get $x | ||
i32.const 1 | ||
i32.add | ||
return | ||
) | ||
(func $start:issues/2825 | ||
(local $i i32) | ||
(local $i|1 i32) | ||
i32.const 0 | ||
local.set $i | ||
loop $for-loop|0 | ||
local.get $i | ||
i32.const 10 | ||
i32.lt_s | ||
if | ||
i32.const 1234 | ||
local.set $i|1 | ||
local.get $i | ||
call $issues/2825/increment | ||
local.set $i | ||
br $for-loop|0 | ||
end | ||
end | ||
) | ||
(func $~start | ||
call $start:issues/2825 | ||
) | ||
) |
This file contains 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 @@ | ||
{} |
This file contains 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,36 @@ | ||
(module | ||
(type $0 (func (param i32 i32 i32 i32))) | ||
(type $1 (func)) | ||
(import "env" "abort" (func $~lib/builtins/abort (param i32 i32 i32 i32))) | ||
(memory $0 1) | ||
(data $0 (i32.const 1036) ",") | ||
(data $0.1 (i32.const 1048) "\02\00\00\00\1c\00\00\00i\00s\00s\00u\00e\00s\00/\002\008\002\005\00.\00t\00s") | ||
(export "memory" (memory $0)) | ||
(start $~start) | ||
(func $~start | ||
(local $0 i32) | ||
loop $for-loop|0 | ||
local.get $0 | ||
i32.const 10 | ||
i32.lt_s | ||
if | ||
local.get $0 | ||
i32.const 1234 | ||
i32.eq | ||
if | ||
i32.const 0 | ||
i32.const 1056 | ||
i32.const 2 | ||
i32.const 3 | ||
call $~lib/builtins/abort | ||
unreachable | ||
end | ||
local.get $0 | ||
i32.const 1 | ||
i32.add | ||
local.set $0 | ||
br $for-loop|0 | ||
end | ||
end | ||
) | ||
) |
This file contains 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,8 @@ | ||
function increment(x: i32): i32 { | ||
assert(x !== 1234); | ||
return x + 1; | ||
} | ||
|
||
for (let i = 0; i < 10; i = increment(i)) { | ||
let i = 1234; | ||
} |