[clang] [clang][Driver] Fix triple config loading for clang-cl (PR #111397)
skoulik wrote: Hello guys, Can you check/confirm if this fix is in any way related to #159229 that I observe? https://github.com/llvm/llvm-project/pull/111397 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Driver] Fix triple config loading for clang-cl (PR #111397)
PaulWagener wrote: I've resolved the conflicts in commit http://github.com/PaulWagener/llvm-project/commit/40a8c7c0ff3f688b690e4c74db734de67f0f89e9 (https://github.com/Bo98/llvm-project/pull/1) I don't know much about the technical details of this PR but I can confirm that this correctly builds and fixes the issue with cross compiling with homebrew clang-cl that I've been having. Would be happy to see this upstreamed. https://github.com/llvm/llvm-project/pull/111397 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Driver] Fix triple config loading for clang-cl (PR #111397)
carlocab wrote: Yep, was just trying to ping @Bo98 for an update here. https://github.com/llvm/llvm-project/pull/111397 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Driver] Fix triple config loading for clang-cl (PR #111397)
zmodem wrote: Okay. I think most of my previous comments (except for "maybe the fix is to always ignore config files in clang-cl mode) still apply though. https://github.com/llvm/llvm-project/pull/111397 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Driver] Fix triple config loading for clang-cl (PR #111397)
carlocab wrote: LLVM 20 is branching soon -- would be good to try to get this in before then. https://github.com/llvm/llvm-project/pull/111397 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Driver] Fix triple config loading for clang-cl (PR #111397)
zmodem wrote: Looks like I was wrong. clang-cl does support `--config` since daebf2c13ce27ac6a7403525cc7fcbc063eb892e, so I suppose we can't just ignore these files. Your change to update the triple based on clang-cl mode earlier makes sense to me. I'm less sure about manually inspecting the `/arm64EC` flag in that code. `Driver::loadDefaultConfigFiles()` has logic to figure out the triple, is it not handled there? I'm even less sure about the "The config file may have changed the architecture so apply it" part. It's not clear to me that we need it at all, and if we do need it, why is it specific to the `/arm64EC` flag? https://github.com/llvm/llvm-project/pull/111397 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Driver] Fix triple config loading for clang-cl (PR #111397)
carlocab wrote: > Maybe the fix is to always _ignore_ config files in clang-cl mode I'd be fine with doing this too -- I just wasn't aware that clang-cl did not support config files (since this fact doesn't seem to be documented anywhere, unless I missed it). https://github.com/llvm/llvm-project/pull/111397 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Driver] Fix triple config loading for clang-cl (PR #111397)
@@ -1247,6 +1247,19 @@ Compilation *Driver::BuildCompilation(ArrayRef ArgList) {
CLOptions = std::make_unique(
ParseArgStrings(ArgList.slice(1), /*UseDriverMode=*/true,
ContainsError));
+ // We want to determine the triple early so that we load the correct config.
+ if (IsCLMode()) {
+// clang-cl targets MSVC-style Win32.
+llvm::Triple T(TargetTriple);
+T.setOS(llvm::Triple::Win32);
+T.setVendor(llvm::Triple::PC);
+T.setEnvironment(llvm::Triple::MSVC);
+T.setObjectFormat(llvm::Triple::COFF);
+if (CLOptions->hasArg(options::OPT__SLASH_arm64EC))
+ T.setArch(llvm::Triple::aarch64, llvm::Triple::AArch64SubArch_arm64ec);
zmodem wrote:
I thought normally the arguments in the config file should get processed
*before* the command-line arguments? What are the rules for this really?
https://github.com/llvm/llvm-project/pull/111397
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Driver] Fix triple config loading for clang-cl (PR #111397)
@@ -1286,6 +1299,16 @@ Compilation *Driver::BuildCompilation(ArrayRef ArgList) {
appendOneArg(Args, Opt, nullptr);
}
}
+
+// The config file may have changed the architecture so apply it.
+if (HasConfigFile && Args.hasArg(options::OPT__SLASH_arm64EC)) {
+ llvm::Triple T(TargetTriple);
+ if (T.getArch() != llvm::Triple::aarch64 ||
+ T.getSubArch() != llvm::Triple::AArch64SubArch_arm64ec) {
+T.setArch(llvm::Triple::aarch64, llvm::Triple::AArch64SubArch_arm64ec);
+TargetTriple = T.str();
zmodem wrote:
Thanks for explaining. I haven't looked at this code in a long time, and
TargetTriple vs. computeTargetTriple() is pretty confusing.
It seems `/arm64EC` is not handled in `computeTargetTriple()`(?) so I suppose
it needs to be handled somewhere :)
https://github.com/llvm/llvm-project/pull/111397
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Driver] Fix triple config loading for clang-cl (PR #111397)
zmodem wrote: > You don't need to use config files with `clang-cl` to need this patch -- you > need it if you use triple-based config files and also use `clang-cl`. The > issue is that if you have, for example, a `x86_64-unknown-linux-gnu.cfg` in a > location that `clang` loads by default, then this breaks `clang-cl` because > running `clang-cl` also loads `x86_64-unknown-linux-gnu.cfg` (which will > generically contain incompatible flags). Okay, but that sounds like a case where clang-cl users *do not want* to use config files. Maybe the fix is to always *ignore* config files in clang-cl mode, since there is no corresponding concept in MSVC cl, and it's not commonly used for the embedded/cross compiling scenarios where config files are used? https://github.com/llvm/llvm-project/pull/111397 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Driver] Fix triple config loading for clang-cl (PR #111397)
@@ -1336,17 +1359,7 @@ Compilation *Driver::BuildCompilation(ArrayRef ArgList) {
// FIXME: TargetTriple is used by the target-prefixed calls to as/ld
// and getToolChain is const.
- if (IsCLMode()) {
-// clang-cl targets MSVC-style Win32.
-llvm::Triple T(TargetTriple);
-T.setOS(llvm::Triple::Win32);
-T.setVendor(llvm::Triple::PC);
-T.setEnvironment(llvm::Triple::MSVC);
-T.setObjectFormat(llvm::Triple::COFF);
-if (Args.hasArg(options::OPT__SLASH_arm64EC))
- T.setArch(llvm::Triple::aarch64, llvm::Triple::AArch64SubArch_arm64ec);
-TargetTriple = T.str();
- } else if (IsDXCMode()) {
+ if (IsDXCMode()) {
Bo98 wrote:
It does but it relies on argument parsing so is trickier to move and I didn't
have a DXC build on hand. I can have a look again though and see if I can get a
build going.
I guess this is the same problem as above. It would be trivial to move this to
`computeTargetTriple` but it seems this changes `TargetTriple` instead.
https://github.com/llvm/llvm-project/pull/111397
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Driver] Fix triple config loading for clang-cl (PR #111397)
https://github.com/Bo98 edited https://github.com/llvm/llvm-project/pull/111397 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Driver] Fix triple config loading for clang-cl (PR #111397)
@@ -1286,6 +1299,16 @@ Compilation *Driver::BuildCompilation(ArrayRef ArgList) {
appendOneArg(Args, Opt, nullptr);
}
}
+
+// The config file may have changed the architecture so apply it.
+if (HasConfigFile && Args.hasArg(options::OPT__SLASH_arm64EC)) {
+ llvm::Triple T(TargetTriple);
+ if (T.getArch() != llvm::Triple::aarch64 ||
+ T.getSubArch() != llvm::Triple::AArch64SubArch_arm64ec) {
+T.setArch(llvm::Triple::aarch64, llvm::Triple::AArch64SubArch_arm64ec);
+TargetTriple = T.str();
Bo98 wrote:
There's two triple systems in the driver: `TargetTriple` and the triple fed to
`ToolChain` (computed by `computeTargetTriple`). The former is feeds into the
latter but is otherwise separate.
`-m32` and `-m64` is already handled in `computeTargetTriple` and so never
affect `TargetTriple`. The code here was to keep the existing behaviour of
`/arm64EC` affecting `TargetTriple`.
To be honest: I have no idea why there is two triples. It would be simpler if
`TargetTriple` became `DefaultTriple` (and remains immutable),
`Driver.getTargetTriple()` was removed and we just moved all this to
`computeTargetTriple` but I was hesitant to change something I don't understand
the history of.
https://github.com/llvm/llvm-project/pull/111397
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Driver] Fix triple config loading for clang-cl (PR #111397)
carlocab wrote: > I didn't even realize people are using config files with clang-cl (since IIRC > it doesn't support the config file command-line options). You don't need to use config files with `clang-cl` to need this patch -- you need it if you use triple-based config files and also use `clang-cl`. The issue is that if you have, for example, a `x86_64-unknown-linux-gnu.cfg` in a location that `clang` loads by default, then this breaks `clang-cl` because running `clang-cl` also loads `x86_64-unknown-linux-gnu.cfg` (which will generically contain incompatible flags). https://github.com/llvm/llvm-project/pull/111397 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Driver] Fix triple config loading for clang-cl (PR #111397)
https://github.com/zmodem edited https://github.com/llvm/llvm-project/pull/111397 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Driver] Fix triple config loading for clang-cl (PR #111397)
@@ -1286,6 +1299,16 @@ Compilation *Driver::BuildCompilation(ArrayRef ArgList) {
appendOneArg(Args, Opt, nullptr);
}
}
+
+// The config file may have changed the architecture so apply it.
+if (HasConfigFile && Args.hasArg(options::OPT__SLASH_arm64EC)) {
+ llvm::Triple T(TargetTriple);
+ if (T.getArch() != llvm::Triple::aarch64 ||
+ T.getSubArch() != llvm::Triple::AArch64SubArch_arm64ec) {
+T.setArch(llvm::Triple::aarch64, llvm::Triple::AArch64SubArch_arm64ec);
+TargetTriple = T.str();
zmodem wrote:
The PR description only mentions moving the default triple calculation earlier,
but not this part.
The config file can presumably change many things, so why does the target
triple need special handling? Also what about flags that affect x86 vs. x86_64
(-m32 and -m64), do we need to handle those too?
https://github.com/llvm/llvm-project/pull/111397
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Driver] Fix triple config loading for clang-cl (PR #111397)
@@ -1336,17 +1359,7 @@ Compilation *Driver::BuildCompilation(ArrayRef ArgList) {
// FIXME: TargetTriple is used by the target-prefixed calls to as/ld
// and getToolChain is const.
- if (IsCLMode()) {
-// clang-cl targets MSVC-style Win32.
-llvm::Triple T(TargetTriple);
-T.setOS(llvm::Triple::Win32);
-T.setVendor(llvm::Triple::PC);
-T.setEnvironment(llvm::Triple::MSVC);
-T.setObjectFormat(llvm::Triple::COFF);
-if (Args.hasArg(options::OPT__SLASH_arm64EC))
- T.setArch(llvm::Triple::aarch64, llvm::Triple::AArch64SubArch_arm64ec);
-TargetTriple = T.str();
- } else if (IsDXCMode()) {
+ if (IsDXCMode()) {
zmodem wrote:
Doesn't this mode have the same issue?
https://github.com/llvm/llvm-project/pull/111397
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Driver] Fix triple config loading for clang-cl (PR #111397)
https://github.com/zmodem commented: I didn't even realize people are using config files with clang-cl (since IIRC it doesn't support the config file command-line options). https://github.com/llvm/llvm-project/pull/111397 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Driver] Fix triple config loading for clang-cl (PR #111397)
https://github.com/carlocab approved this pull request. Needs conflict resolution, but otherwise LGTM https://github.com/llvm/llvm-project/pull/111397 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Driver] Fix triple config loading for clang-cl (PR #111397)
Bo98 wrote: Ping? https://github.com/llvm/llvm-project/pull/111397 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Driver] Fix triple config loading for clang-cl (PR #111397)
https://github.com/Bo98 edited https://github.com/llvm/llvm-project/pull/111397 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Driver] Fix triple config loading for clang-cl (PR #111397)
https://github.com/Bo98 edited https://github.com/llvm/llvm-project/pull/111397 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Driver] Fix triple config loading for clang-cl (PR #111397)
https://github.com/Bo98 edited https://github.com/llvm/llvm-project/pull/111397 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Driver] Fix triple config loading for clang-cl (PR #111397)
https://github.com/Bo98 edited https://github.com/llvm/llvm-project/pull/111397 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Driver] Fix triple config loading for clang-cl (PR #111397)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Bo Anderson (Bo98) Changes `clang-cl` sets the default triple to `-pc-windows-msvc`. The host triple was however being used instead when loading default configs. Move the default triple calculation earlier to handle this. --- Full diff: https://github.com/llvm/llvm-project/pull/111397.diff 4 Files Affected: - (modified) clang/lib/Driver/Driver.cpp (+24-11) - (added) clang/test/Driver/Inputs/config-cl/arm64ec-pc-windows-msvc.cfg () - (added) clang/test/Driver/Inputs/config-cl/config-arm64ec-arg.cfg (+1) - (modified) clang/test/Driver/config-file.c (+10) ``diff diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index a5d43bdac23735..541e79ec97056b 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -1247,6 +1247,19 @@ Compilation *Driver::BuildCompilation(ArrayRef ArgList) { CLOptions = std::make_unique( ParseArgStrings(ArgList.slice(1), /*UseDriverMode=*/true, ContainsError)); + // We want to determine the triple early so that we load the correct config. + if (IsCLMode()) { +// clang-cl targets MSVC-style Win32. +llvm::Triple T(TargetTriple); +T.setOS(llvm::Triple::Win32); +T.setVendor(llvm::Triple::PC); +T.setEnvironment(llvm::Triple::MSVC); +T.setObjectFormat(llvm::Triple::COFF); +if (CLOptions->hasArg(options::OPT__SLASH_arm64EC)) + T.setArch(llvm::Triple::aarch64, llvm::Triple::AArch64SubArch_arm64ec); +TargetTriple = T.str(); + } + // Try parsing configuration file. if (!ContainsError) ContainsError = loadConfigFiles(); @@ -1286,6 +1299,16 @@ Compilation *Driver::BuildCompilation(ArrayRef ArgList) { appendOneArg(Args, Opt, nullptr); } } + +// The config file may have changed the architecture so apply it. +if (HasConfigFile && Args.hasArg(options::OPT__SLASH_arm64EC)) { + llvm::Triple T(TargetTriple); + if (T.getArch() != llvm::Triple::aarch64 || + T.getSubArch() != llvm::Triple::AArch64SubArch_arm64ec) { +T.setArch(llvm::Triple::aarch64, llvm::Triple::AArch64SubArch_arm64ec); +TargetTriple = T.str(); + } +} } // Check for working directory option before accessing any files @@ -1336,17 +1359,7 @@ Compilation *Driver::BuildCompilation(ArrayRef ArgList) { // FIXME: TargetTriple is used by the target-prefixed calls to as/ld // and getToolChain is const. - if (IsCLMode()) { -// clang-cl targets MSVC-style Win32. -llvm::Triple T(TargetTriple); -T.setOS(llvm::Triple::Win32); -T.setVendor(llvm::Triple::PC); -T.setEnvironment(llvm::Triple::MSVC); -T.setObjectFormat(llvm::Triple::COFF); -if (Args.hasArg(options::OPT__SLASH_arm64EC)) - T.setArch(llvm::Triple::aarch64, llvm::Triple::AArch64SubArch_arm64ec); -TargetTriple = T.str(); - } else if (IsDXCMode()) { + if (IsDXCMode()) { // Build TargetTriple from target_profile option for clang-dxc. if (const Arg *A = Args.getLastArg(options::OPT_target_profile)) { StringRef TargetProfile = A->getValue(); diff --git a/clang/test/Driver/Inputs/config-cl/arm64ec-pc-windows-msvc.cfg b/clang/test/Driver/Inputs/config-cl/arm64ec-pc-windows-msvc.cfg new file mode 100644 index 00..e69de29bb2d1d6 diff --git a/clang/test/Driver/Inputs/config-cl/config-arm64ec-arg.cfg b/clang/test/Driver/Inputs/config-cl/config-arm64ec-arg.cfg new file mode 100644 index 00..2eb4402ddf6cd7 --- /dev/null +++ b/clang/test/Driver/Inputs/config-cl/config-arm64ec-arg.cfg @@ -0,0 +1 @@ +/arm64EC diff --git a/clang/test/Driver/config-file.c b/clang/test/Driver/config-file.c index 9df830ca4c7538..cbad0e408b9ab4 100644 --- a/clang/test/Driver/config-file.c +++ b/clang/test/Driver/config-file.c @@ -82,3 +82,13 @@ // CHECK-TWO-CONFIGS: -isysroot // CHECK-TWO-CONFIGS-SAME: /opt/data // CHECK-TWO-CONFIGS-SAME: -Wall + + +//--- clang-cl loads the correct triple +// RUN: env -u CLANG_NO_DEFAULT_CONFIG %clang_cl /arm64EC --config-system-dir=%S/Inputs/config-cl --config-user-dir= -v 2>&1 | FileCheck %s -check-prefix CHECK-CL --implicit-check-not 'Configuration file:' +// CHECK-CL: Configuration file: {{.*}}Inputs{{.}}config-cl{{.}}arm64ec-pc-windows-msvc.cfg + +//--- clang-cl configs support setting /arm64EC +// RUN: %clang_cl --config-system-dir=%S/Inputs/config-cl --config-user-dir= --config=config-arm64ec-arg.cfg -v 2>&1 | FileCheck %s -check-prefix CHECK-CL-FLAG --implicit-check-not 'Configuration file:' +// CHECK-CL-FLAG: Target: arm64ec-pc-windows-msvc +// CHECK-CL-FLAG: Configuration file: {{.*}}Inputs{{.}}config-cl{{.}}config-arm64ec-arg.cfg `` https://github.com/llvm/llvm-project/pull/111397 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Driver] Fix triple config loading for clang-cl (PR #111397)
llvmbot wrote: @llvm/pr-subscribers-clang-driver Author: Bo Anderson (Bo98) Changes `clang-cl` sets the default triple to `-pc-windows-msvc`. The host triple was however being used instead when loading default configs. Move the default triple calculation earlier to handle this. --- Full diff: https://github.com/llvm/llvm-project/pull/111397.diff 4 Files Affected: - (modified) clang/lib/Driver/Driver.cpp (+24-11) - (added) clang/test/Driver/Inputs/config-cl/arm64ec-pc-windows-msvc.cfg () - (added) clang/test/Driver/Inputs/config-cl/config-arm64ec-arg.cfg (+1) - (modified) clang/test/Driver/config-file.c (+10) ``diff diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index a5d43bdac23735..541e79ec97056b 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -1247,6 +1247,19 @@ Compilation *Driver::BuildCompilation(ArrayRef ArgList) { CLOptions = std::make_unique( ParseArgStrings(ArgList.slice(1), /*UseDriverMode=*/true, ContainsError)); + // We want to determine the triple early so that we load the correct config. + if (IsCLMode()) { +// clang-cl targets MSVC-style Win32. +llvm::Triple T(TargetTriple); +T.setOS(llvm::Triple::Win32); +T.setVendor(llvm::Triple::PC); +T.setEnvironment(llvm::Triple::MSVC); +T.setObjectFormat(llvm::Triple::COFF); +if (CLOptions->hasArg(options::OPT__SLASH_arm64EC)) + T.setArch(llvm::Triple::aarch64, llvm::Triple::AArch64SubArch_arm64ec); +TargetTriple = T.str(); + } + // Try parsing configuration file. if (!ContainsError) ContainsError = loadConfigFiles(); @@ -1286,6 +1299,16 @@ Compilation *Driver::BuildCompilation(ArrayRef ArgList) { appendOneArg(Args, Opt, nullptr); } } + +// The config file may have changed the architecture so apply it. +if (HasConfigFile && Args.hasArg(options::OPT__SLASH_arm64EC)) { + llvm::Triple T(TargetTriple); + if (T.getArch() != llvm::Triple::aarch64 || + T.getSubArch() != llvm::Triple::AArch64SubArch_arm64ec) { +T.setArch(llvm::Triple::aarch64, llvm::Triple::AArch64SubArch_arm64ec); +TargetTriple = T.str(); + } +} } // Check for working directory option before accessing any files @@ -1336,17 +1359,7 @@ Compilation *Driver::BuildCompilation(ArrayRef ArgList) { // FIXME: TargetTriple is used by the target-prefixed calls to as/ld // and getToolChain is const. - if (IsCLMode()) { -// clang-cl targets MSVC-style Win32. -llvm::Triple T(TargetTriple); -T.setOS(llvm::Triple::Win32); -T.setVendor(llvm::Triple::PC); -T.setEnvironment(llvm::Triple::MSVC); -T.setObjectFormat(llvm::Triple::COFF); -if (Args.hasArg(options::OPT__SLASH_arm64EC)) - T.setArch(llvm::Triple::aarch64, llvm::Triple::AArch64SubArch_arm64ec); -TargetTriple = T.str(); - } else if (IsDXCMode()) { + if (IsDXCMode()) { // Build TargetTriple from target_profile option for clang-dxc. if (const Arg *A = Args.getLastArg(options::OPT_target_profile)) { StringRef TargetProfile = A->getValue(); diff --git a/clang/test/Driver/Inputs/config-cl/arm64ec-pc-windows-msvc.cfg b/clang/test/Driver/Inputs/config-cl/arm64ec-pc-windows-msvc.cfg new file mode 100644 index 00..e69de29bb2d1d6 diff --git a/clang/test/Driver/Inputs/config-cl/config-arm64ec-arg.cfg b/clang/test/Driver/Inputs/config-cl/config-arm64ec-arg.cfg new file mode 100644 index 00..2eb4402ddf6cd7 --- /dev/null +++ b/clang/test/Driver/Inputs/config-cl/config-arm64ec-arg.cfg @@ -0,0 +1 @@ +/arm64EC diff --git a/clang/test/Driver/config-file.c b/clang/test/Driver/config-file.c index 9df830ca4c7538..cbad0e408b9ab4 100644 --- a/clang/test/Driver/config-file.c +++ b/clang/test/Driver/config-file.c @@ -82,3 +82,13 @@ // CHECK-TWO-CONFIGS: -isysroot // CHECK-TWO-CONFIGS-SAME: /opt/data // CHECK-TWO-CONFIGS-SAME: -Wall + + +//--- clang-cl loads the correct triple +// RUN: env -u CLANG_NO_DEFAULT_CONFIG %clang_cl /arm64EC --config-system-dir=%S/Inputs/config-cl --config-user-dir= -v 2>&1 | FileCheck %s -check-prefix CHECK-CL --implicit-check-not 'Configuration file:' +// CHECK-CL: Configuration file: {{.*}}Inputs{{.}}config-cl{{.}}arm64ec-pc-windows-msvc.cfg + +//--- clang-cl configs support setting /arm64EC +// RUN: %clang_cl --config-system-dir=%S/Inputs/config-cl --config-user-dir= --config=config-arm64ec-arg.cfg -v 2>&1 | FileCheck %s -check-prefix CHECK-CL-FLAG --implicit-check-not 'Configuration file:' +// CHECK-CL-FLAG: Target: arm64ec-pc-windows-msvc +// CHECK-CL-FLAG: Configuration file: {{.*}}Inputs{{.}}config-cl{{.}}config-arm64ec-arg.cfg `` https://github.com/llvm/llvm-project/pull/111397 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Driver] Fix triple config loading for clang-cl (PR #111397)
github-actions[bot] wrote: Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be notified. If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using `@` followed by their GitHub username. If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers. If you have further questions, they may be answered by the [LLVM GitHub User Guide](https://llvm.org/docs/GitHub.html). You can also ask questions in a comment on this PR, on the [LLVM Discord](https://discord.com/invite/xS7Z362) or on the [forums](https://discourse.llvm.org/). https://github.com/llvm/llvm-project/pull/111397 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Driver] Fix triple config loading for clang-cl (PR #111397)
https://github.com/Bo98 edited https://github.com/llvm/llvm-project/pull/111397 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Driver] Fix triple config loading for clang-cl (PR #111397)
https://github.com/Bo98 created https://github.com/llvm/llvm-project/pull/111397
`clang-cl` sets the default triple to `-pc-windows-msvc`. The host triple
was however being used instead when loading config.
Move the default triple calculation earlier to handle this.
>From a3e8b860788934d7cc1489f850f00dcfd9d8b595 Mon Sep 17 00:00:00 2001
From: Bo Anderson
Date: Mon, 7 Oct 2024 17:01:56 +0100
Subject: [PATCH] [clang][Driver] Fix triple config loading for clang-cl
---
clang/lib/Driver/Driver.cpp | 35 +--
.../config-cl/arm64ec-pc-windows-msvc.cfg | 0
.../Inputs/config-cl/config-arm64ec-arg.cfg | 1 +
clang/test/Driver/config-file.c | 10 ++
4 files changed, 35 insertions(+), 11 deletions(-)
create mode 100644
clang/test/Driver/Inputs/config-cl/arm64ec-pc-windows-msvc.cfg
create mode 100644 clang/test/Driver/Inputs/config-cl/config-arm64ec-arg.cfg
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index a5d43bdac23735..541e79ec97056b 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -1247,6 +1247,19 @@ Compilation *Driver::BuildCompilation(ArrayRef ArgList) {
CLOptions = std::make_unique(
ParseArgStrings(ArgList.slice(1), /*UseDriverMode=*/true,
ContainsError));
+ // We want to determine the triple early so that we load the correct config.
+ if (IsCLMode()) {
+// clang-cl targets MSVC-style Win32.
+llvm::Triple T(TargetTriple);
+T.setOS(llvm::Triple::Win32);
+T.setVendor(llvm::Triple::PC);
+T.setEnvironment(llvm::Triple::MSVC);
+T.setObjectFormat(llvm::Triple::COFF);
+if (CLOptions->hasArg(options::OPT__SLASH_arm64EC))
+ T.setArch(llvm::Triple::aarch64, llvm::Triple::AArch64SubArch_arm64ec);
+TargetTriple = T.str();
+ }
+
// Try parsing configuration file.
if (!ContainsError)
ContainsError = loadConfigFiles();
@@ -1286,6 +1299,16 @@ Compilation *Driver::BuildCompilation(ArrayRef ArgList) {
appendOneArg(Args, Opt, nullptr);
}
}
+
+// The config file may have changed the architecture so apply it.
+if (HasConfigFile && Args.hasArg(options::OPT__SLASH_arm64EC)) {
+ llvm::Triple T(TargetTriple);
+ if (T.getArch() != llvm::Triple::aarch64 ||
+ T.getSubArch() != llvm::Triple::AArch64SubArch_arm64ec) {
+T.setArch(llvm::Triple::aarch64, llvm::Triple::AArch64SubArch_arm64ec);
+TargetTriple = T.str();
+ }
+}
}
// Check for working directory option before accessing any files
@@ -1336,17 +1359,7 @@ Compilation *Driver::BuildCompilation(ArrayRef ArgList) {
// FIXME: TargetTriple is used by the target-prefixed calls to as/ld
// and getToolChain is const.
- if (IsCLMode()) {
-// clang-cl targets MSVC-style Win32.
-llvm::Triple T(TargetTriple);
-T.setOS(llvm::Triple::Win32);
-T.setVendor(llvm::Triple::PC);
-T.setEnvironment(llvm::Triple::MSVC);
-T.setObjectFormat(llvm::Triple::COFF);
-if (Args.hasArg(options::OPT__SLASH_arm64EC))
- T.setArch(llvm::Triple::aarch64, llvm::Triple::AArch64SubArch_arm64ec);
-TargetTriple = T.str();
- } else if (IsDXCMode()) {
+ if (IsDXCMode()) {
// Build TargetTriple from target_profile option for clang-dxc.
if (const Arg *A = Args.getLastArg(options::OPT_target_profile)) {
StringRef TargetProfile = A->getValue();
diff --git a/clang/test/Driver/Inputs/config-cl/arm64ec-pc-windows-msvc.cfg
b/clang/test/Driver/Inputs/config-cl/arm64ec-pc-windows-msvc.cfg
new file mode 100644
index 00..e69de29bb2d1d6
diff --git a/clang/test/Driver/Inputs/config-cl/config-arm64ec-arg.cfg
b/clang/test/Driver/Inputs/config-cl/config-arm64ec-arg.cfg
new file mode 100644
index 00..2eb4402ddf6cd7
--- /dev/null
+++ b/clang/test/Driver/Inputs/config-cl/config-arm64ec-arg.cfg
@@ -0,0 +1 @@
+/arm64EC
diff --git a/clang/test/Driver/config-file.c b/clang/test/Driver/config-file.c
index 9df830ca4c7538..cbad0e408b9ab4 100644
--- a/clang/test/Driver/config-file.c
+++ b/clang/test/Driver/config-file.c
@@ -82,3 +82,13 @@
// CHECK-TWO-CONFIGS: -isysroot
// CHECK-TWO-CONFIGS-SAME: /opt/data
// CHECK-TWO-CONFIGS-SAME: -Wall
+
+
+//--- clang-cl loads the correct triple
+// RUN: env -u CLANG_NO_DEFAULT_CONFIG %clang_cl /arm64EC
--config-system-dir=%S/Inputs/config-cl --config-user-dir= -v 2>&1 | FileCheck
%s -check-prefix CHECK-CL --implicit-check-not 'Configuration file:'
+// CHECK-CL: Configuration file:
{{.*}}Inputs{{.}}config-cl{{.}}arm64ec-pc-windows-msvc.cfg
+
+//--- clang-cl configs support setting /arm64EC
+// RUN: %clang_cl --config-system-dir=%S/Inputs/config-cl --config-user-dir=
--config=config-arm64ec-arg.cfg -v 2>&1 | FileCheck %s -check-prefix
CHECK-CL-FLAG --implicit-check-not 'Configuration file:'
+// CHECK-CL-FLAG: Target: arm64ec-pc-windows-msvc
+// CHECK-CL-FLAG: Configuration file:
{{.*}}Inputs{{.}}config-cl{{.}}config-arm64ec-arg.cfg
___
