Fix a rewriter bug which originates in SemaInit involving

Constructor Initialization which computes Source Location
differently now. Fixes radar 8213998.

llvm-svn: 109018
This commit is contained in:
Fariborz Jahanian 2010-07-21 17:36:39 +00:00
parent c63d812f97
commit 34c85987fe
2 changed files with 35 additions and 4 deletions

View File

@ -5098,7 +5098,14 @@ void RewriteObjC::RewriteByRefVar(VarDecl *ND) {
startLoc = E->getLocStart();
startLoc = SM->getInstantiationLoc(startLoc);
endBuf = SM->getCharacterData(startLoc);
if (dyn_cast<CXXConstructExpr>(E)) {
// Hack alter!
// SemaInit sets startLoc to beginning of the initialized variable when
// rhs involvs copy construction initialization. Must compensate for this.
if (char *atEqual = strchr(endBuf, '='))
endBuf = atEqual + 1;
}
ByrefType += " " + Name;
ByrefType += " = {(void*)";
ByrefType += utostr(isa);
@ -5125,11 +5132,11 @@ void RewriteObjC::RewriteByRefVar(VarDecl *ND) {
//
// double __block BYREFVAR = 1.34, BYREFVAR2 = 1.37;
//
const char *startBuf = SM->getCharacterData(startLoc);
const char *semiBuf = strchr(startBuf, ';');
const char *startInitializerBuf = SM->getCharacterData(startLoc);
const char *semiBuf = strchr(startInitializerBuf, ';');
assert((*semiBuf == ';') && "RewriteByRefVar: can't find ';'");
SourceLocation semiLoc =
startLoc.getFileLocWithOffset(semiBuf-startBuf);
startLoc.getFileLocWithOffset(semiBuf-startInitializerBuf);
InsertText(semiLoc, "}");
}

View File

@ -0,0 +1,24 @@
// RUN: %clang_cc1 -x objective-c++ -Wno-return-type -fblocks -fms-extensions -rewrite-objc %s -o %t-rw.cpp
// RUN: %clang_cc1 -fsyntax-only -fblocks -Wno-address-of-temporary -D"SEL=void*" -D"__declspec(X)=" %t-rw.cpp
// rdar : // 8213998
typedef unsigned int NSUInteger;
typedef struct _NSRange {
NSUInteger location;
NSUInteger length;
} NSRange;
static __inline NSRange NSMakeRange(NSUInteger loc, NSUInteger len) {
NSRange r;
r.location = loc;
r.length = len;
return r;
}
void bar() {
__block NSRange previousRange = NSMakeRange(0, 0);
void (^blk)() = ^{
previousRange = NSMakeRange(1, 0);
};
}