[llvm] Add option to dump IR to files instead of stderr (PR #66412)

Sebastian Neubauer via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 26 02:39:37 PDT 2023


================
@@ -697,17 +754,42 @@ PrintIRInstrumentation::popModuleDesc(StringRef PassID) {
   return ModuleDesc;
 }
 
+// Callers are responsible for closing the returned file descriptor
+static int prepareDumpIRFileDescriptor(StringRef DumpIRFilename) {
+  std::error_code EC;
+  auto ParentPath = llvm::sys::path::parent_path(DumpIRFilename);
+  if (!ParentPath.empty()) {
+    std::error_code EC = llvm::sys::fs::create_directories(ParentPath);
+    if (EC)
+      report_fatal_error(Twine("Failed to create directory ") + ParentPath +
+                         " to support -ir-dump-directory: " + EC.message());
+  }
+  int Result = 0;
+  EC =
+      sys::fs::openFile(DumpIRFilename, Result, sys::fs::CD_OpenAlways,
+                        sys::fs::FA_Write | sys::fs::FA_Read, sys::fs::OF_None);
----------------
Flakebi wrote:

This should only request Write.
The enum here is **not** for permissions to create this file, instead it depicts the mode to open the file. We are only going to write into the file, so we only need to open in in write mode.

https://github.com/llvm/llvm-project/pull/66412


More information about the llvm-commits mailing list