diff --git a/mlir/lib/Conversion/StandardToLLVM/StandardToLLVM.cpp b/mlir/lib/Conversion/StandardToLLVM/StandardToLLVM.cpp --- a/mlir/lib/Conversion/StandardToLLVM/StandardToLLVM.cpp +++ b/mlir/lib/Conversion/StandardToLLVM/StandardToLLVM.cpp @@ -266,6 +266,11 @@ // functions have linkage. LLVM::Linkage linkage = LLVM::Linkage::External; if (funcOp->hasAttr("llvm.linkage")) { + auto attr = funcOp->getAttr("llvm.linkage"); + if (!attr.isa()) { + funcOp->emitError() << "Contains llvm.linkage attribute not of type LLVM::LinkageAttr"; + return nullptr; + } linkage = funcOp->getAttr("llvm.linkage") .cast() .getLinkage(); diff --git a/mlir/test/Conversion/StandardToLLVM/convert-funcs.mlir b/mlir/test/Conversion/StandardToLLVM/convert-funcs.mlir --- a/mlir/test/Conversion/StandardToLLVM/convert-funcs.mlir +++ b/mlir/test/Conversion/StandardToLLVM/convert-funcs.mlir @@ -1,4 +1,4 @@ -// RUN: mlir-opt -convert-std-to-llvm %s | FileCheck %s +// RUN: mlir-opt -convert-std-to-llvm -split-input-file -verify-diagnostics %s | FileCheck %s //CHECK: llvm.func @second_order_arg(!llvm.ptr>) func private @second_order_arg(%arg0 : () -> ()) @@ -40,6 +40,7 @@ // CHECK-LABEL: llvm.func extern_weak @llvmlinkage(i32) func private @llvmlinkage(i32) attributes { "llvm.linkage" = #llvm.linkage } + // CHECK-LABEL: llvm.func @body(i32) func private @body(i32) @@ -62,3 +63,6 @@ return %0 : i32 } +// ----- + +func private @badllvmlinkage(i32) attributes { "llvm.linkage" = 3 : i64 } // expected-error {{Contains llvm.linkage attribute not of type LLVM::LinkageAttr}}