From 818c1bea215fff9fe1ae4c6cab0c342ca6ccab32 Mon Sep 17 00:00:00 2001 From: Hans-Kristian Arntzen Date: Mon, 31 Jul 2017 09:31:20 +0200 Subject: [PATCH] Fix spurious struct type aliasing in stripped binaries. Should not consider aliasing when names are stripped. --- spirv_cross.cpp | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/spirv_cross.cpp b/spirv_cross.cpp index 14a946cf..728d9a5d 100644 --- a/spirv_cross.cpp +++ b/spirv_cross.cpp @@ -1533,17 +1533,26 @@ void Compiler::parse(const Instruction &instruction) // types, which we shouldn't normally do. // We should not normally have to consider type aliases like this to begin with // however ... glslang issues #304, #307 cover this. - for (auto &other : global_struct_cache) - { - if (get_name(type.self) == get_name(other) && types_are_logically_equivalent(type, get(other))) - { - type.type_alias = other; - break; - } - } - if (type.type_alias == 0) - global_struct_cache.push_back(id); + // For stripped names, never consider struct type aliasing. + // We risk declaring the same struct multiple times, but type-punning is not allowed + // so this is safe. + bool consider_aliasing = !get_name(type.self).empty(); + if (consider_aliasing) + { + for (auto &other : global_struct_cache) + { + if (get_name(type.self) == get_name(other) && + types_are_logically_equivalent(type, get(other))) + { + type.type_alias = other; + break; + } + } + + if (type.type_alias == 0) + global_struct_cache.push_back(id); + } break; }