Fixes a rewriter bug rewriting function decl.

with block-pointer-type as one or more of its
arguments. Fixes radar 7638400.

llvm-svn: 95992
This commit is contained in:
Fariborz Jahanian 2010-02-12 17:52:31 +00:00
parent 5089c769bb
commit a459c4453d
2 changed files with 30 additions and 2 deletions

View 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 += ", ";
}

View File

@ -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 *));