Add support for emitting cleanup blocks. Make EmitCompoundStatement emit cleanup blocks if necessary

llvm-svn: 64051
This commit is contained in:
Anders Carlsson 2009-02-07 23:50:39 +00:00
parent 4f8542f31d
commit be0f76a712
3 changed files with 34 additions and 1 deletions

View File

@ -123,7 +123,7 @@ bool CodeGenFunction::EmitSimpleStmt(const Stmt *S) {
/// (for use by the statement expression extension). /// (for use by the statement expression extension).
RValue CodeGenFunction::EmitCompoundStmt(const CompoundStmt &S, bool GetLast, RValue CodeGenFunction::EmitCompoundStmt(const CompoundStmt &S, bool GetLast,
llvm::Value *AggLoc, bool isAggVol) { llvm::Value *AggLoc, bool isAggVol) {
// FIXME: handle vla's etc.
CGDebugInfo *DI = CGM.getDebugInfo(); CGDebugInfo *DI = CGM.getDebugInfo();
if (DI) { if (DI) {
EnsureInsertPoint(); EnsureInsertPoint();
@ -131,6 +131,9 @@ RValue CodeGenFunction::EmitCompoundStmt(const CompoundStmt &S, bool GetLast,
DI->EmitRegionStart(CurFn, Builder); DI->EmitRegionStart(CurFn, Builder);
} }
// Keep track of the current cleanup stack depth.
size_t CleanupStackDepth = CleanupEntries.size();
// Push a null stack save value. // Push a null stack save value.
StackSaveValues.push_back(0); StackSaveValues.push_back(0);
@ -171,6 +174,8 @@ RValue CodeGenFunction::EmitCompoundStmt(const CompoundStmt &S, bool GetLast,
Builder.CreateCall(F, V); Builder.CreateCall(F, V);
} }
EmitCleanupBlocks(CleanupStackDepth);
return RV; return RV;
} }

View File

@ -521,3 +521,24 @@ llvm::BasicBlock *CodeGenFunction::CreateCleanupBlock()
return CleanupBlock; return CleanupBlock;
} }
void CodeGenFunction::EmitCleanupBlocks(size_t OldCleanupStackSize)
{
assert(CleanupEntries.size() >= OldCleanupStackSize &&
"Cleanup stack mismatch!");
while (CleanupEntries.size() > OldCleanupStackSize)
EmitCleanupBlock();
}
void CodeGenFunction::EmitCleanupBlock()
{
CleanupEntry &CE = CleanupEntries.back();
llvm::BasicBlock *CleanupBlock = CE.CleanupBlock;
CleanupEntries.pop_back();
EmitBlock(CleanupBlock);
}

View File

@ -151,6 +151,10 @@ public:
} }
}; };
/// EmitCleanupBlocks - Takes the old cleanup stack size and emits the cleanup
/// blocks that have been added.
void EmitCleanupBlocks(size_t OldCleanupStackSize);
private: private:
/// LabelIDs - Track arbitrary ids assigned to labels for use in /// LabelIDs - Track arbitrary ids assigned to labels for use in
/// implementing the GCC address-of-label extension and indirect /// implementing the GCC address-of-label extension and indirect
@ -762,6 +766,9 @@ private:
llvm::Value* EmitAsmInput(const AsmStmt &S, TargetInfo::ConstraintInfo Info, llvm::Value* EmitAsmInput(const AsmStmt &S, TargetInfo::ConstraintInfo Info,
const Expr *InputExpr, std::string &ConstraintStr); const Expr *InputExpr, std::string &ConstraintStr);
/// EmitCleanupBlock - emits a single cleanup block.
void EmitCleanupBlock();
}; };
} // end namespace CodeGen } // end namespace CodeGen
} // end namespace clang } // end namespace clang