[torque] Fix crash when declaring a variable without type

This CL fixes a crash when "constexpr" is infered from the intializer
expression of a variable declaration.

R=sigurds@chromium.org

Bug: v8:7793
Change-Id: I0ec51280fa145d874424e885905bbf79c93b3904
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1627983
Commit-Queue: Simon Zünd <szuend@chromium.org>
Auto-Submit: Simon Zünd <szuend@chromium.org>
Reviewed-by: Sigurd Schneider <sigurds@chromium.org>
Cr-Commit-Position: refs/heads/master@{#61826}
This commit is contained in:
Simon Zünd 2019-05-24 13:29:51 +02:00 committed by Commit Bot
parent 15aa022aad
commit 9609ebf3a9
2 changed files with 13 additions and 4 deletions

View File

@ -541,10 +541,6 @@ const Type* ImplementationVisitor::Visit(
base::Optional<const Type*> type;
if (stmt->type) {
type = TypeVisitor::ComputeType(*stmt->type);
if ((*type)->IsConstexpr() && !stmt->const_qualified) {
ReportError(
"cannot declare variable with constexpr type. Use 'const' instead.");
}
}
base::Optional<VisitResult> init_result;
if (stmt->initializer) {
@ -553,6 +549,13 @@ const Type* ImplementationVisitor::Visit(
if (type) {
init_result = GenerateImplicitConvert(*type, *init_result);
}
type = init_result->type();
if ((*type)->IsConstexpr() && !stmt->const_qualified) {
Error("Use 'const' instead of 'let' for variable '", stmt->name->value,
"' of constexpr type '", (*type)->ToString(), "'.")
.Position(stmt->name->pos)
.Throw();
}
init_result = scope.Yield(*init_result);
} else {
DCHECK(type.has_value());

View File

@ -207,6 +207,12 @@ TEST(Torque, ConditionalFields) {
HasSubstr("aligned"));
}
TEST(Torque, ConstexprLetBindingDoesNotCrash) {
ExpectFailingCompilation(
R"(macro FooBar() { let foo = 0; check(foo >= 0); })",
HasSubstr("Use 'const' instead of 'let' for variable 'foo'"));
}
} // namespace torque
} // namespace internal
} // namespace v8