diff options
| author | River Riddle <riverriddle@google.com> | 2019-08-29 22:19:29 -0700 |
|---|---|---|
| committer | A. Unique TensorFlower <gardener@tensorflow.org> | 2019-08-29 22:20:10 -0700 |
| commit | 3ee3710fd1da25631eb99c2fe58360ccecd3d703 (patch) | |
| tree | 363c338e4d9d71c37f6791d8c170c5ac583f6756 /mlir/lib/Parser | |
| parent | 4bfae66d70aea0df4bf9948e51f4bfa8895a4f4e (diff) | |
| download | bcm5719-llvm-3ee3710fd1da25631eb99c2fe58360ccecd3d703.tar.gz bcm5719-llvm-3ee3710fd1da25631eb99c2fe58360ccecd3d703.zip | |
Change the parseSource* methods to return OwningModuleRef instead of ModuleOp.
This avoids potential memory leaks from misuse of the API.
PiperOrigin-RevId: 266305750
Diffstat (limited to 'mlir/lib/Parser')
| -rw-r--r-- | mlir/lib/Parser/Parser.cpp | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/mlir/lib/Parser/Parser.cpp b/mlir/lib/Parser/Parser.cpp index dde24e4cdb4..a6ccd76e806 100644 --- a/mlir/lib/Parser/Parser.cpp +++ b/mlir/lib/Parser/Parser.cpp @@ -4133,8 +4133,8 @@ ParseResult ModuleParser::parseModule(ModuleOp module) { /// This parses the file specified by the indicated SourceMgr and returns an /// MLIR module if it was valid. If not, it emits diagnostics and returns /// null. -ModuleOp mlir::parseSourceFile(const llvm::SourceMgr &sourceMgr, - MLIRContext *context) { +OwningModuleRef mlir::parseSourceFile(const llvm::SourceMgr &sourceMgr, + MLIRContext *context) { auto sourceBuf = sourceMgr.getMemoryBuffer(sourceMgr.getMainFileID()); // This is the result module we are parsing into. @@ -4150,13 +4150,14 @@ ModuleOp mlir::parseSourceFile(const llvm::SourceMgr &sourceMgr, if (failed(verify(*module))) return nullptr; - return module.release(); + return module; } /// This parses the file specified by the indicated filename and returns an /// MLIR module if it was valid. If not, the error message is emitted through /// the error handler registered in the context, and a null pointer is returned. -ModuleOp mlir::parseSourceFile(StringRef filename, MLIRContext *context) { +OwningModuleRef mlir::parseSourceFile(StringRef filename, + MLIRContext *context) { llvm::SourceMgr sourceMgr; return parseSourceFile(filename, sourceMgr, context); } @@ -4165,8 +4166,9 @@ ModuleOp mlir::parseSourceFile(StringRef filename, MLIRContext *context) { /// SourceMgr and returns an MLIR module if it was valid. If not, the error /// message is emitted through the error handler registered in the context, and /// a null pointer is returned. -ModuleOp mlir::parseSourceFile(StringRef filename, llvm::SourceMgr &sourceMgr, - MLIRContext *context) { +OwningModuleRef mlir::parseSourceFile(StringRef filename, + llvm::SourceMgr &sourceMgr, + MLIRContext *context) { if (sourceMgr.getNumBuffers() != 0) { // TODO(b/136086478): Extend to support multiple buffers. emitError(mlir::UnknownLoc::get(context), @@ -4187,7 +4189,8 @@ ModuleOp mlir::parseSourceFile(StringRef filename, llvm::SourceMgr &sourceMgr, /// This parses the program string to a MLIR module if it was valid. If not, /// it emits diagnostics and returns null. -ModuleOp mlir::parseSourceString(StringRef moduleStr, MLIRContext *context) { +OwningModuleRef mlir::parseSourceString(StringRef moduleStr, + MLIRContext *context) { auto memBuffer = MemoryBuffer::getMemBuffer(moduleStr); if (!memBuffer) return nullptr; |

