[clang] [Driver][LTO] Copy fix empty stats filename to AIX (PR #71738)

via cfe-commits cfe-commits at lists.llvm.org
Wed Nov 8 13:07:22 PST 2023


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang-driver

Author: None (diggerlin)

<details>
<summary>Changes</summary>

copy implement of https://github.com/llvm/llvm-project/pull/71359 to AIX.cpp and add test scenario

---
Full diff: https://github.com/llvm/llvm-project/pull/71738.diff


2 Files Affected:

- (modified) clang/lib/Driver/ToolChains/AIX.cpp (+9-1) 
- (modified) clang/test/Driver/save-stats.c (+9) 


``````````diff
diff --git a/clang/lib/Driver/ToolChains/AIX.cpp b/clang/lib/Driver/ToolChains/AIX.cpp
index 3e5ebafa15ebe1c..aed8734b2bab0ff 100644
--- a/clang/lib/Driver/ToolChains/AIX.cpp
+++ b/clang/lib/Driver/ToolChains/AIX.cpp
@@ -233,7 +233,15 @@ void aix::Linker::ConstructJob(Compilation &C, const JobAction &JA,
 
   if (D.isUsingLTO()) {
     assert(!Inputs.empty() && "Must have at least one input.");
-    addLTOOptions(ToolChain, Args, CmdArgs, Output, Inputs[0],
+    // Find the first filename InputInfo object.
+    auto Input = llvm::find_if(
+        Inputs, [](const InputInfo &II) -> bool { return II.isFilename(); });
+    if (Input == Inputs.end())
+      // For a very rare case, all of the inputs to the linker are
+      // InputArg. If that happens, just use the first InputInfo.
+      Input = Inputs.begin();
+
+    addLTOOptions(ToolChain, Args, CmdArgs, Output, *Input,
                   D.getLTOMode() == LTOK_Thin);
   }
 
diff --git a/clang/test/Driver/save-stats.c b/clang/test/Driver/save-stats.c
index 7b35b80b9f629f8..15f77af19f159ff 100644
--- a/clang/test/Driver/save-stats.c
+++ b/clang/test/Driver/save-stats.c
@@ -28,10 +28,19 @@
 // RUN: %clang --target=x86_64-unknown-fuchsia -save-stats -flto -o obj/dir/save-stats.exe -Wl,-plugin-opt=-dummy %s -### 2>&1 | FileCheck %s -check-prefix=CHECK-LTO
 // RUN: %clang --target=avr -save-stats -flto -o obj/dir/save-stats.exe %s -### 2>&1 | FileCheck %s -check-prefix=CHECK-LTO
 // RUN: %clang --target=avr -save-stats -flto -o obj/dir/save-stats.exe -Wl,-plugin-opt=-dummy %s -### 2>&1 | FileCheck %s -check-prefix=CHECK-LTO
+
 // CHECK-LTO: "-stats-file=save-stats.stats"
 // CHECK-LTO: "-o" "obj/dir{{/|\\\\}}save-stats.exe"
 // CHECK-LTO: "-plugin-opt=stats-file=save-stats.stats"
 
+
+// RUN: %clang --target=powerpc-unknown-aix  -save-stats -flto -o obj/dir/save-stats %s -### 2>&1 | FileCheck %s -check-prefix=CHECK-AIX-LTO
+// RUN: %clang --target=powerpc-unknown-aix  -save-stats -flto -o obj/dir/save-stats -Wl,-plugin-opt=-dummy %s -### 2>&1 | FileCheck %s -check-prefix=CHECK-AIX-LTO
+
+// CHECK-AIX-LTO: "-stats-file=save-stats.stats"
+// CHECK-AIX-LTO: "-o" "obj/dir{{/|\\\\}}save-stats"
+// CHECK-AIX-LTO: "-bplugin_opt:stats-file=save-stats.stats"
+
 // RUN: %clang --target=x86_64-unknown-linux -save-stats=obj -flto -o obj/dir/save-stats.exe %s -### 2>&1 | FileCheck %s -check-prefix=CHECK-LTO-OBJ
 // CHECK-LTO-OBJ: "-plugin-opt=stats-file=obj/dir{{/|\\\\}}save-stats.stats"
 

``````````

</details>


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


More information about the cfe-commits mailing list