r188209 - Fix pretty-printing for unnamed unions.

Eli Friedman eli.friedman at gmail.com
Mon Aug 12 14:54:05 PDT 2013


Author: efriedma
Date: Mon Aug 12 16:54:04 2013
New Revision: 188209

URL: http://llvm.org/viewvc/llvm-project?rev=188209&view=rev
Log:
Fix pretty-printing for unnamed unions.

This is just a couple of minor fixes to account for the existence
of ElaboratedType.

Modified:
    cfe/trunk/lib/AST/DeclPrinter.cpp
    cfe/trunk/lib/AST/TypePrinter.cpp
    cfe/trunk/test/SemaCXX/ast-print.cpp

Modified: cfe/trunk/lib/AST/DeclPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclPrinter.cpp?rev=188209&r1=188208&r2=188209&view=diff
==============================================================================
--- cfe/trunk/lib/AST/DeclPrinter.cpp (original)
+++ cfe/trunk/lib/AST/DeclPrinter.cpp Mon Aug 12 16:54:04 2013
@@ -260,6 +260,8 @@ void DeclPrinter::VisitDeclContext(DeclC
     QualType CurDeclType = getDeclType(*D);
     if (!Decls.empty() && !CurDeclType.isNull()) {
       QualType BaseType = GetBaseType(CurDeclType);
+      if (!BaseType.isNull() && isa<ElaboratedType>(BaseType))
+        BaseType = cast<ElaboratedType>(BaseType)->getNamedType();
       if (!BaseType.isNull() && isa<TagType>(BaseType) &&
           cast<TagType>(BaseType)->getDecl() == Decls[0]) {
         Decls.push_back(*D);

Modified: cfe/trunk/lib/AST/TypePrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/TypePrinter.cpp?rev=188209&r1=188208&r2=188209&view=diff
==============================================================================
--- cfe/trunk/lib/AST/TypePrinter.cpp (original)
+++ cfe/trunk/lib/AST/TypePrinter.cpp Mon Aug 12 16:54:04 2013
@@ -1003,6 +1003,8 @@ void TypePrinter::printInjectedClassName
 
 void TypePrinter::printElaboratedBefore(const ElaboratedType *T,
                                         raw_ostream &OS) {
+  if (Policy.SuppressTag && isa<TagType>(T->getNamedType()))
+    return;
   OS << TypeWithKeyword::getKeywordName(T->getKeyword());
   if (T->getKeyword() != ETK_None)
     OS << " ";

Modified: cfe/trunk/test/SemaCXX/ast-print.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/ast-print.cpp?rev=188209&r1=188208&r2=188209&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/ast-print.cpp (original)
+++ cfe/trunk/test/SemaCXX/ast-print.cpp Mon Aug 12 16:54:04 2013
@@ -153,3 +153,14 @@ void test13() {
   __c11_atomic_load(&i, 0);
 }
 
+
+// CHECK: void test14() {
+// CHECK:     struct X {
+// CHECK:         union {
+// CHECK:             int x;
+// CHECK:         } x;
+// CHECK:     };
+// CHECK: }
+void test14() {
+  struct X { union { int x; } x; };
+}





More information about the cfe-commits mailing list