Skip to content

Conversation

fzou1
Copy link
Contributor

@fzou1 fzou1 commented Sep 10, 2025

The empty triple is passed to lookupTarget function and it's not set to default one. This issue is exposed after changes in #157591.

@llvmbot llvmbot added the LTO Link time optimization (regular/full LTO or ThinLTO) label Sep 10, 2025
@fzou1 fzou1 requested a review from arsenm September 10, 2025 10:41
@llvmbot
Copy link
Member

llvmbot commented Sep 10, 2025

@llvm/pr-subscribers-lto

Author: Feng Zou (fzou1)

Changes

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

1 Files Affected:

  • (modified) llvm/lib/LTO/LTOCodeGenerator.cpp (+3-2)
diff --git a/llvm/lib/LTO/LTOCodeGenerator.cpp b/llvm/lib/LTO/LTOCodeGenerator.cpp
index cdeab98ff6c98..8ea4e530dc3eb 100644
--- a/llvm/lib/LTO/LTOCodeGenerator.cpp
+++ b/llvm/lib/LTO/LTOCodeGenerator.cpp
@@ -377,8 +377,9 @@ bool LTOCodeGenerator::determineTarget() {
 
   TripleStr = MergedModule->getTargetTriple().str();
   llvm::Triple Triple(TripleStr);
-  if (TripleStr.empty()) {
-    TripleStr = sys::getDefaultTargetTriple();
+  if (Triple.empty()) {
+    Triple = llvm::Triple(sys::getDefaultTargetTriple());
+    TripleStr = Triple.getTriple();
     MergedModule->setTargetTriple(Triple);
   }
 

Copy link
Contributor

@arsenm arsenm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Testcase?

@fzou1 fzou1 changed the title [LTO] Fix the issue of setting default triple when the triple is empty. [LTO] Fix the issue of resetting the triple to default when it's empty Sep 10, 2025
@fzou1
Copy link
Contributor Author

fzou1 commented Sep 10, 2025

Testcase?

I added a test case for this issue.

; The test is to check the triple is set to default one when it's empty.
; Otherwise, an error will be raised by llvm-lto.

; CHECK-NOT: llvm-lto: error: No available targets are compatible with triple ""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
; CHECK-NOT: llvm-lto: error: No available targets are compatible with triple ""
; CHECK-NOT: error

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively there's not much gained by checking stderr, since it's not exiting 1 anymore. If you want to check something, that the output is valid might be better

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively there's not much gained by checking stderr, since it's not exiting 1 anymore. If you want to check something, that the output is valid might be better

Updated test to check the symbol if the output is valid.

Comment on lines 1 to 2
; RUN: llvm-as < %s >%t1
; RUN: llvm-lto -o %t2 %t1 2>&1 | FileCheck --allow-empty %s
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is in the X86 subdirectory, but I don't see where X86 use would come from. This is the odd case where "generic" target tests might be appropriate. Can you move this to the parent directory?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -0,0 +1,7 @@
; RUN: llvm-as < %s >%t1
; RUN: llvm-lto -o %t2 %t1 2>&1 | FileCheck --allow-empty %s
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
; RUN: llvm-lto -o %t2 %t1 2>&1 | FileCheck --allow-empty %s
; RUN: llvm-lto -o /dev/null %t1 2>&1 | FileCheck --allow-empty %s

Comment on lines 380 to 383
if (Triple.empty()) {
Triple = llvm::Triple(sys::getDefaultTargetTriple());
TripleStr = Triple.getTriple();
MergedModule->setTargetTriple(Triple);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could also rewrite this to avoid constructing the wrong triple to start with

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated. Thanks.

@fzou1 fzou1 merged commit 33757cd into llvm:main Sep 11, 2025
9 checks passed
@fzou1 fzou1 deleted the lto_empty_triple branch September 11, 2025 02:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
LTO Link time optimization (regular/full LTO or ThinLTO)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants