From f33b60693fa8782e5767e5de0594c224c7b7c610 Mon Sep 17 00:00:00 2001 From: Steven Perron Date: Thu, 18 Jul 2024 08:33:36 -0400 Subject: [PATCH] Check storage class as well. --- source/opt/fix_storage_class.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/source/opt/fix_storage_class.cpp b/source/opt/fix_storage_class.cpp index 2085dda414f..367418d77a5 100644 --- a/source/opt/fix_storage_class.cpp +++ b/source/opt/fix_storage_class.cpp @@ -308,6 +308,8 @@ uint32_t FixStorageClass::WalkAccessChainType(Instruction* inst, uint32_t id) { Instruction* id_type_inst = get_def_use_mgr()->GetDef(id); assert(id_type_inst->opcode() == spv::Op::OpTypePointer); id = id_type_inst->GetSingleWordInOperand(1); + spv::StorageClass input_storage_class = + static_cast(id_type_inst->GetSingleWordInOperand(0)); for (uint32_t i = start_idx; i < inst->NumInOperands(); ++i) { Instruction* type_inst = get_def_use_mgr()->GetDef(id); @@ -341,17 +343,18 @@ uint32_t FixStorageClass::WalkAccessChainType(Instruction* inst, uint32_t id) { } Instruction* orig_type_inst = get_def_use_mgr()->GetDef(inst->type_id()); + spv::StorageClass orig_storage_class = + static_cast(orig_type_inst->GetSingleWordInOperand(0)); assert(orig_type_inst->opcode() == spv::Op::OpTypePointer); - if (orig_type_inst->GetSingleWordInOperand(1) == id) { + if (orig_type_inst->GetSingleWordInOperand(1) == id && + input_storage_class == orig_storage_class) { // The existing type is correct. Avoid the search for the type. Note that if // there is a duplicate type, the search below could return a different type // forcing more changes to the code than necessary. return inst->type_id(); } - return context()->get_type_mgr()->FindPointerToType( - id, static_cast( - orig_type_inst->GetSingleWordInOperand(0))); + return context()->get_type_mgr()->FindPointerToType(id, input_storage_class); } // namespace opt