llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang Author: Evgenii Kudriashov (e-kud) <details> <summary>Changes</summary> On x86_64-windows-msvc after 8ecec455183f, 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. Assisted by Claude (Anthropic). --- Full diff: https://github.com/llvm/llvm-project/pull/210305.diff 3 Files Affected: - (modified) clang/lib/Basic/Targets/X86.cpp (+19) - (modified) clang/lib/Basic/Targets/X86.h (+8) - (modified) clang/test/CodeGen/align-x68_64.c (+2) ``````````diff 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]; `````````` </details> https://github.com/llvm/llvm-project/pull/210305 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
