2020-09-29 18:40:40 +00:00
|
|
|
// Copyright 2020 The Tint Authors.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
2021-06-30 13:23:36 +00:00
|
|
|
#include "src/transform/robustness.h"
|
2020-09-29 18:40:40 +00:00
|
|
|
|
2021-01-06 12:57:41 +00:00
|
|
|
#include "src/transform/test_helper.h"
|
2020-09-29 18:40:40 +00:00
|
|
|
|
|
|
|
namespace tint {
|
|
|
|
namespace transform {
|
|
|
|
namespace {
|
|
|
|
|
2021-06-30 13:23:36 +00:00
|
|
|
using RobustnessTest = TransformTest;
|
2020-09-29 18:40:40 +00:00
|
|
|
|
2021-06-30 13:23:36 +00:00
|
|
|
TEST_F(RobustnessTest, Ptrs_Clamp) {
|
2021-01-06 12:57:41 +00:00
|
|
|
auto* src = R"(
|
2021-04-16 09:26:14 +00:00
|
|
|
var<private> a : array<f32, 3>;
|
2021-02-10 15:34:37 +00:00
|
|
|
|
2021-04-08 15:46:17 +00:00
|
|
|
let c : u32 = 1u;
|
2021-01-06 12:57:41 +00:00
|
|
|
|
2021-04-08 14:39:47 +00:00
|
|
|
fn f() {
|
2021-05-18 10:28:48 +00:00
|
|
|
let b : f32 = a[c];
|
2021-01-06 12:57:41 +00:00
|
|
|
}
|
|
|
|
)";
|
2020-09-29 18:40:40 +00:00
|
|
|
|
2021-01-06 12:57:41 +00:00
|
|
|
auto* expect = R"(
|
2021-04-16 09:26:14 +00:00
|
|
|
var<private> a : array<f32, 3>;
|
2021-02-10 15:34:37 +00:00
|
|
|
|
2021-04-08 15:46:17 +00:00
|
|
|
let c : u32 = 1u;
|
2020-09-29 18:40:40 +00:00
|
|
|
|
2021-04-08 14:39:47 +00:00
|
|
|
fn f() {
|
2021-05-18 10:28:48 +00:00
|
|
|
let b : f32 = a[min(u32(c), 2u)];
|
2021-01-06 12:57:41 +00:00
|
|
|
}
|
|
|
|
)";
|
2020-09-29 18:40:40 +00:00
|
|
|
|
2021-06-30 13:23:36 +00:00
|
|
|
auto got = Run<Robustness>(src);
|
2020-09-29 18:40:40 +00:00
|
|
|
|
2021-02-24 15:55:24 +00:00
|
|
|
EXPECT_EQ(expect, str(got));
|
2021-01-06 12:57:41 +00:00
|
|
|
}
|
2020-09-29 18:40:40 +00:00
|
|
|
|
2021-06-30 13:23:36 +00:00
|
|
|
TEST_F(RobustnessTest, Array_Idx_Nested_Scalar) {
|
2021-01-06 12:57:41 +00:00
|
|
|
auto* src = R"(
|
2021-04-16 09:26:14 +00:00
|
|
|
var<private> a : array<f32, 3>;
|
2021-02-10 15:34:37 +00:00
|
|
|
|
2021-06-16 18:50:13 +00:00
|
|
|
var<private> b : array<i32, 5>;
|
2021-02-10 15:34:37 +00:00
|
|
|
|
2021-04-16 09:26:14 +00:00
|
|
|
var<private> i : u32;
|
2020-10-29 17:56:06 +00:00
|
|
|
|
2021-04-08 14:39:47 +00:00
|
|
|
fn f() {
|
2021-01-06 12:57:41 +00:00
|
|
|
var c : f32 = a[ b[i] ];
|
|
|
|
}
|
|
|
|
)";
|
2020-09-29 18:40:40 +00:00
|
|
|
|
2021-01-06 12:57:41 +00:00
|
|
|
auto* expect = R"(
|
2021-04-16 09:26:14 +00:00
|
|
|
var<private> a : array<f32, 3>;
|
2021-02-10 15:34:37 +00:00
|
|
|
|
2021-06-16 18:50:13 +00:00
|
|
|
var<private> b : array<i32, 5>;
|
2021-02-10 15:34:37 +00:00
|
|
|
|
2021-04-16 09:26:14 +00:00
|
|
|
var<private> i : u32;
|
2020-09-29 18:40:40 +00:00
|
|
|
|
2021-04-08 14:39:47 +00:00
|
|
|
fn f() {
|
2021-01-06 12:57:41 +00:00
|
|
|
var c : f32 = a[min(u32(b[min(u32(i), 4u)]), 2u)];
|
2020-09-29 18:40:40 +00:00
|
|
|
}
|
2021-01-06 12:57:41 +00:00
|
|
|
)";
|
2020-09-29 18:40:40 +00:00
|
|
|
|
2021-06-30 13:23:36 +00:00
|
|
|
auto got = Run<Robustness>(src);
|
2021-01-06 12:57:41 +00:00
|
|
|
|
2021-02-24 15:55:24 +00:00
|
|
|
EXPECT_EQ(expect, str(got));
|
2020-09-29 18:40:40 +00:00
|
|
|
}
|
|
|
|
|
2021-06-30 13:23:36 +00:00
|
|
|
TEST_F(RobustnessTest, Array_Idx_Scalar) {
|
2021-01-06 12:57:41 +00:00
|
|
|
auto* src = R"(
|
2021-04-16 09:26:14 +00:00
|
|
|
var<private> a : array<f32, 3>;
|
2020-09-29 18:40:40 +00:00
|
|
|
|
2021-04-08 14:39:47 +00:00
|
|
|
fn f() {
|
2021-01-06 12:57:41 +00:00
|
|
|
var b : f32 = a[1];
|
|
|
|
}
|
|
|
|
)";
|
2020-09-29 18:40:40 +00:00
|
|
|
|
2021-01-06 12:57:41 +00:00
|
|
|
auto* expect = R"(
|
2021-04-16 09:26:14 +00:00
|
|
|
var<private> a : array<f32, 3>;
|
2020-09-29 18:40:40 +00:00
|
|
|
|
2021-04-08 14:39:47 +00:00
|
|
|
fn f() {
|
2021-01-06 12:57:41 +00:00
|
|
|
var b : f32 = a[1];
|
|
|
|
}
|
|
|
|
)";
|
2020-09-29 18:40:40 +00:00
|
|
|
|
2021-06-30 13:23:36 +00:00
|
|
|
auto got = Run<Robustness>(src);
|
2020-09-29 18:40:40 +00:00
|
|
|
|
2021-02-24 15:55:24 +00:00
|
|
|
EXPECT_EQ(expect, str(got));
|
2020-09-29 18:40:40 +00:00
|
|
|
}
|
|
|
|
|
2021-06-30 13:23:36 +00:00
|
|
|
TEST_F(RobustnessTest, Array_Idx_Expr) {
|
2021-01-06 12:57:41 +00:00
|
|
|
auto* src = R"(
|
2021-04-16 09:26:14 +00:00
|
|
|
var<private> a : array<f32, 3>;
|
2021-02-10 15:34:37 +00:00
|
|
|
|
2021-04-16 09:26:14 +00:00
|
|
|
var<private> c : i32;
|
2021-01-06 12:57:41 +00:00
|
|
|
|
2021-04-08 14:39:47 +00:00
|
|
|
fn f() {
|
2021-01-06 12:57:41 +00:00
|
|
|
var b : f32 = a[c + 2 - 3];
|
|
|
|
}
|
|
|
|
)";
|
|
|
|
|
|
|
|
auto* expect = R"(
|
2021-04-16 09:26:14 +00:00
|
|
|
var<private> a : array<f32, 3>;
|
2021-02-10 15:34:37 +00:00
|
|
|
|
2021-04-16 09:26:14 +00:00
|
|
|
var<private> c : i32;
|
2021-01-06 12:57:41 +00:00
|
|
|
|
2021-04-08 14:39:47 +00:00
|
|
|
fn f() {
|
2021-01-06 12:57:41 +00:00
|
|
|
var b : f32 = a[min(u32(((c + 2) - 3)), 2u)];
|
|
|
|
}
|
|
|
|
)";
|
|
|
|
|
2021-06-30 13:23:36 +00:00
|
|
|
auto got = Run<Robustness>(src);
|
2021-01-06 12:57:41 +00:00
|
|
|
|
2021-02-24 15:55:24 +00:00
|
|
|
EXPECT_EQ(expect, str(got));
|
2020-09-29 18:40:40 +00:00
|
|
|
}
|
|
|
|
|
2021-06-30 13:23:36 +00:00
|
|
|
TEST_F(RobustnessTest, Array_Idx_Negative) {
|
2021-01-06 12:57:41 +00:00
|
|
|
auto* src = R"(
|
2021-04-16 09:26:14 +00:00
|
|
|
var<private> a : array<f32, 3>;
|
2020-09-29 18:40:40 +00:00
|
|
|
|
2021-04-08 14:39:47 +00:00
|
|
|
fn f() {
|
2021-01-06 12:57:41 +00:00
|
|
|
var b : f32 = a[-1];
|
|
|
|
}
|
|
|
|
)";
|
2020-09-29 18:40:40 +00:00
|
|
|
|
2021-01-06 12:57:41 +00:00
|
|
|
auto* expect = R"(
|
2021-04-16 09:26:14 +00:00
|
|
|
var<private> a : array<f32, 3>;
|
2020-09-29 18:40:40 +00:00
|
|
|
|
2021-04-08 14:39:47 +00:00
|
|
|
fn f() {
|
2021-01-06 12:57:41 +00:00
|
|
|
var b : f32 = a[0];
|
|
|
|
}
|
|
|
|
)";
|
2020-09-29 18:40:40 +00:00
|
|
|
|
2021-06-30 13:23:36 +00:00
|
|
|
auto got = Run<Robustness>(src);
|
2020-09-29 18:40:40 +00:00
|
|
|
|
2021-02-24 15:55:24 +00:00
|
|
|
EXPECT_EQ(expect, str(got));
|
2020-09-29 18:40:40 +00:00
|
|
|
}
|
|
|
|
|
2021-06-30 13:23:36 +00:00
|
|
|
TEST_F(RobustnessTest, Array_Idx_OutOfBounds) {
|
2021-01-06 12:57:41 +00:00
|
|
|
auto* src = R"(
|
2021-04-16 09:26:14 +00:00
|
|
|
var<private> a : array<f32, 3>;
|
2020-09-29 18:40:40 +00:00
|
|
|
|
2021-04-08 14:39:47 +00:00
|
|
|
fn f() {
|
2021-01-06 12:57:41 +00:00
|
|
|
var b : f32 = a[3];
|
|
|
|
}
|
|
|
|
)";
|
2020-09-29 18:40:40 +00:00
|
|
|
|
2021-01-06 12:57:41 +00:00
|
|
|
auto* expect = R"(
|
2021-04-16 09:26:14 +00:00
|
|
|
var<private> a : array<f32, 3>;
|
2020-09-29 18:40:40 +00:00
|
|
|
|
2021-04-08 14:39:47 +00:00
|
|
|
fn f() {
|
2021-01-06 12:57:41 +00:00
|
|
|
var b : f32 = a[2];
|
|
|
|
}
|
|
|
|
)";
|
2020-09-29 18:40:40 +00:00
|
|
|
|
2021-06-30 13:23:36 +00:00
|
|
|
auto got = Run<Robustness>(src);
|
2020-09-29 18:40:40 +00:00
|
|
|
|
2021-02-24 15:55:24 +00:00
|
|
|
EXPECT_EQ(expect, str(got));
|
2020-09-29 18:40:40 +00:00
|
|
|
}
|
|
|
|
|
2021-06-30 13:23:36 +00:00
|
|
|
TEST_F(RobustnessTest, Vector_Idx_Scalar) {
|
2021-01-06 12:57:41 +00:00
|
|
|
auto* src = R"(
|
2021-04-16 09:26:14 +00:00
|
|
|
var<private> a : vec3<f32>;
|
2020-09-29 18:40:40 +00:00
|
|
|
|
2021-04-08 14:39:47 +00:00
|
|
|
fn f() {
|
2021-01-06 12:57:41 +00:00
|
|
|
var b : f32 = a[1];
|
|
|
|
}
|
|
|
|
)";
|
2020-09-29 18:40:40 +00:00
|
|
|
|
2021-01-06 12:57:41 +00:00
|
|
|
auto* expect = R"(
|
2021-04-16 09:26:14 +00:00
|
|
|
var<private> a : vec3<f32>;
|
2020-09-29 18:40:40 +00:00
|
|
|
|
2021-04-08 14:39:47 +00:00
|
|
|
fn f() {
|
2021-01-06 12:57:41 +00:00
|
|
|
var b : f32 = a[1];
|
|
|
|
}
|
|
|
|
)";
|
2020-09-29 18:40:40 +00:00
|
|
|
|
2021-06-30 13:23:36 +00:00
|
|
|
auto got = Run<Robustness>(src);
|
2020-09-29 18:40:40 +00:00
|
|
|
|
2021-02-24 15:55:24 +00:00
|
|
|
EXPECT_EQ(expect, str(got));
|
2020-09-29 18:40:40 +00:00
|
|
|
}
|
|
|
|
|
2021-06-30 13:23:36 +00:00
|
|
|
TEST_F(RobustnessTest, Vector_Idx_Expr) {
|
2021-01-06 12:57:41 +00:00
|
|
|
auto* src = R"(
|
2021-04-16 09:26:14 +00:00
|
|
|
var<private> a : vec3<f32>;
|
2021-02-10 15:34:37 +00:00
|
|
|
|
2021-04-16 09:26:14 +00:00
|
|
|
var<private> c : i32;
|
2021-01-06 12:57:41 +00:00
|
|
|
|
2021-04-08 14:39:47 +00:00
|
|
|
fn f() {
|
2021-01-06 12:57:41 +00:00
|
|
|
var b : f32 = a[c + 2 - 3];
|
2020-09-29 18:40:40 +00:00
|
|
|
}
|
2021-01-06 12:57:41 +00:00
|
|
|
)";
|
2020-09-29 18:40:40 +00:00
|
|
|
|
2021-01-06 12:57:41 +00:00
|
|
|
auto* expect = R"(
|
2021-04-16 09:26:14 +00:00
|
|
|
var<private> a : vec3<f32>;
|
2021-02-10 15:34:37 +00:00
|
|
|
|
2021-04-16 09:26:14 +00:00
|
|
|
var<private> c : i32;
|
2020-09-29 18:40:40 +00:00
|
|
|
|
2021-04-08 14:39:47 +00:00
|
|
|
fn f() {
|
2021-01-06 12:57:41 +00:00
|
|
|
var b : f32 = a[min(u32(((c + 2) - 3)), 2u)];
|
|
|
|
}
|
|
|
|
)";
|
2020-09-29 18:40:40 +00:00
|
|
|
|
2021-06-30 13:23:36 +00:00
|
|
|
auto got = Run<Robustness>(src);
|
2020-09-29 18:40:40 +00:00
|
|
|
|
2021-02-24 15:55:24 +00:00
|
|
|
EXPECT_EQ(expect, str(got));
|
2021-01-06 12:57:41 +00:00
|
|
|
}
|
2020-09-29 18:40:40 +00:00
|
|
|
|
2021-06-30 13:23:36 +00:00
|
|
|
TEST_F(RobustnessTest, Vector_Swizzle_Idx_Scalar) {
|
2021-02-26 18:53:36 +00:00
|
|
|
auto* src = R"(
|
2021-04-16 09:26:14 +00:00
|
|
|
var<private> a : vec3<f32>;
|
2021-02-26 18:53:36 +00:00
|
|
|
|
2021-04-08 14:39:47 +00:00
|
|
|
fn f() {
|
2021-02-26 18:53:36 +00:00
|
|
|
var b : f32 = a.xy[2];
|
|
|
|
}
|
|
|
|
)";
|
|
|
|
|
|
|
|
auto* expect = R"(
|
2021-04-16 09:26:14 +00:00
|
|
|
var<private> a : vec3<f32>;
|
2021-02-26 18:53:36 +00:00
|
|
|
|
2021-04-08 14:39:47 +00:00
|
|
|
fn f() {
|
2021-02-26 18:53:36 +00:00
|
|
|
var b : f32 = a.xy[1];
|
|
|
|
}
|
|
|
|
)";
|
|
|
|
|
2021-06-30 13:23:36 +00:00
|
|
|
auto got = Run<Robustness>(src);
|
2021-02-26 18:53:36 +00:00
|
|
|
|
|
|
|
EXPECT_EQ(expect, str(got));
|
|
|
|
}
|
|
|
|
|
2021-06-30 13:23:36 +00:00
|
|
|
TEST_F(RobustnessTest, Vector_Swizzle_Idx_Var) {
|
2021-02-26 18:53:36 +00:00
|
|
|
auto* src = R"(
|
2021-04-16 09:26:14 +00:00
|
|
|
var<private> a : vec3<f32>;
|
2021-02-26 18:53:36 +00:00
|
|
|
|
2021-04-16 09:26:14 +00:00
|
|
|
var<private> c : i32;
|
2021-02-26 18:53:36 +00:00
|
|
|
|
2021-04-08 14:39:47 +00:00
|
|
|
fn f() {
|
2021-02-26 18:53:36 +00:00
|
|
|
var b : f32 = a.xy[c];
|
|
|
|
}
|
|
|
|
)";
|
|
|
|
|
|
|
|
auto* expect = R"(
|
2021-04-16 09:26:14 +00:00
|
|
|
var<private> a : vec3<f32>;
|
2021-02-26 18:53:36 +00:00
|
|
|
|
2021-04-16 09:26:14 +00:00
|
|
|
var<private> c : i32;
|
2021-02-26 18:53:36 +00:00
|
|
|
|
2021-04-08 14:39:47 +00:00
|
|
|
fn f() {
|
2021-02-26 18:53:36 +00:00
|
|
|
var b : f32 = a.xy[min(u32(c), 1u)];
|
|
|
|
}
|
|
|
|
)";
|
|
|
|
|
2021-06-30 13:23:36 +00:00
|
|
|
auto got = Run<Robustness>(src);
|
2021-02-26 18:53:36 +00:00
|
|
|
|
|
|
|
EXPECT_EQ(expect, str(got));
|
|
|
|
}
|
2021-06-30 13:23:36 +00:00
|
|
|
TEST_F(RobustnessTest, Vector_Swizzle_Idx_Expr) {
|
2021-02-26 18:53:36 +00:00
|
|
|
auto* src = R"(
|
2021-04-16 09:26:14 +00:00
|
|
|
var<private> a : vec3<f32>;
|
2021-02-26 18:53:36 +00:00
|
|
|
|
2021-04-16 09:26:14 +00:00
|
|
|
var<private> c : i32;
|
2021-02-26 18:53:36 +00:00
|
|
|
|
2021-04-08 14:39:47 +00:00
|
|
|
fn f() {
|
2021-02-26 18:53:36 +00:00
|
|
|
var b : f32 = a.xy[c + 2 - 3];
|
|
|
|
}
|
|
|
|
)";
|
|
|
|
|
|
|
|
auto* expect = R"(
|
2021-04-16 09:26:14 +00:00
|
|
|
var<private> a : vec3<f32>;
|
2021-02-26 18:53:36 +00:00
|
|
|
|
2021-04-16 09:26:14 +00:00
|
|
|
var<private> c : i32;
|
2021-02-26 18:53:36 +00:00
|
|
|
|
2021-04-08 14:39:47 +00:00
|
|
|
fn f() {
|
2021-02-26 18:53:36 +00:00
|
|
|
var b : f32 = a.xy[min(u32(((c + 2) - 3)), 1u)];
|
|
|
|
}
|
|
|
|
)";
|
|
|
|
|
2021-06-30 13:23:36 +00:00
|
|
|
auto got = Run<Robustness>(src);
|
2021-02-26 18:53:36 +00:00
|
|
|
|
|
|
|
EXPECT_EQ(expect, str(got));
|
|
|
|
}
|
|
|
|
|
2021-06-30 13:23:36 +00:00
|
|
|
TEST_F(RobustnessTest, Vector_Idx_Negative) {
|
2021-01-06 12:57:41 +00:00
|
|
|
auto* src = R"(
|
2021-04-16 09:26:14 +00:00
|
|
|
var<private> a : vec3<f32>;
|
2020-09-29 18:40:40 +00:00
|
|
|
|
2021-04-08 14:39:47 +00:00
|
|
|
fn f() {
|
2021-01-06 12:57:41 +00:00
|
|
|
var b : f32 = a[-1];
|
2020-09-29 18:40:40 +00:00
|
|
|
}
|
2021-01-06 12:57:41 +00:00
|
|
|
)";
|
2020-09-29 18:40:40 +00:00
|
|
|
|
2021-01-06 12:57:41 +00:00
|
|
|
auto* expect = R"(
|
2021-04-16 09:26:14 +00:00
|
|
|
var<private> a : vec3<f32>;
|
2020-09-29 18:40:40 +00:00
|
|
|
|
2021-04-08 14:39:47 +00:00
|
|
|
fn f() {
|
2021-01-06 12:57:41 +00:00
|
|
|
var b : f32 = a[0];
|
|
|
|
}
|
|
|
|
)";
|
2020-09-29 18:40:40 +00:00
|
|
|
|
2021-06-30 13:23:36 +00:00
|
|
|
auto got = Run<Robustness>(src);
|
2020-09-29 18:40:40 +00:00
|
|
|
|
2021-02-24 15:55:24 +00:00
|
|
|
EXPECT_EQ(expect, str(got));
|
2021-01-06 12:57:41 +00:00
|
|
|
}
|
2020-09-29 18:40:40 +00:00
|
|
|
|
2021-06-30 13:23:36 +00:00
|
|
|
TEST_F(RobustnessTest, Vector_Idx_OutOfBounds) {
|
2021-01-06 12:57:41 +00:00
|
|
|
auto* src = R"(
|
2021-04-16 09:26:14 +00:00
|
|
|
var<private> a : vec3<f32>;
|
2020-09-29 18:40:40 +00:00
|
|
|
|
2021-04-08 14:39:47 +00:00
|
|
|
fn f() {
|
2021-01-06 12:57:41 +00:00
|
|
|
var b : f32 = a[3];
|
2020-09-29 18:40:40 +00:00
|
|
|
}
|
2021-01-06 12:57:41 +00:00
|
|
|
)";
|
2020-09-29 18:40:40 +00:00
|
|
|
|
2021-01-06 12:57:41 +00:00
|
|
|
auto* expect = R"(
|
2021-04-16 09:26:14 +00:00
|
|
|
var<private> a : vec3<f32>;
|
2020-09-29 18:40:40 +00:00
|
|
|
|
2021-04-08 14:39:47 +00:00
|
|
|
fn f() {
|
2021-01-06 12:57:41 +00:00
|
|
|
var b : f32 = a[2];
|
|
|
|
}
|
|
|
|
)";
|
2020-09-29 18:40:40 +00:00
|
|
|
|
2021-06-30 13:23:36 +00:00
|
|
|
auto got = Run<Robustness>(src);
|
2020-09-29 18:40:40 +00:00
|
|
|
|
2021-02-24 15:55:24 +00:00
|
|
|
EXPECT_EQ(expect, str(got));
|
2021-01-06 12:57:41 +00:00
|
|
|
}
|
2020-09-29 18:40:40 +00:00
|
|
|
|
2021-06-30 13:23:36 +00:00
|
|
|
TEST_F(RobustnessTest, Matrix_Idx_Scalar) {
|
2021-01-06 12:57:41 +00:00
|
|
|
auto* src = R"(
|
2021-04-16 09:26:14 +00:00
|
|
|
var<private> a : mat3x2<f32>;
|
2020-09-29 18:40:40 +00:00
|
|
|
|
2021-04-08 14:39:47 +00:00
|
|
|
fn f() {
|
2021-01-06 12:57:41 +00:00
|
|
|
var b : f32 = a[2][1];
|
|
|
|
}
|
|
|
|
)";
|
2020-09-29 18:40:40 +00:00
|
|
|
|
2021-01-06 12:57:41 +00:00
|
|
|
auto* expect = R"(
|
2021-04-16 09:26:14 +00:00
|
|
|
var<private> a : mat3x2<f32>;
|
2020-09-29 18:40:40 +00:00
|
|
|
|
2021-04-08 14:39:47 +00:00
|
|
|
fn f() {
|
2021-01-06 12:57:41 +00:00
|
|
|
var b : f32 = a[2][1];
|
|
|
|
}
|
|
|
|
)";
|
2020-09-29 18:40:40 +00:00
|
|
|
|
2021-06-30 13:23:36 +00:00
|
|
|
auto got = Run<Robustness>(src);
|
2020-09-29 18:40:40 +00:00
|
|
|
|
2021-02-24 15:55:24 +00:00
|
|
|
EXPECT_EQ(expect, str(got));
|
2020-09-29 18:40:40 +00:00
|
|
|
}
|
|
|
|
|
2021-06-30 13:23:36 +00:00
|
|
|
TEST_F(RobustnessTest, Matrix_Idx_Expr_Column) {
|
2021-01-06 12:57:41 +00:00
|
|
|
auto* src = R"(
|
2021-04-16 09:26:14 +00:00
|
|
|
var<private> a : mat3x2<f32>;
|
2021-02-10 15:34:37 +00:00
|
|
|
|
2021-04-16 09:26:14 +00:00
|
|
|
var<private> c : i32;
|
2020-09-29 18:40:40 +00:00
|
|
|
|
2021-04-08 14:39:47 +00:00
|
|
|
fn f() {
|
2021-01-06 12:57:41 +00:00
|
|
|
var b : f32 = a[c + 2 - 3][1];
|
2020-09-29 18:40:40 +00:00
|
|
|
}
|
2021-01-06 12:57:41 +00:00
|
|
|
)";
|
2020-09-29 18:40:40 +00:00
|
|
|
|
2021-01-06 12:57:41 +00:00
|
|
|
auto* expect = R"(
|
2021-04-16 09:26:14 +00:00
|
|
|
var<private> a : mat3x2<f32>;
|
2021-02-10 15:34:37 +00:00
|
|
|
|
2021-04-16 09:26:14 +00:00
|
|
|
var<private> c : i32;
|
2020-12-03 20:25:29 +00:00
|
|
|
|
2021-04-08 14:39:47 +00:00
|
|
|
fn f() {
|
2021-01-06 12:57:41 +00:00
|
|
|
var b : f32 = a[min(u32(((c + 2) - 3)), 2u)][1];
|
|
|
|
}
|
|
|
|
)";
|
2020-12-03 20:25:29 +00:00
|
|
|
|
2021-06-30 13:23:36 +00:00
|
|
|
auto got = Run<Robustness>(src);
|
2020-09-29 18:40:40 +00:00
|
|
|
|
2021-02-24 15:55:24 +00:00
|
|
|
EXPECT_EQ(expect, str(got));
|
2021-01-06 12:57:41 +00:00
|
|
|
}
|
2020-09-29 18:40:40 +00:00
|
|
|
|
2021-06-30 13:23:36 +00:00
|
|
|
TEST_F(RobustnessTest, Matrix_Idx_Expr_Row) {
|
2021-01-06 12:57:41 +00:00
|
|
|
auto* src = R"(
|
2021-04-16 09:26:14 +00:00
|
|
|
var<private> a : mat3x2<f32>;
|
2021-02-10 15:34:37 +00:00
|
|
|
|
2021-04-16 09:26:14 +00:00
|
|
|
var<private> c : i32;
|
2020-09-29 18:40:40 +00:00
|
|
|
|
2021-04-08 14:39:47 +00:00
|
|
|
fn f() {
|
2021-01-06 12:57:41 +00:00
|
|
|
var b : f32 = a[1][c + 2 - 3];
|
|
|
|
}
|
|
|
|
)";
|
2020-09-29 18:40:40 +00:00
|
|
|
|
2021-01-06 12:57:41 +00:00
|
|
|
auto* expect = R"(
|
2021-04-16 09:26:14 +00:00
|
|
|
var<private> a : mat3x2<f32>;
|
2021-02-10 15:34:37 +00:00
|
|
|
|
2021-04-16 09:26:14 +00:00
|
|
|
var<private> c : i32;
|
2020-09-29 18:40:40 +00:00
|
|
|
|
2021-04-08 14:39:47 +00:00
|
|
|
fn f() {
|
2021-01-06 12:57:41 +00:00
|
|
|
var b : f32 = a[1][min(u32(((c + 2) - 3)), 1u)];
|
2020-09-29 18:40:40 +00:00
|
|
|
}
|
2021-01-06 12:57:41 +00:00
|
|
|
)";
|
2020-09-29 18:40:40 +00:00
|
|
|
|
2021-06-30 13:23:36 +00:00
|
|
|
auto got = Run<Robustness>(src);
|
2020-12-03 20:25:29 +00:00
|
|
|
|
2021-02-24 15:55:24 +00:00
|
|
|
EXPECT_EQ(expect, str(got));
|
2021-01-06 12:57:41 +00:00
|
|
|
}
|
2020-12-03 20:25:29 +00:00
|
|
|
|
2021-06-30 13:23:36 +00:00
|
|
|
TEST_F(RobustnessTest, Matrix_Idx_Negative_Column) {
|
2021-01-06 12:57:41 +00:00
|
|
|
auto* src = R"(
|
2021-04-16 09:26:14 +00:00
|
|
|
var<private> a : mat3x2<f32>;
|
2020-12-03 20:25:29 +00:00
|
|
|
|
2021-04-08 14:39:47 +00:00
|
|
|
fn f() {
|
2021-01-06 12:57:41 +00:00
|
|
|
var b : f32 = a[-1][1];
|
|
|
|
}
|
|
|
|
)";
|
2020-12-03 20:25:29 +00:00
|
|
|
|
2021-01-06 12:57:41 +00:00
|
|
|
auto* expect = R"(
|
2021-04-16 09:26:14 +00:00
|
|
|
var<private> a : mat3x2<f32>;
|
2020-09-29 18:40:40 +00:00
|
|
|
|
2021-04-08 14:39:47 +00:00
|
|
|
fn f() {
|
2021-01-06 12:57:41 +00:00
|
|
|
var b : f32 = a[0][1];
|
|
|
|
}
|
|
|
|
)";
|
2020-09-29 18:40:40 +00:00
|
|
|
|
2021-06-30 13:23:36 +00:00
|
|
|
auto got = Run<Robustness>(src);
|
2020-09-29 18:40:40 +00:00
|
|
|
|
2021-02-24 15:55:24 +00:00
|
|
|
EXPECT_EQ(expect, str(got));
|
2021-01-06 12:57:41 +00:00
|
|
|
}
|
2020-09-29 18:40:40 +00:00
|
|
|
|
2021-06-30 13:23:36 +00:00
|
|
|
TEST_F(RobustnessTest, Matrix_Idx_Negative_Row) {
|
2021-01-06 12:57:41 +00:00
|
|
|
auto* src = R"(
|
2021-04-16 09:26:14 +00:00
|
|
|
var<private> a : mat3x2<f32>;
|
2020-09-29 18:40:40 +00:00
|
|
|
|
2021-04-08 14:39:47 +00:00
|
|
|
fn f() {
|
2021-01-06 12:57:41 +00:00
|
|
|
var b : f32 = a[2][-1];
|
2020-09-29 18:40:40 +00:00
|
|
|
}
|
2021-01-06 12:57:41 +00:00
|
|
|
)";
|
2020-09-29 18:40:40 +00:00
|
|
|
|
2021-01-06 12:57:41 +00:00
|
|
|
auto* expect = R"(
|
2021-04-16 09:26:14 +00:00
|
|
|
var<private> a : mat3x2<f32>;
|
2020-09-29 18:40:40 +00:00
|
|
|
|
2021-04-08 14:39:47 +00:00
|
|
|
fn f() {
|
2021-01-06 12:57:41 +00:00
|
|
|
var b : f32 = a[2][0];
|
|
|
|
}
|
|
|
|
)";
|
2020-09-29 18:40:40 +00:00
|
|
|
|
2021-06-30 13:23:36 +00:00
|
|
|
auto got = Run<Robustness>(src);
|
2020-09-29 18:40:40 +00:00
|
|
|
|
2021-02-24 15:55:24 +00:00
|
|
|
EXPECT_EQ(expect, str(got));
|
2021-01-06 12:57:41 +00:00
|
|
|
}
|
2020-09-29 18:40:40 +00:00
|
|
|
|
2021-06-30 13:23:36 +00:00
|
|
|
TEST_F(RobustnessTest, Matrix_Idx_OutOfBounds_Column) {
|
2021-01-06 12:57:41 +00:00
|
|
|
auto* src = R"(
|
2021-04-16 09:26:14 +00:00
|
|
|
var<private> a : mat3x2<f32>;
|
2020-09-29 18:40:40 +00:00
|
|
|
|
2021-04-08 14:39:47 +00:00
|
|
|
fn f() {
|
2021-01-06 12:57:41 +00:00
|
|
|
var b : f32 = a[5][1];
|
|
|
|
}
|
|
|
|
)";
|
2020-09-29 18:40:40 +00:00
|
|
|
|
2021-01-06 12:57:41 +00:00
|
|
|
auto* expect = R"(
|
2021-04-16 09:26:14 +00:00
|
|
|
var<private> a : mat3x2<f32>;
|
2020-09-29 18:40:40 +00:00
|
|
|
|
2021-04-08 14:39:47 +00:00
|
|
|
fn f() {
|
2021-01-06 12:57:41 +00:00
|
|
|
var b : f32 = a[2][1];
|
|
|
|
}
|
|
|
|
)";
|
2020-09-29 18:40:40 +00:00
|
|
|
|
2021-06-30 13:23:36 +00:00
|
|
|
auto got = Run<Robustness>(src);
|
2020-09-29 18:40:40 +00:00
|
|
|
|
2021-02-24 15:55:24 +00:00
|
|
|
EXPECT_EQ(expect, str(got));
|
2020-09-29 18:40:40 +00:00
|
|
|
}
|
|
|
|
|
2021-06-30 13:23:36 +00:00
|
|
|
TEST_F(RobustnessTest, Matrix_Idx_OutOfBounds_Row) {
|
2021-01-06 12:57:41 +00:00
|
|
|
auto* src = R"(
|
2021-04-16 09:26:14 +00:00
|
|
|
var<private> a : mat3x2<f32>;
|
2020-09-29 18:40:40 +00:00
|
|
|
|
2021-04-08 14:39:47 +00:00
|
|
|
fn f() {
|
2021-01-06 12:57:41 +00:00
|
|
|
var b : f32 = a[2][5];
|
|
|
|
}
|
|
|
|
)";
|
2020-09-29 18:40:40 +00:00
|
|
|
|
2021-01-06 12:57:41 +00:00
|
|
|
auto* expect = R"(
|
2021-04-16 09:26:14 +00:00
|
|
|
var<private> a : mat3x2<f32>;
|
2020-09-29 18:40:40 +00:00
|
|
|
|
2021-04-08 14:39:47 +00:00
|
|
|
fn f() {
|
2021-01-06 12:57:41 +00:00
|
|
|
var b : f32 = a[2][1];
|
|
|
|
}
|
|
|
|
)";
|
2020-09-29 18:40:40 +00:00
|
|
|
|
2021-06-30 13:23:36 +00:00
|
|
|
auto got = Run<Robustness>(src);
|
2020-09-29 18:40:40 +00:00
|
|
|
|
2021-02-24 15:55:24 +00:00
|
|
|
EXPECT_EQ(expect, str(got));
|
2020-09-29 18:40:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// TODO(dsinclair): Implement when constant_id exists
|
2021-06-30 13:23:36 +00:00
|
|
|
TEST_F(RobustnessTest, DISABLED_Vector_Constant_Id_Clamps) {
|
2021-04-30 17:14:19 +00:00
|
|
|
// [[override(1300)]] let idx : i32;
|
2020-09-29 18:40:40 +00:00
|
|
|
// var a : vec3<f32>
|
|
|
|
// var b : f32 = a[idx]
|
|
|
|
//
|
2021-01-06 12:57:41 +00:00
|
|
|
// ->var b : f32 = a[min(u32(idx), 2)]
|
2020-09-29 18:40:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// TODO(dsinclair): Implement when constant_id exists
|
2021-06-30 13:23:36 +00:00
|
|
|
TEST_F(RobustnessTest, DISABLED_Array_Constant_Id_Clamps) {
|
2021-04-30 17:14:19 +00:00
|
|
|
// [[override(1300)]] let idx : i32;
|
2020-09-29 18:40:40 +00:00
|
|
|
// var a : array<f32, 4>
|
|
|
|
// var b : f32 = a[idx]
|
|
|
|
//
|
2020-10-29 17:56:06 +00:00
|
|
|
// -> var b : f32 = a[min(u32(idx), 3)]
|
2020-09-29 18:40:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// TODO(dsinclair): Implement when constant_id exists
|
2021-06-30 13:23:36 +00:00
|
|
|
TEST_F(RobustnessTest, DISABLED_Matrix_Column_Constant_Id_Clamps) {
|
2021-04-30 17:14:19 +00:00
|
|
|
// [[override(1300)]] let idx : i32;
|
2020-09-29 18:40:40 +00:00
|
|
|
// var a : mat3x2<f32>
|
|
|
|
// var b : f32 = a[idx][1]
|
|
|
|
//
|
2020-10-29 17:56:06 +00:00
|
|
|
// -> var b : f32 = a[min(u32(idx), 2)][1]
|
2020-09-29 18:40:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// TODO(dsinclair): Implement when constant_id exists
|
2021-06-30 13:23:36 +00:00
|
|
|
TEST_F(RobustnessTest, DISABLED_Matrix_Row_Constant_Id_Clamps) {
|
2021-04-30 17:14:19 +00:00
|
|
|
// [[override(1300)]] let idx : i32;
|
2020-09-29 18:40:40 +00:00
|
|
|
// var a : mat3x2<f32>
|
|
|
|
// var b : f32 = a[1][idx]
|
|
|
|
//
|
2020-10-29 17:56:06 +00:00
|
|
|
// -> var b : f32 = a[1][min(u32(idx), 0, 1)]
|
2020-09-29 18:40:40 +00:00
|
|
|
}
|
|
|
|
|
2021-06-30 13:23:36 +00:00
|
|
|
TEST_F(RobustnessTest, RuntimeArray_Clamps) {
|
2021-01-06 14:33:31 +00:00
|
|
|
auto* src = R"(
|
2021-03-18 17:59:54 +00:00
|
|
|
[[block]]
|
2021-01-06 14:33:31 +00:00
|
|
|
struct S {
|
|
|
|
a : f32;
|
|
|
|
b : array<f32>;
|
|
|
|
};
|
2021-06-04 20:41:47 +00:00
|
|
|
[[group(0), binding(0)]] var<storage, read> s : S;
|
2021-01-06 14:33:31 +00:00
|
|
|
|
2021-04-08 14:39:47 +00:00
|
|
|
fn f() {
|
2021-01-06 14:33:31 +00:00
|
|
|
var d : f32 = s.b[25];
|
|
|
|
}
|
|
|
|
)";
|
|
|
|
|
|
|
|
auto* expect = R"(
|
2021-03-18 17:59:54 +00:00
|
|
|
[[block]]
|
2021-01-06 14:33:31 +00:00
|
|
|
struct S {
|
|
|
|
a : f32;
|
|
|
|
b : array<f32>;
|
|
|
|
};
|
|
|
|
|
2021-06-04 20:41:47 +00:00
|
|
|
[[group(0), binding(0)]] var<storage, read> s : S;
|
2021-01-06 14:33:31 +00:00
|
|
|
|
2021-04-08 14:39:47 +00:00
|
|
|
fn f() {
|
2021-06-15 15:05:17 +00:00
|
|
|
var d : f32 = s.b[min(u32(25), (arrayLength(&(s.b)) - 1u))];
|
2021-01-06 14:33:31 +00:00
|
|
|
}
|
|
|
|
)";
|
|
|
|
|
2021-06-30 13:23:36 +00:00
|
|
|
auto got = Run<Robustness>(src);
|
2021-01-06 14:33:31 +00:00
|
|
|
|
2021-02-24 15:55:24 +00:00
|
|
|
EXPECT_EQ(expect, str(got));
|
2020-09-29 18:40:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// TODO(dsinclair): Clamp atomics when available.
|
2021-06-30 13:23:36 +00:00
|
|
|
TEST_F(RobustnessTest, DISABLED_Atomics_Clamp) {
|
2020-09-29 18:40:40 +00:00
|
|
|
FAIL();
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO(dsinclair): Clamp texture coord values. Depends on:
|
|
|
|
// https://github.com/gpuweb/gpuweb/issues/1107
|
2021-06-30 13:23:36 +00:00
|
|
|
TEST_F(RobustnessTest, DISABLED_TextureCoord_Clamp) {
|
2020-09-29 18:40:40 +00:00
|
|
|
FAIL();
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO(dsinclair): Test for scoped variables when Lexical Scopes implemented
|
2021-06-30 13:23:36 +00:00
|
|
|
TEST_F(RobustnessTest, DISABLED_Scoped_Variable) {
|
2020-09-29 18:40:40 +00:00
|
|
|
// var a : array<f32, 3>;
|
|
|
|
// var i : u32;
|
|
|
|
// {
|
|
|
|
// var a : array<f32, 5>;
|
|
|
|
// var b : f32 = a[i];
|
|
|
|
// }
|
|
|
|
// var c : f32 = a[i];
|
|
|
|
//
|
2020-10-29 17:56:06 +00:00
|
|
|
// -> var b : f32 = a[min(u32(i), 4)];
|
|
|
|
// var c : f32 = a[min(u32(i), 2)];
|
2020-09-29 18:40:40 +00:00
|
|
|
FAIL();
|
|
|
|
}
|
|
|
|
|
2021-04-14 14:29:28 +00:00
|
|
|
// Check that existing use of min() and arrayLength() do not get renamed.
|
2021-06-30 13:23:36 +00:00
|
|
|
TEST_F(RobustnessTest, DontRenameSymbols) {
|
2021-04-14 14:29:28 +00:00
|
|
|
auto* src = R"(
|
|
|
|
[[block]]
|
|
|
|
struct S {
|
|
|
|
a : f32;
|
|
|
|
b : array<f32>;
|
|
|
|
};
|
|
|
|
|
2021-06-04 20:41:47 +00:00
|
|
|
[[group(0), binding(0)]] var<storage, read> s : S;
|
2021-04-14 14:29:28 +00:00
|
|
|
|
|
|
|
let c : u32 = 1u;
|
|
|
|
|
|
|
|
fn f() {
|
|
|
|
let b : f32 = s.b[c];
|
|
|
|
let x : i32 = min(1, 2);
|
2021-06-18 22:44:31 +00:00
|
|
|
let y : u32 = arrayLength(&s.b);
|
2021-04-14 14:29:28 +00:00
|
|
|
}
|
|
|
|
)";
|
|
|
|
|
|
|
|
auto* expect = R"(
|
|
|
|
[[block]]
|
|
|
|
struct S {
|
|
|
|
a : f32;
|
|
|
|
b : array<f32>;
|
|
|
|
};
|
|
|
|
|
2021-06-04 20:41:47 +00:00
|
|
|
[[group(0), binding(0)]] var<storage, read> s : S;
|
2021-04-14 14:29:28 +00:00
|
|
|
|
|
|
|
let c : u32 = 1u;
|
|
|
|
|
|
|
|
fn f() {
|
2021-06-15 15:05:17 +00:00
|
|
|
let b : f32 = s.b[min(u32(c), (arrayLength(&(s.b)) - 1u))];
|
2021-04-14 14:29:28 +00:00
|
|
|
let x : i32 = min(1, 2);
|
2021-06-18 22:44:31 +00:00
|
|
|
let y : u32 = arrayLength(&(s.b));
|
2021-04-14 14:29:28 +00:00
|
|
|
}
|
|
|
|
)";
|
|
|
|
|
2021-06-30 13:23:36 +00:00
|
|
|
auto got = Run<Robustness>(src);
|
2021-04-14 14:29:28 +00:00
|
|
|
|
|
|
|
EXPECT_EQ(expect, str(got));
|
|
|
|
}
|
|
|
|
|
2020-09-29 18:40:40 +00:00
|
|
|
} // namespace
|
|
|
|
} // namespace transform
|
|
|
|
} // namespace tint
|