Skip to content

Conversation

@tonykuttai
Copy link
Contributor

PR #145685 introduced constructor overload ambiguity in the Triple class, causing updateTripleOSVersion() to construct Triple objects with unknown instead of the configured target triple (e.g., powerpc-ibm-aix7.3.0.0). This results in Clang driver errors like error: unknown target triple 'unknown'.

Used Twine constructor with braced initialization to bypass ambiguity.

@tonykuttai tonykuttai marked this pull request as ready for review July 8, 2025 09:10
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.

Is this testable? The TargetParser really shouldn't depend on the host triple for any reason

Copy link
Contributor

Choose a reason for hiding this comment

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

This function shouldn't depend on the host triple in the first place

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a test file to lock this down.

Copy link
Collaborator

Choose a reason for hiding this comment

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

This function shouldn't depend on the host triple in the first place

This function intends to transfer host characteristics (the OS version information) to AIX target triples (which is then used in Clang for predefined macros, among other things). The host characteristics have no reasonable relation to the AIX target triple unless the compiler is hosted on AIX.

@tonykuttai tonykuttai force-pushed the tvarghese/targettriple branch from e2993cc to d6c634b Compare July 8, 2025 09:46
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' labels Jul 8, 2025
@llvmbot
Copy link
Member

llvmbot commented Jul 8, 2025

@llvm/pr-subscribers-clang

Author: Tony Varghese (tonykuttai)

Changes

PR #145685 introduced constructor overload ambiguity in the Triple class, causing updateTripleOSVersion() to construct Triple objects with unknown instead of the configured target triple (e.g., powerpc-ibm-aix7.3.0.0). This results in Clang driver errors like error: unknown target triple 'unknown'.

Used Twine constructor with braced initialization to bypass ambiguity.


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

2 Files Affected:

  • (added) clang/test/Driver/aix-default-target-triple.c (+18)
  • (modified) llvm/lib/TargetParser/Unix/Host.inc (+1-1)
diff --git a/clang/test/Driver/aix-default-target-triple.c b/clang/test/Driver/aix-default-target-triple.c
new file mode 100644
index 0000000000000..2802e6a60719a
--- /dev/null
+++ b/clang/test/Driver/aix-default-target-triple.c
@@ -0,0 +1,18 @@
+// Test for the Triple constructor ambiguity fix on AIX
+// This test verifies that the default target triple is correctly resolved
+// and doesn't fall back to "unknown" due to constructor ambiguity.
+
+// REQUIRES: system-aix
+// RUN: %clang -v %s -c 2>&1 | FileCheck %s --check-prefix=CHECK-TARGET
+
+// Test that the target triple contains AIX and is not "unknown"
+// The target should be something like "powerpc-ibm-aix7.3.0.0"
+// CHECK-TARGET: Target: {{.*}}aix{{.*}}
+// CHECK-TARGET-NOT: error: unknown target triple 'unknown'
+
+#include <stdio.h>
+
+int main() {
+    printf("Target triple resolution test passed\n");
+    return 0;
+}
diff --git a/llvm/lib/TargetParser/Unix/Host.inc b/llvm/lib/TargetParser/Unix/Host.inc
index ef9e288ee3a01..aeb2f59218700 100644
--- a/llvm/lib/TargetParser/Unix/Host.inc
+++ b/llvm/lib/TargetParser/Unix/Host.inc
@@ -55,7 +55,7 @@ static std::string updateTripleOSVersion(std::string TargetTripleString) {
   // On AIX, the AIX version and release should be that of the current host
   // unless if the version has already been specified.
   if (Triple(LLVM_HOST_TRIPLE).getOS() == Triple::AIX) {
-    Triple TT(std::move(TargetTripleString));
+    Triple TT{TargetTripleString};
     if (TT.getOS() == Triple::AIX && !TT.getOSMajorVersion()) {
       struct utsname name;
       if (uname(&name) != -1) {

@llvmbot
Copy link
Member

llvmbot commented Jul 8, 2025

@llvm/pr-subscribers-clang-driver

Author: Tony Varghese (tonykuttai)

Changes

PR #145685 introduced constructor overload ambiguity in the Triple class, causing updateTripleOSVersion() to construct Triple objects with unknown instead of the configured target triple (e.g., powerpc-ibm-aix7.3.0.0). This results in Clang driver errors like error: unknown target triple 'unknown'.

Used Twine constructor with braced initialization to bypass ambiguity.


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

2 Files Affected:

  • (added) clang/test/Driver/aix-default-target-triple.c (+18)
  • (modified) llvm/lib/TargetParser/Unix/Host.inc (+1-1)
diff --git a/clang/test/Driver/aix-default-target-triple.c b/clang/test/Driver/aix-default-target-triple.c
new file mode 100644
index 0000000000000..2802e6a60719a
--- /dev/null
+++ b/clang/test/Driver/aix-default-target-triple.c
@@ -0,0 +1,18 @@
+// Test for the Triple constructor ambiguity fix on AIX
+// This test verifies that the default target triple is correctly resolved
+// and doesn't fall back to "unknown" due to constructor ambiguity.
+
+// REQUIRES: system-aix
+// RUN: %clang -v %s -c 2>&1 | FileCheck %s --check-prefix=CHECK-TARGET
+
+// Test that the target triple contains AIX and is not "unknown"
+// The target should be something like "powerpc-ibm-aix7.3.0.0"
+// CHECK-TARGET: Target: {{.*}}aix{{.*}}
+// CHECK-TARGET-NOT: error: unknown target triple 'unknown'
+
+#include <stdio.h>
+
+int main() {
+    printf("Target triple resolution test passed\n");
+    return 0;
+}
diff --git a/llvm/lib/TargetParser/Unix/Host.inc b/llvm/lib/TargetParser/Unix/Host.inc
index ef9e288ee3a01..aeb2f59218700 100644
--- a/llvm/lib/TargetParser/Unix/Host.inc
+++ b/llvm/lib/TargetParser/Unix/Host.inc
@@ -55,7 +55,7 @@ static std::string updateTripleOSVersion(std::string TargetTripleString) {
   // On AIX, the AIX version and release should be that of the current host
   // unless if the version has already been specified.
   if (Triple(LLVM_HOST_TRIPLE).getOS() == Triple::AIX) {
-    Triple TT(std::move(TargetTripleString));
+    Triple TT{TargetTripleString};
     if (TT.getOS() == Triple::AIX && !TT.getOSMajorVersion()) {
       struct utsname name;
       if (uname(&name) != -1) {

@tonykuttai tonykuttai requested review from arsenm and nikic and removed request for nikic July 8, 2025 09:50
@tonykuttai tonykuttai force-pushed the tvarghese/targettriple branch from d6c634b to 859bdf0 Compare July 8, 2025 09:52
@tonykuttai tonykuttai force-pushed the tvarghese/targettriple branch from 859bdf0 to 9d9ed1f Compare July 8, 2025 09:53
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.

lgtm with test nits

@tonykuttai tonykuttai merged commit b4b150f into llvm:main Jul 8, 2025
7 of 9 checks passed
// This test verifies that the default target triple is correctly resolved
// and doesn't fall back to "unknown" due to constructor ambiguity.

// REQUIRES: system-aix
Copy link
Collaborator

Choose a reason for hiding this comment

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

@tonykuttai, this is not sufficient. The target also has to be AIX to begin with (as opposed to an AIX-hosted cross-compiling configuration).

tonykuttai added a commit that referenced this pull request Jul 9, 2025
…ple.c for AIX specific targets (#147584)

This is a followup on the [[PowerPC][clang] Fix triple constructor
ambiguity causing "unknown" target triple on
AIX](#147488 (comment)) to address
the [post-commit review
comment](#147488 (comment)).

---------

Co-authored-by: Tony Varghese <[email protected]>
llvm-sync bot pushed a commit to arm/arm-toolchain that referenced this pull request Jul 9, 2025
…-target-triple.c for AIX specific targets (#147584)

This is a followup on the [[PowerPC][clang] Fix triple constructor
ambiguity causing "unknown" target triple on
AIX](llvm/llvm-project#147488 (comment)) to address
the [post-commit review
comment](llvm/llvm-project#147488 (comment)).

---------

Co-authored-by: Tony Varghese <[email protected]>
@tonykuttai tonykuttai deleted the tvarghese/targettriple branch July 21, 2025 05:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' clang Clang issues not falling into any other category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants