[cfe-commits] r56102 - in /cfe/trunk/lib/CodeGen: CGObjC.cpp CGObjCMac.cpp CGStmt.cpp CodeGenFunction.cpp CodeGenFunction.h
Anders Carlsson
andersca at mac.com
Thu Sep 11 02:15:35 PDT 2008
Author: andersca
Date: Thu Sep 11 04:15:33 2008
New Revision: 56102
URL: http://llvm.org/viewvc/llvm-project?rev=56102&view=rev
Log:
Make sure to store the exception in the catch parameter.
Modified:
cfe/trunk/lib/CodeGen/CGObjC.cpp
cfe/trunk/lib/CodeGen/CGObjCMac.cpp
cfe/trunk/lib/CodeGen/CGStmt.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.h
Modified: cfe/trunk/lib/CodeGen/CGObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjC.cpp?rev=56102&r1=56101&r2=56102&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGObjC.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjC.cpp Thu Sep 11 04:15:33 2008
@@ -456,12 +456,4 @@
CGM.getObjCRuntime().EmitThrowStmt(*this, S);
}
-void CodeGenFunction::EmitObjCAtCatchStmt(const ObjCAtCatchStmt &S)
-{
- if (const Stmt *CatchParam = S.getCatchParamStmt())
- EmitStmt(CatchParam);
-
- EmitStmt(S.getCatchBody());
-}
-
CGObjCRuntime::~CGObjCRuntime() {}
Modified: cfe/trunk/lib/CodeGen/CGObjCMac.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjCMac.cpp?rev=56102&r1=56101&r2=56102&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGObjCMac.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjCMac.cpp Thu Sep 11 04:15:33 2008
@@ -1442,16 +1442,18 @@
// Handle catch list
for (; CatchStmt; CatchStmt = CatchStmt->getNextCatchStmt()) {
llvm::BasicBlock *NextCatchBlock = llvm::BasicBlock::Create("nextcatch");
+ llvm::Value *Caught = CGF.Builder.CreateLoad(CaughtPtr, "caught");
QualType T;
bool MatchesAll = false;
-
+ const DeclStmt *CatchParam =
+ cast_or_null<DeclStmt>(CatchStmt->getCatchParamStmt());
+
// catch(...) always matches.
- if (CatchStmt->hasEllipsis())
+ if (!CatchParam)
MatchesAll = true;
else {
- const DeclStmt *DS = cast<DeclStmt>(CatchStmt->getCatchParamStmt());
- QualType PT = cast<ValueDecl>(DS->getDecl())->getType();
+ QualType PT = cast<ValueDecl>(CatchParam->getDecl())->getType();
T = PT->getAsPointerType()->getPointeeType();
// catch(id e) always matches.
@@ -1460,10 +1462,18 @@
}
if (MatchesAll) {
- CGF.EmitStmt(CatchStmt);
+ if (CatchParam) {
+ CGF.EmitStmt(CatchParam);
+
+ const VarDecl *VD = cast<VarDecl>(CatchParam->getDecl());
+
+ llvm::Value *V = CGF.GetAddrOfLocalVar(VD);
+
+ CGF.Builder.CreateStore(Caught, V);
+ }
+ CGF.EmitStmt(CatchStmt->getCatchBody());
CGF.Builder.CreateBr(FinallyBlock);
-
CGF.EmitBlock(NextCatchBlock);
break;
}
@@ -1474,7 +1484,6 @@
// Check if the @catch block matches the exception object.
llvm::Value *Class = EmitClassRef(CGF.Builder, ObjCType->getDecl());
- llvm::Value *Caught = CGF.Builder.CreateLoad(CaughtPtr, "caught");
llvm::Value *Match = CGF.Builder.CreateCall2(ObjCTypes.ExceptionMatchFn,
Class, Caught, "match");
@@ -1486,7 +1495,18 @@
// Emit the @catch block.
CGF.EmitBlock(MatchedBlock);
- CGF.EmitStmt(CatchStmt);
+ if (CatchParam) {
+ CGF.EmitStmt(CatchParam);
+
+ const VarDecl *VD = cast<VarDecl>(CatchParam->getDecl());
+
+ llvm::Value *Tmp =
+ CGF.Builder.CreateBitCast(Caught, CGF.ConvertType(VD->getType()),
+ "tmp");
+ CGF.Builder.CreateStore(Tmp, CGF.GetAddrOfLocalVar(VD));
+ }
+
+ CGF.EmitStmt(CatchStmt->getCatchBody());
CGF.Builder.CreateBr(FinallyBlock);
CGF.EmitBlock(NextCatchBlock);
Modified: cfe/trunk/lib/CodeGen/CGStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGStmt.cpp?rev=56102&r1=56101&r2=56102&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGStmt.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGStmt.cpp Thu Sep 11 04:15:33 2008
@@ -81,8 +81,8 @@
EmitObjCAtTryStmt(cast<ObjCAtTryStmt>(*S));
break;
case Stmt::ObjCAtCatchStmtClass:
- EmitObjCAtCatchStmt(cast<ObjCAtCatchStmt>(*S));
- break;
+ assert(0 && "@catch statements should be handled by EmitObjCAtTryStmt");
+ break;
case Stmt::ObjCAtFinallyStmtClass:
assert(0 && "@finally statements should be handled by EmitObjCAtTryStmt");
break;
Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.cpp?rev=56102&r1=56101&r2=56102&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenFunction.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.cpp Thu Sep 11 04:15:33 2008
@@ -47,6 +47,11 @@
return cast<llvm::Constant>(LocalDeclMap[BVD]);
}
+llvm::Value *CodeGenFunction::GetAddrOfLocalVar(const VarDecl *VD)
+{
+ return LocalDeclMap[VD];
+}
+
const llvm::Type *CodeGenFunction::ConvertType(QualType T) {
return CGM.getTypes().ConvertType(T);
}
Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.h?rev=56102&r1=56101&r2=56102&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenFunction.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.h Thu Sep 11 04:15:33 2008
@@ -221,6 +221,9 @@
/// GetAddrOfStaticLocalVar - Return the address of a static local variable.
llvm::Constant *GetAddrOfStaticLocalVar(const VarDecl *BVD);
+ /// GetAddrOfLocalVar - Return the address of a local variable.
+ llvm::Value *GetAddrOfLocalVar(const VarDecl *VD);
+
/// getAccessedFieldNo - Given an encoded value and a result number, return
/// the input field number being accessed.
static unsigned getAccessedFieldNo(unsigned Idx, const llvm::Constant *Elts);
@@ -269,7 +272,6 @@
void EmitObjCForCollectionStmt(const ObjCForCollectionStmt &S);
void EmitObjCAtTryStmt(const ObjCAtTryStmt &S);
- void EmitObjCAtCatchStmt(const ObjCAtCatchStmt &S);
void EmitObjCAtThrowStmt(const ObjCAtThrowStmt &S);
//===--------------------------------------------------------------------===//
More information about the cfe-commits
mailing list