From: Anders Carlsson Date: Wed, 24 Nov 2010 19:51:04 +0000 (+0000) Subject: Make CodeGenTypes::getCGRecordLayout compute the layout lazily if it doesn't exist... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c8f01ebbce3c874b43ee78535f7d179517f5f436;p=clang Make CodeGenTypes::getCGRecordLayout compute the layout lazily if it doesn't exist. This matches ASTContext::getASTRecordLayout and is less confusing. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@120107 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/CodeGenTypes.cpp b/lib/CodeGen/CodeGenTypes.cpp index 84c1ceb1ff..5ff9da4c48 100644 --- a/lib/CodeGen/CodeGenTypes.cpp +++ b/lib/CodeGen/CodeGenTypes.cpp @@ -488,6 +488,14 @@ const CGRecordLayout & CodeGenTypes::getCGRecordLayout(const RecordDecl *TD) const { const Type *Key = Context.getTagDeclType(TD).getTypePtr(); const CGRecordLayout *Layout = CGRecordLayouts.lookup(Key); + if (!Layout) { + // Compute the type information. + ConvertTagDeclType(TD); + + // Now try again. + Layout = CGRecordLayouts.lookup(Key); + } + assert(Layout && "Unable to find record layout information for type"); return *Layout; } diff --git a/lib/CodeGen/CodeGenTypes.h b/lib/CodeGen/CodeGenTypes.h index 36acd72ec4..c2b0b75878 100644 --- a/lib/CodeGen/CodeGenTypes.h +++ b/lib/CodeGen/CodeGenTypes.h @@ -143,7 +143,7 @@ public: /// and/or incomplete argument types, this will return the opaque type. const llvm::Type *GetFunctionTypeForVTable(GlobalDecl GD); - const CGRecordLayout &getCGRecordLayout(const RecordDecl*) const; + const CGRecordLayout &getCGRecordLayout(const RecordDecl*); /// UpdateCompletedType - When we find the full definition for a TagDecl, /// replace the 'opaque' type we previously made for it if applicable.