[spirv-reader] Ignore empty string user names
Bug: tint:3 Change-Id: Ibef645b123706cf9fa7d5b98413a709d4624244d Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/25102 Reviewed-by: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
parent
5f43fedcdd
commit
d8a4d4b06f
|
@ -487,16 +487,22 @@ bool ParserImpl::RegisterUserAndStructMemberNames() {
|
|||
// Register names from OpName and OpMemberName
|
||||
for (const auto& inst : module_->debugs2()) {
|
||||
switch (inst.opcode()) {
|
||||
case SpvOpName:
|
||||
namer_.SuggestSanitizedName(inst.GetSingleWordInOperand(0),
|
||||
inst.GetInOperand(1).AsString());
|
||||
|
||||
case SpvOpName: {
|
||||
const auto name = inst.GetInOperand(1).AsString();
|
||||
if (!name.empty()) {
|
||||
namer_.SuggestSanitizedName(inst.GetSingleWordInOperand(0), name);
|
||||
}
|
||||
break;
|
||||
case SpvOpMemberName:
|
||||
namer_.SuggestSanitizedMemberName(inst.GetSingleWordInOperand(0),
|
||||
inst.GetSingleWordInOperand(1),
|
||||
inst.GetInOperand(2).AsString());
|
||||
}
|
||||
case SpvOpMemberName: {
|
||||
const auto name = inst.GetInOperand(2).AsString();
|
||||
if (!name.empty()) {
|
||||
namer_.SuggestSanitizedMemberName(inst.GetSingleWordInOperand(0),
|
||||
inst.GetSingleWordInOperand(1),
|
||||
name);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -36,6 +36,15 @@ TEST_F(SpvParserTest, UserName_RespectOpName) {
|
|||
EXPECT_THAT(p->namer().GetName(1), Eq("the_void_type"));
|
||||
}
|
||||
|
||||
TEST_F(SpvParserTest, UserName_IgnoreEmptyName) {
|
||||
auto* p = parser(test::Assemble(R"(
|
||||
OpName %1 ""
|
||||
%1 = OpTypeVoid
|
||||
)"));
|
||||
EXPECT_TRUE(p->BuildAndParseInternalModule());
|
||||
EXPECT_FALSE(p->namer().HasName(1));
|
||||
}
|
||||
|
||||
TEST_F(SpvParserTest, UserName_DistinguishDuplicateSuggestion) {
|
||||
auto* p = parser(test::Assemble(R"(
|
||||
OpName %1 "vanilla"
|
||||
|
@ -62,6 +71,16 @@ TEST_F(SpvParserTest, UserName_RespectOpMemberName) {
|
|||
EXPECT_THAT(p->namer().GetMemberName(3, 2), Eq("chocolate"));
|
||||
}
|
||||
|
||||
TEST_F(SpvParserTest, UserName_IgnoreEmptyMemberName) {
|
||||
auto* p = parser(test::Assemble(R"(
|
||||
OpMemberName %3 0 ""
|
||||
%2 = OpTypeInt 32 0
|
||||
%3 = OpTypeStruct %2
|
||||
)"));
|
||||
EXPECT_TRUE(p->BuildAndParseInternalModule());
|
||||
EXPECT_THAT(p->namer().GetMemberName(3, 0), Eq("field0"));
|
||||
}
|
||||
|
||||
TEST_F(SpvParserTest, UserName_SynthesizeMemberNames) {
|
||||
auto* p = parser(test::Assemble(R"(
|
||||
%2 = OpTypeInt 32 0
|
||||
|
|
Loading…
Reference in New Issue