Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Fix backward branching in SwitchImm.
Summary: `SwitchImm` can subtract from `ip`, but it was reading the offset from a `uint32_t *` instead of `int32_t *`. Change the type to the correct one. Reviewed By: dulinriley Differential Revision: D23114516 fbshipit-source-id: d4ddab94eb16dc1ce479590851eeb1ab428bd5d6
- Loading branch information
1 parent
5e557a4
commit 2c7af7e
Showing
3 changed files
with
82 additions
and
2 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,36 @@ | ||
| /** | ||
| * Copyright (c) Facebook, Inc. and its affiliates. | ||
| * | ||
| * This source code is licensed under the MIT license found in the | ||
| * LICENSE file in the root directory of this source tree. | ||
| */ | ||
|
|
||
| // RUN: %hermes -O -dump-ir %s | %FileCheck %s | ||
|
|
||
| function backwards_branch() { | ||
| for (var i = 0; i < 4; i++) { | ||
| switch (i) { | ||
| case 0: | ||
| case 1: | ||
| case 2: | ||
| case 3: | ||
| case 4: | ||
| case 5: | ||
| case 6: | ||
| case 7: | ||
| case 8: | ||
| case 9: | ||
| break; | ||
| } | ||
| i = 2; | ||
| } | ||
| } | ||
|
|
||
| // CHECK-LABEL: function backwards_branch() : undefined | ||
| // CHECK-NEXT: frame = [] | ||
| // CHECK-NEXT: %BB0: | ||
| // CHECK-NEXT: %0 = BranchInst %BB1 | ||
| // CHECK-NEXT: %BB1: | ||
| // CHECK-NEXT: %1 = PhiInst 0 : number, %BB0, 3 : number, %BB1 | ||
| // CHECK-NEXT: %2 = SwitchInst %1 : number, %BB1, 0 : number, %BB1, 1 : number, %BB1, 2 : number, %BB1, 3 : number, %BB1, 4 : number, %BB1, 5 : number, %BB1, 6 : number, %BB1, 7 : number, %BB1, 8 : number, %BB1, 9 : number, %BB1 | ||
| // CHECK-NEXT: function_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,43 @@ | ||
| /** | ||
| * Copyright (c) Facebook, Inc. and its affiliates. | ||
| * | ||
| * This source code is licensed under the MIT license found in the | ||
| * LICENSE file in the root directory of this source tree. | ||
| */ | ||
|
|
||
| // RUN: %hermes -O0 %s | %FileCheck --match-full-lines %s | ||
| // RUN: %hermes -O %s | %FileCheck --match-full-lines %s | ||
| // RUN: %hermes -O -emit-binary -out %t.hbc %s && %hermes %t.hbc | %FileCheck --match-full-lines %s | ||
|
|
||
| // Ensure that switch statements that are backwards branches work properly. | ||
|
|
||
| (function() { | ||
| var j = 0; | ||
| for (var i = 0; i < 4; i++) { | ||
| ++j; | ||
| if (j > 5) { | ||
| return; | ||
| } | ||
| print(i); | ||
| switch (i) { | ||
| case 0: | ||
| case 1: | ||
| case 2: | ||
| case 3: | ||
| case 4: | ||
| case 5: | ||
| case 6: | ||
| case 7: | ||
| case 8: | ||
| case 9: | ||
| break; | ||
| } | ||
| i = 2; | ||
| } | ||
| })(); | ||
|
|
||
| // CHECK: 0 | ||
| // CHECK: 3 | ||
| // CHECK: 3 | ||
| // CHECK: 3 | ||
| // CHECK: 3 |