Change the key of CGRecordLayouts from being an llvm type* to being a decl*. LLVM
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
diff --git a/CodeGen/CGExprConstant.cpp b/CodeGen/CGExprConstant.cpp
index fbf65aa..f72994d 100644
--- a/CodeGen/CGExprConstant.cpp
+++ b/CodeGen/CGExprConstant.cpp
@@ -104,8 +104,9 @@
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();
diff --git a/CodeGen/CodeGenFunction.cpp b/CodeGen/CodeGenFunction.cpp
index 98d0b01..dc31a27 100644
--- a/CodeGen/CodeGenFunction.cpp
+++ b/CodeGen/CodeGenFunction.cpp
@@ -139,14 +139,11 @@
/// 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
diff --git a/CodeGen/CodeGenTypes.cpp b/CodeGen/CodeGenTypes.cpp
index 06ec467..97fc61d 100644
--- a/CodeGen/CodeGenTypes.cpp
+++ b/CodeGen/CodeGenTypes.cpp
@@ -84,7 +84,7 @@
}
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;
@@ -332,7 +332,7 @@
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);
@@ -356,7 +356,7 @@
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);
@@ -436,9 +436,9 @@
/// 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;
diff --git a/CodeGen/CodeGenTypes.h b/CodeGen/CodeGenTypes.h
index 2ca3d34..0da71ca 100644
--- a/CodeGen/CodeGenTypes.h
+++ b/CodeGen/CodeGenTypes.h
@@ -81,7 +81,7 @@
/// 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.
@@ -136,7 +136,7 @@
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.