Skip to content

Commit c2c8a98

Browse files
rmacnak-googleCommit Queue
authored andcommitted
[vm, compiler] Handle invalid shift amount during code generation by emitting a break instead of asserting.
The compiler sometimes fails to remove unreachable IL instructions, and such instructions can have contradictory range information. TEST=dartfuzz Bug: #56947 Change-Id: I435019ea87804fdb649e7ff8cee855d08be24019 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/392403 Commit-Queue: Ryan Macnak <[email protected]> Reviewed-by: Alexander Markov <[email protected]>
1 parent 78edbe3 commit c2c8a98

File tree

5 files changed

+58
-10
lines changed

5 files changed

+58
-10
lines changed

runtime/vm/compiler/backend/il_arm.cc

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6491,7 +6491,11 @@ static void EmitShiftInt64ByConstant(FlowGraphCompiler* compiler,
64916491
Register left_hi,
64926492
const Object& right) {
64936493
const int64_t shift = Integer::Cast(right).Value();
6494-
ASSERT(shift >= 0);
6494+
if (shift < 0) {
6495+
// The compiler sometimes fails to eliminate unreachable code.
6496+
__ Stop("Unreachable shift");
6497+
return;
6498+
}
64956499

64966500
switch (op_kind) {
64976501
case Token::kSHR: {
@@ -6594,7 +6598,12 @@ static void EmitShiftUint32ByConstant(FlowGraphCompiler* compiler,
65946598
Register left,
65956599
const Object& right) {
65966600
const int64_t shift = Integer::Cast(right).Value();
6597-
ASSERT(shift >= 0);
6601+
if (shift < 0) {
6602+
// The compiler sometimes fails to eliminate unreachable code.
6603+
__ Stop("Unreachable shift");
6604+
return;
6605+
}
6606+
65986607
if (shift >= 32) {
65996608
__ LoadImmediate(out, 0);
66006609
} else {

runtime/vm/compiler/backend/il_arm64.cc

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5654,7 +5654,12 @@ static void EmitShiftInt64ByConstant(FlowGraphCompiler* compiler,
56545654
Register left,
56555655
const Object& right) {
56565656
const int64_t shift = Integer::Cast(right).Value();
5657-
ASSERT(shift >= 0);
5657+
if (shift < 0) {
5658+
// The compiler sometimes fails to eliminate unreachable code.
5659+
__ Stop("Unreachable shift");
5660+
return;
5661+
}
5662+
56585663
switch (op_kind) {
56595664
case Token::kSHR: {
56605665
__ AsrImmediate(out, left,
@@ -5705,7 +5710,12 @@ static void EmitShiftUint32ByConstant(FlowGraphCompiler* compiler,
57055710
Register left,
57065711
const Object& right) {
57075712
const int64_t shift = Integer::Cast(right).Value();
5708-
ASSERT(shift >= 0);
5713+
if (shift < 0) {
5714+
// The compiler sometimes fails to eliminate unreachable code.
5715+
__ Stop("Unreachable shift");
5716+
return;
5717+
}
5718+
57095719
if (shift >= 32) {
57105720
__ LoadImmediate(out, 0);
57115721
} else {

runtime/vm/compiler/backend/il_ia32.cc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5600,7 +5600,12 @@ static void EmitShiftInt64ByConstant(FlowGraphCompiler* compiler,
56005600
Register left_hi,
56015601
const Object& right) {
56025602
const int64_t shift = Integer::Cast(right).Value();
5603-
ASSERT(shift >= 0);
5603+
if (shift < 0) {
5604+
// The compiler sometimes fails to eliminate unreachable code.
5605+
__ Stop("Unreachable shift");
5606+
return;
5607+
}
5608+
56045609
switch (op_kind) {
56055610
case Token::kSHR: {
56065611
if (shift > 31) {

runtime/vm/compiler/backend/il_riscv.cc

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5802,7 +5802,11 @@ static void EmitShiftInt64ByConstant(FlowGraphCompiler* compiler,
58025802
Register left_hi,
58035803
const Object& right) {
58045804
const int64_t shift = Integer::Cast(right).Value();
5805-
ASSERT(shift >= 0);
5805+
if (shift < 0) {
5806+
// The compiler sometimes fails to eliminate unreachable code.
5807+
__ Stop("Unreachable shift");
5808+
return;
5809+
}
58065810

58075811
switch (op_kind) {
58085812
case Token::kSHR: {
@@ -5869,7 +5873,12 @@ static void EmitShiftInt64ByConstant(FlowGraphCompiler* compiler,
58695873
Register left,
58705874
const Object& right) {
58715875
const int64_t shift = Integer::Cast(right).Value();
5872-
ASSERT(shift >= 0);
5876+
if (shift < 0) {
5877+
// The compiler sometimes fails to eliminate unreachable code.
5878+
__ Stop("Unreachable shift");
5879+
return;
5880+
}
5881+
58735882
switch (op_kind) {
58745883
case Token::kSHR: {
58755884
__ srai(out, left, Utils::Minimum<int64_t>(shift, XLEN - 1));
@@ -6002,7 +6011,12 @@ static void EmitShiftUint32ByConstant(FlowGraphCompiler* compiler,
60026011
Register left,
60036012
const Object& right) {
60046013
const int64_t shift = Integer::Cast(right).Value();
6005-
ASSERT(shift >= 0);
6014+
if (shift < 0) {
6015+
// The compiler sometimes fails to eliminate unreachable code.
6016+
__ Stop("Unreachable shift");
6017+
return;
6018+
}
6019+
60066020
if (shift >= 32) {
60076021
__ li(out, 0);
60086022
} else {

runtime/vm/compiler/backend/il_x64.cc

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6000,7 +6000,12 @@ static void EmitShiftInt64ByConstant(FlowGraphCompiler* compiler,
60006000
Register left,
60016001
const Object& right) {
60026002
const int64_t shift = Integer::Cast(right).Value();
6003-
ASSERT(shift >= 0);
6003+
if (shift < 0) {
6004+
// The compiler sometimes fails to eliminate unreachable code.
6005+
__ Stop("Unreachable shift");
6006+
return;
6007+
}
6008+
60046009
switch (op_kind) {
60056010
case Token::kSHR:
60066011
__ sarq(left, compiler::Immediate(
@@ -6046,7 +6051,12 @@ static void EmitShiftUint32ByConstant(FlowGraphCompiler* compiler,
60466051
Register left,
60476052
const Object& right) {
60486053
const int64_t shift = Integer::Cast(right).Value();
6049-
ASSERT(shift >= 0);
6054+
if (shift < 0) {
6055+
// The compiler sometimes fails to eliminate unreachable code.
6056+
__ Stop("Unreachable shift");
6057+
return;
6058+
}
6059+
60506060
if (shift >= 32) {
60516061
__ xorl(left, left);
60526062
} else {

0 commit comments

Comments
 (0)