diff --git a/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp b/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp --- a/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp +++ b/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp @@ -1729,29 +1729,31 @@ // Verifier for LLVM::AddressOfOp. //===----------------------------------------------------------------------===// -template -static OpTy lookupSymbolInModule(Operation *parent, StringRef name) { +static Operation *lookupSymbolInModule(Operation *parent, StringRef name) { Operation *module = parent; while (module && !satisfiesLLVMModule(module)) module = module->getParentOp(); assert(module && "unexpected operation outside of a module"); - return dyn_cast_or_null( - mlir::SymbolTable::lookupSymbolIn(module, name)); + return mlir::SymbolTable::lookupSymbolIn(module, name); } GlobalOp AddressOfOp::getGlobal() { - return lookupSymbolInModule((*this)->getParentOp(), - getGlobalName()); + return dyn_cast_or_null( + lookupSymbolInModule((*this)->getParentOp(), getGlobalName())); } LLVMFuncOp AddressOfOp::getFunction() { - return lookupSymbolInModule((*this)->getParentOp(), - getGlobalName()); + return dyn_cast_or_null( + lookupSymbolInModule((*this)->getParentOp(), getGlobalName())); } LogicalResult AddressOfOp::verify() { - auto global = getGlobal(); - auto function = getFunction(); + Operation *symbol = + lookupSymbolInModule((*this)->getParentOp(), getGlobalName()); + + auto global = dyn_cast_or_null(symbol); + auto function = dyn_cast_or_null(symbol); + if (!global && !function) return emitOpError( "must reference a global defined by 'llvm.mlir.global' or 'llvm.func'");