Commit e58cd935 authored by Tobias Tebbi's avatar Tobias Tebbi Committed by Commit Bot

[torque] fix unused code errors for code used in asserts

The assert code gets put into an unreachable block in release builds
to make sure it's type-checked and torque knows the code it contains is
used, but still it doesn't emit actual machine code.

Bug: v8:7793
Change-Id: I580fdd7ac059e0dbe85283fd35c3038634a7228e
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1857226Reviewed-by: 's avatarMaya Lekova <mslekova@chromium.org>
Commit-Queue: Maya Lekova <mslekova@chromium.org>
Auto-Submit: Tobias Tebbi <tebbi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#64270}
parent 31da5d19
......@@ -45,9 +45,6 @@ namespace bigint {
MutableBigInt, intptr, uintptr): void;
extern macro CodeStubAssembler::LoadBigIntDigit(BigIntBase, intptr): uintptr;
@export // Silence unused warning.
// TODO(szuend): Remove @export once macros that are only used in
// asserts are no longer detected as unused.
macro IsCanonicalized(bigint: BigIntBase): bool {
const length = ReadBigIntLength(bigint);
......
......@@ -28,8 +28,6 @@ namespace internal_coverage {
return UnsafeCast<CoverageInfo>(debugInfo.coverage_info);
}
@export // Silence unused warning on release builds. SlotCount is only used
// in an assert. TODO(szuend): Remove once macros and asserts work.
macro SlotCount(coverageInfo: CoverageInfo): Smi {
assert(kFirstSlotIndex == 0); // Otherwise we'd have to consider it below.
assert(kFirstSlotIndex == (coverageInfo.length & kSlotIndexCountMask));
......
......@@ -1007,48 +1007,40 @@ const Type* ImplementationVisitor::Visit(AssertStatement* stmt) {
#if defined(DEBUG)
do_check = true;
#endif
if (do_check) {
// CSA_ASSERT & co. are not used here on purpose for two reasons. First,
// Torque allows and handles two types of expressions in the if protocol
// automagically, ones that return TNode<BoolT> and those that use the
// BranchIf(..., Label* true, Label* false) idiom. Because the machinery to
// handle this is embedded in the expression handling and to it's not
// possible to make the decision to use CSA_ASSERT or CSA_ASSERT_BRANCH
// isn't trivial up-front. Secondly, on failure, the assert text should be
// the corresponding Torque code, not the -gen.cc code, which would be the
// case when using CSA_ASSERT_XXX.
Block* true_block = assembler().NewBlock(assembler().CurrentStack());
Block* false_block = assembler().NewBlock(assembler().CurrentStack(), true);
GenerateExpressionBranch(stmt->expression, true_block, false_block);
Block* resume_block;
if (!do_check) {
Block* unreachable_block = assembler().NewBlock(assembler().CurrentStack());
resume_block = assembler().NewBlock(assembler().CurrentStack());
assembler().Goto(resume_block);
assembler().Bind(unreachable_block);
}
// CSA_ASSERT & co. are not used here on purpose for two reasons. First,
// Torque allows and handles two types of expressions in the if protocol
// automagically, ones that return TNode<BoolT> and those that use the
// BranchIf(..., Label* true, Label* false) idiom. Because the machinery to
// handle this is embedded in the expression handling and to it's not
// possible to make the decision to use CSA_ASSERT or CSA_ASSERT_BRANCH
// isn't trivial up-front. Secondly, on failure, the assert text should be
// the corresponding Torque code, not the -gen.cc code, which would be the
// case when using CSA_ASSERT_XXX.
Block* true_block = assembler().NewBlock(assembler().CurrentStack());
Block* false_block = assembler().NewBlock(assembler().CurrentStack(), true);
GenerateExpressionBranch(stmt->expression, true_block, false_block);
assembler().Bind(false_block);
assembler().Bind(false_block);
assembler().Emit(AbortInstruction{
AbortInstruction::Kind::kAssertionFailure,
"Torque assert '" + FormatAssertSource(stmt->source) + "' failed"});
assembler().Emit(AbortInstruction{
AbortInstruction::Kind::kAssertionFailure,
"Torque assert '" + FormatAssertSource(stmt->source) + "' failed"});
assembler().Bind(true_block);
} else {
// Visit the expression so bindings only used in asserts are marked
// as such. Otherwise they might be wrongly reported as unused bindings
// in release builds.
stmt->expression->VisitAllSubExpressions([](Expression* expression) {
if (auto id = IdentifierExpression::DynamicCast(expression)) {
ValueBindingsManager::Get().TryLookup(id->name->value);
} else if (auto call = CallExpression::DynamicCast(expression)) {
for (Identifier* label : call->labels) {
LabelBindingsManager::Get().TryLookup(label->value);
}
// TODO(szuend): In case the call expression resolves to a macro
// callable, mark the macro as used as well.
} else if (auto call = CallMethodExpression::DynamicCast(expression)) {
for (Identifier* label : call->labels) {
LabelBindingsManager::Get().TryLookup(label->value);
}
// TODO(szuend): Mark the underlying macro as used.
}
});
assembler().Bind(true_block);
if (!do_check) {
assembler().Bind(resume_block);
}
return TypeOracle::GetVoidType();
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment