https://github.com/e-kud updated 
https://github.com/llvm/llvm-project/pull/210305

>From eb7972bc5ab85a87e77cc45b8a93609f965bd236 Mon Sep 17 00:00:00 2001
From: Evgenii Kudriashov <[email protected]>
Date: Fri, 17 Jul 2026 04:23:45 -0700
Subject: [PATCH 1/2] [Clang][X86] Introduce Clang ABI Gate for MSVC alignment

On x86_64-windows-msvc, clang applies the MSVC size-based
global-alignment scheme (Microsoft64BitMinGlobalAlign) and does not
apply the Sys V "large array" alignment increase. Users may want to
preserve the earlier ABI for compatibility with objects produced by
older clang releases.

Gate this behavior on the Clang ABI compatibility level. When
-fclang-abi-compat=22 (or lower) is in effect, MicrosoftX86_64TargetInfo
restores LargeArrayMinWidth/LargeArrayAlign to 128 and getMinGlobalAlign
skips the Microsoft64BitMinGlobalAlign step, matching the older
alignment choices.
---
 clang/lib/Basic/Targets/X86.cpp   | 19 +++++++++++++++++++
 clang/lib/Basic/Targets/X86.h     |  8 ++++++++
 clang/test/CodeGen/align-x68_64.c |  2 ++
 3 files changed, 29 insertions(+)

diff --git a/clang/lib/Basic/Targets/X86.cpp b/clang/lib/Basic/Targets/X86.cpp
index f77b2d4e0815d..460f11030207b 100644
--- a/clang/lib/Basic/Targets/X86.cpp
+++ b/clang/lib/Basic/Targets/X86.cpp
@@ -1873,5 +1873,24 @@ MicrosoftX86_64TargetInfo::getMinGlobalAlign(uint64_t 
TypeSize,
   unsigned Align =
       WindowsX86_64TargetInfo::getMinGlobalAlign(TypeSize, HasNonWeakDef);
 
+  // Skip the MSVC size-based global-alignment increase under
+  // -fclang-abi-compat<=22.
+  if (!UseMSVCCompatGlobalAlign)
+    return Align;
+
   return std::max(Align, Microsoft64BitMinGlobalAlign(TypeSize));
 }
+
+void MicrosoftX86_64TargetInfo::adjust(DiagnosticsEngine &Diags,
+                                       LangOptions &Opts,
+                                       const TargetInfo *Aux) {
+  WindowsX86_64TargetInfo::adjust(Diags, Opts, Aux);
+  // Under -fclang-abi-compat<=22, restore the prior x86_64-windows-msvc
+  // behavior: apply the Sys V "large array" alignment increase and skip the
+  // MSVC size-based global-alignment increase.
+  if (Opts.isCompatibleWith(LangOptions::ClangABI::Ver22)) {
+    UseMSVCCompatGlobalAlign = false;
+    LargeArrayMinWidth = 128;
+    LargeArrayAlign = 128;
+  }
+}
diff --git a/clang/lib/Basic/Targets/X86.h b/clang/lib/Basic/Targets/X86.h
index e305d9017d897..27f33c9d03672 100644
--- a/clang/lib/Basic/Targets/X86.h
+++ b/clang/lib/Basic/Targets/X86.h
@@ -982,6 +982,14 @@ class LLVM_LIBRARY_VISIBILITY MicrosoftX86_64TargetInfo
 
   unsigned getMinGlobalAlign(uint64_t TypeSize,
                              bool HasNonWeakDef) const override;
+
+  void adjust(DiagnosticsEngine &Diags, LangOptions &Opts,
+              const TargetInfo *Aux) override;
+
+private:
+  // Whether to apply the MSVC size-based global-alignment scheme. Disabled by
+  // -fclang-abi-compat<=22 to restore prior x86_64-windows-msvc behavior.
+  bool UseMSVCCompatGlobalAlign = true;
 };
 
 // x86-64 MinGW target
diff --git a/clang/test/CodeGen/align-x68_64.c 
b/clang/test/CodeGen/align-x68_64.c
index 91f5fac199136..af20ffa3a4d1e 100644
--- a/clang/test/CodeGen/align-x68_64.c
+++ b/clang/test/CodeGen/align-x68_64.c
@@ -1,6 +1,8 @@
 // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm %s -o - | 
FileCheck %s
 // RUN: %clang_cc1 -triple x86_64-windows-gnu       -emit-llvm %s -o - | 
FileCheck %s
 // RUN: %clang_cc1 -triple x86_64-windows-msvc      -emit-llvm %s -o - | 
FileCheck --check-prefix=MSVC %s
+// RUN: %clang_cc1 -triple x86_64-windows-msvc -fclang-abi-compat=22 \
+// RUN:   -emit-llvm %s -o - | FileCheck %s
 // PR5599
 
 char arr[16];

>From 5a19385c4bb8b975c20416050eada20e38e9534c Mon Sep 17 00:00:00 2001
From: Evgenii Kudriashov <[email protected]>
Date: Tue, 21 Jul 2026 10:49:21 -0700
Subject: [PATCH 2/2] Update ABIVersions.def

---
 clang/include/clang/Basic/ABIVersions.def | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/clang/include/clang/Basic/ABIVersions.def 
b/clang/include/clang/Basic/ABIVersions.def
index 15fb8ddf6d774..b55e8dfa2bbc1 100644
--- a/clang/include/clang/Basic/ABIVersions.def
+++ b/clang/include/clang/Basic/ABIVersions.def
@@ -136,8 +136,13 @@ ABI_VER_MAJOR(20)
 ABI_VER_MAJOR(21)
 
 /// Attempt to be ABI-compatible with code generated by Clang 22.0.x.
-/// This causes clang to mangle lambdas in default member initializers of
-/// local classes as nested-name entities instead of local-name entities.
+/// This causes clang to:
+///   - Mangle lambdas in default member initializers of local classes as
+///     nested-name entities instead of local-name entities.
+///   - On x86_64 Windows, apply the System V psABI "large array" alignment
+///     rule instead of matching MSVC.
+///   - On x86_64 Windows, omit MSVC's size-based minimum alignment of global
+///     variables.
 ABI_VER_MAJOR(22)
 
 /// Attempt to be ABI-compatible with code generated by Clang 23.0.x.

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to