[cfe-commits] r95992 - in /cfe/trunk: lib/Frontend/RewriteObjC.cpp test/Rewriter/rewrite-block-pointer.mm

Fariborz Jahanian fjahanian at apple.com
Fri Feb 12 09:52:31 PST 2010


Author: fjahanian
Date: Fri Feb 12 11:52:31 2010
New Revision: 95992

URL: http://llvm.org/viewvc/llvm-project?rev=95992&view=rev
Log:
Fixes a rewriter bug rewriting function decl.
with block-pointer-type as one or more of its
arguments. Fixes radar 7638400.

Added:
    cfe/trunk/test/Rewriter/rewrite-block-pointer.mm
Modified:
    cfe/trunk/lib/Frontend/RewriteObjC.cpp

Modified: cfe/trunk/lib/Frontend/RewriteObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/RewriteObjC.cpp?rev=95992&r1=95991&r2=95992&view=diff

==============================================================================
--- cfe/trunk/lib/Frontend/RewriteObjC.cpp (original)
+++ cfe/trunk/lib/Frontend/RewriteObjC.cpp Fri Feb 12 11:52:31 2010
@@ -2208,6 +2208,19 @@
   RewriteObjCQualifiedInterfaceTypes(FD);
 }
 
+static void RewriteBlockPointerType(std::string& Str, QualType Type) {
+  std::string TypeString(Type.getAsString());
+  const char *argPtr = TypeString.c_str();
+  if (!strchr(argPtr, '^')) {
+    Str += TypeString;
+    return;
+  }
+  while (*argPtr) {
+    Str += (*argPtr == '^' ? '*' : *argPtr);
+    argPtr++;
+  }
+}
+
 void RewriteObjC::RewriteBlockLiteralFunctionDecl(FunctionDecl *FD) {
   SourceLocation FunLocStart = FD->getTypeSpecStartLoc();
   const FunctionType *funcType = FD->getType()->getAs<FunctionType>();
@@ -2222,8 +2235,7 @@
   unsigned numArgs = proto->getNumArgs();
   for (unsigned i = 0; i < numArgs; i++) {
     QualType ArgType = proto->getArgType(i);
-    FdStr += ArgType.getAsString();
-    
+    RewriteBlockPointerType(FdStr, ArgType);
     if (i+1 < numArgs)
       FdStr += ", ";
   }

Added: cfe/trunk/test/Rewriter/rewrite-block-pointer.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Rewriter/rewrite-block-pointer.mm?rev=95992&view=auto

==============================================================================
--- cfe/trunk/test/Rewriter/rewrite-block-pointer.mm (added)
+++ cfe/trunk/test/Rewriter/rewrite-block-pointer.mm Fri Feb 12 11:52:31 2010
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -x objective-c++ -Wno-return-type -fblocks -fms-extensions -rewrite-objc %s -o %t-rw.cpp
+// RUN: FileCheck -check-prefix LP --input-file=%t-rw.cpp %s
+// radar 7638400
+
+ at interface X
+ at end
+
+void foo(void (^block)(int));
+
+ at implementation X
+static void enumerateIt(void (^block)(id, id, char *)) {
+      foo(^(int idx) { });
+}
+ at end
+
+// CHECK-LP: static void enumerateIt(void (*)(id, id, char *));





More information about the cfe-commits mailing list