Skip to content

Commit

Permalink
Fix segfault (nullptr dereference) when passing a non-existent file t…
Browse files Browse the repository at this point in the history
…o the Toy tutorial compiler

Fix tensorflow/mlir#229

PiperOrigin-RevId: 279557863
  • Loading branch information
joker-eph authored and tensorflower-gardener committed Nov 10, 2019
1 parent 1328f93 commit 85612fe
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 0 deletions.
2 changes: 2 additions & 0 deletions mlir/examples/toy/Ch2/toyc.cpp
Expand Up @@ -85,6 +85,8 @@ int dumpMLIR() {
if (inputType != InputType::MLIR &&
!llvm::StringRef(inputFilename).endswith(".mlir")) {
auto moduleAST = parseInputFile(inputFilename);
if (!moduleAST)
return 6;
mlir::OwningModuleRef module = mlirGen(context, *moduleAST);
if (!module)
return 1;
Expand Down
2 changes: 2 additions & 0 deletions mlir/examples/toy/Ch3/toyc.cpp
Expand Up @@ -85,6 +85,8 @@ int loadMLIR(llvm::SourceMgr &sourceMgr, mlir::MLIRContext &context,
if (inputType != InputType::MLIR &&
!llvm::StringRef(inputFilename).endswith(".mlir")) {
auto moduleAST = parseInputFile(inputFilename);
if (!moduleAST)
return 6;
module = mlirGen(context, *moduleAST);
return !module ? 1 : 0;
}
Expand Down
2 changes: 2 additions & 0 deletions mlir/examples/toy/Ch4/toyc.cpp
Expand Up @@ -86,6 +86,8 @@ int loadMLIR(llvm::SourceMgr &sourceMgr, mlir::MLIRContext &context,
if (inputType != InputType::MLIR &&
!llvm::StringRef(inputFilename).endswith(".mlir")) {
auto moduleAST = parseInputFile(inputFilename);
if (!moduleAST)
return 6;
module = mlirGen(context, *moduleAST);
return !module ? 1 : 0;
}
Expand Down
2 changes: 2 additions & 0 deletions mlir/examples/toy/Ch5/toyc.cpp
Expand Up @@ -88,6 +88,8 @@ int loadMLIR(llvm::SourceMgr &sourceMgr, mlir::MLIRContext &context,
if (inputType != InputType::MLIR &&
!llvm::StringRef(inputFilename).endswith(".mlir")) {
auto moduleAST = parseInputFile(inputFilename);
if (!moduleAST)
return 6;
module = mlirGen(context, *moduleAST);
return !module ? 1 : 0;
}
Expand Down
2 changes: 2 additions & 0 deletions mlir/examples/toy/Ch6/toyc.cpp
Expand Up @@ -106,6 +106,8 @@ int loadMLIR(mlir::MLIRContext &context, mlir::OwningModuleRef &module) {
if (inputType != InputType::MLIR &&
!llvm::StringRef(inputFilename).endswith(".mlir")) {
auto moduleAST = parseInputFile(inputFilename);
if (!moduleAST)
return 6;
module = mlirGen(context, *moduleAST);
return !module ? 1 : 0;
}
Expand Down
2 changes: 2 additions & 0 deletions mlir/examples/toy/Ch7/toyc.cpp
Expand Up @@ -106,6 +106,8 @@ int loadMLIR(mlir::MLIRContext &context, mlir::OwningModuleRef &module) {
if (inputType != InputType::MLIR &&
!llvm::StringRef(inputFilename).endswith(".mlir")) {
auto moduleAST = parseInputFile(inputFilename);
if (!moduleAST)
return 6;
module = mlirGen(context, *moduleAST);
return !module ? 1 : 0;
}
Expand Down

0 comments on commit 85612fe

Please sign in to comment.