Skip to content

Commit 8371222

Browse files
mahmood82Mahmood Yassin
andauthored
[CIR] Fix handling of varargs and void-return builtins in intrinsic t… (#2021)
Fix several issues in CIR intrinsic type construction for built-in functions such as printf (variadic) and void-return intrinsics. - Treat IITDescriptor::VarArg as a terminator marker rather than a type. It is now handled correctly in getIntrinsicType instead of decodeFixedType. - Added support for marking CIR function types as variadic. - Added proper handling of builtins returning void: CIRFuncType now omits an explicit void return type when appropriate. - Ensures correct CIR signatures for OpenCL and C built-ins that use ellipsis (printf) or return void (e.g. printf). Co-authored-by: Mahmood Yassin <[email protected]>
1 parent e8f6d60 commit 8371222

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,8 @@ decodeFixedType(ArrayRef<llvm::Intrinsic::IITDescriptor> &infos,
475475
case IITDescriptor::Void:
476476
return VoidType::get(context);
477477
case IITDescriptor::VarArg:
478-
llvm_unreachable("NYI: IITDescriptor::VarArg");
478+
// VarArg isn't a type, just a marker. The caller should handle it.
479+
llvm_unreachable("VarArg should be handled by getIntrinsicType, not here");
479480
case IITDescriptor::MMX:
480481
llvm_unreachable("NYI: IITDescriptor::MMX");
481482
case IITDescriptor::Token:
@@ -577,10 +578,22 @@ static cir::FuncType getIntrinsicType(mlir::MLIRContext *context,
577578
mlir::Type resultTy = decodeFixedType(tableRef, context);
578579

579580
SmallVector<mlir::Type, 8> argTypes;
580-
while (!tableRef.empty())
581+
bool isVarArg = false;
582+
while (!tableRef.empty()) {
583+
auto kind = tableRef.front().Kind;
584+
if (kind == IITDescriptor::VarArg) {
585+
isVarArg = true;
586+
break; // VarArg is last
587+
}
581588
argTypes.push_back(decodeFixedType(tableRef, context));
589+
}
590+
591+
// CIR convention: no explicit void return type
592+
if (isa<cir::VoidType>(resultTy))
593+
return FuncType::get(context, argTypes, /*optionalReturnType=*/nullptr,
594+
isVarArg);
582595

583-
return FuncType::get(argTypes, resultTy);
596+
return cir::FuncType::get(context, argTypes, resultTy, isVarArg);
584597
}
585598

586599
RValue CIRGenFunction::emitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,

0 commit comments

Comments
 (0)