https://github.com/ilovepi created https://github.com/llvm/llvm-project/pull/82400
ARM's Clang and GCC embedded compilers default to allowing unaligned access for ARMv7+. This patch changes the Clang driver default to match. Users can opt out with `-mno-unaligned-access`. Fixes #59560 >From 20634c2f54ae667ee8374d12e58e582aa6cdd051 Mon Sep 17 00:00:00 2001 From: Paul Kirth <paulki...@google.com> Date: Tue, 20 Feb 2024 10:34:57 -0800 Subject: [PATCH] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20initia?= =?UTF-8?q?l=20version?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Created using spr 1.3.4 --- clang/lib/Driver/ToolChains/Arch/ARM.cpp | 14 ++++++-------- clang/test/Driver/arm-alignment.c | 8 ++++++++ 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/clang/lib/Driver/ToolChains/Arch/ARM.cpp b/clang/lib/Driver/ToolChains/Arch/ARM.cpp index e6ee2f88a84edf..3bf6056f0c3ecc 100644 --- a/clang/lib/Driver/ToolChains/Arch/ARM.cpp +++ b/clang/lib/Driver/ToolChains/Arch/ARM.cpp @@ -895,20 +895,18 @@ llvm::ARM::FPUKind arm::getARMTargetFeatures(const Driver &D, // defaults this bit to 0 and handles it as a system-wide (not // per-process) setting. It is therefore safe to assume that ARMv7+ // Linux targets support unaligned accesses. The same goes for NaCl - // and Windows. - // - // The above behavior is consistent with GCC. + // and Windows. However, ARM's forks of GCC and Clang both allow + // unaligned accesses by default for all targets. We follow this + // behavior and enable unaligned accesses by default for ARMv7+ targets. + // Users can disable behavior via compiler options (-mno-unaliged-access). + // See https://github.com/llvm/llvm-project/issues/59560 for more info. int VersionNum = getARMSubArchVersionNumber(Triple); if (Triple.isOSDarwin() || Triple.isOSNetBSD()) { if (VersionNum < 6 || Triple.getSubArch() == llvm::Triple::SubArchType::ARMSubArch_v6m) Features.push_back("+strict-align"); - } else if (Triple.isOSLinux() || Triple.isOSNaCl() || - Triple.isOSWindows()) { - if (VersionNum < 7) + } else if (VersionNum < 7) Features.push_back("+strict-align"); - } else - Features.push_back("+strict-align"); } // llvm does not support reserving registers in general. There is support diff --git a/clang/test/Driver/arm-alignment.c b/clang/test/Driver/arm-alignment.c index 9177b625729b85..6d0084451e82c7 100644 --- a/clang/test/Driver/arm-alignment.c +++ b/clang/test/Driver/arm-alignment.c @@ -22,6 +22,14 @@ // RUN: %clang -target armv7-windows -### %s 2> %t // RUN: FileCheck --check-prefix=CHECK-UNALIGNED-ARM < %t %s +/// Ensure that by default before ARMv7 we default to +strict-align +// RUN: %clang -target armv6 -### %s 2> %t +// RUN: FileCheck --check-prefix=CHECK-ALIGNED-ARM < %t %s + +/// After ARMv7 by default we allow unaligned accesses for all targets +// RUN: %clang -target armv7 -### %s 2> %t +// RUN: FileCheck --check-prefix=CHECK-UNALIGNED-ARM < %t %s + // RUN: %clang --target=aarch64 -munaligned-access -### %s 2> %t // RUN: FileCheck --check-prefix=CHECK-UNALIGNED-AARCH64 < %t %s _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits