-
Notifications
You must be signed in to change notification settings - Fork 182
[CIR] Add code to detect non-zero-initializable records #1603
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
Changes from all commits
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 |
|---|---|---|
|
|
@@ -300,6 +300,7 @@ void CIRRecordLowering::lower(bool nonVirtualBaseType) { | |
| insertPadding(); | ||
| members.pop_back(); | ||
|
|
||
| calculateZeroInit(); | ||
| fillOutputFields(); | ||
| computeVolatileBitfields(); | ||
| } | ||
|
|
@@ -628,6 +629,24 @@ void CIRRecordLowering::accumulateFields() { | |
| } | ||
| } | ||
|
|
||
| void CIRRecordLowering::calculateZeroInit() { | ||
| for (const MemberInfo &member : members) { | ||
| if (member.kind == MemberInfo::InfoKind::Field) { | ||
| if (!member.fieldDecl || isZeroInitializable(member.fieldDecl)) | ||
| continue; | ||
| IsZeroInitializable = IsZeroInitializableAsBase = false; | ||
|
Collaborator
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 think
Collaborator
Author
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. They are accessed using a function that returns bool. You don't see that here because it was already present in the code and just always returned |
||
| return; | ||
| } else if (member.kind == MemberInfo::InfoKind::Base || | ||
| member.kind == MemberInfo::InfoKind::VBase) { | ||
| if (isZeroInitializable(member.cxxRecordDecl)) | ||
| continue; | ||
| IsZeroInitializable = false; | ||
| if (member.kind == MemberInfo::InfoKind::Base) | ||
| IsZeroInitializableAsBase = false; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| void CIRRecordLowering::determinePacked(bool NVBaseType) { | ||
| if (isPacked) | ||
| return; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o %t.cir | ||
| // RUN: FileCheck --input-file=%t.cir %s | ||
|
|
||
| // This case is not yet implemented. | ||
| // XFAIL: * | ||
|
|
||
| struct Other { | ||
| int x; | ||
| }; | ||
|
|
||
| struct Trivial { | ||
| int x; | ||
| double y; | ||
| decltype(&Other::x) ptr; | ||
| }; | ||
|
|
||
| // This case has a trivial default constructor, but can't be zero-initialized. | ||
| Trivial t; | ||
|
|
||
| // The type is wrong on the last member here. It needs to be initialized to -1, | ||
| // but I don't know what that will look like. | ||
|
Collaborator
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. Maybe you can
Collaborator
Author
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. When this test runs, it hits the |
||
| // CHECK: cir.global {{.*}} @t = #cir.const_record<{#cir.int<0> : !s32i, #cir.fp<0.000000e+00> : !cir.double, #cir.int<-1> : !s64i}> | ||
|
Collaborator
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. It is a little weird to model function pointers/member function pointers as a type other than a pointer. IMO, we need to have CIR model member function pointers in a way that IT handles the 'assigned to zero actually means -1'.
Collaborator
Author
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. Yes. I just didn't really know what that would be. When this gets implemented the check will be updated.
Member
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.
Yea, the |
||
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.
Can you clarify that this is an ABI thing? Data member pointers are zero initialized in the standard sense. It's just that most popular ABIs including Itanium have a non-zero bit representation of a null data member pointer