Skip to content

Commit 2a5a4e7

Browse files
authored
Prevent duplicate array type insertion into TypeMap. (#3186)
Check if an array type exists in TypeMap before inserting it to prevent duplications.
1 parent 6efaf77 commit 2a5a4e7

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

lib/SPIRV/SPIRVWriter.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -461,11 +461,13 @@ SPIRVType *LLVMToSPIRVBase::transType(Type *T) {
461461
ConstantInt::get(getSizetType(), ArraySize, false), nullptr)));
462462
mapType(T, TransType);
463463
if (ElTy->isPointerTy()) {
464-
mapType(
464+
Type *ArrTy =
465465
ArrayType::get(TypedPointerType::get(Type::getInt8Ty(*Ctx),
466466
ElTy->getPointerAddressSpace()),
467-
ArraySize),
468-
TransType);
467+
ArraySize);
468+
LLVMToSPIRVTypeMap::iterator Loc = TypeMap.find(ArrTy);
469+
if (Loc == TypeMap.end())
470+
mapType(ArrTy, TransType);
469471
}
470472
return TransType;
471473
}

test/duplicate-types.ll

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
; Check that we don't end up with duplicated array types in TypeMap.
2+
; No FileCheck needed, we only want to check the absence of errors.
3+
; RUN: llvm-as %s -o %t.bc
4+
; RUN: llvm-spirv %t.bc -o %t.spv
5+
; RUN: spirv-val %t.spv
6+
7+
; ModuleID = 'duplicate-array-types'
8+
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-G1"
9+
target triple = "spir64-unknown-unknown"
10+
11+
%duplicate = type { [2 x ptr addrspace(4)] }
12+
13+
; Function Attrs: mustprogress norecurse nounwind
14+
define spir_kernel void @foo() {
15+
entry:
16+
alloca [2 x ptr addrspace(4)], align 8
17+
alloca %duplicate, align 8
18+
ret void
19+
}

0 commit comments

Comments
 (0)