Skip to content

Commit b24c6d7

Browse files
committed
add assert, move conversion
1 parent 0d2579a commit b24c6d7

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

clang/lib/CodeGen/Targets/DirectX.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,18 @@ llvm::Type *DirectXTargetCodeGenInfo::getHLSLType(CodeGenModule &CGM,
4343
if (ContainedTy.isNull())
4444
return nullptr;
4545

46-
// convert element type
4746
llvm::Type *ElemType = CGM.getTypes().ConvertType(ContainedTy);
4847

48+
// target ext type parameters may not be named struct types
49+
// so we should convert any named struct types to anonymous
50+
// struct types in the parameter list
51+
llvm::Type *ConvertedElemType = ElemType;
52+
if (auto *STy = dyn_cast<llvm::StructType>(ElemType)) {
53+
if (STy->hasName())
54+
ConvertedElemType =
55+
llvm::StructType::get(Ctx, STy->elements(), /*isPacked=*/false);
56+
}
57+
4958
llvm::StringRef TypeName =
5059
ResAttrs.RawBuffer ? "dx.RawBuffer" : "dx.TypedBuffer";
5160
SmallVector<unsigned, 3> Ints = {/*IsWriteable*/ ResAttrs.ResourceClass ==
@@ -54,7 +63,7 @@ llvm::Type *DirectXTargetCodeGenInfo::getHLSLType(CodeGenModule &CGM,
5463
if (!ResAttrs.RawBuffer)
5564
Ints.push_back(/*IsSigned*/ ContainedTy->isSignedIntegerType());
5665

57-
return llvm::TargetExtType::get(Ctx, TypeName, {ElemType}, Ints);
66+
return llvm::TargetExtType::get(Ctx, TypeName, {ConvertedElemType}, Ints);
5867
}
5968
case llvm::dxil::ResourceClass::CBuffer:
6069
llvm_unreachable("dx.CBuffer handles are not implemented yet");

llvm/lib/IR/Type.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -799,10 +799,10 @@ TargetExtType::TargetExtType(LLVMContext &C, StringRef Name,
799799
// so we should convert any named struct types to anonymous
800800
// struct types in the parameter list
801801
Type *ConvertedTy = T;
802-
if (auto *STy = dyn_cast<StructType>(T)) {
803-
if (STy->hasName())
804-
ConvertedTy = StructType::get(C, STy->elements(), /*isPacked=*/false);
805-
}
802+
if (auto *STy = dyn_cast<StructType>(T))
803+
assert(!STy->hasName() &&
804+
"named structs are not allowed in target extension types");
805+
806806
*Params++ = ConvertedTy;
807807
}
808808

0 commit comments

Comments
 (0)