diff --git a/mlir/lib/Target/LLVMIR/ConvertToLLVMIR.cpp b/mlir/lib/Target/LLVMIR/ConvertToLLVMIR.cpp index c473e3c05877..6a4ab56f6645 100644 --- a/mlir/lib/Target/LLVMIR/ConvertToLLVMIR.cpp +++ b/mlir/lib/Target/LLVMIR/ConvertToLLVMIR.cpp @@ -83,8 +83,8 @@ private: // MLIR LLVM IR dialect types. Use `loc` as a location when reporting errors. // Return nullptr on errors. static llvm::FunctionType *convertFunctionType(llvm::LLVMContext &llvmContext, - FunctionType type, - Location loc) { + FunctionType type, Location loc, + bool isVarArgs) { assert(type && "expected non-null type"); auto context = type.getContext(); @@ -105,14 +105,14 @@ static llvm::FunctionType *convertFunctionType(llvm::LLVMContext &llvmContext, if (type.getNumResults() == 0) return llvm::FunctionType::get(llvm::Type::getVoidTy(llvmContext), argTypes, - /*isVarArg=*/false); + isVarArgs); auto wrappedResultType = type.getResult(0).dyn_cast(); if (!wrappedResultType) return context->emitError(loc, "non-LLVM function result"), nullptr; return llvm::FunctionType::get(wrappedResultType.getUnderlyingType(), - argTypes, /*isVarArg=*/false); + argTypes, isVarArgs); } // Create an LLVM IR constant of `llvmType` from the MLIR attribute `attr`. @@ -417,8 +417,12 @@ bool ModuleTranslation::convertFunctions() { // call graph with cycles. for (Function &function : mlirModule) { Function *functionPtr = &function; - llvm::FunctionType *functionType = convertFunctionType( - llvmModule->getContext(), function.getType(), function.getLoc()); + mlir::BoolAttr isVarArgsAttr = + function.getAttrOfType("std.varargs"); + bool isVarArgs = isVarArgsAttr && isVarArgsAttr.getValue(); + llvm::FunctionType *functionType = + convertFunctionType(llvmModule->getContext(), function.getType(), + function.getLoc(), isVarArgs); if (!functionType) return true; llvm::FunctionCallee llvmFuncCst = diff --git a/mlir/test/Target/llvmir.mlir b/mlir/test/Target/llvmir.mlir index 380ab9adf569..b3dcda8ec3f9 100644 --- a/mlir/test/Target/llvmir.mlir +++ b/mlir/test/Target/llvmir.mlir @@ -793,3 +793,7 @@ func @cond_br_arguments(%arg0: !llvm.i1, %arg1: !llvm.i1) { func @llvm_noalias(%arg0: !llvm<"float*"> {llvm.noalias: true}) { llvm.return } + +// CHECK-LABEL: @llvm_varargs(...) +func @llvm_varargs() + attributes {std.varargs: true}