[cfe-commits] r61384 - in /cfe/trunk: Driver/RewriteObjC.cpp test/Rewriter/objc-super-test.m
Steve Naroff
snaroff at apple.com
Tue Dec 23 12:11:24 PST 2008
Author: snaroff
Date: Tue Dec 23 14:11:22 2008
New Revision: 61384
URL: http://llvm.org/viewvc/llvm-project?rev=61384&view=rev
Log:
Fix <rdar://problem/6465284> clang ObjC rewriter: objc_super messed up again.
Modified:
cfe/trunk/Driver/RewriteObjC.cpp
cfe/trunk/test/Rewriter/objc-super-test.m
Modified: cfe/trunk/Driver/RewriteObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/RewriteObjC.cpp?rev=61384&r1=61383&r2=61384&view=diff
==============================================================================
--- cfe/trunk/Driver/RewriteObjC.cpp (original)
+++ cfe/trunk/Driver/RewriteObjC.cpp Tue Dec 23 14:11:22 2008
@@ -461,17 +461,14 @@
if (IsHeader)
Preamble = "#pragma once\n";
Preamble += "struct objc_selector; struct objc_class;\n";
- Preamble += "#ifndef OBJC_SUPER\n";
- Preamble += "struct objc_super { struct objc_object *object; ";
+ Preamble += "struct __rw_objc_super { struct objc_object *object; ";
Preamble += "struct objc_object *superClass; ";
if (LangOpts.Microsoft) {
// Add a constructor for creating temporary objects.
- Preamble += "objc_super(struct objc_object *o, struct objc_object *s) : ";
+ Preamble += "__rw_objc_super(struct objc_object *o, struct objc_object *s) : ";
Preamble += "object(o), superClass(s) {} ";
}
Preamble += "};\n";
- Preamble += "#define OBJC_SUPER\n";
- Preamble += "#endif\n";
Preamble += "#ifndef _REWRITER_typedef_Protocol\n";
Preamble += "typedef struct objc_object Protocol;\n";
Preamble += "#define _REWRITER_typedef_Protocol\n";
@@ -1951,7 +1948,7 @@
void RewriteObjC::SynthSuperContructorFunctionDecl() {
if (SuperContructorFunctionDecl)
return;
- IdentifierInfo *msgSendIdent = &Context->Idents.get("objc_super");
+ IdentifierInfo *msgSendIdent = &Context->Idents.get("__rw_objc_super");
llvm::SmallVector<QualType, 16> ArgTys;
QualType argT = Context->getObjCIdType();
assert(!argT.isNull() && "Can't find 'id' type");
@@ -2296,6 +2293,18 @@
superType, SourceLocation());
SuperRep = new CallExpr(DRE, &InitExprs[0], InitExprs.size(),
superType, SourceLocation());
+ // The code for super is a little tricky to prevent collision with
+ // the structure definition in the header. The rewriter has it's own
+ // internal definition (__rw_objc_super) that is uses. This is why
+ // we need the cast below. For example:
+ // (struct objc_super *)&__rw_objc_super((id)self, (id)objc_getClass("SUPER"))
+ //
+ SuperRep = new UnaryOperator(SuperRep, UnaryOperator::AddrOf,
+ Context->getPointerType(SuperRep->getType()),
+ SourceLocation());
+ SuperRep = new CStyleCastExpr(Context->getPointerType(superType),
+ SuperRep, Context->getPointerType(superType),
+ SourceLocation(), SourceLocation());
} else {
// (struct objc_super) { <exprs from above> }
InitListExpr *ILE = new InitListExpr(SourceLocation(),
@@ -2303,12 +2312,12 @@
SourceLocation(), false);
SuperRep = new CompoundLiteralExpr(SourceLocation(), superType, ILE,
false);
+ // struct objc_super *
+ SuperRep = new UnaryOperator(SuperRep, UnaryOperator::AddrOf,
+ Context->getPointerType(SuperRep->getType()),
+ SourceLocation());
}
- // struct objc_super *
- Expr *Unop = new UnaryOperator(SuperRep, UnaryOperator::AddrOf,
- Context->getPointerType(SuperRep->getType()),
- SourceLocation());
- MsgExprs.push_back(Unop);
+ MsgExprs.push_back(SuperRep);
} else {
llvm::SmallVector<Expr*, 8> ClsExprs;
QualType argType = Context->getPointerType(Context->CharTy);
@@ -2365,6 +2374,18 @@
superType, SourceLocation());
SuperRep = new CallExpr(DRE, &InitExprs[0], InitExprs.size(),
superType, SourceLocation());
+ // The code for super is a little tricky to prevent collision with
+ // the structure definition in the header. The rewriter has it's own
+ // internal definition (__rw_objc_super) that is uses. This is why
+ // we need the cast below. For example:
+ // (struct objc_super *)&__rw_objc_super((id)self, (id)objc_getClass("SUPER"))
+ //
+ SuperRep = new UnaryOperator(SuperRep, UnaryOperator::AddrOf,
+ Context->getPointerType(SuperRep->getType()),
+ SourceLocation());
+ SuperRep = new CStyleCastExpr(Context->getPointerType(superType),
+ SuperRep, Context->getPointerType(superType),
+ SourceLocation(), SourceLocation());
} else {
// (struct objc_super) { <exprs from above> }
InitListExpr *ILE = new InitListExpr(SourceLocation(),
@@ -2372,11 +2393,7 @@
SourceLocation(), false);
SuperRep = new CompoundLiteralExpr(SourceLocation(), superType, ILE, false);
}
- // struct objc_super *
- Expr *Unop = new UnaryOperator(SuperRep, UnaryOperator::AddrOf,
- Context->getPointerType(SuperRep->getType()),
- SourceLocation());
- MsgExprs.push_back(Unop);
+ MsgExprs.push_back(SuperRep);
} else {
// Remove all type-casts because it may contain objc-style types; e.g.
// Foo<Proto> *.
Modified: cfe/trunk/test/Rewriter/objc-super-test.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Rewriter/objc-super-test.m?rev=61384&r1=61383&r2=61384&view=diff
==============================================================================
--- cfe/trunk/test/Rewriter/objc-super-test.m (original)
+++ cfe/trunk/test/Rewriter/objc-super-test.m Tue Dec 23 14:11:22 2008
@@ -1,5 +1,8 @@
// RUN: clang -rewrite-objc %s -o - | grep objc_msgSendSuper | grep MainMethod
+typedef struct objc_selector *SEL;
+typedef struct objc_object *id;
+
@interface SUPER
- (int) MainMethod;
@end
More information about the cfe-commits
mailing list