Skip to content

Commit 026501c

Browse files
committed
Add unbounded array support by modifying LLVM IR -> SPIRV type lowering
1 parent 40eb63e commit 026501c

File tree

2 files changed

+6
-10
lines changed

2 files changed

+6
-10
lines changed

clang/lib/CodeGen/CodeGenTypes.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -807,8 +807,9 @@ llvm::Type *CodeGenTypes::ConvertType(QualType T) {
807807
if (!ResultType->isSized()) {
808808
SkippedLayout = true;
809809
ResultType = llvm::Type::getInt8Ty(getLLVMContext());
810-
}
811-
ResultType = llvm::ArrayType::get(ResultType, Context.getLangOpts().SYCLIsDevice ? 1 : 0);
810+
}
811+
ResultType = llvm::ArrayType::get(
812+
ResultType, 0);
812813
break;
813814
}
814815
case Type::ArrayParameter:

llvm-spirv/lib/SPIRV/SPIRVWriter.cpp

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -453,24 +453,19 @@ SPIRVType *LLVMToSPIRVBase::transType(Type *T) {
453453
if (T->isArrayTy()) {
454454
// SPIR-V 1.3 s3.32.6: Length is the number of elements in the array.
455455
// It must be at least 1.
456-
if (T->getArrayNumElements() < 1) {
457-
std::string Str;
458-
llvm::raw_string_ostream OS(Str);
459-
OS << *T;
460-
SPIRVCK(T->getArrayNumElements() >= 1, InvalidArraySize, OS.str());
461-
}
456+
const auto ArraySize = T->getArrayNumElements() ? T->getArrayNumElements() : 1;
462457
Type *ElTy = T->getArrayElementType();
463458
SPIRVType *TransType = BM->addArrayType(
464459
transType(ElTy),
465460
static_cast<SPIRVConstant *>(transValue(
466-
ConstantInt::get(getSizetType(), T->getArrayNumElements(), false),
461+
ConstantInt::get(getSizetType(), ArraySize, false),
467462
nullptr)));
468463
mapType(T, TransType);
469464
if (ElTy->isPointerTy()) {
470465
mapType(
471466
ArrayType::get(TypedPointerType::get(Type::getInt8Ty(*Ctx),
472467
ElTy->getPointerAddressSpace()),
473-
T->getArrayNumElements()),
468+
ArraySize),
474469
TransType);
475470
}
476471
return TransType;

0 commit comments

Comments
 (0)