[cfe-commits] r58654 - in /cfe/trunk: Driver/RewriteObjC.cpp include/clang/AST/Expr.h lib/AST/StmtSerialization.cpp lib/Sema/SemaExpr.cpp
Steve Naroff
snaroff at apple.com
Mon Nov 3 15:29:32 PST 2008
Author: snaroff
Date: Mon Nov 3 17:29:32 2008
New Revision: 58654
URL: http://llvm.org/viewvc/llvm-project?rev=58654&view=rev
Log:
Fix <rdar://problem/6339636> clang ObjC rewriter: Assertion failed: FileID-1 < FileIDs.size() && "Invalid FileID!", file c:\cygwin\home\Administrator\llvm\tools\clang\include\clang/Basic/SourceManager.h, line 513
Modified:
cfe/trunk/Driver/RewriteObjC.cpp
cfe/trunk/include/clang/AST/Expr.h
cfe/trunk/lib/AST/StmtSerialization.cpp
cfe/trunk/lib/Sema/SemaExpr.cpp
Modified: cfe/trunk/Driver/RewriteObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/RewriteObjC.cpp?rev=58654&r1=58653&r2=58654&view=diff
==============================================================================
--- cfe/trunk/Driver/RewriteObjC.cpp (original)
+++ cfe/trunk/Driver/RewriteObjC.cpp Mon Nov 3 17:29:32 2008
@@ -298,7 +298,7 @@
}
bool PointerTypeTakesAnyBlockArguments(QualType QT);
void GetExtentOfArgList(const char *Name, const char *&LParen, const char *&RParen);
- void RewriteCastExpr(CastExpr *CE);
+ void RewriteCastExpr(CStyleCastExpr *CE);
FunctionDecl *SynthBlockInitFunctionDecl(const char *name);
Stmt *SynthBlockInitExpr(BlockExpr *Exp);
@@ -923,7 +923,7 @@
assert(RD && "RewriteObjCIvarRefExpr(): Can't find RecordDecl");
QualType castT = Context->getPointerType(Context->getTagDeclType(RD));
CastExpr *castExpr = new CStyleCastExpr(castT, IV->getBase(), castT,
- SourceLocation());
+ SourceLocation(), SourceLocation());
// Don't forget the parens to enforce the proper binding.
ParenExpr *PE = new ParenExpr(IV->getBase()->getLocStart(),
IV->getBase()->getLocEnd(),
@@ -965,7 +965,7 @@
assert(RD && "RewriteObjCIvarRefExpr(): Can't find RecordDecl");
QualType castT = Context->getPointerType(Context->getTagDeclType(RD));
CastExpr *castExpr = new CStyleCastExpr(castT, IV->getBase(), castT,
- SourceLocation());
+ SourceLocation(), SourceLocation());
// Don't forget the parens to enforce the proper binding.
ParenExpr *PE = new ParenExpr(IV->getBase()->getLocStart(),
IV->getBase()->getLocEnd(), castExpr);
@@ -1262,7 +1262,7 @@
Expr *syncExpr = new CStyleCastExpr(Context->getObjCIdType(),
S->getSynchExpr(),
Context->getObjCIdType(),
- SourceLocation());
+ SourceLocation(), SourceLocation());
std::string syncExprBufS;
llvm::raw_string_ostream syncExprBuf(syncExprBufS);
syncExpr->printPretty(syncExprBuf);
@@ -1889,7 +1889,7 @@
SourceLocation());
// cast to NSConstantString *
CastExpr *cast = new CStyleCastExpr(Exp->getType(), Unop,
- Exp->getType(), SourceLocation());
+ Exp->getType(), SourceLocation(), SourceLocation());
ReplaceStmt(Exp, cast);
delete Exp;
return cast;
@@ -2027,7 +2027,7 @@
InitExprs.push_back( // set 'super class', using objc_getClass().
new CStyleCastExpr(Context->getObjCIdType(),
Cls, Context->getObjCIdType(),
- SourceLocation()));
+ SourceLocation(), SourceLocation()));
// struct objc_super
QualType superType = getSuperStructType();
Expr *SuperRep;
@@ -2081,7 +2081,7 @@
Context->getObjCIdType(),
SourceLocation()),
Context->getObjCIdType(),
- SourceLocation())); // set the 'receiver'.
+ SourceLocation(), SourceLocation())); // set the 'receiver'.
llvm::SmallVector<Expr*, 8> ClsExprs;
QualType argType = Context->getPointerType(Context->CharTy);
@@ -2096,7 +2096,7 @@
InitExprs.push_back(
// set 'super class', using objc_getClass().
new CStyleCastExpr(Context->getObjCIdType(),
- Cls, Context->getObjCIdType(), SourceLocation()));
+ Cls, Context->getObjCIdType(), SourceLocation(), SourceLocation()));
// struct objc_super
QualType superType = getSuperStructType();
Expr *SuperRep;
@@ -2127,7 +2127,7 @@
recExpr = CE->getSubExpr();
recExpr = new CStyleCastExpr(Context->getObjCIdType(), recExpr,
Context->getObjCIdType(),
- SourceLocation());
+ SourceLocation(), SourceLocation());
MsgExprs.push_back(recExpr);
}
}
@@ -2151,7 +2151,7 @@
QualType type = ICE->getType()->isObjCQualifiedIdType()
? Context->getObjCIdType()
: ICE->getType();
- userExpr = new CStyleCastExpr(type, userExpr, type, SourceLocation());
+ userExpr = new CStyleCastExpr(type, userExpr, type, SourceLocation(), SourceLocation());
}
// Make id<P...> cast into an 'id' cast.
else if (CStyleCastExpr *CE = dyn_cast<CStyleCastExpr>(userExpr)) {
@@ -2160,7 +2160,7 @@
userExpr = CE->getSubExpr();
userExpr = new CStyleCastExpr(Context->getObjCIdType(),
userExpr, Context->getObjCIdType(),
- SourceLocation());
+ SourceLocation(), SourceLocation());
}
}
MsgExprs.push_back(userExpr);
@@ -2210,7 +2210,7 @@
// xx.m:13: note: if this code is reached, the program will abort
cast = new CStyleCastExpr(Context->getPointerType(Context->VoidTy), DRE,
Context->getPointerType(Context->VoidTy),
- SourceLocation());
+ SourceLocation(), SourceLocation());
// Now do the "normal" pointer to function cast.
QualType castType = Context->getFunctionType(returnType,
@@ -2218,7 +2218,7 @@
// If we don't have a method decl, force a variadic cast.
Exp->getMethodDecl() ? Exp->getMethodDecl()->isVariadic() : true, 0);
castType = Context->getPointerType(castType);
- cast = new CStyleCastExpr(castType, cast, castType, SourceLocation());
+ cast = new CStyleCastExpr(castType, cast, castType, SourceLocation(), SourceLocation());
// Don't forget the parens to enforce the proper binding.
ParenExpr *PE = new ParenExpr(SourceLocation(), SourceLocation(), cast);
@@ -2239,13 +2239,13 @@
// Need to cast objc_msgSend_stret to "void *" (see above comment).
cast = new CStyleCastExpr(Context->getPointerType(Context->VoidTy), STDRE,
Context->getPointerType(Context->VoidTy),
- SourceLocation());
+ SourceLocation(), SourceLocation());
// Now do the "normal" pointer to function cast.
castType = Context->getFunctionType(returnType,
&ArgTypes[0], ArgTypes.size(),
Exp->getMethodDecl() ? Exp->getMethodDecl()->isVariadic() : false, 0);
castType = Context->getPointerType(castType);
- cast = new CStyleCastExpr(castType, cast, castType, SourceLocation());
+ cast = new CStyleCastExpr(castType, cast, castType, SourceLocation(), SourceLocation());
// Don't forget the parens to enforce the proper binding.
PE = new ParenExpr(SourceLocation(), SourceLocation(), cast);
@@ -3529,7 +3529,7 @@
PtrToFuncCastType = Context->getPointerType(PtrToFuncCastType);
- CastExpr *BlkCast = new CStyleCastExpr(PtrBlock, Exp->getCallee(), PtrBlock, SourceLocation());
+ CastExpr *BlkCast = new CStyleCastExpr(PtrBlock, Exp->getCallee(), PtrBlock, SourceLocation(), SourceLocation());
// Don't forget the parens to enforce the proper binding.
ParenExpr *PE = new ParenExpr(SourceLocation(), SourceLocation(), BlkCast);
//PE->dump();
@@ -3538,7 +3538,7 @@
&Context->Idents.get("FuncPtr"), Context->VoidPtrTy);
MemberExpr *ME = new MemberExpr(PE, true, FD, SourceLocation(), FD->getType());
- CastExpr *FunkCast = new CStyleCastExpr(PtrToFuncCastType, ME, PtrToFuncCastType, SourceLocation());
+ CastExpr *FunkCast = new CStyleCastExpr(PtrToFuncCastType, ME, PtrToFuncCastType, SourceLocation(), SourceLocation());
PE = new ParenExpr(SourceLocation(), SourceLocation(), FunkCast);
llvm::SmallVector<Expr*, 8> BlkExprs;
@@ -3563,9 +3563,9 @@
InsertText(BDRE->getLocStart(), "*", 1);
}
-void RewriteObjC::RewriteCastExpr(CastExpr *CE) {
- SourceLocation LocStart = CE->getLocStart();
- SourceLocation LocEnd = CE->getLocEnd();
+void RewriteObjC::RewriteCastExpr(CStyleCastExpr *CE) {
+ SourceLocation LocStart = CE->getLParenLoc();
+ SourceLocation LocEnd = CE->getRParenLoc();
// Need to avoid trying to rewrite synthesized casts.
if (LocStart.isInvalid())
@@ -3781,7 +3781,7 @@
FD = SynthBlockInitFunctionDecl(Func.c_str());
DeclRefExpr *Arg = new DeclRefExpr(FD, FD->getType(), SourceLocation());
CastExpr *castExpr = new CStyleCastExpr(Context->VoidPtrTy, Arg,
- Context->VoidPtrTy, SourceLocation());
+ Context->VoidPtrTy, SourceLocation(), SourceLocation());
InitExprs.push_back(castExpr);
if (ImportedBlockDecls.size()) {
@@ -3789,14 +3789,14 @@
FD = SynthBlockInitFunctionDecl(Buf.c_str());
Arg = new DeclRefExpr(FD, FD->getType(), SourceLocation());
castExpr = new CStyleCastExpr(Context->VoidPtrTy, Arg,
- Context->VoidPtrTy, SourceLocation());
+ Context->VoidPtrTy, SourceLocation(), SourceLocation());
InitExprs.push_back(castExpr);
Buf = "__" + FuncName + "_block_dispose_" + BlockNumber;
FD = SynthBlockInitFunctionDecl(Buf.c_str());
Arg = new DeclRefExpr(FD, FD->getType(), SourceLocation());
castExpr = new CStyleCastExpr(Context->VoidPtrTy, Arg,
- Context->VoidPtrTy, SourceLocation());
+ Context->VoidPtrTy, SourceLocation(), SourceLocation());
InitExprs.push_back(castExpr);
}
// Add initializers for any closure decl refs.
@@ -3813,7 +3813,7 @@
FD = SynthBlockInitFunctionDecl((*I)->getName());
Arg = new DeclRefExpr(FD, FD->getType(), SourceLocation());
Exp = new CStyleCastExpr(Context->VoidPtrTy, Arg,
- Context->VoidPtrTy, SourceLocation());
+ Context->VoidPtrTy, SourceLocation(), SourceLocation());
} else {
FD = SynthBlockInitFunctionDecl((*I)->getName());
Exp = new DeclRefExpr(FD, FD->getType(), SourceLocation());
@@ -3835,7 +3835,7 @@
NewRep = new UnaryOperator(NewRep, UnaryOperator::AddrOf,
Context->getPointerType(NewRep->getType()),
SourceLocation());
- NewRep = new CStyleCastExpr(FType, NewRep, FType, SourceLocation());
+ NewRep = new CStyleCastExpr(FType, NewRep, FType, SourceLocation(), SourceLocation());
BlockDeclRefs.clear();
BlockByRefDecls.clear();
BlockByCopyDecls.clear();
@@ -3987,7 +3987,7 @@
return BlockCall;
}
}
- if (CastExpr *CE = dyn_cast<CastExpr>(S)) {
+ if (CStyleCastExpr *CE = dyn_cast<CStyleCastExpr>(S)) {
RewriteCastExpr(CE);
}
#if 0
@@ -4050,7 +4050,7 @@
else if (VD->getType()->isFunctionPointerType()) {
CheckFunctionPointerDecl(VD->getType(), VD);
if (VD->getInit()) {
- if (CastExpr *CE = dyn_cast<CastExpr>(VD->getInit())) {
+ if (CStyleCastExpr *CE = dyn_cast<CStyleCastExpr>(VD->getInit())) {
RewriteCastExpr(CE);
}
}
@@ -4062,7 +4062,7 @@
GlobalVarDecl = 0;
// This is needed for blocks.
- if (CastExpr *CE = dyn_cast<CastExpr>(VD->getInit())) {
+ if (CStyleCastExpr *CE = dyn_cast<CStyleCastExpr>(VD->getInit())) {
RewriteCastExpr(CE);
}
}
Modified: cfe/trunk/include/clang/AST/Expr.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=58654&r1=58653&r2=58654&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Mon Nov 3 17:29:32 2008
@@ -884,16 +884,19 @@
/// cast in C++ (C++ [expr.cast]), which uses the syntax
/// (Type)expr. For example: @c (int)f.
class CStyleCastExpr : public ExplicitCastExpr {
- SourceLocation Loc; // the location of the left paren
+ SourceLocation LPLoc; // the location of the left paren
+ SourceLocation RPLoc; // the location of the right paren
public:
CStyleCastExpr(QualType exprTy, Expr *op, QualType writtenTy,
- SourceLocation l) :
- ExplicitCastExpr(CStyleCastExprClass, exprTy, op, writtenTy), Loc(l) {}
+ SourceLocation l, SourceLocation r) :
+ ExplicitCastExpr(CStyleCastExprClass, exprTy, op, writtenTy),
+ LPLoc(l), RPLoc(r) {}
- SourceLocation getLParenLoc() const { return Loc; }
+ SourceLocation getLParenLoc() const { return LPLoc; }
+ SourceLocation getRParenLoc() const { return RPLoc; }
virtual SourceRange getSourceRange() const {
- return SourceRange(Loc, getSubExpr()->getSourceRange().getEnd());
+ return SourceRange(LPLoc, getSubExpr()->getSourceRange().getEnd());
}
static bool classof(const Stmt *T) {
return T->getStmtClass() == CStyleCastExprClass;
Modified: cfe/trunk/lib/AST/StmtSerialization.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/StmtSerialization.cpp?rev=58654&r1=58653&r2=58654&view=diff
==============================================================================
--- cfe/trunk/lib/AST/StmtSerialization.cpp (original)
+++ cfe/trunk/lib/AST/StmtSerialization.cpp Mon Nov 3 17:29:32 2008
@@ -379,16 +379,18 @@
void CStyleCastExpr::EmitImpl(Serializer& S) const {
S.Emit(getType());
S.Emit(getTypeAsWritten());
- S.Emit(Loc);
+ S.Emit(LPLoc);
+ S.Emit(RPLoc);
S.EmitOwnedPtr(getSubExpr());
}
CStyleCastExpr* CStyleCastExpr::CreateImpl(Deserializer& D, ASTContext& C) {
QualType t = QualType::ReadVal(D);
QualType writtenTy = QualType::ReadVal(D);
- SourceLocation Loc = SourceLocation::ReadVal(D);
+ SourceLocation LPLoc = SourceLocation::ReadVal(D);
+ SourceLocation RPLoc = SourceLocation::ReadVal(D);
Expr* Op = D.ReadOwnedPtr<Expr>(C);
- return new CStyleCastExpr(t,Op,writtenTy,Loc);
+ return new CStyleCastExpr(t,Op,writtenTy,LPLoc,RPLoc);
}
void CharacterLiteral::EmitImpl(Serializer& S) const {
Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=58654&r1=58653&r2=58654&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Mon Nov 3 17:29:32 2008
@@ -1324,7 +1324,7 @@
if (CheckCastTypes(SourceRange(LParenLoc, RParenLoc), castType, castExpr))
return true;
- return new CStyleCastExpr(castType, castExpr, castType, LParenLoc);
+ return new CStyleCastExpr(castType, castExpr, castType, LParenLoc, RParenLoc);
}
/// Note that lex is not null here, even if this is the gnu "x ?: y" extension.
More information about the cfe-commits
mailing list