tint: Fix AInt -> AFloat implicit conversion from construction

Bug: tint:1581
Change-Id: I8c6a1e375130ab38ef52cb0d8dddaca03cc098da
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/100800
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
This commit is contained in:
Antonio Maiorano 2022-08-31 13:48:41 +00:00 committed by Dawn LUCI CQ
parent 5361d9e778
commit ff0295ebd8
2 changed files with 31 additions and 3 deletions

View File

@ -2982,6 +2982,32 @@ TEST_F(ResolverConstEvalTest, MemberAccess) {
EXPECT_EQ(i2->ConstantValue()->As<u32>(), 2_u);
}
TEST_F(ResolverConstEvalTest, Matrix_AFloat_Construct_From_AInt_Vectors) {
auto* c = Const("a", Construct(ty.mat(nullptr, 2, 2), //
Construct(ty.vec(nullptr, 2), Expr(1_a), Expr(2_a)),
Construct(ty.vec(nullptr, 2), Expr(3_a), Expr(4_a))));
WrapInFunction(c);
EXPECT_TRUE(r()->Resolve()) << r()->error();
auto* sem = Sem().Get(c);
ASSERT_NE(sem, nullptr);
EXPECT_TRUE(sem->Type()->Is<sem::Matrix>());
auto* cv = sem->ConstantValue();
EXPECT_TYPE(cv->Type(), sem->Type());
EXPECT_TRUE(cv->Index(0)->Type()->Is<sem::Vector>());
EXPECT_TRUE(cv->Index(0)->Index(0)->Type()->Is<sem::AbstractFloat>());
EXPECT_FALSE(cv->AllEqual());
EXPECT_FALSE(cv->AnyZero());
EXPECT_FALSE(cv->AllZero());
auto* c0 = cv->Index(0);
auto* c1 = cv->Index(1);
EXPECT_EQ(std::get<AFloat>(c0->Index(0)->Value()), 1.0);
EXPECT_EQ(std::get<AFloat>(c0->Index(1)->Value()), 2.0);
EXPECT_EQ(std::get<AFloat>(c1->Index(0)->Value()), 3.0);
EXPECT_EQ(std::get<AFloat>(c1->Index(1)->Value()), 4.0);
}
////////////////////////////////////////////////////////////////////////////////////////////////////
// Unary op
////////////////////////////////////////////////////////////////////////////////////////////////////

View File

@ -1690,10 +1690,12 @@ sem::Call* Resolver::Call(const ast::CallExpression* expr) {
const sem::Constant* value = nullptr;
auto stage = sem::EarliestStage(ctor_or_conv.target->Stage(), args_stage);
if (stage == sem::EvaluationStage::kConstant) {
auto const_args =
utils::Transform(args, [](auto* arg) { return arg->ConstantValue(); });
auto const_args = ConvertArguments(args, ctor_or_conv.target);
if (!const_args) {
return nullptr;
}
if (auto r = (const_eval_.*ctor_or_conv.const_eval_fn)(
ctor_or_conv.target->ReturnType(), const_args, expr->source)) {
ctor_or_conv.target->ReturnType(), const_args.Get(), expr->source)) {
value = r.Get();
} else {
return nullptr;