diff options
author | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2012-02-12 04:48:45 +0000 |
---|---|---|
committer | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2012-02-12 04:48:45 +0000 |
commit | 75627ad8baf9f623953042a3204570a8d211ee94 (patch) | |
tree | 0cd2c9f749391f60aa5aa605598d4de77f22e192 | |
parent | f285256f72a50440c8cab3537581f4d5e9ae260a (diff) | |
download | bcm5719-llvm-75627ad8baf9f623953042a3204570a8d211ee94.tar.gz bcm5719-llvm-75627ad8baf9f623953042a3204570a8d211ee94.zip |
Fix the rewriter that broke with r149987.
r149987 changed the way parsing happens inside an @implementation;
it aggregates the declarations inside and reports them together as a DeclGroup.
This had the side effect that function declarations were reported together with
their definition, while the rewriter expected for function declarations to be
reported immediately to the consumer and thus not have a body.
Fix this by having the rewriter actually check with isThisDeclarationADefinition()
to make sure the body comes from the current decl before rewriting it.
llvm-svn: 150325
-rw-r--r-- | clang/lib/Rewrite/RewriteModernObjC.cpp | 3 | ||||
-rw-r--r-- | clang/lib/Rewrite/RewriteObjC.cpp | 3 | ||||
-rw-r--r-- | clang/test/Rewriter/func-in-impl.m | 29 |
3 files changed, 35 insertions, 0 deletions
diff --git a/clang/lib/Rewrite/RewriteModernObjC.cpp b/clang/lib/Rewrite/RewriteModernObjC.cpp index a981ffdf6e7..26646901f04 100644 --- a/clang/lib/Rewrite/RewriteModernObjC.cpp +++ b/clang/lib/Rewrite/RewriteModernObjC.cpp @@ -4834,6 +4834,9 @@ void RewriteModernObjC::HandleDeclInMainFile(Decl *D) { // definitions using the same code. RewriteBlocksInFunctionProtoType(FD->getType(), FD); + if (!FD->isThisDeclarationADefinition()) + break; + // FIXME: If this should support Obj-C++, support CXXTryStmt if (CompoundStmt *Body = dyn_cast_or_null<CompoundStmt>(FD->getBody())) { CurFunctionDef = FD; diff --git a/clang/lib/Rewrite/RewriteObjC.cpp b/clang/lib/Rewrite/RewriteObjC.cpp index 50181126997..6e8789f6dbc 100644 --- a/clang/lib/Rewrite/RewriteObjC.cpp +++ b/clang/lib/Rewrite/RewriteObjC.cpp @@ -4922,6 +4922,9 @@ void RewriteObjC::HandleDeclInMainFile(Decl *D) { // definitions using the same code. RewriteBlocksInFunctionProtoType(FD->getType(), FD); + if (!FD->isThisDeclarationADefinition()) + break; + // FIXME: If this should support Obj-C++, support CXXTryStmt if (CompoundStmt *Body = dyn_cast_or_null<CompoundStmt>(FD->getBody())) { CurFunctionDef = FD; diff --git a/clang/test/Rewriter/func-in-impl.m b/clang/test/Rewriter/func-in-impl.m new file mode 100644 index 00000000000..6242c7ea770 --- /dev/null +++ b/clang/test/Rewriter/func-in-impl.m @@ -0,0 +1,29 @@ +// RUN: %clang_cc1 -rewrite-objc %s -o - | FileCheck %s + +@interface I { + id _delegate; +} +-(void)foo; +@end + +@implementation I + +static void KKKK(int w); + +-(void) foo { + KKKK(0); +} + +static void KKKK(int w) { + I *self = (I *)0; + if ([self->_delegate respondsToSelector:@selector(handlePortMessage:)]) { + } +} + +-(void) foo2 { + KKKK(0); +} + +@end + +// CHECK: if (((id (*)(id, SEL, ...))(void *)objc_msgSend)((id)((struct I_IMPL *)self)->_delegate, sel_registerName("respondsToSelector:"), sel_registerName("handlePortMessage:"))) |