aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Support/GraphWriter.cpp
diff options
context:
space:
mode:
authorJustice Adams <justice.adams@sony.com>2020-05-05 16:58:44 -0700
committerReid Kleckner <rnk@google.com>2020-05-05 17:01:05 -0700
commit89c7451c35919a95aa654c6ff5204d3ceb37dd3d (patch)
tree9a910d294ba41e9b05eef9238fcb79957a31dae5 /llvm/lib/Support/GraphWriter.cpp
parent0274c797c65a720010aee7f40cff621cd993ba15 (diff)
downloadllvm-89c7451c35919a95aa654c6ff5204d3ceb37dd3d.zip
llvm-89c7451c35919a95aa654c6ff5204d3ceb37dd3d.tar.gz
llvm-89c7451c35919a95aa654c6ff5204d3ceb37dd3d.tar.bz2
Fix SelectionDAG Graph Printing on Windows
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. Reviewed By: rnk Differential Revision: https://reviews.llvm.org/D76863
Diffstat (limited to 'llvm/lib/Support/GraphWriter.cpp')
-rw-r--r--llvm/lib/Support/GraphWriter.cpp27
1 files changed, 26 insertions, 1 deletions
diff --git a/llvm/lib/Support/GraphWriter.cpp b/llvm/lib/Support/GraphWriter.cpp
index 214a903..d8aae92 100644
--- a/llvm/lib/Support/GraphWriter.cpp
+++ b/llvm/lib/Support/GraphWriter.cpp
@@ -76,10 +76,35 @@ StringRef llvm::DOT::getColorString(unsigned ColorNumber) {
return Colors[ColorNumber % NumColors];
}
+static std::string replaceIllegalFilenameChars(std::string Filename,
+ const char ReplacementChar) {
+#ifdef _WIN32
+ std::string IllegalChars = "\\/:?\"<>|";
+#else
+ std::string IllegalChars = "/";
+#endif
+
+ for (char IllegalChar : IllegalChars) {
+ std::replace(Filename.begin(), Filename.end(), IllegalChar,
+ ReplacementChar);
+ }
+
+ 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);
+
+ // Windows can't always handle long paths, so limit the length of the name.
+ std::string N = Name.str();
+ N = N.substr(0, std::min<std::size_t>(N.size(), 140));
+
+ // Replace illegal characters in graph Filename with '_' if needed
+ std::string CleansedName = replaceIllegalFilenameChars(N, '_');
+
+ std::error_code EC =
+ sys::fs::createTemporaryFile(CleansedName, "dot", FD, Filename);
if (EC) {
errs() << "Error: " << EC.message() << "\n";
return "";