tint/sem: Fix Constant constructor with initializer_list
This was always constructing the elements with AFloat, when it should pick between AInt / AFloat based on the type T. Bug: tint:1504 Change-Id: I2dd4a9bcd829c47c9b0e8d730c5f58a5266d3626 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/92240 Kokoro: Kokoro <noreply+kokoro@google.com> Reviewed-by: Zhaoming Jiang <zhaoming.jiang@intel.com> Reviewed-by: Antonio Maiorano <amaiorano@google.com> Commit-Queue: Ben Clayton <bclayton@chromium.org>
This commit is contained in:
parent
8e3485248e
commit
a20ef0c0f1
|
@ -48,6 +48,10 @@ class Constant {
|
|||
/// Elements is either a vector of AInts or AFloats
|
||||
using Elements = std::variant<AInts, AFloats>;
|
||||
|
||||
/// Helper that resolves to either AInt or AFloat based on the element type T.
|
||||
template <typename T>
|
||||
using ElementFor = std::conditional_t<IsFloatingPoint<UnwrapNumber<T>>, AFloat, AInt>;
|
||||
|
||||
/// Helper that resolves to either AInts or AFloats based on the element type T.
|
||||
template <typename T>
|
||||
using ElementVectorFor = std::conditional_t<IsFloatingPoint<UnwrapNumber<T>>, AFloats, AInts>;
|
||||
|
@ -164,7 +168,7 @@ Constant::Constant(const sem::Type* ty, std::initializer_list<T> els)
|
|||
ElementVectorFor<T> elements;
|
||||
elements.reserve(els.size());
|
||||
for (auto el : els) {
|
||||
elements.emplace_back(AFloat(el));
|
||||
elements.emplace_back(ElementFor<T>(el));
|
||||
}
|
||||
elems_ = Elements{std::move(elements)};
|
||||
}
|
||||
|
|
|
@ -29,16 +29,19 @@ using ConstantTest = TestHelper;
|
|||
|
||||
TEST_F(ConstantTest, ConstructorInitializerList) {
|
||||
{
|
||||
Constant c(create<AbstractInt>(), {1_a});
|
||||
c.WithElements([&](auto&& vec) { EXPECT_THAT(vec, testing::ElementsAre(1_a)); });
|
||||
auto i = AInt(AInt::kHighest);
|
||||
Constant c(create<AbstractInt>(), {i});
|
||||
c.WithElements([&](auto&& vec) { EXPECT_THAT(vec, testing::ElementsAre(i)); });
|
||||
}
|
||||
{
|
||||
Constant c(create<I32>(), {1_i});
|
||||
c.WithElements([&](auto&& vec) { EXPECT_THAT(vec, testing::ElementsAre(1_a)); });
|
||||
auto i = i32(i32::kHighest);
|
||||
Constant c(create<I32>(), {i});
|
||||
c.WithElements([&](auto&& vec) { EXPECT_THAT(vec, testing::ElementsAre(i)); });
|
||||
}
|
||||
{
|
||||
Constant c(create<U32>(), {1_u});
|
||||
c.WithElements([&](auto&& vec) { EXPECT_THAT(vec, testing::ElementsAre(1_a)); });
|
||||
auto i = u32(u32::kHighest);
|
||||
Constant c(create<U32>(), {i});
|
||||
c.WithElements([&](auto&& vec) { EXPECT_THAT(vec, testing::ElementsAre(i)); });
|
||||
}
|
||||
{
|
||||
Constant c(create<Bool>(), {false});
|
||||
|
@ -49,16 +52,19 @@ TEST_F(ConstantTest, ConstructorInitializerList) {
|
|||
c.WithElements([&](auto&& vec) { EXPECT_THAT(vec, testing::ElementsAre(1_a)); });
|
||||
}
|
||||
{
|
||||
Constant c(create<AbstractFloat>(), {1.0_a});
|
||||
c.WithElements([&](auto&& vec) { EXPECT_THAT(vec, testing::ElementsAre(1.0_a)); });
|
||||
auto f = AFloat(AFloat::kHighest);
|
||||
Constant c(create<AbstractFloat>(), {f});
|
||||
c.WithElements([&](auto&& vec) { EXPECT_THAT(vec, testing::ElementsAre(f)); });
|
||||
}
|
||||
{
|
||||
Constant c(create<F32>(), {1.0_f});
|
||||
c.WithElements([&](auto&& vec) { EXPECT_THAT(vec, testing::ElementsAre(1.0_a)); });
|
||||
auto f = f32(f32::kHighest);
|
||||
Constant c(create<F32>(), {f});
|
||||
c.WithElements([&](auto&& vec) { EXPECT_THAT(vec, testing::ElementsAre(f)); });
|
||||
}
|
||||
{
|
||||
Constant c(create<F16>(), {1.0_h});
|
||||
c.WithElements([&](auto&& vec) { EXPECT_THAT(vec, testing::ElementsAre(1.0_a)); });
|
||||
auto f = f16(f16::kHighest);
|
||||
Constant c(create<F16>(), {f});
|
||||
c.WithElements([&](auto&& vec) { EXPECT_THAT(vec, testing::ElementsAre(f)); });
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue