Files
llvm-project/clang/test/CodeGen/mms-bitfields.c
Dan Klishch 1760effa33 [clang] Implement gcc_struct attribute on Itanium targets (#71148)
This commit implements gcc_struct attribute with the behavior similar to
one in GCC. Current behavior is as follows:

When ItaniumRecordLayoutBuilder is used, [[gcc_struct]] will locally
cancel the effect of -mms-bitfields on a record. If -mms-bitfields is
not supplied and is not a default behavior on a target, [[gcc_struct]]
will be a no-op. This should provide enough compatibility with GCC.

If C++ ABI is "Microsoft", [[gcc_struct]] will currently always produce
a diagnostic, since support for it is not yet implemented in
MicrosoftRecordLayoutBuilder. Note, however, that all the infrastructure
is ready for the future implementation.

In particular, check for default value of -mms-bitfields is moved from a
driver to ASTContext, since it now non-trivially depends on other
supplied flags. This also, unfortunately, makes it impossible to use
usual argument parsing for `-m{no-,}ms-bitfields`.

The patch doesn't introduce any backwards-incompatible changes, except
for situations when cc1 is called directly with `-mms-bitfields` option.

Work towards #24757

---------

Co-authored-by: Martin Storsjö <martin@martin.st>
2025-12-12 19:22:40 +02:00

66 lines
1.9 KiB
C

// RUN: %clang_cc1 -triple i386-apple-darwin10 -fms-layout-compatibility=microsoft -emit-llvm %s -o - | FileCheck %s
struct s1 {
int f32;
long long f64;
} s1;
// CHECK: %struct.s1 = type { i32, [4 x i8], i64 }
struct s2 {
int f32;
long long f64[4];
} s2;
// CHECK: %struct.s2 = type { i32, [4 x i8], [4 x i64] }
struct s3 {
int f32;
struct s1 s;
} s3;
// CHECK: %struct.s3 = type { i32, [4 x i8], %struct.s1 }
// PR32482:
#pragma pack (push,1)
typedef unsigned int UINT32;
struct Inner {
UINT32 A : 1;
UINT32 B : 1;
UINT32 C : 1;
UINT32 D : 30;
} Inner;
#pragma pack (pop)
// CHECK: %struct.Inner = type { i32, i32 }
// CHECK: %struct.A = type { i32, i32, i32 }
#pragma pack(push, 1)
union HEADER {
struct A {
int : 3; // Bits 2:0
int a : 9; // Bits 11:3
int : 12; // Bits 23:12
int b : 17; // Bits 40:24
int : 7; // Bits 47:41
int c : 4; // Bits 51:48
int : 4; // Bits 55:52
int d : 3; // Bits 58:56
int : 5; // Bits 63:59
} Bits;
} HEADER;
#pragma pack(pop)
struct Inner variable = { 1,0,1, 21 };
union HEADER hdr = {{1,2,3,4}};
// CHECK: @variable ={{.*}} global { i8, [3 x i8], i8, i8, i8, i8 } { i8 5, [3 x i8] zeroinitializer, i8 21, i8 0, i8 0, i8 0 }, align 1
// CHECK: @hdr ={{.*}} global { { i8, i8, [2 x i8], i8, i8, i8, i8, i8, [3 x i8] } } { { i8, i8, [2 x i8], i8, i8, i8, i8, i8, [3 x i8] } { i8 8, i8 0, [2 x i8] zeroinitializer, i8 2, i8 0, i8 0, i8 3, i8 4, [3 x i8] zeroinitializer } }, align 1