Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid generating duplicate names when merging types #1374

Merged
merged 1 commit into from Mar 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions source/opt/remove_duplicates_pass.cpp
Expand Up @@ -130,6 +130,7 @@ bool RemoveDuplicatesPass::RemoveDuplicateTypes(
visited_types.emplace_back(i);
} else {
// The same type has already been seen before, remove this one.
ir_context->KillNamesAndDecorates(i->result_id());
ir_context->ReplaceAllUsesWith(i->result_id(), id_to_keep);
modified = true;
to_delete.emplace_back(i);
Expand Down
23 changes: 23 additions & 0 deletions test/opt/pass_remove_duplicates_test.cpp
Expand Up @@ -219,6 +219,29 @@ OpDecorate %1 GLSLPacked
EXPECT_THAT(GetErrorMessage(), "");
}

TEST_F(RemoveDuplicatesTest, SameTypeAndDifferentName) {
const std::string spirv = R"(
OpCapability Shader
OpCapability Linkage
OpMemoryModel Logical GLSL450
OpName %1 "Type1"
OpName %2 "Type2"
%3 = OpTypeInt 32 0
%1 = OpTypeStruct %3 %3
%2 = OpTypeStruct %3 %3
)";
const std::string after = R"(OpCapability Shader
OpCapability Linkage
OpMemoryModel Logical GLSL450
OpName %1 "Type1"
%3 = OpTypeInt 32 0
%1 = OpTypeStruct %3 %3
)";

EXPECT_THAT(RunPass(spirv), after);
EXPECT_THAT(GetErrorMessage(), "");
}

// Check that #1033 has been fixed.
TEST_F(RemoveDuplicatesTest, DoNotRemoveDifferentOpDecorationGroup) {
const std::string spirv = R"(
Expand Down