From: Sean Callanan Date: Fri, 4 May 2012 18:22:53 +0000 (+0000) Subject: IsTailPaddedMemberArray uses a FieldDecl's X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d2cf348f0df76bf1745f131db2ceeb59f23a7305;p=clang IsTailPaddedMemberArray uses a FieldDecl's getTypeSourceInfo() without checking for NULL. FieldDecls may have NULL TypeSourceInfo, and in fact some FieldDecls generated by Clang -- and all FieldDecls generated by LLDB -- have no TypeSourceInfo. This patch makes IsTailPaddedMemberArray check for NULL. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@156186 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaChecking.cpp b/lib/Sema/SemaChecking.cpp index 4504a6a1e1..44f4ac671f 100644 --- a/lib/Sema/SemaChecking.cpp +++ b/lib/Sema/SemaChecking.cpp @@ -4587,11 +4587,15 @@ static bool IsTailPaddedMemberArray(Sema &S, llvm::APInt Size, // Don't consider sizes resulting from macro expansions or template argument // substitution to form C89 tail-padded arrays. - ConstantArrayTypeLoc TL = - cast(FD->getTypeSourceInfo()->getTypeLoc()); - const Expr *SizeExpr = dyn_cast(TL.getSizeExpr()); - if (!SizeExpr || SizeExpr->getExprLoc().isMacroID()) - return false; + + TypeSourceInfo *TInfo = FD->getTypeSourceInfo(); + if (TInfo) { + ConstantArrayTypeLoc TL = + cast(TInfo->getTypeLoc()); + const Expr *SizeExpr = dyn_cast(TL.getSizeExpr()); + if (!SizeExpr || SizeExpr->getExprLoc().isMacroID()) + return false; + } const RecordDecl *RD = dyn_cast(FD->getDeclContext()); if (!RD) return false;