]> granicus.if.org Git - clang/commitdiff
Fix crash caused by unnamed union or struct when doing ast-print
authorSerge Pavlov <sepavloff@gmail.com>
Fri, 20 Jun 2014 17:08:28 +0000 (17:08 +0000)
committerSerge Pavlov <sepavloff@gmail.com>
Fri, 20 Jun 2014 17:08:28 +0000 (17:08 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@211380 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/StmtPrinter.cpp
test/Coverage/c-language-features.inc

index db70cbe72de1928f3629fbf452fb0d87506df14b..0f4fd552461bb458a900137c1d97a78d5accae7b 100644 (file)
@@ -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()) {
index 0ff1237b12e8f6efcf2f115a8c1a6150ca533ea4..356687907d905730ea841e4ea0aa90839bb811ca 100644 (file)
@@ -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 };
+}