From 97fd83a8d827400afda3c5fba0840c1f10007239 Mon Sep 17 00:00:00 2001 From: Fariborz Jahanian Date: Mon, 11 Jan 2010 21:17:32 +0000 Subject: [PATCH] Fix a problem related to rewrite of anonymous unions. (fixes radar 6948022) git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@93186 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/AST/StmtPrinter.cpp | 5 +++-- test/Rewriter/rewrite-anonymous-union.m | 30 +++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 test/Rewriter/rewrite-anonymous-union.m diff --git a/lib/AST/StmtPrinter.cpp b/lib/AST/StmtPrinter.cpp index a7e42af04d..83d38f8452 100644 --- a/lib/AST/StmtPrinter.cpp +++ b/lib/AST/StmtPrinter.cpp @@ -739,9 +739,10 @@ void StmtPrinter::VisitCallExpr(CallExpr *Call) { void StmtPrinter::VisitMemberExpr(MemberExpr *Node) { // FIXME: Suppress printing implicit bases (like "this") PrintExpr(Node->getBase()); + if (FieldDecl *FD = dyn_cast(Node->getMemberDecl())) + if (FD->isAnonymousStructOrUnion()) + return; OS << (Node->isArrow() ? "->" : "."); - // FIXME: Suppress printing references to unnamed objects - // representing anonymous unions/structs if (NestedNameSpecifier *Qualifier = Node->getQualifier()) Qualifier->print(OS, Policy); diff --git a/test/Rewriter/rewrite-anonymous-union.m b/test/Rewriter/rewrite-anonymous-union.m new file mode 100644 index 0000000000..579a06854f --- /dev/null +++ b/test/Rewriter/rewrite-anonymous-union.m @@ -0,0 +1,30 @@ +// RUN: %clang_cc1 -rewrite-objc -o - %s +// rdar://6948022 + +typedef unsigned int uint32_t; + +typedef struct { + union { + uint32_t daysOfWeek; + uint32_t dayOfMonth; + }; + uint32_t nthOccurrence; +} OSPatternSpecificData; + +@interface NSNumber ++ (NSNumber *)numberWithLong:(long)value; +@end + +@interface OSRecurrence { + OSPatternSpecificData _pts; +} +- (void)_setTypeSpecificInfoOnRecord; +@end + +@implementation OSRecurrence +- (void)_setTypeSpecificInfoOnRecord +{ + [NSNumber numberWithLong:(_pts.dayOfMonth >= 31 ? -1 : _pts.dayOfMonth)]; +} +@end +