Author: Alan Zhao
Date: 2025-04-30T14:48:17-07:00
New Revision: 69327c16d17b13cb2bc27968a557276bd82eef9a

URL: 
https://github.com/llvm/llvm-project/commit/69327c16d17b13cb2bc27968a557276bd82eef9a
DIFF: 
https://github.com/llvm/llvm-project/commit/69327c16d17b13cb2bc27968a557276bd82eef9a.diff

LOG: [clang] Make `-ftime-report` and `-ftime-report-json` honor 
`-info-output-file` (#138035)

This way, the output of `-ftime-report` and `-ftime-report-json` can be
redirected to a specific file rather than just stderr.

Added: 
    

Modified: 
    clang/test/Misc/time-passes.c
    clang/tools/driver/cc1_main.cpp

Removed: 
    


################################################################################
diff  --git a/clang/test/Misc/time-passes.c b/clang/test/Misc/time-passes.c
index 35b5e1634ee73..370f52e4904fe 100644
--- a/clang/test/Misc/time-passes.c
+++ b/clang/test/Misc/time-passes.c
@@ -3,6 +3,10 @@
 // RUN:     -ftime-report %s -o /dev/null 2>&1 | \
 // RUN:     FileCheck %s --check-prefixes=TIME,NPM
 // RUN: %clang_cc1 -emit-obj -O1 \
+// RUN:     -ftime-report %s -o /dev/null \
+// RUN:     -mllvm -info-output-file=%t
+// RUN: cat %t | FileCheck %s --check-prefixes=TIME,NPM
+// RUN: %clang_cc1 -emit-obj -O1 \
 // RUN:     -ftime-report=per-pass %s -o /dev/null 2>&1 | \
 // RUN:     FileCheck %s --check-prefixes=TIME,NPM
 // RUN: %clang_cc1 -emit-obj -O1 \
@@ -11,6 +15,10 @@
 // RUN: %clang_cc1 -emit-obj -O1 \
 // RUN:     -ftime-report-json %s -o /dev/null 2>&1 | \
 // RUN:     FileCheck %s --check-prefixes=JSON
+// RUN: %clang_cc1 -emit-obj -O1 \
+// RUN:     -ftime-report-json %s -o /dev/null \
+// RUN:     -mllvm -info-output-file=%t
+// RUN: cat %t | FileCheck %s --check-prefixes=JSON
 
 // TIME: Pass execution timing report
 // TIME: Total Execution Time:

diff  --git a/clang/tools/driver/cc1_main.cpp b/clang/tools/driver/cc1_main.cpp
index 1e79e78fdea62..dd53712bcfc96 100644
--- a/clang/tools/driver/cc1_main.cpp
+++ b/clang/tools/driver/cc1_main.cpp
@@ -296,12 +296,13 @@ int cc1_main(ArrayRef<const char *> Argv, const char 
*Argv0, void *MainAddr) {
 
   // If any timers were active but haven't been destroyed yet, print their
   // results now.  This happens in -disable-free mode.
+  std::unique_ptr<raw_ostream> IOFile = llvm::CreateInfoOutputFile();
   if (Clang->getCodeGenOpts().TimePassesJson) {
-    llvm::errs() << "{\n";
-    llvm::TimerGroup::printAllJSONValues(llvm::errs(), "");
-    llvm::errs() << "\n}\n";
+    *IOFile << "{\n";
+    llvm::TimerGroup::printAllJSONValues(*IOFile, "");
+    *IOFile << "\n}\n";
   } else {
-    llvm::TimerGroup::printAll(llvm::errs());
+    llvm::TimerGroup::printAll(*IOFile);
   }
   llvm::TimerGroup::clearAll();
 


        
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to