mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-11 14:41:50 +00:00
Validate that Symbols are all part of the same program
Assert in each AST constructor that symbols belong to the program of the parent. Bug: tint:709 Change-Id: I82ae9b23c88e89714a44e057a0272f0293385aaf Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/47624 Commit-Queue: Ben Clayton <bclayton@chromium.org> Kokoro: Kokoro <noreply+kokoro@google.com> Reviewed-by: James Price <jrprice@google.com> Reviewed-by: Antonio Maiorano <amaiorano@google.com>
This commit is contained in:
committed by
Commit Bot service account
parent
f0c816a757
commit
13ef87caab
@@ -38,6 +38,7 @@ Function::Function(ProgramID program_id,
|
||||
body_(body),
|
||||
decorations_(std::move(decorations)),
|
||||
return_type_decorations_(std::move(return_type_decorations)) {
|
||||
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(symbol_, program_id);
|
||||
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(body, program_id);
|
||||
for (auto* param : params_) {
|
||||
TINT_ASSERT(param && param->is_const());
|
||||
|
||||
@@ -79,6 +79,16 @@ TEST_F(FunctionTest, Assert_Null_Param) {
|
||||
"internal compiler error");
|
||||
}
|
||||
|
||||
TEST_F(FunctionTest, Assert_DifferentProgramID_Symbol) {
|
||||
EXPECT_FATAL_FAILURE(
|
||||
{
|
||||
ProgramBuilder b1;
|
||||
ProgramBuilder b2;
|
||||
b1.Func(b2.Sym("func"), VariableList{}, b1.ty.void_(), StatementList{});
|
||||
},
|
||||
"internal compiler error");
|
||||
}
|
||||
|
||||
TEST_F(FunctionTest, Assert_DifferentProgramID_Param) {
|
||||
EXPECT_FATAL_FAILURE(
|
||||
{
|
||||
|
||||
@@ -25,6 +25,7 @@ IdentifierExpression::IdentifierExpression(ProgramID program_id,
|
||||
const Source& source,
|
||||
Symbol sym)
|
||||
: Base(program_id, source), sym_(sym) {
|
||||
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(sym_, program_id);
|
||||
TINT_ASSERT(sym_.IsValid());
|
||||
}
|
||||
|
||||
|
||||
@@ -23,12 +23,12 @@ using IdentifierExpressionTest = TestHelper;
|
||||
|
||||
TEST_F(IdentifierExpressionTest, Creation) {
|
||||
auto* i = Expr("ident");
|
||||
EXPECT_EQ(i->symbol(), Symbol(1));
|
||||
EXPECT_EQ(i->symbol(), Symbol(1, ID()));
|
||||
}
|
||||
|
||||
TEST_F(IdentifierExpressionTest, Creation_WithSource) {
|
||||
auto* i = Expr(Source{Source::Location{20, 2}}, "ident");
|
||||
EXPECT_EQ(i->symbol(), Symbol(1));
|
||||
EXPECT_EQ(i->symbol(), Symbol(1, ID()));
|
||||
|
||||
auto src = i->source();
|
||||
EXPECT_EQ(src.range.begin.line, 20u);
|
||||
@@ -49,6 +49,16 @@ TEST_F(IdentifierExpressionTest, Assert_InvalidSymbol) {
|
||||
"internal compiler error");
|
||||
}
|
||||
|
||||
TEST_F(IdentifierExpressionTest, Assert_DifferentProgramID_Symbol) {
|
||||
EXPECT_FATAL_FAILURE(
|
||||
{
|
||||
ProgramBuilder b1;
|
||||
ProgramBuilder b2;
|
||||
b1.Expr(b2.Sym(""));
|
||||
},
|
||||
"internal compiler error");
|
||||
}
|
||||
|
||||
TEST_F(IdentifierExpressionTest, ToStr) {
|
||||
auto* i = Expr("ident");
|
||||
EXPECT_EQ(str(i), R"(Identifier[not set]{ident}
|
||||
|
||||
@@ -32,6 +32,7 @@ StructMember::StructMember(ProgramID program_id,
|
||||
decorations_(std::move(decorations)) {
|
||||
TINT_ASSERT(type);
|
||||
TINT_ASSERT(symbol_.IsValid());
|
||||
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(symbol_, program_id);
|
||||
for (auto* deco : decorations_) {
|
||||
TINT_ASSERT(deco);
|
||||
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(deco, program_id);
|
||||
|
||||
@@ -23,7 +23,7 @@ using StructMemberTest = TestHelper;
|
||||
|
||||
TEST_F(StructMemberTest, Creation) {
|
||||
auto* st = Member("a", ty.i32(), {MemberSize(4)});
|
||||
EXPECT_EQ(st->symbol(), Symbol(1));
|
||||
EXPECT_EQ(st->symbol(), Symbol(1, ID()));
|
||||
EXPECT_EQ(st->type(), ty.i32());
|
||||
EXPECT_EQ(st->decorations().size(), 1u);
|
||||
EXPECT_TRUE(st->decorations()[0]->Is<StructMemberSizeDecoration>());
|
||||
@@ -37,7 +37,7 @@ TEST_F(StructMemberTest, CreationWithSource) {
|
||||
auto* st = Member(
|
||||
Source{Source::Range{Source::Location{27, 4}, Source::Location{27, 8}}},
|
||||
"a", ty.i32());
|
||||
EXPECT_EQ(st->symbol(), Symbol(1));
|
||||
EXPECT_EQ(st->symbol(), Symbol(1, ID()));
|
||||
EXPECT_EQ(st->type(), ty.i32());
|
||||
EXPECT_EQ(st->decorations().size(), 0u);
|
||||
EXPECT_EQ(st->source().range.begin.line, 27u);
|
||||
@@ -73,6 +73,16 @@ TEST_F(StructMemberTest, Assert_Null_Decoration) {
|
||||
"internal compiler error");
|
||||
}
|
||||
|
||||
TEST_F(StructMemberTest, Assert_DifferentProgramID_Symbol) {
|
||||
EXPECT_FATAL_FAILURE(
|
||||
{
|
||||
ProgramBuilder b1;
|
||||
ProgramBuilder b2;
|
||||
b1.Member(b2.Sym("a"), b1.ty.i32(), {b1.MemberSize(4)});
|
||||
},
|
||||
"internal compiler error");
|
||||
}
|
||||
|
||||
TEST_F(StructMemberTest, Assert_DifferentProgramID_Decoration) {
|
||||
EXPECT_FATAL_FAILURE(
|
||||
{
|
||||
|
||||
@@ -39,6 +39,7 @@ Variable::Variable(ProgramID program_id,
|
||||
decorations_(std::move(decorations)),
|
||||
declared_storage_class_(declared_storage_class) {
|
||||
TINT_ASSERT(symbol_.IsValid());
|
||||
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(symbol_, program_id);
|
||||
// no type means we must have a constructor to infer it
|
||||
TINT_ASSERT(declared_type_ || constructor);
|
||||
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(constructor, program_id);
|
||||
|
||||
@@ -25,7 +25,7 @@ using VariableTest = TestHelper;
|
||||
TEST_F(VariableTest, Creation) {
|
||||
auto* v = Var("my_var", ty.i32(), StorageClass::kFunction);
|
||||
|
||||
EXPECT_EQ(v->symbol(), Symbol(1));
|
||||
EXPECT_EQ(v->symbol(), Symbol(1, ID()));
|
||||
EXPECT_EQ(v->declared_storage_class(), StorageClass::kFunction);
|
||||
EXPECT_EQ(v->declared_type(), ty.i32());
|
||||
EXPECT_EQ(v->source().range.begin.line, 0u);
|
||||
@@ -39,7 +39,7 @@ TEST_F(VariableTest, CreationWithSource) {
|
||||
Source{Source::Range{Source::Location{27, 4}, Source::Location{27, 5}}},
|
||||
"i", ty.f32(), StorageClass::kPrivate, nullptr, DecorationList{});
|
||||
|
||||
EXPECT_EQ(v->symbol(), Symbol(1));
|
||||
EXPECT_EQ(v->symbol(), Symbol(1, ID()));
|
||||
EXPECT_EQ(v->declared_storage_class(), StorageClass::kPrivate);
|
||||
EXPECT_EQ(v->declared_type(), ty.f32());
|
||||
EXPECT_EQ(v->source().range.begin.line, 27u);
|
||||
@@ -53,7 +53,7 @@ TEST_F(VariableTest, CreationEmpty) {
|
||||
Source{Source::Range{Source::Location{27, 4}, Source::Location{27, 7}}},
|
||||
"a_var", ty.i32(), StorageClass::kWorkgroup, nullptr, DecorationList{});
|
||||
|
||||
EXPECT_EQ(v->symbol(), Symbol(1));
|
||||
EXPECT_EQ(v->symbol(), Symbol(1, ID()));
|
||||
EXPECT_EQ(v->declared_storage_class(), StorageClass::kWorkgroup);
|
||||
EXPECT_EQ(v->declared_type(), ty.i32());
|
||||
EXPECT_EQ(v->source().range.begin.line, 27u);
|
||||
@@ -80,6 +80,16 @@ TEST_F(VariableTest, Assert_Null_Type) {
|
||||
"internal compiler error");
|
||||
}
|
||||
|
||||
TEST_F(VariableTest, Assert_DifferentProgramID_Symbol) {
|
||||
EXPECT_FATAL_FAILURE(
|
||||
{
|
||||
ProgramBuilder b1;
|
||||
ProgramBuilder b2;
|
||||
b1.Var(b2.Sym("x"), b1.ty.f32(), StorageClass::kNone);
|
||||
},
|
||||
"internal compiler error");
|
||||
}
|
||||
|
||||
TEST_F(VariableTest, Assert_DifferentProgramID_Constructor) {
|
||||
EXPECT_FATAL_FAILURE(
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user