forked from OSchip/llvm-project
Lazily create the abort message, so only translation units that use unwind
will actually get it. llvm-svn: 17700
This commit is contained in:
parent
9b0291b18d
commit
2858e17538
|
@ -66,6 +66,7 @@ namespace {
|
|||
bool doInitialization(Module &M);
|
||||
bool runOnFunction(Function &F);
|
||||
private:
|
||||
void createAbortMessage();
|
||||
void writeAbortMessage(Instruction *IB);
|
||||
bool insertCheapEHSupport(Function &F);
|
||||
bool insertExpensiveEHSupport(Function &F);
|
||||
|
@ -119,31 +120,6 @@ bool LowerInvoke::doInitialization(Module &M) {
|
|||
LongJmpFn = M.getOrInsertFunction("llvm.longjmp", Type::VoidTy,
|
||||
PointerType::get(JmpBufTy),
|
||||
Type::IntTy, 0);
|
||||
|
||||
// The abort message for expensive EH support tells the user that the
|
||||
// program 'unwound' without an 'invoke' instruction.
|
||||
Constant *Msg =
|
||||
ConstantArray::get("ERROR: Exception thrown, but not caught!\n");
|
||||
AbortMessageLength = Msg->getNumOperands()-1; // don't include \0
|
||||
|
||||
GlobalVariable *MsgGV = new GlobalVariable(Msg->getType(), true,
|
||||
GlobalValue::InternalLinkage,
|
||||
Msg, "abortmsg", &M);
|
||||
std::vector<Constant*> GEPIdx(2, Constant::getNullValue(Type::LongTy));
|
||||
AbortMessage = ConstantExpr::getGetElementPtr(MsgGV, GEPIdx);
|
||||
} else {
|
||||
// The abort message for cheap EH support tells the user that EH is not
|
||||
// enabled.
|
||||
Constant *Msg =
|
||||
ConstantArray::get("Exception handler needed, but not enabled. Recompile"
|
||||
" program with -enable-correct-eh-support.\n");
|
||||
AbortMessageLength = Msg->getNumOperands()-1; // don't include \0
|
||||
|
||||
GlobalVariable *MsgGV = new GlobalVariable(Msg->getType(), true,
|
||||
GlobalValue::InternalLinkage,
|
||||
Msg, "abortmsg", &M);
|
||||
std::vector<Constant*> GEPIdx(2, Constant::getNullValue(Type::LongTy));
|
||||
AbortMessage = ConstantExpr::getGetElementPtr(MsgGV, GEPIdx);
|
||||
}
|
||||
|
||||
// We need the 'write' and 'abort' functions for both models.
|
||||
|
@ -169,8 +145,41 @@ bool LowerInvoke::doInitialization(Module &M) {
|
|||
return true;
|
||||
}
|
||||
|
||||
void LowerInvoke::createAbortMessage() {
|
||||
Module &M = *WriteFn->getParent();
|
||||
if (ExpensiveEHSupport) {
|
||||
// The abort message for expensive EH support tells the user that the
|
||||
// program 'unwound' without an 'invoke' instruction.
|
||||
Constant *Msg =
|
||||
ConstantArray::get("ERROR: Exception thrown, but not caught!\n");
|
||||
AbortMessageLength = Msg->getNumOperands()-1; // don't include \0
|
||||
|
||||
GlobalVariable *MsgGV = new GlobalVariable(Msg->getType(), true,
|
||||
GlobalValue::InternalLinkage,
|
||||
Msg, "abortmsg", &M);
|
||||
std::vector<Constant*> GEPIdx(2, Constant::getNullValue(Type::LongTy));
|
||||
AbortMessage = ConstantExpr::getGetElementPtr(MsgGV, GEPIdx);
|
||||
} else {
|
||||
// The abort message for cheap EH support tells the user that EH is not
|
||||
// enabled.
|
||||
Constant *Msg =
|
||||
ConstantArray::get("Exception handler needed, but not enabled. Recompile"
|
||||
" program with -enable-correct-eh-support.\n");
|
||||
AbortMessageLength = Msg->getNumOperands()-1; // don't include \0
|
||||
|
||||
GlobalVariable *MsgGV = new GlobalVariable(Msg->getType(), true,
|
||||
GlobalValue::InternalLinkage,
|
||||
Msg, "abortmsg", &M);
|
||||
std::vector<Constant*> GEPIdx(2, Constant::getNullValue(Type::LongTy));
|
||||
AbortMessage = ConstantExpr::getGetElementPtr(MsgGV, GEPIdx);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void LowerInvoke::writeAbortMessage(Instruction *IB) {
|
||||
if (WriteFn) {
|
||||
if (AbortMessage == 0) createAbortMessage();
|
||||
|
||||
// These are the arguments we WANT...
|
||||
std::vector<Value*> Args;
|
||||
Args.push_back(ConstantInt::get(Type::IntTy, 2));
|
||||
|
|
Loading…
Reference in New Issue