r211380 - Fix crash caused by unnamed union or struct when doing ast-print

Serge Pavlov sepavloff at gmail.com
Fri Jun 20 10:08:33 PDT 2014


Author: sepavloff
Date: Fri Jun 20 12:08:28 2014
New Revision: 211380

URL: http://llvm.org/viewvc/llvm-project?rev=211380&view=rev
Log:
Fix crash caused by unnamed union or struct when doing ast-print

Modified:
    cfe/trunk/lib/AST/StmtPrinter.cpp
    cfe/trunk/test/Coverage/c-language-features.inc

Modified: cfe/trunk/lib/AST/StmtPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/StmtPrinter.cpp?rev=211380&r1=211379&r2=211380&view=diff
==============================================================================
--- cfe/trunk/lib/AST/StmtPrinter.cpp (original)
+++ cfe/trunk/lib/AST/StmtPrinter.cpp Fri Jun 20 12:08:28 2014
@@ -1274,10 +1274,12 @@ void StmtPrinter::VisitDesignatedInitExp
                       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()) {

Modified: cfe/trunk/test/Coverage/c-language-features.inc
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Coverage/c-language-features.inc?rev=211380&r1=211379&r2=211380&view=diff
==============================================================================
--- cfe/trunk/test/Coverage/c-language-features.inc (original)
+++ cfe/trunk/test/Coverage/c-language-features.inc Fri Jun 20 12:08:28 2014
@@ -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 };
+}





More information about the cfe-commits mailing list