tint: Skip short-circuited array init const eval

Otherwise we will dereference the nullptr constant::Value constructor
arguments.

Bug: chromium:1420256
Change-Id: I5cace9c7c4bab7815f319793fdd88be294cd0ceb
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/122101
Reviewed-by: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: James Price <jrprice@google.com>
This commit is contained in:
James Price 2023-02-28 19:28:50 +00:00 committed by Dawn LUCI CQ
parent f93f7ae8b1
commit b7c2aed189
2 changed files with 39 additions and 0 deletions

View File

@ -2008,6 +2008,42 @@ TEST_F(ResolverConstEvalTest, ShortCircuit_Or_Error_StructInit) {
"expected 'f32', found 'bool'");
}
TEST_F(ResolverConstEvalTest, ShortCircuit_And_Error_ArrayInit) {
// const one = 1;
// const result = (one == 0) && array(4) == 0;
GlobalConst("one", Expr(1_a));
auto* lhs = Equal("one", 0_a);
auto* rhs = Equal(Call("array", Expr(4_a)), 0_a);
GlobalConst("result", LogicalAnd(lhs, rhs));
EXPECT_FALSE(r()->Resolve());
EXPECT_EQ(r()->error(),
R"(error: no matching overload for operator == (array<abstract-int, 1>, abstract-int)
2 candidate operators:
operator == (T, T) -> bool where: T is abstract-int, abstract-float, f32, f16, i32, u32 or bool
operator == (vecN<T>, vecN<T>) -> vecN<bool> where: T is abstract-int, abstract-float, f32, f16, i32, u32 or bool
)");
}
TEST_F(ResolverConstEvalTest, ShortCircuit_Or_Error_ArrayInit) {
// const one = 1;
// const result = (one == 1) || array(4) == 0;
GlobalConst("one", Expr(1_a));
auto* lhs = Equal("one", 1_a);
auto* rhs = Equal(Call("array", Expr(4_a)), 0_a);
GlobalConst("result", LogicalOr(lhs, rhs));
EXPECT_FALSE(r()->Resolve());
EXPECT_EQ(r()->error(),
R"(error: no matching overload for operator == (array<abstract-int, 1>, abstract-int)
2 candidate operators:
operator == (T, T) -> bool where: T is abstract-int, abstract-float, f32, f16, i32, u32 or bool
operator == (vecN<T>, vecN<T>) -> vecN<bool> where: T is abstract-int, abstract-float, f32, f16, i32, u32 or bool
)");
}
////////////////////////////////////////////////
// Short-Circuit Builtin Call
////////////////////////////////////////////////

View File

@ -2012,6 +2012,9 @@ sem::Call* Resolver::Call(const ast::CallExpression* expr) {
auto stage = args_stage; // The evaluation stage of the call
const constant::Value* value = nullptr; // The constant value for the call
if (stage == sem::EvaluationStage::kConstant && skip_const_eval_.Contains(expr)) {
stage = sem::EvaluationStage::kNotEvaluated;
}
if (stage == sem::EvaluationStage::kConstant) {
auto els = utils::Transform(args, [&](auto* arg) { return arg->ConstantValue(); });
if (auto r = const_eval_.ArrayOrStructCtor(ty, std::move(els))) {