[PATCH] D76863: Fix SelectionDAG Graph Printing on Windows
Justice Adams via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Mar 26 09:45:53 PDT 2020
justice_adams created this revision.
justice_adams added a project: LLVM.
Herald added a subscriber: hiraditya.
Currently, when compiling to IR (presumably at the clang level) LLVM mangles symbols and sometimes they have illegal file characters including `?`'s in them. This causes a problem when building a graph via llc on Windows because the code currently passes the machine function name all the way down to the Windows API which frequently returns error 123 **ERROR_INVALID_NAME**
https://docs.microsoft.com/en-us/windows/win32/debug/system-error-codes--0-499-
Thus, we need to remove those illegal characters from the machine function name before generating a graph, which is the purpose of this patch.
https://docs.microsoft.com/en-us/windows/win32/fileio/naming-a-file
I've created a static helper function replace_illegal_filename_chars which within GraphWriter.cpp to help with replacing illegal file character names before generating a dot graph filename.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D76863
Files:
llvm/include/llvm/Support/GraphWriter.h
llvm/lib/Support/GraphWriter.cpp
Index: llvm/lib/Support/GraphWriter.cpp
===================================================================
--- llvm/lib/Support/GraphWriter.cpp
+++ llvm/lib/Support/GraphWriter.cpp
@@ -76,10 +76,32 @@
return Colors[ColorNumber % NumColors];
}
+static std::string
+llvm::replace_illegal_filename_chars(std::string filename,
+ const char replacement_char) {
+#ifdef _WIN32
+ std::string illegalChars = "\\/:?\"<>|";
+#else
+ std::string illegalChars = "/";
+#endif
+
+ for (std::string::iterator it = illegalChars.begin(); it < illegalChars.end();
+ ++it) {
+ std::replace(filename.begin(), filename.end(), *it, replacement_char);
+ }
+
+ return filename;
+}
+
std::string llvm::createGraphFilename(const Twine &Name, int &FD) {
FD = -1;
SmallString<128> Filename;
- std::error_code EC = sys::fs::createTemporaryFile(Name, "dot", FD, Filename);
+
+ // Replace illegal characters in graph filename with '_' if needed
+ std::string CleansedName = replace_illegal_filename_chars(Name.str(), '_');
+
+ std::error_code EC =
+ sys::fs::createTemporaryFile(CleansedName, "dot", FD, Filename);
if (EC) {
errs() << "Error: " << EC.message() << "\n";
return "";
Index: llvm/include/llvm/Support/GraphWriter.h
===================================================================
--- llvm/include/llvm/Support/GraphWriter.h
+++ llvm/include/llvm/Support/GraphWriter.h
@@ -318,6 +318,9 @@
return O;
}
+static std::string replace_illegal_filename_chars(std::string filename,
+ const char replacement_char);
+
std::string createGraphFilename(const Twine &Name, int &FD);
/// Writes graph into a provided {@code Filename}.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D76863.252879.patch
Type: text/x-patch
Size: 1749 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200326/b948169e/attachment.bin>
More information about the llvm-commits
mailing list