diff --git a/mlir/include/mlir/IR/OwningOpRef.h b/mlir/include/mlir/IR/OwningOpRef.h --- a/mlir/include/mlir/IR/OwningOpRef.h +++ b/mlir/include/mlir/IR/OwningOpRef.h @@ -49,7 +49,17 @@ /// Allow accessing the internal op. OpTy get() const { return op; } OpTy operator*() const { return op; } - OpTy *operator->() { return &op; } + /// Specialize for the case where OpTy is a pointer, to allow using + /// OwningOpRef. + template + typename std::enable_if::value, Op *>::type + operator->() { + return &op; + } + template + typename std::enable_if::value, Op>::type operator->() { + return op; + } explicit operator bool() const { return op; } /// Downcast to generic operation. diff --git a/mlir/lib/Tools/mlir-lsp-server/MLIRServer.cpp b/mlir/lib/Tools/mlir-lsp-server/MLIRServer.cpp --- a/mlir/lib/Tools/mlir-lsp-server/MLIRServer.cpp +++ b/mlir/lib/Tools/mlir-lsp-server/MLIRServer.cpp @@ -1322,13 +1322,13 @@ // Extract the top-level op so that aliases get printed. // FIXME: We should be able to enable aliases without having to do this! OwningOpRef topOp = &parsedBlock.front(); - (*topOp)->remove(); + topOp->remove(); AsmState state(*topOp, OpPrintingFlags().enableDebugInfo().assumeVerified(), /*locationMap=*/nullptr, &fallbackResourceMap); llvm::raw_string_ostream os(result.output); - (*topOp)->print(os, state); + topOp->print(os, state); } return std::move(result); }