From 9609ebf3a9bd8919dd0228970f31e284da190776 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20Z=C3=BCnd?= Date: Fri, 24 May 2019 13:29:51 +0200 Subject: [PATCH] [torque] Fix crash when declaring a variable without type MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Auto-Submit: Simon Zünd Reviewed-by: Sigurd Schneider Cr-Commit-Position: refs/heads/master@{#61826} --- src/torque/implementation-visitor.cc | 11 +++++++---- test/unittests/torque/torque-unittest.cc | 6 ++++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/torque/implementation-visitor.cc b/src/torque/implementation-visitor.cc index 8b139ade7c..58caa9e1fd 100644 --- a/src/torque/implementation-visitor.cc +++ b/src/torque/implementation-visitor.cc @@ -541,10 +541,6 @@ const Type* ImplementationVisitor::Visit( base::Optional 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 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()); diff --git a/test/unittests/torque/torque-unittest.cc b/test/unittests/torque/torque-unittest.cc index 8ad277ec92..9a82498ee4 100644 --- a/test/unittests/torque/torque-unittest.cc +++ b/test/unittests/torque/torque-unittest.cc @@ -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