summaryrefslogtreecommitdiffstats
path: root/clang/lib
diff options
context:
space:
mode:
Diffstat (limited to 'clang/lib')
-rw-r--r--clang/lib/CodeGen/CGExprConstant.cpp10
-rw-r--r--clang/lib/CodeGen/CGRecordLayoutBuilder.cpp10
2 files changed, 15 insertions, 5 deletions
diff --git a/clang/lib/CodeGen/CGExprConstant.cpp b/clang/lib/CodeGen/CGExprConstant.cpp
index 73ca0cc1c3d..b90b3ab61d8 100644
--- a/clang/lib/CodeGen/CGExprConstant.cpp
+++ b/clang/lib/CodeGen/CGExprConstant.cpp
@@ -1349,8 +1349,14 @@ static llvm::Constant *EmitNullConstant(CodeGenModule &CGM,
}
// For unions, stop after the first named field.
- if (record->isUnion() && Field->getDeclName())
- break;
+ if (record->isUnion()) {
+ if (Field->getIdentifier())
+ break;
+ if (const auto *FieldRD =
+ dyn_cast_or_null<RecordDecl>(Field->getType()->getAsTagDecl()))
+ if (FieldRD->findFirstNamedDataMember())
+ break;
+ }
}
// Fill in the virtual bases, if we're working with the complete object.
diff --git a/clang/lib/CodeGen/CGRecordLayoutBuilder.cpp b/clang/lib/CodeGen/CGRecordLayoutBuilder.cpp
index 72ecd65c28a..c89d5cc3892 100644
--- a/clang/lib/CodeGen/CGRecordLayoutBuilder.cpp
+++ b/clang/lib/CodeGen/CGRecordLayoutBuilder.cpp
@@ -314,9 +314,13 @@ void CGRecordLowering::lowerUnion() {
// If this is the case, then we aught not to try and come up with a "better"
// type, it might not be very easy to come up with a Constant which
// correctly initializes it.
- if (!SeenNamedMember && Field->getDeclName()) {
- SeenNamedMember = true;
- if (!isZeroInitializable(Field)) {
+ if (!SeenNamedMember) {
+ SeenNamedMember = Field->getIdentifier();
+ if (!SeenNamedMember)
+ if (const auto *FieldRD =
+ dyn_cast_or_null<RecordDecl>(Field->getType()->getAsTagDecl()))
+ SeenNamedMember = FieldRD->findFirstNamedDataMember();
+ if (SeenNamedMember && !isZeroInitializable(Field)) {
IsZeroInitializable = IsZeroInitializableAsBase = false;
StorageType = FieldType;
}
OpenPOWER on IntegriCloud