From 9c7537daae43a49ea154300f5b51246888b0cc53 Mon Sep 17 00:00:00 2001 From: Brian Atkinson Date: Wed, 19 Feb 2020 16:37:06 -0800 Subject: [PATCH] Use io::JoinPath to build paths and avoid `\` when constructing file names. JoinPath is being made to deal with different OS path separators. Defaulting to `/` doesn't work in all cases. As an example, on Windows, when a `\` is in a path, `/` is no longer considered a path separator which is why we want to avoid it in filenames. PiperOrigin-RevId: 296086151 Change-Id: Ib2dfef55e9e779ff5138f960dc462fce8a14833b --- .../compiler/mlir/tensorflow/utils/dump_mlir_util.cc | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/tensorflow/compiler/mlir/tensorflow/utils/dump_mlir_util.cc b/tensorflow/compiler/mlir/tensorflow/utils/dump_mlir_util.cc index f06734a26bd..1b8ae8403bf 100644 --- a/tensorflow/compiler/mlir/tensorflow/utils/dump_mlir_util.cc +++ b/tensorflow/compiler/mlir/tensorflow/utils/dump_mlir_util.cc @@ -43,7 +43,8 @@ std::string MakeUniqueFilename(string name) { // Remove illegal characters from `name`. for (int i = 0; i < name.size(); ++i) { char ch = name[i]; - if (ch == '/' || ch == '[' || ch == ']' || ch == '*' || ch == '?') { + if (ch == '/' || ch == '[' || ch == ']' || ch == '*' || ch == '?' || + ch == '\\') { name[i] = '_'; } } @@ -123,10 +124,7 @@ Status CreateFileForDumping(llvm::StringRef name, << "' directory for dumping: " << status; return Status(error::Code::UNAVAILABLE, "(unavailable)"); } - *filepath = llvm::Twine(dir) - .concat("/") - .concat(MakeUniqueFilename(std::string(name))) - .str(); + *filepath = io::JoinPath(dir, MakeUniqueFilename(std::string(name))); // Try to open the file and generate a raw_ostream. std::unique_ptr file;