[cfe-commits] r150325 - in /cfe/trunk: lib/Rewrite/RewriteModernObjC.cpp lib/Rewrite/RewriteObjC.cpp test/Rewriter/func-in-impl.m

Argyrios Kyrtzidis akyrtzi at gmail.com
Sat Feb 11 20:48:45 PST 2012


Author: akirtzidis
Date: Sat Feb 11 22:48:45 2012
New Revision: 150325

URL: http://llvm.org/viewvc/llvm-project?rev=150325&view=rev
Log:
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.

Added:
    cfe/trunk/test/Rewriter/func-in-impl.m
Modified:
    cfe/trunk/lib/Rewrite/RewriteModernObjC.cpp
    cfe/trunk/lib/Rewrite/RewriteObjC.cpp

Modified: cfe/trunk/lib/Rewrite/RewriteModernObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Rewrite/RewriteModernObjC.cpp?rev=150325&r1=150324&r2=150325&view=diff
==============================================================================
--- cfe/trunk/lib/Rewrite/RewriteModernObjC.cpp (original)
+++ cfe/trunk/lib/Rewrite/RewriteModernObjC.cpp Sat Feb 11 22:48:45 2012
@@ -4834,6 +4834,9 @@
       // 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;

Modified: cfe/trunk/lib/Rewrite/RewriteObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Rewrite/RewriteObjC.cpp?rev=150325&r1=150324&r2=150325&view=diff
==============================================================================
--- cfe/trunk/lib/Rewrite/RewriteObjC.cpp (original)
+++ cfe/trunk/lib/Rewrite/RewriteObjC.cpp Sat Feb 11 22:48:45 2012
@@ -4922,6 +4922,9 @@
       // 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;

Added: cfe/trunk/test/Rewriter/func-in-impl.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Rewriter/func-in-impl.m?rev=150325&view=auto
==============================================================================
--- cfe/trunk/test/Rewriter/func-in-impl.m (added)
+++ cfe/trunk/test/Rewriter/func-in-impl.m Sat Feb 11 22:48:45 2012
@@ -0,0 +1,29 @@
+// RUN: %clang_cc1 -rewrite-objc %s -o - | FileCheck %s
+
+ at interface I {
+  id _delegate;
+}
+-(void)foo;
+ at end
+
+ at 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);
+}
+
+ at end
+
+// CHECK: if (((id (*)(id, SEL, ...))(void *)objc_msgSend)((id)((struct I_IMPL *)self)->_delegate, sel_registerName("respondsToSelector:"), sel_registerName("handlePortMessage:")))





More information about the cfe-commits mailing list