ProgramBuilder: Don't wrap call-exprs with a call-stmts
ast::CallExpression will soon encompase function & intrinsic calls, along with type-constructors and type-casts. The latter two cannot be wrapped with a CallStatement, so change ProgramBuilder::WrapInStatement() to always assign the expression to a temporary. Fix the few places that actually relied on this behavior to use CallStmt() explicitly. Bug: tint:888 Change-Id: I48b8a2be73128df9cd2b4bdcc00ae81c4a872359 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/69104 Kokoro: Kokoro <noreply+kokoro@google.com> Commit-Queue: Ben Clayton <bclayton@google.com> Reviewed-by: James Price <jrprice@google.com>
This commit is contained in:
parent
a539d8d33c
commit
9de93ca105
|
@ -116,9 +116,6 @@ ProgramBuilder::TypesBuilder::TypesBuilder(ProgramBuilder* pb) : builder(pb) {}
|
|||
|
||||
const ast::Statement* ProgramBuilder::WrapInStatement(
|
||||
const ast::Expression* expr) {
|
||||
if (auto* ce = expr->As<ast::CallExpression>()) {
|
||||
return CallStmt(ce);
|
||||
}
|
||||
// Create a temporary variable of inferred type from expr.
|
||||
return Decl(Const(symbols_.New(), nullptr, expr));
|
||||
}
|
||||
|
|
|
@ -913,8 +913,8 @@ TEST_F(ResolverTest, Function_CallSites) {
|
|||
auto* call_2 = Call("foo");
|
||||
auto* bar = Func("bar", ast::VariableList{}, ty.void_(),
|
||||
{
|
||||
WrapInStatement(call_1),
|
||||
WrapInStatement(call_2),
|
||||
CallStmt(call_1),
|
||||
CallStmt(call_2),
|
||||
});
|
||||
|
||||
EXPECT_TRUE(r()->Resolve()) << r()->error();
|
||||
|
|
|
@ -264,7 +264,7 @@ TEST_F(GlslGeneratorImplTest_Intrinsic, Intrinsic_Call) {
|
|||
Global("param1", ty.vec3<f32>(), ast::StorageClass::kPrivate);
|
||||
Global("param2", ty.vec3<f32>(), ast::StorageClass::kPrivate);
|
||||
|
||||
WrapInFunction(call);
|
||||
WrapInFunction(CallStmt(call));
|
||||
|
||||
GeneratorImpl& gen = Build();
|
||||
|
||||
|
@ -276,7 +276,7 @@ TEST_F(GlslGeneratorImplTest_Intrinsic, Intrinsic_Call) {
|
|||
|
||||
TEST_F(GlslGeneratorImplTest_Intrinsic, Select_Scalar) {
|
||||
auto* call = Call("select", 1.0f, 2.0f, true);
|
||||
WrapInFunction(call);
|
||||
WrapInFunction(CallStmt(call));
|
||||
GeneratorImpl& gen = Build();
|
||||
|
||||
gen.increment_indent();
|
||||
|
@ -288,7 +288,7 @@ TEST_F(GlslGeneratorImplTest_Intrinsic, Select_Scalar) {
|
|||
TEST_F(GlslGeneratorImplTest_Intrinsic, Select_Vector) {
|
||||
auto* call =
|
||||
Call("select", vec2<i32>(1, 2), vec2<i32>(3, 4), vec2<bool>(true, false));
|
||||
WrapInFunction(call);
|
||||
WrapInFunction(CallStmt(call));
|
||||
GeneratorImpl& gen = Build();
|
||||
|
||||
gen.increment_indent();
|
||||
|
@ -385,7 +385,7 @@ TEST_F(GlslGeneratorImplTest_Intrinsic, IsNormal_Vector) {
|
|||
TEST_F(GlslGeneratorImplTest_Intrinsic, Pack4x8Snorm) {
|
||||
auto* call = Call("pack4x8snorm", "p1");
|
||||
Global("p1", ty.vec4<f32>(), ast::StorageClass::kPrivate);
|
||||
WrapInFunction(call);
|
||||
WrapInFunction(CallStmt(call));
|
||||
GeneratorImpl& gen = Build();
|
||||
|
||||
gen.increment_indent();
|
||||
|
@ -400,7 +400,7 @@ TEST_F(GlslGeneratorImplTest_Intrinsic, Pack4x8Snorm) {
|
|||
TEST_F(GlslGeneratorImplTest_Intrinsic, Pack4x8Unorm) {
|
||||
auto* call = Call("pack4x8unorm", "p1");
|
||||
Global("p1", ty.vec4<f32>(), ast::StorageClass::kPrivate);
|
||||
WrapInFunction(call);
|
||||
WrapInFunction(CallStmt(call));
|
||||
GeneratorImpl& gen = Build();
|
||||
|
||||
gen.increment_indent();
|
||||
|
@ -415,7 +415,7 @@ TEST_F(GlslGeneratorImplTest_Intrinsic, Pack4x8Unorm) {
|
|||
TEST_F(GlslGeneratorImplTest_Intrinsic, Pack2x16Snorm) {
|
||||
auto* call = Call("pack2x16snorm", "p1");
|
||||
Global("p1", ty.vec2<f32>(), ast::StorageClass::kPrivate);
|
||||
WrapInFunction(call);
|
||||
WrapInFunction(CallStmt(call));
|
||||
GeneratorImpl& gen = Build();
|
||||
|
||||
gen.increment_indent();
|
||||
|
@ -429,7 +429,7 @@ TEST_F(GlslGeneratorImplTest_Intrinsic, Pack2x16Snorm) {
|
|||
TEST_F(GlslGeneratorImplTest_Intrinsic, Pack2x16Unorm) {
|
||||
auto* call = Call("pack2x16unorm", "p1");
|
||||
Global("p1", ty.vec2<f32>(), ast::StorageClass::kPrivate);
|
||||
WrapInFunction(call);
|
||||
WrapInFunction(CallStmt(call));
|
||||
GeneratorImpl& gen = Build();
|
||||
|
||||
gen.increment_indent();
|
||||
|
@ -443,7 +443,7 @@ TEST_F(GlslGeneratorImplTest_Intrinsic, Pack2x16Unorm) {
|
|||
TEST_F(GlslGeneratorImplTest_Intrinsic, Pack2x16Float) {
|
||||
auto* call = Call("pack2x16float", "p1");
|
||||
Global("p1", ty.vec2<f32>(), ast::StorageClass::kPrivate);
|
||||
WrapInFunction(call);
|
||||
WrapInFunction(CallStmt(call));
|
||||
GeneratorImpl& gen = Build();
|
||||
|
||||
gen.increment_indent();
|
||||
|
@ -456,7 +456,7 @@ TEST_F(GlslGeneratorImplTest_Intrinsic, Pack2x16Float) {
|
|||
TEST_F(GlslGeneratorImplTest_Intrinsic, Unpack4x8Snorm) {
|
||||
auto* call = Call("unpack4x8snorm", "p1");
|
||||
Global("p1", ty.u32(), ast::StorageClass::kPrivate);
|
||||
WrapInFunction(call);
|
||||
WrapInFunction(CallStmt(call));
|
||||
GeneratorImpl& gen = Build();
|
||||
|
||||
gen.increment_indent();
|
||||
|
@ -473,7 +473,7 @@ TEST_F(GlslGeneratorImplTest_Intrinsic, Unpack4x8Snorm) {
|
|||
TEST_F(GlslGeneratorImplTest_Intrinsic, Unpack4x8Unorm) {
|
||||
auto* call = Call("unpack4x8unorm", "p1");
|
||||
Global("p1", ty.u32(), ast::StorageClass::kPrivate);
|
||||
WrapInFunction(call);
|
||||
WrapInFunction(CallStmt(call));
|
||||
GeneratorImpl& gen = Build();
|
||||
|
||||
gen.increment_indent();
|
||||
|
@ -490,7 +490,7 @@ TEST_F(GlslGeneratorImplTest_Intrinsic, Unpack4x8Unorm) {
|
|||
TEST_F(GlslGeneratorImplTest_Intrinsic, Unpack2x16Snorm) {
|
||||
auto* call = Call("unpack2x16snorm", "p1");
|
||||
Global("p1", ty.u32(), ast::StorageClass::kPrivate);
|
||||
WrapInFunction(call);
|
||||
WrapInFunction(CallStmt(call));
|
||||
GeneratorImpl& gen = Build();
|
||||
|
||||
gen.increment_indent();
|
||||
|
@ -507,7 +507,7 @@ TEST_F(GlslGeneratorImplTest_Intrinsic, Unpack2x16Snorm) {
|
|||
TEST_F(GlslGeneratorImplTest_Intrinsic, Unpack2x16Unorm) {
|
||||
auto* call = Call("unpack2x16unorm", "p1");
|
||||
Global("p1", ty.u32(), ast::StorageClass::kPrivate);
|
||||
WrapInFunction(call);
|
||||
WrapInFunction(CallStmt(call));
|
||||
GeneratorImpl& gen = Build();
|
||||
|
||||
gen.increment_indent();
|
||||
|
@ -523,7 +523,7 @@ TEST_F(GlslGeneratorImplTest_Intrinsic, Unpack2x16Unorm) {
|
|||
TEST_F(GlslGeneratorImplTest_Intrinsic, Unpack2x16Float) {
|
||||
auto* call = Call("unpack2x16float", "p1");
|
||||
Global("p1", ty.u32(), ast::StorageClass::kPrivate);
|
||||
WrapInFunction(call);
|
||||
WrapInFunction(CallStmt(call));
|
||||
GeneratorImpl& gen = Build();
|
||||
|
||||
gen.increment_indent();
|
||||
|
@ -601,7 +601,7 @@ void main() {
|
|||
|
||||
TEST_F(GlslGeneratorImplTest_Intrinsic, DotI32) {
|
||||
Global("v", ty.vec3<i32>(), ast::StorageClass::kPrivate);
|
||||
WrapInFunction(Call("dot", "v", "v"));
|
||||
WrapInFunction(CallStmt(Call("dot", "v", "v")));
|
||||
|
||||
GeneratorImpl& gen = SanitizeAndBuild();
|
||||
|
||||
|
@ -630,7 +630,7 @@ void main() {
|
|||
|
||||
TEST_F(GlslGeneratorImplTest_Intrinsic, DotU32) {
|
||||
Global("v", ty.vec3<u32>(), ast::StorageClass::kPrivate);
|
||||
WrapInFunction(Call("dot", "v", "v"));
|
||||
WrapInFunction(CallStmt(Call("dot", "v", "v")));
|
||||
|
||||
GeneratorImpl& gen = SanitizeAndBuild();
|
||||
|
||||
|
|
|
@ -264,7 +264,7 @@ TEST_F(HlslGeneratorImplTest_Intrinsic, Intrinsic_Call) {
|
|||
Global("param1", ty.vec3<f32>(), ast::StorageClass::kPrivate);
|
||||
Global("param2", ty.vec3<f32>(), ast::StorageClass::kPrivate);
|
||||
|
||||
WrapInFunction(call);
|
||||
WrapInFunction(CallStmt(call));
|
||||
|
||||
GeneratorImpl& gen = Build();
|
||||
|
||||
|
@ -276,7 +276,7 @@ TEST_F(HlslGeneratorImplTest_Intrinsic, Intrinsic_Call) {
|
|||
|
||||
TEST_F(HlslGeneratorImplTest_Intrinsic, Select_Scalar) {
|
||||
auto* call = Call("select", 1.0f, 2.0f, true);
|
||||
WrapInFunction(call);
|
||||
WrapInFunction(CallStmt(call));
|
||||
GeneratorImpl& gen = Build();
|
||||
|
||||
gen.increment_indent();
|
||||
|
@ -288,7 +288,7 @@ TEST_F(HlslGeneratorImplTest_Intrinsic, Select_Scalar) {
|
|||
TEST_F(HlslGeneratorImplTest_Intrinsic, Select_Vector) {
|
||||
auto* call =
|
||||
Call("select", vec2<i32>(1, 2), vec2<i32>(3, 4), vec2<bool>(true, false));
|
||||
WrapInFunction(call);
|
||||
WrapInFunction(CallStmt(call));
|
||||
GeneratorImpl& gen = Build();
|
||||
|
||||
gen.increment_indent();
|
||||
|
@ -299,7 +299,7 @@ TEST_F(HlslGeneratorImplTest_Intrinsic, Select_Vector) {
|
|||
|
||||
TEST_F(HlslGeneratorImplTest_Intrinsic, Modf_Scalar) {
|
||||
auto* call = Call("modf", 1.0f);
|
||||
WrapInFunction(call);
|
||||
WrapInFunction(CallStmt(call));
|
||||
|
||||
GeneratorImpl& gen = SanitizeAndBuild();
|
||||
|
||||
|
@ -325,7 +325,7 @@ void test_function() {
|
|||
|
||||
TEST_F(HlslGeneratorImplTest_Intrinsic, Modf_Vector) {
|
||||
auto* call = Call("modf", vec3<f32>());
|
||||
WrapInFunction(call);
|
||||
WrapInFunction(CallStmt(call));
|
||||
|
||||
GeneratorImpl& gen = SanitizeAndBuild();
|
||||
|
||||
|
@ -351,7 +351,7 @@ void test_function() {
|
|||
|
||||
TEST_F(HlslGeneratorImplTest_Intrinsic, Frexp_Scalar_i32) {
|
||||
auto* call = Call("frexp", 1.0f);
|
||||
WrapInFunction(call);
|
||||
WrapInFunction(CallStmt(call));
|
||||
|
||||
GeneratorImpl& gen = SanitizeAndBuild();
|
||||
|
||||
|
@ -377,7 +377,7 @@ void test_function() {
|
|||
|
||||
TEST_F(HlslGeneratorImplTest_Intrinsic, Frexp_Vector_i32) {
|
||||
auto* call = Call("frexp", vec3<f32>());
|
||||
WrapInFunction(call);
|
||||
WrapInFunction(CallStmt(call));
|
||||
|
||||
GeneratorImpl& gen = SanitizeAndBuild();
|
||||
|
||||
|
@ -418,7 +418,7 @@ TEST_F(HlslGeneratorImplTest_Intrinsic, IsNormal_Scalar) {
|
|||
[numthreads(1, 1, 1)]
|
||||
void test_function() {
|
||||
float val = 0.0f;
|
||||
tint_isNormal(val);
|
||||
const bool tint_symbol = tint_isNormal(val);
|
||||
return;
|
||||
}
|
||||
)");
|
||||
|
@ -441,7 +441,7 @@ TEST_F(HlslGeneratorImplTest_Intrinsic, IsNormal_Vector) {
|
|||
[numthreads(1, 1, 1)]
|
||||
void test_function() {
|
||||
float3 val = float3(0.0f, 0.0f, 0.0f);
|
||||
tint_isNormal(val);
|
||||
const bool3 tint_symbol = tint_isNormal(val);
|
||||
return;
|
||||
}
|
||||
)");
|
||||
|
@ -450,7 +450,7 @@ void test_function() {
|
|||
TEST_F(HlslGeneratorImplTest_Intrinsic, Pack4x8Snorm) {
|
||||
auto* call = Call("pack4x8snorm", "p1");
|
||||
Global("p1", ty.vec4<f32>(), ast::StorageClass::kPrivate);
|
||||
WrapInFunction(call);
|
||||
WrapInFunction(CallStmt(call));
|
||||
GeneratorImpl& gen = Build();
|
||||
|
||||
ASSERT_TRUE(gen.Generate()) << gen.error();
|
||||
|
@ -472,7 +472,7 @@ void test_function() {
|
|||
TEST_F(HlslGeneratorImplTest_Intrinsic, Pack4x8Unorm) {
|
||||
auto* call = Call("pack4x8unorm", "p1");
|
||||
Global("p1", ty.vec4<f32>(), ast::StorageClass::kPrivate);
|
||||
WrapInFunction(call);
|
||||
WrapInFunction(CallStmt(call));
|
||||
GeneratorImpl& gen = Build();
|
||||
|
||||
ASSERT_TRUE(gen.Generate()) << gen.error();
|
||||
|
@ -494,7 +494,7 @@ void test_function() {
|
|||
TEST_F(HlslGeneratorImplTest_Intrinsic, Pack2x16Snorm) {
|
||||
auto* call = Call("pack2x16snorm", "p1");
|
||||
Global("p1", ty.vec2<f32>(), ast::StorageClass::kPrivate);
|
||||
WrapInFunction(call);
|
||||
WrapInFunction(CallStmt(call));
|
||||
GeneratorImpl& gen = Build();
|
||||
|
||||
ASSERT_TRUE(gen.Generate()) << gen.error();
|
||||
|
@ -516,7 +516,7 @@ void test_function() {
|
|||
TEST_F(HlslGeneratorImplTest_Intrinsic, Pack2x16Unorm) {
|
||||
auto* call = Call("pack2x16unorm", "p1");
|
||||
Global("p1", ty.vec2<f32>(), ast::StorageClass::kPrivate);
|
||||
WrapInFunction(call);
|
||||
WrapInFunction(CallStmt(call));
|
||||
GeneratorImpl& gen = Build();
|
||||
|
||||
ASSERT_TRUE(gen.Generate()) << gen.error();
|
||||
|
@ -538,7 +538,7 @@ void test_function() {
|
|||
TEST_F(HlslGeneratorImplTest_Intrinsic, Pack2x16Float) {
|
||||
auto* call = Call("pack2x16float", "p1");
|
||||
Global("p1", ty.vec2<f32>(), ast::StorageClass::kPrivate);
|
||||
WrapInFunction(call);
|
||||
WrapInFunction(CallStmt(call));
|
||||
GeneratorImpl& gen = Build();
|
||||
|
||||
ASSERT_TRUE(gen.Generate()) << gen.error();
|
||||
|
@ -560,7 +560,7 @@ void test_function() {
|
|||
TEST_F(HlslGeneratorImplTest_Intrinsic, Unpack4x8Snorm) {
|
||||
auto* call = Call("unpack4x8snorm", "p1");
|
||||
Global("p1", ty.u32(), ast::StorageClass::kPrivate);
|
||||
WrapInFunction(call);
|
||||
WrapInFunction(CallStmt(call));
|
||||
GeneratorImpl& gen = Build();
|
||||
|
||||
ASSERT_TRUE(gen.Generate()) << gen.error();
|
||||
|
@ -583,7 +583,7 @@ void test_function() {
|
|||
TEST_F(HlslGeneratorImplTest_Intrinsic, Unpack4x8Unorm) {
|
||||
auto* call = Call("unpack4x8unorm", "p1");
|
||||
Global("p1", ty.u32(), ast::StorageClass::kPrivate);
|
||||
WrapInFunction(call);
|
||||
WrapInFunction(CallStmt(call));
|
||||
GeneratorImpl& gen = Build();
|
||||
|
||||
ASSERT_TRUE(gen.Generate()) << gen.error();
|
||||
|
@ -606,7 +606,7 @@ void test_function() {
|
|||
TEST_F(HlslGeneratorImplTest_Intrinsic, Unpack2x16Snorm) {
|
||||
auto* call = Call("unpack2x16snorm", "p1");
|
||||
Global("p1", ty.u32(), ast::StorageClass::kPrivate);
|
||||
WrapInFunction(call);
|
||||
WrapInFunction(CallStmt(call));
|
||||
GeneratorImpl& gen = Build();
|
||||
|
||||
ASSERT_TRUE(gen.Generate()) << gen.error();
|
||||
|
@ -629,7 +629,7 @@ void test_function() {
|
|||
TEST_F(HlslGeneratorImplTest_Intrinsic, Unpack2x16Unorm) {
|
||||
auto* call = Call("unpack2x16unorm", "p1");
|
||||
Global("p1", ty.u32(), ast::StorageClass::kPrivate);
|
||||
WrapInFunction(call);
|
||||
WrapInFunction(CallStmt(call));
|
||||
GeneratorImpl& gen = Build();
|
||||
|
||||
ASSERT_TRUE(gen.Generate()) << gen.error();
|
||||
|
@ -652,7 +652,7 @@ void test_function() {
|
|||
TEST_F(HlslGeneratorImplTest_Intrinsic, Unpack2x16Float) {
|
||||
auto* call = Call("unpack2x16float", "p1");
|
||||
Global("p1", ty.u32(), ast::StorageClass::kPrivate);
|
||||
WrapInFunction(call);
|
||||
WrapInFunction(CallStmt(call));
|
||||
GeneratorImpl& gen = Build();
|
||||
|
||||
ASSERT_TRUE(gen.Generate()) << gen.error();
|
||||
|
|
|
@ -288,7 +288,7 @@ TEST_F(MslGeneratorImplTest, Intrinsic_Call) {
|
|||
Global("param2", ty.vec2<f32>(), ast::StorageClass::kPrivate);
|
||||
|
||||
auto* call = Call("dot", "param1", "param2");
|
||||
WrapInFunction(call);
|
||||
WrapInFunction(CallStmt(call));
|
||||
|
||||
GeneratorImpl& gen = Build();
|
||||
|
||||
|
@ -322,7 +322,7 @@ TEST_F(MslGeneratorImplTest, WorkgroupBarrier) {
|
|||
TEST_F(MslGeneratorImplTest, Pack2x16Float) {
|
||||
auto* call = Call("pack2x16float", "p1");
|
||||
Global("p1", ty.vec2<f32>(), ast::StorageClass::kPrivate);
|
||||
WrapInFunction(call);
|
||||
WrapInFunction(CallStmt(call));
|
||||
|
||||
GeneratorImpl& gen = Build();
|
||||
|
||||
|
@ -334,7 +334,7 @@ TEST_F(MslGeneratorImplTest, Pack2x16Float) {
|
|||
TEST_F(MslGeneratorImplTest, Unpack2x16Float) {
|
||||
auto* call = Call("unpack2x16float", "p1");
|
||||
Global("p1", ty.u32(), ast::StorageClass::kPrivate);
|
||||
WrapInFunction(call);
|
||||
WrapInFunction(CallStmt(call));
|
||||
|
||||
GeneratorImpl& gen = Build();
|
||||
|
||||
|
@ -345,7 +345,7 @@ TEST_F(MslGeneratorImplTest, Unpack2x16Float) {
|
|||
|
||||
TEST_F(MslGeneratorImplTest, DotI32) {
|
||||
Global("v", ty.vec3<i32>(), ast::StorageClass::kPrivate);
|
||||
WrapInFunction(Call("dot", "v", "v"));
|
||||
WrapInFunction(CallStmt(Call("dot", "v", "v")));
|
||||
|
||||
GeneratorImpl& gen = SanitizeAndBuild();
|
||||
|
||||
|
|
Loading…
Reference in New Issue