]> granicus.if.org Git - clang/commitdiff
Fixes a rewriter bug rewriting function decl.
authorFariborz Jahanian <fjahanian@apple.com>
Fri, 12 Feb 2010 17:52:31 +0000 (17:52 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Fri, 12 Feb 2010 17:52:31 +0000 (17:52 +0000)
with block-pointer-type as one or more of its
arguments. Fixes radar 7638400.

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

lib/Frontend/RewriteObjC.cpp
test/Rewriter/rewrite-block-pointer.mm [new file with mode: 0644]

index 91b1aaf4c86af59f14f8e98b0dcac6269c929714..ba2d1c2880431b161eaf316d19e67d841e1f6310 100644 (file)
@@ -2208,6 +2208,19 @@ void RewriteObjC::RewriteFunctionDecl(FunctionDecl *FD) {
   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 @@ void RewriteObjC::RewriteBlockLiteralFunctionDecl(FunctionDecl *FD) {
   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 += ", ";
   }
diff --git a/test/Rewriter/rewrite-block-pointer.mm b/test/Rewriter/rewrite-block-pointer.mm
new file mode 100644 (file)
index 0000000..b03b7a9
--- /dev/null
@@ -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
+
+@interface X
+@end
+
+void foo(void (^block)(int));
+
+@implementation X
+static void enumerateIt(void (^block)(id, id, char *)) {
+      foo(^(int idx) { });
+}
+@end
+
+// CHECK-LP: static void enumerateIt(void (*)(id, id, char *));