[clang] [clang][driver] Allow unaligned access on ARMv7 and higher by default (PR #82400)

Paul Kirth via cfe-commits cfe-commits at lists.llvm.org
Wed Feb 21 08:39:38 PST 2024


================
@@ -886,28 +886,16 @@ llvm::ARM::FPUKind arm::getARMTargetFeatures(const Driver &D,
   } else {
     // Assume pre-ARMv6 doesn't support unaligned accesses.
     //
-    // ARMv6 may or may not support unaligned accesses depending on the
-    // SCTLR.U bit, which is architecture-specific. We assume ARMv6
-    // Darwin and NetBSD targets support unaligned accesses, and others don't.
+    // Assume ARMv6+ supports unaligned accesses, except Armv6-M, and Armv8-M
+    // without the Main Extension. This aligns with the default behavior of
+    // ARM's downstream versions of GCC and Clang
     //
-    // ARMv7 always has SCTLR.U set to 1, but it has a new SCTLR.A bit
-    // which raises an alignment fault on unaligned accesses. Linux
-    // 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.
+    // Users can disable behavior via -mno-unaliged-access.
     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)
-        Features.push_back("+strict-align");
-    } else
+    if (VersionNum < 6 ||
+        Triple.getSubArch() == llvm::Triple::SubArchType::ARMSubArch_v6m ||
+        Triple.getSubArch() ==
+            llvm::Triple::SubArchType::ARMSubArch_v8m_baseline)
----------------
ilovepi wrote:

I think this is a good start. We can discuss relaxing our treatment of v6 later without much trouble. I'll go ahead and update the comments and release notes to match this a bit more closely.

https://github.com/llvm/llvm-project/pull/82400


More information about the cfe-commits mailing list