diff --git a/mlir/lib/Target/LLVMIR/ModuleImport.cpp b/mlir/lib/Target/LLVMIR/ModuleImport.cpp --- a/mlir/lib/Target/LLVMIR/ModuleImport.cpp +++ b/mlir/lib/Target/LLVMIR/ModuleImport.cpp @@ -761,8 +761,8 @@ // Returns the static shape of the provided type if possible. auto getConstantShape = [&](llvm::Type *type) { - return llvm::dyn_cast_if_present(getBuiltinTypeForAttr(convertType(type)) - ); + return llvm::dyn_cast_if_present( + getBuiltinTypeForAttr(convertType(type))); }; // Convert one-dimensional constant arrays or vectors that store 1/2/4/8-byte @@ -829,8 +829,8 @@ // Convert zero aggregates. if (auto *constZero = dyn_cast(constant)) { - auto shape = llvm::dyn_cast_if_present(getBuiltinTypeForAttr(convertType(constZero->getType())) - ); + auto shape = llvm::dyn_cast_if_present( + getBuiltinTypeForAttr(convertType(constZero->getType()))); if (!shape) return {}; // Convert zero aggregates with a static shape to splat elements attributes. @@ -1683,6 +1683,8 @@ // Convert the result attributes and attach them wrapped in an ArrayAttribute // to the funcOp. llvm::AttributeSet llvmResAttr = llvmAttrs.getRetAttrs(); + if (!llvmResAttr.hasAttributes()) + return; funcOp.setResAttrsAttr( builder.getArrayAttr(convertParameterAttribute(llvmResAttr, builder))); } diff --git a/mlir/test/Target/LLVMIR/Import/function-attributes-generic.ll b/mlir/test/Target/LLVMIR/Import/function-attributes-generic.ll new file mode 100644 --- /dev/null +++ b/mlir/test/Target/LLVMIR/Import/function-attributes-generic.ll @@ -0,0 +1,9 @@ +; RUN: mlir-translate -import-llvm -split-input-file %s --mlir-print-op-generic | FileCheck %s + +; Ensure that no empty parameter attribute lists are created. +; CHECK: "llvm.func" +; CHECK-SAME: <{ +; CHECK-NOT: arg_attr +; CHECK-NOT: res_attrs +; CHECK-SAME: }> +declare ptr @func_no_param_attrs()