Issue 137622
Summary `--mlir-print-ir-tree-dir` fails with "Error while creating directory ...: No such file or directory" if symbol name contains path separator
Labels new issue
Assignees
Reporter i-ky
    Consider the following example MLIR code in `/tmp/test.mlir`:
```mlir
module @"/foo/bar/" {}
```

Running `mlir-opt --canonicalize --mlir-print-ir-before-all --mlir-print-ir-after-all /tmp/test.mlir` outputs the following (as expected):
```
// -----// IR Dump Before Canonicalizer (canonicalize) //----- //
module @"/foo/bar/" {
}


// -----// IR Dump After Canonicalizer (canonicalize) //----- //
module @"/foo/bar/" {
}


module @"/foo/bar/" {
}

```

But when `--mlir-print-ir-tree-dir=/tmp/test` is added to the command - `mlir-opt --canonicalize --mlir-print-ir-before-all --mlir-print-ir-after-all --mlir-print-ir-tree-dir=/tmp/test /tmp/test.mlir` - the output is the following (note the errors):
```
Error while creating directory /tmp/test/builtin_module_/foo/bar/: No such file or directory
Error while creating directory /tmp/test/builtin_module_/foo/bar/: No such file or directory
module @"/foo/bar/" {
}

```
...and the `/tmp/test/` directory is empty.

There is no issue if `/` is swapped for `\` (I am on MacOS, on Windows it may be the opposite):
```
mlir-opt --canonicalize --mlir-print-ir-before-all --mlir-print-ir-after-all --mlir-print-ir-tree-dir=/tmp/test /tmp/test.mlir
module @"\\foo\\bar\\" {
}

tree /tmp/test                                                                                                                                              
/tmp/test
└── builtin_module_\foo\bar\
    ├── 0_canonicalize.mlir
    └── 1_canonicalize.mlir

2 directories, 2 files
```

The code responsible for generating paths is sanitizing op names by replacing `.` with `_`, but does nothing to symbol names:
https://github.com/llvm/llvm-project/blob/e086d7b1464ad091ae849cb907f8647c8439cb66/mlir/lib/Pass/IRPrinting.cpp#L207-L240

[Symbol names can be string literals](https://mlir.llvm.org/docs/LangRef/#identifiers-and-keywords), so there is a need to sanitize them before using in filesystem paths.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to