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 <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
This commit is contained in:
Antonio Maiorano 2022-08-16 16:00:02 +00:00 committed by Dawn LUCI CQ
parent bade13a5d2
commit 2de4deea1f
2 changed files with 19 additions and 5 deletions

View File

@ -3262,9 +3262,9 @@ TEST_F(ResolverConstEvalTest, BinaryAbstractAddUnderflow_AFloat) {
EXPECT_EQ(r()->error(), "1:1 error: '-inf' cannot be represented as 'abstract-float'"); EXPECT_EQ(r()->error(), "1:1 error: '-inf' cannot be represented as 'abstract-float'");
} }
TEST_F(ResolverConstEvalTest, BinaryAbstractMixed) { TEST_F(ResolverConstEvalTest, BinaryAbstractMixed_ScalarScalar) {
auto* a = Const("a", nullptr, Expr(1_a)); auto* a = Const("a", nullptr, Expr(1_a)); // AInt
auto* b = Const("b", nullptr, Expr(2.3_a)); auto* b = Const("b", nullptr, Expr(2.3_a)); // AFloat
auto* c = Add(Expr("a"), Expr("b")); auto* c = Add(Expr("a"), Expr("b"));
WrapInFunction(a, b, c); WrapInFunction(a, b, c);
EXPECT_TRUE(r()->Resolve()) << r()->error(); EXPECT_TRUE(r()->Resolve()) << r()->error();
@ -3275,6 +3275,20 @@ TEST_F(ResolverConstEvalTest, BinaryAbstractMixed) {
EXPECT_EQ(result, 3.3f); 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<AFloat>(), 3.3f);
EXPECT_EQ(sem->ConstantValue()->Index(1)->As<AFloat>(), 3.3f);
EXPECT_EQ(sem->ConstantValue()->Index(2)->As<AFloat>(), 3.3f);
}
} // namespace binary_op } // namespace binary_op
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////

View File

@ -2329,10 +2329,10 @@ sem::Expression* Resolver::Binary(const ast::BinaryExpression* expr) {
if (op.const_eval_fn) { if (op.const_eval_fn) {
auto const_args = utils::Vector{lhs->ConstantValue(), rhs->ConstantValue()}; auto const_args = utils::Vector{lhs->ConstantValue(), rhs->ConstantValue()};
// Implicit conversion (e.g. AInt -> AFloat) // 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; return nullptr;
} }
if (!Convert(const_args[1], op.result, rhs->Declaration()->source)) { if (!Convert(const_args[1], op.rhs, rhs->Declaration()->source)) {
return nullptr; return nullptr;
} }