Only add the global variable with the abort message if an unwind actually

occurs in the program.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@11249 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner 2004-02-09 22:48:47 +00:00
parent 71be6db3ef
commit f1d0d3519f

View File

@ -49,6 +49,7 @@ namespace {
// Used for both models. // Used for both models.
Function *WriteFn; Function *WriteFn;
Function *AbortFn; Function *AbortFn;
Constant *AbortMessageInit;
Value *AbortMessage; Value *AbortMessage;
unsigned AbortMessageLength; unsigned AbortMessageLength;
@ -76,6 +77,7 @@ FunctionPass *llvm::createLowerInvokePass() { return new LowerInvoke(); }
// current module. // current module.
bool LowerInvoke::doInitialization(Module &M) { bool LowerInvoke::doInitialization(Module &M) {
const Type *VoidPtrTy = PointerType::get(Type::SByteTy); const Type *VoidPtrTy = PointerType::get(Type::SByteTy);
AbortMessage = 0;
if (ExpensiveEHSupport) { if (ExpensiveEHSupport) {
// Insert a type for the linked list of jump buffers. Unfortunately, we // Insert a type for the linked list of jump buffers. Unfortunately, we
// don't know the size of the target's setjmp buffer, so we make a guess. // don't know the size of the target's setjmp buffer, so we make a guess.
@ -115,17 +117,17 @@ bool LowerInvoke::doInitialization(Module &M) {
Constant *Msg = Constant *Msg =
ConstantArray::get("ERROR: Exception thrown, but not caught!\n"); ConstantArray::get("ERROR: Exception thrown, but not caught!\n");
AbortMessageLength = Msg->getNumOperands()-1; // don't include \0 AbortMessageLength = Msg->getNumOperands()-1; // don't include \0
AbortMessageInit = Msg;
GlobalVariable *MsgGV = M.getGlobalVariable("abort.msg", Msg->getType()); GlobalVariable *MsgGV = M.getGlobalVariable("abort.msg", Msg->getType());
if (MsgGV && (!MsgGV->hasInitializer() || MsgGV->getInitializer() != Msg)) if (MsgGV && (!MsgGV->hasInitializer() || MsgGV->getInitializer() != Msg))
MsgGV = 0; MsgGV = 0;
if (!MsgGV)
MsgGV = new GlobalVariable(Msg->getType(), true, if (MsgGV) {
GlobalValue::InternalLinkage, std::vector<Constant*> GEPIdx(2, Constant::getNullValue(Type::LongTy));
Msg, "abort.msg", &M); AbortMessage =
std::vector<Constant*> GEPIdx(2, Constant::getNullValue(Type::LongTy)); ConstantExpr::getGetElementPtr(ConstantPointerRef::get(MsgGV), GEPIdx);
AbortMessage = }
ConstantExpr::getGetElementPtr(ConstantPointerRef::get(MsgGV), GEPIdx);
} else { } else {
// The abort message for cheap EH support tells the user that EH is not // The abort message for cheap EH support tells the user that EH is not
@ -134,18 +136,17 @@ bool LowerInvoke::doInitialization(Module &M) {
ConstantArray::get("Exception handler needed, but not enabled. Recompile" ConstantArray::get("Exception handler needed, but not enabled. Recompile"
" program with -enable-correct-eh-support.\n"); " program with -enable-correct-eh-support.\n");
AbortMessageLength = Msg->getNumOperands()-1; // don't include \0 AbortMessageLength = Msg->getNumOperands()-1; // don't include \0
AbortMessageInit = Msg;
GlobalVariable *MsgGV = M.getGlobalVariable("abort.msg", Msg->getType()); GlobalVariable *MsgGV = M.getGlobalVariable("abort.msg", Msg->getType());
if (MsgGV && (!MsgGV->hasInitializer() || MsgGV->getInitializer() != Msg)) if (MsgGV && (!MsgGV->hasInitializer() || MsgGV->getInitializer() != Msg))
MsgGV = 0; MsgGV = 0;
if (!MsgGV) if (MsgGV) {
MsgGV = new GlobalVariable(Msg->getType(), true, std::vector<Constant*> GEPIdx(2, Constant::getNullValue(Type::LongTy));
GlobalValue::InternalLinkage, AbortMessage =
Msg, "abort.msg", &M); ConstantExpr::getGetElementPtr(ConstantPointerRef::get(MsgGV), GEPIdx);
std::vector<Constant*> GEPIdx(2, Constant::getNullValue(Type::LongTy)); }
AbortMessage =
ConstantExpr::getGetElementPtr(ConstantPointerRef::get(MsgGV), GEPIdx);
} }
// We need the 'write' and 'abort' functions for both models. // We need the 'write' and 'abort' functions for both models.
@ -173,6 +174,17 @@ bool LowerInvoke::doInitialization(Module &M) {
void LowerInvoke::writeAbortMessage(Instruction *IB) { void LowerInvoke::writeAbortMessage(Instruction *IB) {
if (WriteFn) { if (WriteFn) {
if (!AbortMessage) {
GlobalVariable *MsgGV = new GlobalVariable(AbortMessageInit->getType(),
true,
GlobalValue::InternalLinkage,
AbortMessageInit, "abort.msg",
WriteFn->getParent());
std::vector<Constant*> GEPIdx(2, Constant::getNullValue(Type::LongTy));
AbortMessage =
ConstantExpr::getGetElementPtr(ConstantPointerRef::get(MsgGV), GEPIdx);
}
// These are the arguments we WANT... // These are the arguments we WANT...
std::vector<Value*> Args; std::vector<Value*> Args;
Args.push_back(ConstantInt::get(Type::IntTy, 2)); Args.push_back(ConstantInt::get(Type::IntTy, 2));