Type*'s can change as types are refined, so we can't use them as a stable key in
the map. Decls don't change, so use them instead.
This patch was written by Anders, but he's too shy to commit it himself :)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@46743
91177308-0d34-0410-b5e6-
96231b3b80d8
llvm::Constant *EmitStructInitialization(InitListExpr *ILE,
const llvm::StructType *SType) {
+ TagDecl *TD = ILE->getType()->getAsRecordType()->getDecl();
std::vector<llvm::Constant*> Elts;
- const CGRecordLayout *CGR = CGM.getTypes().getCGRecordLayout(SType);
+ const CGRecordLayout *CGR = CGM.getTypes().getCGRecordLayout(TD);
unsigned NumInitElements = ILE->getNumInits();
unsigned NumElements = SType->getNumElements();
/// getCGRecordLayout - Return record layout info.
const CGRecordLayout *CodeGenFunction::getCGRecordLayout(CodeGenTypes &CGT,
- QualType RTy) {
- assert (isa<RecordType>(RTy)
- && "Unexpected type. RecordType expected here.");
+ QualType Ty) {
+ const RecordType *RTy = Ty->getAsRecordType();
+ assert (RTy && "Unexpected type. RecordType expected here.");
- const llvm::Type *Ty = ConvertType(RTy);
- assert (Ty && "Unable to find llvm::Type");
-
- return CGT.getCGRecordLayout(Ty);
+ return CGT.getCGRecordLayout(RTy->getDecl());
}
/// WarnUnsupported - Print out a warning that codegen doesn't support the
}
CodeGenTypes::~CodeGenTypes() {
- for(llvm::DenseMap<const llvm::Type *, CGRecordLayout *>::iterator
+ for(llvm::DenseMap<const TagDecl *, CGRecordLayout *>::iterator
I = CGRecordLayouts.begin(), E = CGRecordLayouts.end();
I != E; ++I)
delete I->second;
CGRecordLayout *RLI = new CGRecordLayout(RO.getLLVMType(),
RO.getPaddingFields());
ResultType = TagDeclTypes[TD] = RLI->getLLVMType();
- CGRecordLayouts[ResultType] = RLI;
+ CGRecordLayouts[TD] = RLI;
// Refine any OpaqueType associated with this RecordDecl.
OpaqueTy->refineAbstractTypeTo(ResultType);
CGRecordLayout *RLI = new CGRecordLayout(RO.getLLVMType(),
RO.getPaddingFields());
ResultType = TagDeclTypes[TD] = RLI->getLLVMType();
- CGRecordLayouts[ResultType] = RLI;
+ CGRecordLayouts[TD] = RLI;
} else {
std::vector<const llvm::Type*> Fields;
ResultType = TagDeclTypes[TD] = llvm::StructType::get(Fields);
/// getCGRecordLayout - Return record layout info for the given llvm::Type.
const CGRecordLayout *
-CodeGenTypes::getCGRecordLayout(const llvm::Type* Ty) const {
- llvm::DenseMap<const llvm::Type*, CGRecordLayout *>::iterator I
- = CGRecordLayouts.find(Ty);
+CodeGenTypes::getCGRecordLayout(const TagDecl *TD) const {
+ llvm::DenseMap<const TagDecl*, CGRecordLayout *>::iterator I
+ = CGRecordLayouts.find(TD);
assert (I != CGRecordLayouts.end()
&& "Unable to find record layout information for type");
return I->second;
/// record layout info.
/// FIXME : If CGRecordLayout is less than 16 bytes then use
/// inline it in the map.
- llvm::DenseMap<const llvm::Type*, CGRecordLayout *> CGRecordLayouts;
+ llvm::DenseMap<const TagDecl*, CGRecordLayout *> CGRecordLayouts;
/// FieldInfo - This maps struct field with corresponding llvm struct type
/// field no. This info is populated by record organizer.
const llvm::Type *ConvertTypeForMem(QualType T);
- const CGRecordLayout *getCGRecordLayout(const llvm::Type*) const;
+ const CGRecordLayout *getCGRecordLayout(const TagDecl*) const;
/// getLLVMFieldNo - Return llvm::StructType element number
/// that corresponds to the field FD.