diff --git a/llvm-spirv/lib/SPIRV/SPIRVWriter.cpp b/llvm-spirv/lib/SPIRV/SPIRVWriter.cpp index 2853410fd8b61..8071d6dfcdc5e 100644 --- a/llvm-spirv/lib/SPIRV/SPIRVWriter.cpp +++ b/llvm-spirv/lib/SPIRV/SPIRVWriter.cpp @@ -1793,7 +1793,10 @@ LLVMToSPIRVBase::transValueWithoutDecoration(Value *V, SPIRVBasicBlock *BB, } SPIRVType *LLVMToSPIRVBase::mapType(Type *T, SPIRVType *BT) { - TypeMap[T] = BT; + auto EmplaceStatus = TypeMap.try_emplace(T, BT); + (void)EmplaceStatus; + // TODO: Uncomment the assertion, once the type mapping issue is resolved + // assert(EmplaceStatus.second && "The type was already added to the map"); SPIRVDBG(dbgs() << "[mapType] " << *T << " => "; spvdbgs() << *BT << '\n'); return BT; } diff --git a/llvm-spirv/test/pointer_type_mapping.ll b/llvm-spirv/test/pointer_type_mapping.ll new file mode 100644 index 0000000000000..e76b360d1cd48 --- /dev/null +++ b/llvm-spirv/test/pointer_type_mapping.ll @@ -0,0 +1,30 @@ +; RUN: llvm-as %s -o %t.bc +; RUN: llvm-spirv %t.bc --spirv-ext=+all -spirv-text -o %t +; RUN: FileCheck < %t %s + +; CHECK: Name [[#NAME:]] "struct._ZTS6Object.Object" +; CHECK-COUNT-1: TypeStruct [[#NAME]] +; TODO add check count one and remove unused, when the type mapping bug is fixed +; CHECK: TypePointer [[#UNUSED:]] {{.*}} [[#NAME]] +; CHECK: TypePointer [[#PTRTY:]] {{.*}} [[#NAME]] +; CHECK: FunctionParameter [[#PTRTY]] +; CHECK-NOT: FunctionParameter [[#UNUSED]] + +; ModuleID = 'sycl_test.bc' +source_filename = "sycl_test.cpp" +target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-n8:16:32:64" +target triple = "spir64-unknown-unknown-sycldevice" + +%struct._ZTS4Args.Args = type { %struct._ZTS6Object.Object addrspace(4)* } +%struct._ZTS6Object.Object = type { i32 (%struct._ZTS6Object.Object addrspace(4)*, i32)* } + +; Function Attrs: convergent norecurse nounwind mustprogress +define dso_local spir_func i32 @_Z9somefunc0P4Args(%struct._ZTS4Args.Args addrspace(4)* %a, %struct._ZTS6Object.Object addrspace(4)* %b) { +entry: + ret i32 0 +} + +!opencl.spir.version = !{!0} +!spirv.Source = !{!1} +!0 = !{i32 1, i32 2} +!1 = !{i32 4, i32 100000}