From: Serge Pavlov Date: Fri, 20 Jun 2014 17:08:28 +0000 (+0000) Subject: Fix crash caused by unnamed union or struct when doing ast-print X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=426974cf6ddb91596b810e73a479e324ecf5c5f0;p=clang Fix crash caused by unnamed union or struct when doing ast-print git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@211380 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/AST/StmtPrinter.cpp b/lib/AST/StmtPrinter.cpp index db70cbe72d..0f4fd55246 100644 --- a/lib/AST/StmtPrinter.cpp +++ b/lib/AST/StmtPrinter.cpp @@ -1274,10 +1274,12 @@ void StmtPrinter::VisitDesignatedInitExpr(DesignatedInitExpr *Node) { DEnd = Node->designators_end(); D != DEnd; ++D) { if (D->isFieldDesignator()) { - if (D->getDotLoc().isInvalid()) - OS << D->getFieldName()->getName() << ":"; - else + if (D->getDotLoc().isInvalid()) { + if (IdentifierInfo *II = D->getFieldName()) + OS << II->getName() << ":"; + } else { OS << "." << D->getFieldName()->getName(); + } } else { OS << "["; if (D->isArrayDesignator()) { diff --git a/test/Coverage/c-language-features.inc b/test/Coverage/c-language-features.inc index 0ff1237b12..356687907d 100644 --- a/test/Coverage/c-language-features.inc +++ b/test/Coverage/c-language-features.inc @@ -196,3 +196,15 @@ struct s11 { } f0; int f1; }; + +// Unnamed structures. +struct s12 { + struct { + unsigned char aa; + unsigned char bb; + }; +}; + +void f11() { + struct s12 var = { .aa = 33 }; +}