-
Notifications
You must be signed in to change notification settings - Fork 11.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[clang][CGRecordLayout] Remove dependency on isZeroSize #96422
Changes from all commits
46d1543
23f298d
a24099d
a008bae
7ea1b50
0ef2c88
5936851
3afa138
dd38db8
2d97ced
9041aa7
2097deb
f6693e4
2d22773
f6c64fe
4e5002d
c7e6468
5312be4
02165f5
a4b15f0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -137,6 +137,16 @@ bool isEmptyField(ASTContext &Context, const FieldDecl *FD, bool AllowArrays, | |
bool isEmptyRecord(ASTContext &Context, QualType T, bool AllowArrays, | ||
bool AsIfNoUniqueAddr = false); | ||
|
||
/// isEmptyFieldForLayout - Return true iff the field is "empty", that is, | ||
/// either a zero-width bit-field or an \ref isEmptyRecordForLayout. | ||
bool isEmptyFieldForLayout(const ASTContext &Context, const FieldDecl *FD); | ||
|
||
/// isEmptyRecordForLayout - Return true iff a structure contains only empty | ||
/// base classes (per \ref isEmptyRecordForLayout) and fields (per | ||
/// \ref isEmptyFieldForLayout). Note, C++ record fields are considered empty | ||
/// if the [[no_unique_address]] attribute would have made them empty. | ||
bool isEmptyRecordForLayout(const ASTContext &Context, QualType T); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These functions don't belong here. This file contains helper functions for use in implementations of ABIInfo class. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I put those here just to have them next to |
||
|
||
/// isSingleElementStruct - Determine if a structure is a "single | ||
/// element struct", i.e. it has exactly one non-empty field or | ||
/// exactly one field which is itself a single element | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,19 @@ | ||
// RUN: %clang_cc1 -emit-llvm < %s | grep "zeroinitializer, i16 16877" | ||
// RUN: %clang_cc1 %s -emit-llvm -triple x86_64-linux-gnu -o - | FileCheck %s --check-prefixes=CHECK,EMPTY | ||
// RUN: %clang_cc1 %s -emit-llvm -triple x86_64-windows-msvc -o - | FileCheck %s --check-prefixes=CHECK,EMPTY-MSVC | ||
// PR4390 | ||
struct sysfs_dirent { | ||
union { struct sysfs_elem_dir {} s_dir; }; | ||
union { struct sysfs_elem_dir { int x; } s_dir; }; | ||
unsigned short s_mode; | ||
}; | ||
struct sysfs_dirent sysfs_root = { {}, 16877 }; | ||
|
||
// CHECK: @sysfs_root = {{.*}}global %struct.sysfs_dirent { %union.anon zeroinitializer, i16 16877 } | ||
|
||
struct Foo { | ||
union { struct empty {} x; }; | ||
unsigned short s_mode; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks weird at first glance, but I guess the union has size zero in C, so this is fine. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yup, can confirm that as C++ we'd get:
|
||
}; | ||
struct Foo foo = { {}, 16877 }; | ||
|
||
// EMPTY: @foo = {{.*}}global %struct.Foo { i16 16877 } | ||
// EMPTY-MSVC: @foo = {{.*}}global %struct.Foo { [4 x i8] undef, i16 16877 } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @efriedma-quic For MSVC targets we don't emit a zeroinitializer here now despite the empty union occupying some storage. Do we expect there to be a zeroinitializer here? For C++ we don't emit the zeroinitializer with top-of-tree, but not sure what the expectation/promise for C is here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. clang doesn't currently implement the C23 rules for empty-brace initialization... but I guess if you extend those rules to empty structs/unions (which aren't valid C, but ignoring that), we arguably should zero-init? But really, nobody should notice; this weird stuff is only realistically used for stuff like FAMs. Testcase which MSVC accepts:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Empty base classes and fields.