-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[LTO] Fix the issue of resetting the triple to default when it's empty #157829
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@llvm/pr-subscribers-lto Author: Feng Zou (fzou1) ChangesFull diff: https://github.com/llvm/llvm-project/pull/157829.diff 1 Files Affected:
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);
}
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Testcase?
I added a test case for this issue. |
llvm/test/LTO/X86/empty-triple.ll
Outdated
; 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 "" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
; CHECK-NOT: llvm-lto: error: No available targets are compatible with triple "" | |
; CHECK-NOT: error |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
llvm/test/LTO/X86/empty-triple.ll
Outdated
; RUN: llvm-as < %s >%t1 | ||
; RUN: llvm-lto -o %t2 %t1 2>&1 | FileCheck --allow-empty %s |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
llvm/test/LTO/X86/empty-triple.ll
Outdated
@@ -0,0 +1,7 @@ | |||
; RUN: llvm-as < %s >%t1 | |||
; RUN: llvm-lto -o %t2 %t1 2>&1 | FileCheck --allow-empty %s |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
; 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 |
llvm/lib/LTO/LTOCodeGenerator.cpp
Outdated
if (Triple.empty()) { | ||
Triple = llvm::Triple(sys::getDefaultTargetTriple()); | ||
TripleStr = Triple.getTriple(); | ||
MergedModule->setTargetTriple(Triple); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated. Thanks.
The empty triple is passed to lookupTarget function and it's not set to default one. This issue is exposed after changes in #157591.