Files
llvm-tms34010/clang/test/CodeGenCXX/ms-constexpr-static-data-member.cpp
Evgenii Kudriashov 9d3cf1dff4 [Clang][X86] Introduce Clang ABI Gate for MSVC alignment (#210305)
On x86_64-windows-msvc after 8ecec45518, 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).

(cherry picked from commit cb383a37440d27238f8a01eee05228910d65d63e)
2026-07-29 08:57:11 +02:00

35 lines
1.3 KiB
C++

// 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; };
struct S {
// PR36125
static constexpr char sdm_char_array[] = "asdf";
// PR43280
static constexpr const char *sdm_char_ptr = "asdf";
static constexpr Foo sdm_udt{1, 2};
};
void useptr(const void *p);
void usethem() {
useptr(&S::sdm_char_array);
useptr(&S::sdm_char_ptr);
useptr(&S::sdm_udt);
}
// CHECK-DAG: @"?sdm_char_array@S@@2QBDB" = linkonce_odr dso_local constant [5 x i8] c"asdf\00", comdat, align 4
// 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