]> granicus.if.org Git - clang/commitdiff
Fix the rewriter that broke with r149987.
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Sun, 12 Feb 2012 04:48:45 +0000 (04:48 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Sun, 12 Feb 2012 04:48:45 +0000 (04:48 +0000)
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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@150325 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Rewrite/RewriteModernObjC.cpp
lib/Rewrite/RewriteObjC.cpp
test/Rewriter/func-in-impl.m [new file with mode: 0644]

index a981ffdf6e72179b008d2f3d30aa3de2e3c2e66a..26646901f043f7e4444a4440bc53911a74ebc3a4 100644 (file)
@@ -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;
index 501811269977f639d5fa089dee125afd71f7cff4..6e8789f6dbc8fedaee7ea836532b4ee8ccbae844 100644 (file)
@@ -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/test/Rewriter/func-in-impl.m b/test/Rewriter/func-in-impl.m
new file mode 100644 (file)
index 0000000..6242c7e
--- /dev/null
@@ -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:")))