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)
llvm-svn: 211380

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

index db70cbe..0f4fd55 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 0ff1237..3566879 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 };
+}