From 2de4deea1f4de5bae44be624e0ec88060e8aae60 Mon Sep 17 00:00:00 2001 From: Antonio Maiorano Date: Tue, 16 Aug 2022 16:00:02 +0000 Subject: [PATCH] tint: Fix implicit conversion of vector-scalar of abstract types in binary operations Example: const v2 = vec3(1) + 2.2; Bug: chromium:1350147 Change-Id: Ie75d76bf00a6b2f6abd49293290f6e5065c31dfb Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/99301 Reviewed-by: Ben Clayton Kokoro: Kokoro Commit-Queue: Antonio Maiorano --- src/tint/resolver/const_eval_test.cc | 20 +++++++++++++++++--- src/tint/resolver/resolver.cc | 4 ++-- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/tint/resolver/const_eval_test.cc b/src/tint/resolver/const_eval_test.cc index a82e471682..6623a5aeb9 100644 --- a/src/tint/resolver/const_eval_test.cc +++ b/src/tint/resolver/const_eval_test.cc @@ -3262,9 +3262,9 @@ TEST_F(ResolverConstEvalTest, BinaryAbstractAddUnderflow_AFloat) { EXPECT_EQ(r()->error(), "1:1 error: '-inf' cannot be represented as 'abstract-float'"); } -TEST_F(ResolverConstEvalTest, BinaryAbstractMixed) { - auto* a = Const("a", nullptr, Expr(1_a)); - auto* b = Const("b", nullptr, Expr(2.3_a)); +TEST_F(ResolverConstEvalTest, BinaryAbstractMixed_ScalarScalar) { + auto* a = Const("a", nullptr, Expr(1_a)); // AInt + auto* b = Const("b", nullptr, Expr(2.3_a)); // AFloat auto* c = Add(Expr("a"), Expr("b")); WrapInFunction(a, b, c); EXPECT_TRUE(r()->Resolve()) << r()->error(); @@ -3275,6 +3275,20 @@ TEST_F(ResolverConstEvalTest, BinaryAbstractMixed) { EXPECT_EQ(result, 3.3f); } +TEST_F(ResolverConstEvalTest, BinaryAbstractMixed_ScalarVector) { + auto* a = Const("a", nullptr, Expr(1_a)); // AInt + auto* b = Const("b", nullptr, Construct(ty.vec(nullptr, 3), Expr(2.3_a))); // AFloat + auto* c = Add(Expr("a"), Expr("b")); + WrapInFunction(a, b, c); + EXPECT_TRUE(r()->Resolve()) << r()->error(); + auto* sem = Sem().Get(c); + ASSERT_TRUE(sem); + ASSERT_TRUE(sem->ConstantValue()); + EXPECT_EQ(sem->ConstantValue()->Index(0)->As(), 3.3f); + EXPECT_EQ(sem->ConstantValue()->Index(1)->As(), 3.3f); + EXPECT_EQ(sem->ConstantValue()->Index(2)->As(), 3.3f); +} + } // namespace binary_op //////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/tint/resolver/resolver.cc b/src/tint/resolver/resolver.cc index 028cf1ad33..2edab1f650 100644 --- a/src/tint/resolver/resolver.cc +++ b/src/tint/resolver/resolver.cc @@ -2329,10 +2329,10 @@ sem::Expression* Resolver::Binary(const ast::BinaryExpression* expr) { if (op.const_eval_fn) { auto const_args = utils::Vector{lhs->ConstantValue(), rhs->ConstantValue()}; // Implicit conversion (e.g. AInt -> AFloat) - if (!Convert(const_args[0], op.result, lhs->Declaration()->source)) { + if (!Convert(const_args[0], op.lhs, lhs->Declaration()->source)) { return nullptr; } - if (!Convert(const_args[1], op.result, rhs->Declaration()->source)) { + if (!Convert(const_args[1], op.rhs, rhs->Declaration()->source)) { return nullptr; }