@@ -80,7 +80,7 @@ class FuncOpLowering : public OpConversionPattern<cxx::FuncOp> {
80
80
? LLVM::LLVMVoidType::get (getContext ())
81
81
: resultTypes.front ();
82
82
83
- const auto isVarArg = false ;
83
+ const auto isVarArg = funcType. getVariadic () ;
84
84
85
85
auto llvmFuncType =
86
86
LLVM::LLVMFunctionType::get (returnType, argumentTypes, isVarArg);
@@ -159,6 +159,12 @@ class CallOpLowering : public OpConversionPattern<cxx::CallOp> {
159
159
auto llvmCallOp = rewriter.create <LLVM::CallOp>(
160
160
op.getLoc (), resultTypes, adaptor.getCallee (), adaptor.getInputs ());
161
161
162
+ if (op.getVarCalleeType ().has_value ()) {
163
+ auto varCalleeType =
164
+ typeConverter->convertType (op.getVarCalleeType ().value ());
165
+ llvmCallOp.setVarCalleeType (cast<LLVM::LLVMFunctionType>(varCalleeType));
166
+ }
167
+
162
168
rewriter.replaceOp (op, llvmCallOp);
163
169
return success ();
164
170
}
@@ -1251,6 +1257,28 @@ void CxxToLLVMLoweringPass::runOnOperation() {
1251
1257
return LLVM::LLVMArrayType::get (elementType, size);
1252
1258
});
1253
1259
1260
+ typeConverter.addConversion ([&](cxx::FunctionType type) -> Type {
1261
+ SmallVector<Type> inputs;
1262
+ for (auto argType : type.getInputs ()) {
1263
+ auto convertedType = typeConverter.convertType (argType);
1264
+ inputs.push_back (convertedType);
1265
+ }
1266
+ SmallVector<Type> results;
1267
+ for (auto resultType : type.getResults ()) {
1268
+ auto convertedType = typeConverter.convertType (resultType);
1269
+ results.push_back (convertedType);
1270
+ }
1271
+ if (results.size () > 1 ) {
1272
+ return {};
1273
+ }
1274
+ if (results.empty ()) {
1275
+ results.push_back (LLVM::LLVMVoidType::get (type.getContext ()));
1276
+ }
1277
+ auto context = type.getContext ();
1278
+ return LLVM::LLVMFunctionType::get (context, results.front (), inputs,
1279
+ type.getVariadic ());
1280
+ });
1281
+
1254
1282
DenseMap<cxx::ClassType, Type> convertedClassTypes;
1255
1283
typeConverter.addConversion ([&](cxx::ClassType type) -> Type {
1256
1284
if (auto it = convertedClassTypes.find (type);
0 commit comments