forked from OSchip/llvm-project
Reorganize EmitMemberInitializer to put anonymous unions on the common codepath.
llvm-svn: 88995
This commit is contained in:
parent
0632b53bfe
commit
5e7d969526
|
@ -1515,11 +1515,7 @@ static void EmitMemberInitializer(CodeGenFunction &CGF,
|
||||||
|
|
||||||
// non-static data member initializers.
|
// non-static data member initializers.
|
||||||
FieldDecl *Field = MemberInit->getMember();
|
FieldDecl *Field = MemberInit->getMember();
|
||||||
QualType FieldType = CGF.getContext().getCanonicalType((Field)->getType());
|
QualType FieldType = CGF.getContext().getCanonicalType(Field->getType());
|
||||||
const ConstantArrayType *Array =
|
|
||||||
CGF.getContext().getAsConstantArrayType(FieldType);
|
|
||||||
if (Array)
|
|
||||||
FieldType = CGF.getContext().getBaseElementType(FieldType);
|
|
||||||
|
|
||||||
llvm::Value *ThisPtr = CGF.LoadCXXThis();
|
llvm::Value *ThisPtr = CGF.LoadCXXThis();
|
||||||
LValue LHS;
|
LValue LHS;
|
||||||
|
@ -1532,32 +1528,38 @@ static void EmitMemberInitializer(CodeGenFunction &CGF,
|
||||||
} else {
|
} else {
|
||||||
LHS = CGF.EmitLValueForField(ThisPtr, Field, ClassDecl->isUnion(), 0);
|
LHS = CGF.EmitLValueForField(ThisPtr, Field, ClassDecl->isUnion(), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If we are initializing an anonymous union field, drill down to the field.
|
||||||
|
if (MemberInit->getAnonUnionMember()) {
|
||||||
|
Field = MemberInit->getAnonUnionMember();
|
||||||
|
LHS = CGF.EmitLValueForField(LHS.getAddress(), Field,
|
||||||
|
/*IsUnion=*/true, 0);
|
||||||
|
FieldType = Field->getType();
|
||||||
|
}
|
||||||
|
|
||||||
|
// If the field is an array, branch based on the element type.
|
||||||
|
const ConstantArrayType *Array =
|
||||||
|
CGF.getContext().getAsConstantArrayType(FieldType);
|
||||||
|
if (Array)
|
||||||
|
FieldType = CGF.getContext().getBaseElementType(FieldType);
|
||||||
|
|
||||||
if (FieldType->getAs<RecordType>()) {
|
if (FieldType->getAs<RecordType>()) {
|
||||||
if (!Field->isAnonymousStructOrUnion()) {
|
assert(MemberInit->getConstructor() &&
|
||||||
assert(MemberInit->getConstructor() &&
|
"EmitCtorPrologue - no constructor to initialize member");
|
||||||
"EmitCtorPrologue - no constructor to initialize member");
|
if (Array) {
|
||||||
if (Array) {
|
const llvm::Type *BasePtr = CGF.ConvertType(FieldType);
|
||||||
const llvm::Type *BasePtr = CGF.ConvertType(FieldType);
|
BasePtr = llvm::PointerType::getUnqual(BasePtr);
|
||||||
BasePtr = llvm::PointerType::getUnqual(BasePtr);
|
llvm::Value *BaseAddrPtr =
|
||||||
llvm::Value *BaseAddrPtr =
|
CGF.Builder.CreateBitCast(LHS.getAddress(), BasePtr);
|
||||||
CGF.Builder.CreateBitCast(LHS.getAddress(), BasePtr);
|
CGF.EmitCXXAggrConstructorCall(MemberInit->getConstructor(),
|
||||||
CGF.EmitCXXAggrConstructorCall(MemberInit->getConstructor(),
|
Array, BaseAddrPtr);
|
||||||
Array, BaseAddrPtr);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
CGF.EmitCXXConstructorCall(MemberInit->getConstructor(),
|
|
||||||
Ctor_Complete, LHS.getAddress(),
|
|
||||||
MemberInit->const_arg_begin(),
|
|
||||||
MemberInit->const_arg_end());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
// Initializing an anonymous union data member.
|
|
||||||
FieldDecl *anonMember = MemberInit->getAnonUnionMember();
|
|
||||||
LHS = CGF.EmitLValueForField(LHS.getAddress(), anonMember,
|
|
||||||
/*IsUnion=*/true, 0);
|
|
||||||
FieldType = anonMember->getType();
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
CGF.EmitCXXConstructorCall(MemberInit->getConstructor(),
|
||||||
|
Ctor_Complete, LHS.getAddress(),
|
||||||
|
MemberInit->const_arg_begin(),
|
||||||
|
MemberInit->const_arg_end());
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(MemberInit->getNumArgs() == 1 && "Initializer count must be 1 only");
|
assert(MemberInit->getNumArgs() == 1 && "Initializer count must be 1 only");
|
||||||
|
|
Loading…
Reference in New Issue