llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang Author: llvmbot <details> <summary>Changes</summary> Backport cb383a37440d27238f8a01eee05228910d65d63e Requested by: @<!-- -->zwuis --- Full diff: https://github.com/llvm/llvm-project/pull/212122.diff 5 Files Affected: - (modified) clang/include/clang/Basic/ABIVersions.def (+7-2) - (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) - (modified) clang/test/CodeGenCXX/ms-constexpr-static-data-member.cpp (+8) ``````````diff diff --git a/clang/include/clang/Basic/ABIVersions.def b/clang/include/clang/Basic/ABIVersions.def index a9f72481ee0ea..967a409ca22bf 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) /// Conform to the underlying platform's C and C++ ABIs as closely as we can. diff --git a/clang/lib/Basic/Targets/X86.cpp b/clang/lib/Basic/Targets/X86.cpp index 7d8a74d62be74..8ab39b750dc99 100644 --- a/clang/lib/Basic/Targets/X86.cpp +++ b/clang/lib/Basic/Targets/X86.cpp @@ -1882,5 +1882,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]; diff --git a/clang/test/CodeGenCXX/ms-constexpr-static-data-member.cpp b/clang/test/CodeGenCXX/ms-constexpr-static-data-member.cpp index 4b191fd472c20..623eb312ccf3c 100644 --- a/clang/test/CodeGenCXX/ms-constexpr-static-data-member.cpp +++ b/clang/test/CodeGenCXX/ms-constexpr-static-data-member.cpp @@ -1,4 +1,6 @@ // RUN: %clang_cc1 -emit-llvm -triple=x86_64-windows-msvc %s -o - | FileCheck %s +// RUN: %clang_cc1 -emit-llvm -triple=x86_64-windows-msvc \ +// RUN: -fclang-abi-compat=22 %s -o - | FileCheck %s --check-prefix=COMPAT struct Foo { int x, y; }; @@ -24,3 +26,9 @@ void usethem() { // CHECK-DAG: @"?sdm_char_ptr@S@@2QEBDEB" = linkonce_odr dso_local constant ptr @"??_C@_04JIHMPGLA@asdf?$AA@", comdat, align 8 // CHECK-DAG: @"?sdm_udt@S@@2UFoo@@B" = linkonce_odr dso_local constant %struct.Foo { i32 1, i32 2 }, comdat, align 8 + +// COMPAT-DAG: @"?sdm_char_array@S@@2QBDB" = linkonce_odr dso_local constant [5 x i8] c"asdf\00", comdat, align 1 + +// COMPAT-DAG: @"?sdm_char_ptr@S@@2QEBDEB" = linkonce_odr dso_local constant ptr @"??_C@_04JIHMPGLA@asdf?$AA@", comdat, align 8 + +// COMPAT-DAG: @"?sdm_udt@S@@2UFoo@@B" = linkonce_odr dso_local constant %struct.Foo { i32 1, i32 2 }, comdat, align 4 `````````` </details> https://github.com/llvm/llvm-project/pull/212122 _______________________________________________ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
