summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Blaikie <dblaikie@gmail.com>2013-08-20 21:03:29 +0000
committerDavid Blaikie <dblaikie@gmail.com>2013-08-20 21:03:29 +0000
commit8d5e128bd48a9c481150251c9761ce7838e65e87 (patch)
tree0d47e10113a65904e836d220cbedc6706089ef41
parentd8f336255731adfce67fbefcef214bd26b346814 (diff)
downloadbcm5719-llvm-8d5e128bd48a9c481150251c9761ce7838e65e87.tar.gz
bcm5719-llvm-8d5e128bd48a9c481150251c9761ce7838e65e87.zip
DebugInfo: Simplify/clarify propagation of typemembers between declaration and definition
Based on code review feedback from Eric Christopher (on r188739) and Adrian Prantl (r188642). llvm-svn: 188829
-rw-r--r--clang/lib/CodeGen/CGDebugInfo.cpp48
-rw-r--r--clang/lib/CodeGen/CGDebugInfo.h5
2 files changed, 21 insertions, 32 deletions
diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp
index 7177fe2cc32..d30925c7d22 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -602,10 +602,11 @@ llvm::DIType CGDebugInfo::CreateType(const PointerType *Ty,
}
// Creates a forward declaration for a RecordDecl in the given context.
-llvm::DIType CGDebugInfo::getOrCreateRecordFwdDecl(const RecordDecl *RD,
- llvm::DIDescriptor Ctx) {
+llvm::DICompositeType
+CGDebugInfo::getOrCreateRecordFwdDecl(const RecordDecl *RD,
+ llvm::DIDescriptor Ctx) {
if (llvm::DIType T = getTypeOrNull(CGM.getContext().getRecordType(RD)))
- return T;
+ return llvm::DICompositeType(T);
llvm::DIFile DefUnit = getOrCreateFile(RD->getLocation());
unsigned Line = getLineNumber(RD->getLocation());
StringRef RDName = getClassName(RD);
@@ -642,29 +643,11 @@ llvm::DIDescriptor CGDebugInfo::createContextChain(const Decl *Context) {
if (const NamespaceDecl *NSDecl = dyn_cast<NamespaceDecl>(Context))
return llvm::DIDescriptor(getOrCreateNameSpace(NSDecl));
- if (const RecordDecl *RD = dyn_cast<RecordDecl>(Context)) {
- if (!RD->isDependentType()) {
- llvm::DICompositeType T(getTypeOrNull(CGM.getContext().getRecordType(RD)));
- llvm::DICompositeType Ty(getOrCreateLimitedType(
+ if (const RecordDecl *RD = dyn_cast<RecordDecl>(Context))
+ if (!RD->isDependentType())
+ return getOrCreateLimitedType(
CGM.getContext().getRecordType(RD)->castAs<RecordType>(),
- getOrCreateMainFile()));
- if (!Ty.getTypeArray().getNumElements()) {
- if (T) {
- llvm::DIArray PrevMem = T.getTypeArray();
- unsigned NumElements = PrevMem.getNumElements();
- if (NumElements == 1 && !PrevMem.getElement(0))
- NumElements = 0;
- SmallVector<llvm::Value *, 16> EltTys;
- EltTys.reserve(NumElements);
- for (unsigned i = 0; i != NumElements; ++i)
- EltTys.push_back(PrevMem.getElement(i));
- llvm::DIArray Elements = DBuilder.getOrCreateArray(EltTys);
- Ty.setTypeArray(Elements);
- }
- }
- return llvm::DIDescriptor(Ty);
- }
- }
+ getOrCreateMainFile());
return TheCU;
}
@@ -2195,7 +2178,7 @@ llvm::DIType CGDebugInfo::getOrCreateLimitedType(const RecordType *Ty,
llvm::DIFile Unit) {
QualType QTy(Ty, 0);
- llvm::DIType T = getTypeOrNull(QTy);
+ llvm::DICompositeType T(getTypeOrNull(QTy));
// We may have cached a forward decl when we could have created
// a non-forward decl. Go ahead and create a non-forward decl
@@ -2203,7 +2186,12 @@ llvm::DIType CGDebugInfo::getOrCreateLimitedType(const RecordType *Ty,
if (T && !T.isForwardDecl()) return T;
// Otherwise create the type.
- llvm::DIType Res = CreateLimitedType(Ty);
+ llvm::DICompositeType Res = CreateLimitedType(Ty);
+
+ // Propagate members from the declaration to the definition
+ // CreateType(const RecordType*) will overwrite this with the members in the
+ // correct order if the full type is needed.
+ Res.setTypeArray(T.getTypeArray());
if (T && T.isForwardDecl())
ReplaceMap.push_back(
@@ -2215,7 +2203,7 @@ llvm::DIType CGDebugInfo::getOrCreateLimitedType(const RecordType *Ty,
}
// TODO: Currently used for context chains when limiting debug info.
-llvm::DIType CGDebugInfo::CreateLimitedType(const RecordType *Ty) {
+llvm::DICompositeType CGDebugInfo::CreateLimitedType(const RecordType *Ty) {
RecordDecl *RD = Ty->getDecl();
// Get overall information about the record type for the debug info.
@@ -2238,8 +2226,8 @@ llvm::DIType CGDebugInfo::CreateLimitedType(const RecordType *Ty) {
// destined for completion (might still have an issue if this caller only
// required a declaration but the context construction ended up creating a
// definition)
- if (llvm::DIType T = getTypeOrNull(CGM.getContext().getRecordType(RD)))
- if (!T.isForwardDecl() || !RD->getDefinition())
+ llvm::DICompositeType T(getTypeOrNull(CGM.getContext().getRecordType(RD)));
+ if (T && (!T.isForwardDecl() || !RD->getDefinition()))
return T;
// If this is just a forward declaration, construct an appropriately
diff --git a/clang/lib/CodeGen/CGDebugInfo.h b/clang/lib/CodeGen/CGDebugInfo.h
index d0e16bfe3eb..6ecc7e5fe10 100644
--- a/clang/lib/CodeGen/CGDebugInfo.h
+++ b/clang/lib/CodeGen/CGDebugInfo.h
@@ -116,7 +116,7 @@ class CGDebugInfo {
llvm::DIType CreateType(const FunctionType *Ty, llvm::DIFile F);
llvm::DIType CreateType(const RecordType *Ty, bool Declaration);
llvm::DIType CreateTypeDefinition(const RecordType *Ty);
- llvm::DIType CreateLimitedType(const RecordType *Ty);
+ llvm::DICompositeType CreateLimitedType(const RecordType *Ty);
void CollectContainingType(const CXXRecordDecl *RD, llvm::DICompositeType CT);
llvm::DIType CreateType(const ObjCInterfaceType *Ty, llvm::DIFile F);
llvm::DIType CreateType(const ObjCObjectType *Ty, llvm::DIFile F);
@@ -309,7 +309,8 @@ private:
llvm::DIScope getCurrentContextDescriptor(const Decl *Decl);
/// \brief Create a forward decl for a RecordType in a given context.
- llvm::DIType getOrCreateRecordFwdDecl(const RecordDecl *, llvm::DIDescriptor);
+ llvm::DICompositeType getOrCreateRecordFwdDecl(const RecordDecl *,
+ llvm::DIDescriptor);
/// createContextChain - Create a set of decls for the context chain.
llvm::DIDescriptor createContextChain(const Decl *Decl);
OpenPOWER on IntegriCloud