[llvm] 777a67b - PR#72453 : Exceeding maximum file name length (#72654)

via llvm-commits llvm-commits at lists.llvm.org
Sun Jan 14 04:54:29 PST 2024


Author: Shahid Iqbal
Date: 2024-01-14T18:24:24+05:30
New Revision: 777a67b2d9fbf9a871d8951e6e7fd0f9f16ea54b

URL: https://github.com/llvm/llvm-project/commit/777a67b2d9fbf9a871d8951e6e7fd0f9f16ea54b
DIFF: https://github.com/llvm/llvm-project/commit/777a67b2d9fbf9a871d8951e6e7fd0f9f16ea54b.diff

LOG: PR#72453 : Exceeding maximum file name length (#72654)

Added: 
    

Modified: 
    llvm/include/llvm/Analysis/DOTGraphTraitsPass.h

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/Analysis/DOTGraphTraitsPass.h b/llvm/include/llvm/Analysis/DOTGraphTraitsPass.h
index 07c08bc1cc3bcb..182cc118670425 100644
--- a/llvm/include/llvm/Analysis/DOTGraphTraitsPass.h
+++ b/llvm/include/llvm/Analysis/DOTGraphTraitsPass.h
@@ -16,6 +16,9 @@
 #include "llvm/Analysis/CFGPrinter.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/GraphWriter.h"
+#include <unordered_set>
+
+static std::unordered_set<std::string> nameObj;
 
 namespace llvm {
 
@@ -83,10 +86,28 @@ struct DOTGraphTraitsViewer
   StringRef Name;
 };
 
+static void shortenFileName(std::string &FN, unsigned char len = 250) {
+
+  FN = FN.substr(0, len);
+
+  auto strLen = FN.length();
+  while (strLen > 0) {
+    if (auto it = nameObj.find(FN); it != nameObj.end()) {
+      FN = FN.substr(0, --len);
+    } else {
+      nameObj.insert(FN);
+      break;
+    }
+    strLen--;
+  }
+}
+
 template <typename GraphT>
 void printGraphForFunction(Function &F, GraphT Graph, StringRef Name,
                            bool IsSimple) {
-  std::string Filename = Name.str() + "." + F.getName().str() + ".dot";
+  std::string Filename = Name.str() + "." + F.getName().str();
+  shortenFileName(Filename);
+  Filename = Filename + ".dot";
   std::error_code EC;
 
   errs() << "Writing '" << Filename << "'...";
@@ -272,6 +293,7 @@ class DOTGraphTraitsModulePrinterWrapperPass : public ModulePass {
 
   bool runOnModule(Module &M) override {
     GraphT Graph = AnalysisGraphTraitsT::getGraph(&getAnalysis<AnalysisT>());
+    shortenFileName(Name);
     std::string Filename = Name + ".dot";
     std::error_code EC;
 
@@ -301,7 +323,9 @@ class DOTGraphTraitsModulePrinterWrapperPass : public ModulePass {
 template <typename GraphT>
 void WriteDOTGraphToFile(Function &F, GraphT &&Graph,
                          std::string FileNamePrefix, bool IsSimple) {
-  std::string Filename = FileNamePrefix + "." + F.getName().str() + ".dot";
+  std::string Filename = FileNamePrefix + "." + F.getName().str();
+  shortenFileName(Filename);
+  Filename = Filename + ".dot";
   std::error_code EC;
 
   errs() << "Writing '" << Filename << "'...";


        


More information about the llvm-commits mailing list