https://github.com/simpal01 created https://github.com/llvm/llvm-project/pull/134099
Update the multilib selection logic to bypass the alignment option based on each architecture’s feature set, rather than relying on command-line options. Previously, alignment option was bypassed only when -mno-unaligned-access was explicitly specified on the command line. This change makes the selection more robust and architecture aware. >From 7f6302053575732f633c69bbf55f2624da1e8bf4 Mon Sep 17 00:00:00 2001 From: Simi Pallipurath <simi.pallipur...@arm.com> Date: Wed, 2 Apr 2025 12:35:16 +0100 Subject: [PATCH] Refine multilib selection to handle alignment based on architecture features. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Update the multilib selection logic to bypass the alignment option based on each architecture’s feature set, rather than relying solely on command-line options. Previously, alignment option was bypassed only when -mno-unaligned-access was explicitly specified on the commandline. This change makes the selection more robust and architecture aware. --- clang/lib/Driver/ToolChain.cpp | 24 +++++++++---------- .../test/Driver/print-multi-selection-flags.c | 6 +++++ 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp index 8a922b283daf5..476026f82b32b 100644 --- a/clang/lib/Driver/ToolChain.cpp +++ b/clang/lib/Driver/ToolChain.cpp @@ -239,12 +239,12 @@ static void getAArch64MultilibFlags(const Driver &D, Result.push_back(BranchProtectionArg->getAsString(Args)); } - if (Arg *AlignArg = Args.getLastArg( - options::OPT_mstrict_align, options::OPT_mno_strict_align, - options::OPT_mno_unaligned_access, options::OPT_munaligned_access)) { - if (AlignArg->getOption().matches(options::OPT_mstrict_align) || - AlignArg->getOption().matches(options::OPT_mno_unaligned_access)) - Result.push_back(AlignArg->getAsString(Args)); + if (FeatureSet.contains("+strict-align")) { + Result.push_back("-mno-unaligned-access"); + Result.push_back("-mstrict-align"); + } else { + Result.push_back("-munaligned-access"); + Result.push_back("-mno-strict-align"); } if (Arg *Endian = Args.getLastArg(options::OPT_mbig_endian, @@ -313,12 +313,12 @@ static void getARMMultilibFlags(const Driver &D, Result.push_back(BranchProtectionArg->getAsString(Args)); } - if (Arg *AlignArg = Args.getLastArg( - options::OPT_mstrict_align, options::OPT_mno_strict_align, - options::OPT_mno_unaligned_access, options::OPT_munaligned_access)) { - if (AlignArg->getOption().matches(options::OPT_mstrict_align) || - AlignArg->getOption().matches(options::OPT_mno_unaligned_access)) - Result.push_back(AlignArg->getAsString(Args)); + if (FeatureSet.contains("+strict-align")) { + Result.push_back("-mno-unaligned-access"); + Result.push_back("-mstrict-align"); + } else { + Result.push_back("-munaligned-access"); + Result.push_back("-mno-strict-align"); } if (Arg *Endian = Args.getLastArg(options::OPT_mbig_endian, diff --git a/clang/test/Driver/print-multi-selection-flags.c b/clang/test/Driver/print-multi-selection-flags.c index 5a35ae374f011..b21c2d11c1009 100644 --- a/clang/test/Driver/print-multi-selection-flags.c +++ b/clang/test/Driver/print-multi-selection-flags.c @@ -69,9 +69,15 @@ // CHECK-BRANCH-PROTECTION: -mbranch-protection=standard // RUN: %clang -multi-lib-config=%S/Inputs/multilib/empty.yaml -print-multi-flags-experimental --target=arm-none-eabi -mno-unaligned-access | FileCheck --check-prefix=CHECK-NO-UNALIGNED-ACCESS %s +// RUN: %clang -multi-lib-config=%S/Inputs/multilib/empty.yaml -print-multi-flags-experimental --target=arm-none-eabi | FileCheck --check-prefix=CHECK-NO-UNALIGNED-ACCESS %s // RUN: %clang -multi-lib-config=%S/Inputs/multilib/empty.yaml -print-multi-flags-experimental --target=aarch64-none-elf -mno-unaligned-access | FileCheck --check-prefix=CHECK-NO-UNALIGNED-ACCESS %s // CHECK-NO-UNALIGNED-ACCESS: -mno-unaligned-access +// RUN: %clang -multi-lib-config=%S/Inputs/multilib/empty.yaml -print-multi-flags-experimental --target=arm-none-eabi -munaligned-access | FileCheck --check-prefix=CHECK-UNALIGNED-ACCESS %s +// RUN: %clang -multi-lib-config=%S/Inputs/multilib/empty.yaml -print-multi-flags-experimental --target=aarch64-none-elf | FileCheck --check-prefix=CHECK-UNALIGNED-ACCESS %s +// RUN: %clang -multi-lib-config=%S/Inputs/multilib/empty.yaml -print-multi-flags-experimental --target=aarch64-none-elf -munaligned-access | FileCheck --check-prefix=CHECK-UNALIGNED-ACCESS %s +// CHECK-UNALIGNED-ACCESS: -munaligned-access + // RUN: %clang -multi-lib-config=%S/Inputs/multilib/empty.yaml -print-multi-flags-experimental --target=arm-none-eabi -mbig-endian | FileCheck --check-prefix=CHECK-BIG-ENDIAN %s // RUN: %clang -multi-lib-config=%S/Inputs/multilib/empty.yaml -print-multi-flags-experimental --target=aarch64-none-elf -mbig-endian | FileCheck --check-prefix=CHECK-BIG-ENDIAN %s // CHECK-BIG-ENDIAN: -mbig-endian _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits