mirror of
https://gitee.com/openharmony/third_party_spirv-tools
synced 2024-11-27 01:21:25 +00:00
Generate null pointer by converting uint64 zero to pointer. (#2935)
Fixes #2929.
This commit is contained in:
parent
8fa0f1a656
commit
ad3d23f478
@ -96,8 +96,22 @@ void InstBuffAddrCheckPass::GenCheckCode(
|
||||
uid2offset_[ref_inst->unique_id()], stage_idx,
|
||||
{error_id, lo_uptr_inst->result_id(), hi_uptr_inst->result_id()},
|
||||
&builder);
|
||||
// Gen zero for invalid reference
|
||||
uint32_t ref_type_id = ref_inst->type_id();
|
||||
// Gen zero for invalid load. If pointer type, need to convert uint64
|
||||
// zero to pointer; cannot create ConstantNull of pointer type.
|
||||
uint32_t null_id = 0;
|
||||
if (new_ref_id != 0) {
|
||||
uint32_t ref_type_id = ref_inst->type_id();
|
||||
analysis::TypeManager* type_mgr = context()->get_type_mgr();
|
||||
analysis::Type* ref_type = type_mgr->GetType(ref_type_id);
|
||||
if (ref_type->AsPointer() != nullptr) {
|
||||
uint32_t null_u64_id = GetNullId(GetUint64Id());
|
||||
Instruction* null_ptr_inst =
|
||||
builder.AddUnaryOp(ref_type_id, SpvOpConvertUToPtr, null_u64_id);
|
||||
null_id = null_ptr_inst->result_id();
|
||||
} else {
|
||||
null_id = GetNullId(ref_type_id);
|
||||
}
|
||||
}
|
||||
(void)builder.AddBranch(merge_blk_id);
|
||||
new_blocks->push_back(std::move(new_blk_ptr));
|
||||
// Gen merge block
|
||||
@ -107,9 +121,9 @@ void InstBuffAddrCheckPass::GenCheckCode(
|
||||
// result id of the original reference with that of the Phi. Kill original
|
||||
// reference.
|
||||
if (new_ref_id != 0) {
|
||||
Instruction* phi_inst = builder.AddPhi(
|
||||
ref_type_id,
|
||||
{new_ref_id, valid_blk_id, GetNullId(ref_type_id), invalid_blk_id});
|
||||
Instruction* phi_inst =
|
||||
builder.AddPhi(ref_inst->type_id(),
|
||||
{new_ref_id, valid_blk_id, null_id, invalid_blk_id});
|
||||
context()->ReplaceAllUsesWith(ref_inst->result_id(), phi_inst->result_id());
|
||||
}
|
||||
new_blocks->push_back(std::move(new_blk_ptr));
|
||||
|
@ -464,7 +464,7 @@ OpTypeForwardPointer %_ptr_PhysicalStorageBuffer_blockType PhysicalStorageBuffer
|
||||
%uint_7 = OpConstant %uint 7
|
||||
%uint_9 = OpConstant %uint 9
|
||||
%uint_44 = OpConstant %uint 44
|
||||
%132 = OpConstantNull %_ptr_PhysicalStorageBuffer_blockType
|
||||
%132 = OpConstantNull %ulong
|
||||
%uint_46 = OpConstant %uint 46
|
||||
)";
|
||||
|
||||
@ -499,24 +499,25 @@ OpBranch %68
|
||||
%74 = OpShiftRightLogical %ulong %30 %uint_32
|
||||
%75 = OpUConvert %uint %74
|
||||
%131 = OpFunctionCall %void %76 %uint_44 %uint_2 %72 %75
|
||||
%133 = OpConvertUToPtr %_ptr_PhysicalStorageBuffer_blockType %132
|
||||
OpBranch %68
|
||||
%68 = OpLabel
|
||||
%133 = OpPhi %_ptr_PhysicalStorageBuffer_blockType %71 %69 %132 %70
|
||||
%26 = OpAccessChain %_ptr_PhysicalStorageBuffer_int %133 %int_0
|
||||
%134 = OpConvertPtrToU %ulong %26
|
||||
%135 = OpFunctionCall %bool %32 %134 %uint_4
|
||||
OpSelectionMerge %136 None
|
||||
OpBranchConditional %135 %137 %138
|
||||
%137 = OpLabel
|
||||
OpStore %26 %int_531 Aligned 16
|
||||
OpBranch %136
|
||||
%134 = OpPhi %_ptr_PhysicalStorageBuffer_blockType %71 %69 %133 %70
|
||||
%26 = OpAccessChain %_ptr_PhysicalStorageBuffer_int %134 %int_0
|
||||
%135 = OpConvertPtrToU %ulong %26
|
||||
%136 = OpFunctionCall %bool %32 %135 %uint_4
|
||||
OpSelectionMerge %137 None
|
||||
OpBranchConditional %136 %138 %139
|
||||
%138 = OpLabel
|
||||
%139 = OpUConvert %uint %134
|
||||
%140 = OpShiftRightLogical %ulong %134 %uint_32
|
||||
%141 = OpUConvert %uint %140
|
||||
%143 = OpFunctionCall %void %76 %uint_46 %uint_2 %139 %141
|
||||
OpBranch %136
|
||||
%136 = OpLabel
|
||||
OpStore %26 %int_531 Aligned 16
|
||||
OpBranch %137
|
||||
%139 = OpLabel
|
||||
%140 = OpUConvert %uint %135
|
||||
%141 = OpShiftRightLogical %ulong %135 %uint_32
|
||||
%142 = OpUConvert %uint %141
|
||||
%144 = OpFunctionCall %void %76 %uint_46 %uint_2 %140 %142
|
||||
OpBranch %137
|
||||
%137 = OpLabel
|
||||
OpReturn
|
||||
OpFunctionEnd
|
||||
)";
|
||||
@ -608,12 +609,10 @@ OpReturn
|
||||
OpFunctionEnd
|
||||
)";
|
||||
|
||||
// Issue #2929: cannot use OpConstantNull of a physical storage buffer
|
||||
// pointer.
|
||||
SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
|
||||
SinglePassRunAndCheck<InstBuffAddrCheckPass>(
|
||||
defs_before + func_before, defs_after + func_after + new_funcs, true,
|
||||
false, 7u, 23u, 2u);
|
||||
true, 7u, 23u, 2u);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
Loading…
Reference in New Issue
Block a user