Skip to content

Commit 4aebac3

Browse files
sstricklCommit Queue
authored and
Commit Queue
committed
[vm] Verify STC input count matches stub expected input count in DEBUG.
If these checks fail, then a `SubtypeNTestCache` stub has been called with a `SubtypeTestCache` that uses a different number of inputs than the stub expects, which could lead to unexpected false negatives or false positives, so catch it early. TEST=vm/cc/TTS, ci Change-Id: Ia9c48aad4c35872cad32b7b6f3eead3ee9e59680 Cq-Include-Trybots: luci.dart.try:vm-mac-debug-arm64-try,vm-linux-debug-x64c-try,vm-linux-debug-x64-try,vm-linux-debug-simriscv64-try,vm-linux-debug-ia32-try,vm-aot-linux-debug-simriscv64-try,vm-aot-linux-debug-simarm_x64-try,vm-aot-linux-debug-x64-try,vm-aot-linux-debug-x64c-try Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/311380 Commit-Queue: Tess Strickland <[email protected]> Reviewed-by: Daco Harkes <[email protected]>
1 parent f1cd87e commit 4aebac3

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

runtime/vm/compiler/stub_code_compiler.cc

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,15 +1104,6 @@ void StubCodeCompiler::GenerateSlowTypeTestStub() {
11041104
__ BranchIf(EQUAL, &call_4, Assembler::kNearJump);
11051105
__ CompareImmediate(TypeTestABI::kScratchReg, 6);
11061106
__ BranchIf(EQUAL, &call_6, Assembler::kNearJump);
1107-
#if defined(DEBUG)
1108-
// Verify we have the all inputs case.
1109-
Label perform_check;
1110-
__ CompareImmediate(TypeTestABI::kScratchReg,
1111-
target::SubtypeTestCache::kMaxInputs);
1112-
__ BranchIf(EQUAL, &perform_check, Assembler::kNearJump);
1113-
__ Breakpoint();
1114-
__ Bind(&perform_check);
1115-
#endif
11161107
// Fall through to the all inputs case.
11171108

11181109
{
@@ -3102,6 +3093,15 @@ void StubCodeCompiler::GenerateSubtypeTestCacheSearch(
31023093
}
31033094
// We use this as a scratch, so it has to be distinct from the others.
31043095
ASSERT(!input_regs.ContainsRegister(TypeTestABI::kScratchReg));
3096+
3097+
// Verify the STC we received has exactly as many inputs as this stub expects.
3098+
Label search_stc;
3099+
__ LoadFromSlot(TypeTestABI::kScratchReg, TypeTestABI::kSubtypeTestCacheReg,
3100+
Slot::SubtypeTestCache_num_inputs());
3101+
__ CompareImmediate(TypeTestABI::kScratchReg, n);
3102+
__ BranchIf(EQUAL, &search_stc, Assembler::kNearJump);
3103+
__ Breakpoint();
3104+
__ Bind(&search_stc);
31053105
#endif
31063106

31073107
__ LoadAcquireCompressed(

runtime/vm/compiler/stub_code_compiler_ia32.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2454,6 +2454,16 @@ void StubCodeCompiler::GenerateSubtypeNTestCacheStub(Assembler* assembler,
24542454
// Loop initialization (moved up here to avoid having all dependent loads
24552455
// after each other)
24562456
__ LoadFromStack(STCInternal::kCacheArrayReg, STCInternal::kCacheDepth);
2457+
#if defined(DEBUG)
2458+
// Verify the STC we received has exactly as many inputs as this stub expects.
2459+
Label search_stc;
2460+
__ LoadFromSlot(STCInternal::kScratchReg, STCInternal::kCacheArrayReg,
2461+
Slot::SubtypeTestCache_num_inputs());
2462+
__ CompareImmediate(STCInternal::kScratchReg, n);
2463+
__ BranchIf(EQUAL, &search_stc, Assembler::kNearJump);
2464+
__ Breakpoint();
2465+
__ Bind(&search_stc);
2466+
#endif
24572467
// We avoid a load-acquire barrier here by relying on the fact that all other
24582468
// loads from the array are data-dependent loads.
24592469
__ movl(STCInternal::kCacheArrayReg,

0 commit comments

Comments
 (0)