[cfe-commits] r155740 - in /cfe/trunk: lib/Rewrite/RewriteModernObjC.cpp test/Rewriter/rewrite-modern-struct-ivar.mm
Fariborz Jahanian
fjahanian at apple.com
Fri Apr 27 15:48:54 PDT 2012
Author: fjahanian
Date: Fri Apr 27 17:48:54 2012
New Revision: 155740
URL: http://llvm.org/viewvc/llvm-project?rev=155740&view=rev
Log:
objective-c modern translator: Correctly translate
nonfragile ivar access code when ivar type is a
locally defined struct/union type. // rdar://11323187
Modified:
cfe/trunk/lib/Rewrite/RewriteModernObjC.cpp
cfe/trunk/test/Rewriter/rewrite-modern-struct-ivar.mm
Modified: cfe/trunk/lib/Rewrite/RewriteModernObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Rewrite/RewriteModernObjC.cpp?rev=155740&r1=155739&r2=155740&view=diff
==============================================================================
--- cfe/trunk/lib/Rewrite/RewriteModernObjC.cpp (original)
+++ cfe/trunk/lib/Rewrite/RewriteModernObjC.cpp Fri Apr 27 17:48:54 2012
@@ -7245,13 +7245,50 @@
SourceLocation(),
addExpr);
QualType IvarT = D->getType();
+
+ if (IvarT->isRecordType()) {
+ RecordDecl *RD = IvarT->getAs<RecordType>()->getDecl();
+ RD = RD->getDefinition();
+ bool structIsInside = RD &&
+ Context->getSourceManager().isBeforeInTranslationUnit(
+ iFaceDecl->getDecl()->getLocation(), RD->getLocation());
+ if (structIsInside) {
+ // decltype(((Foo_IMPL*)0)->bar) *
+ std::string RecName = iFaceDecl->getDecl()->getName();
+ RecName += "_IMPL";
+ RecordDecl *RD = RecordDecl::Create(*Context, TTK_Struct, TUDecl,
+ SourceLocation(), SourceLocation(),
+ &Context->Idents.get(RecName.c_str()));
+ QualType PtrStructIMPL = Context->getPointerType(Context->getTagDeclType(RD));
+ unsigned UnsignedIntSize =
+ static_cast<unsigned>(Context->getTypeSize(Context->UnsignedIntTy));
+ Expr *Zero = IntegerLiteral::Create(*Context,
+ llvm::APInt(UnsignedIntSize, 0),
+ Context->UnsignedIntTy, SourceLocation());
+ Zero = NoTypeInfoCStyleCastExpr(Context, PtrStructIMPL, CK_BitCast, Zero);
+ ParenExpr *PE = new (Context) ParenExpr(SourceLocation(), SourceLocation(),
+ Zero);
+ FieldDecl *FD = FieldDecl::Create(*Context, 0, SourceLocation(),
+ SourceLocation(),
+ &Context->Idents.get(D->getNameAsString()),
+ IvarT, 0,
+ /*BitWidth=*/0, /*Mutable=*/true,
+ /*HasInit=*/false);
+ MemberExpr *ME = new (Context) MemberExpr(PE, true, FD, SourceLocation(),
+ FD->getType(), VK_LValue,
+ OK_Ordinary);
+ IvarT = Context->getDecltypeType(ME, ME->getType());
+ }
+ }
convertObjCTypeToCStyleType(IvarT);
QualType castT = Context->getPointerType(IvarT);
-
+
castExpr = NoTypeInfoCStyleCastExpr(Context,
castT,
CK_BitCast,
PE);
+
+
Expr *Exp = new (Context) UnaryOperator(castExpr, UO_Deref, IvarT,
VK_LValue, OK_Ordinary,
SourceLocation());
Modified: cfe/trunk/test/Rewriter/rewrite-modern-struct-ivar.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Rewriter/rewrite-modern-struct-ivar.mm?rev=155740&r1=155739&r2=155740&view=diff
==============================================================================
--- cfe/trunk/test/Rewriter/rewrite-modern-struct-ivar.mm (original)
+++ cfe/trunk/test/Rewriter/rewrite-modern-struct-ivar.mm Fri Apr 27 17:48:54 2012
@@ -1,7 +1,7 @@
// RUN: %clang_cc1 -E %s -o %t.mm
// RUN: %clang_cc1 -fblocks -rewrite-objc -fms-extensions %t.mm -o %t-rw.cpp
// RUN: FileCheck --input-file=%t-rw.cpp %s
-// RUN: %clang_cc1 -fsyntax-only -Wno-address-of-temporary -D"Class=void*" -D"id=void*" -D"SEL=void*" -D"__declspec(X)=" %t-rw.cpp
+// RUN: %clang_cc1 -fsyntax-only -Wno-address-of-temporary -Wno-c++11-narrowing -std=c++11 -D"Class=void*" -D"id=void*" -D"SEL=void*" -D"__declspec(X)=" %t-rw.cpp
struct S {
int i1;
@@ -20,5 +20,33 @@
@implementation I
- (struct S) dMeth{ return struct_ivar; }
@end
-
+
// CHECK: return (*(struct S *)((char *)self + OBJC_IVAR_$_I$struct_ivar));
+
+// rdar://11323187
+ at interface Foo{
+ @protected
+ struct {
+ int x:1;
+ int y:1;
+ } bar;
+
+ struct _S {
+ int x:1;
+ int y:1;
+ } s;
+
+}
+ at end
+ at implementation Foo
+- (void)x {
+ bar.x = 0;
+ bar.y = 1;
+
+ s.x = 0;
+ s.y = 1;
+}
+ at end
+
+// CHECK: (*(decltype(((Foo_IMPL *)0U)->bar) *)((char *)self + OBJC_IVAR_$_Foo$bar)).x = 0;
+// CHECK: (*(decltype(((Foo_IMPL *)0U)->s) *)((char *)self + OBJC_IVAR_$_Foo$s)).x = 0;
More information about the cfe-commits
mailing list