Skip to content

Commit c575a7d

Browse files
authored
[AMDGPU] Provide default value in get intrinsic param type (#122448)
Make sure that a default value (nullptr) is returned from `getIntrinsicParamType`, also validate uses of this helper function.
1 parent cfee344 commit c575a7d

File tree

1 file changed

+34
-16
lines changed

1 file changed

+34
-16
lines changed

llvm/lib/Target/AMDGPU/AMDGPULibFunc.cpp

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -929,23 +929,38 @@ AMDGPULibFuncBase::Param AMDGPULibFuncBase::Param::getFromTy(Type *Ty,
929929
return P;
930930
}
931931

932-
static Type* getIntrinsicParamType(
933-
LLVMContext& C,
934-
const AMDGPULibFunc::Param& P,
935-
bool useAddrSpace) {
936-
Type* T = nullptr;
932+
static Type *getIntrinsicParamType(LLVMContext &C,
933+
const AMDGPULibFunc::Param &P,
934+
bool UseAddrSpace) {
935+
Type *T = nullptr;
937936
switch (P.ArgType) {
937+
default:
938+
return nullptr;
938939
case AMDGPULibFunc::U8:
939-
case AMDGPULibFunc::I8: T = Type::getInt8Ty(C); break;
940+
case AMDGPULibFunc::I8:
941+
T = Type::getInt8Ty(C);
942+
break;
940943
case AMDGPULibFunc::U16:
941-
case AMDGPULibFunc::I16: T = Type::getInt16Ty(C); break;
944+
case AMDGPULibFunc::I16:
945+
T = Type::getInt16Ty(C);
946+
break;
942947
case AMDGPULibFunc::U32:
943-
case AMDGPULibFunc::I32: T = Type::getInt32Ty(C); break;
948+
case AMDGPULibFunc::I32:
949+
T = Type::getInt32Ty(C);
950+
break;
944951
case AMDGPULibFunc::U64:
945-
case AMDGPULibFunc::I64: T = Type::getInt64Ty(C); break;
946-
case AMDGPULibFunc::F16: T = Type::getHalfTy(C); break;
947-
case AMDGPULibFunc::F32: T = Type::getFloatTy(C); break;
948-
case AMDGPULibFunc::F64: T = Type::getDoubleTy(C); break;
952+
case AMDGPULibFunc::I64:
953+
T = Type::getInt64Ty(C);
954+
break;
955+
case AMDGPULibFunc::F16:
956+
T = Type::getHalfTy(C);
957+
break;
958+
case AMDGPULibFunc::F32:
959+
T = Type::getFloatTy(C);
960+
break;
961+
case AMDGPULibFunc::F64:
962+
T = Type::getDoubleTy(C);
963+
break;
949964

950965
case AMDGPULibFunc::IMG1DA:
951966
case AMDGPULibFunc::IMG1DB:
@@ -972,7 +987,7 @@ static Type* getIntrinsicParamType(
972987
T = FixedVectorType::get(T, P.VectorSize);
973988
if (P.PtrKind != AMDGPULibFunc::BYVALUE)
974989
T = PointerType::get(
975-
C, useAddrSpace ? ((P.PtrKind & AMDGPULibFunc::ADDR_SPACE) - 1) : 0);
990+
C, UseAddrSpace ? ((P.PtrKind & AMDGPULibFunc::ADDR_SPACE) - 1) : 0);
976991
return T;
977992
}
978993

@@ -989,9 +1004,11 @@ FunctionType *AMDGPUMangledLibFunc::getFunctionType(const Module &M) const {
9891004
Args.push_back(ParamTy);
9901005
}
9911006

992-
return FunctionType::get(
993-
getIntrinsicParamType(C, getRetType(FuncId, Leads), true),
994-
Args, false);
1007+
Type *RetTy = getIntrinsicParamType(C, getRetType(FuncId, Leads), true);
1008+
if (!RetTy)
1009+
return nullptr;
1010+
1011+
return FunctionType::get(RetTy, Args, false);
9951012
}
9961013

9971014
unsigned AMDGPUMangledLibFunc::getNumArgs() const {
@@ -1080,6 +1097,7 @@ FunctionCallee AMDGPULibFunc::getOrInsertFunction(Module *M,
10801097
}
10811098

10821099
FunctionType *FuncTy = fInfo.getFunctionType(*M);
1100+
assert(FuncTy);
10831101

10841102
bool hasPtr = false;
10851103
for (FunctionType::param_iterator

0 commit comments

Comments
 (0)