1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-23 11:13:28 +01:00

Obtain the exit function before execution just in case the module

disappears before we get to calling the exit function.

llvm-svn: 34953
This commit is contained in:
Reid Spencer 2007-03-06 03:12:55 +00:00
parent 3b08509917
commit b99271c33c

View File

@ -124,6 +124,10 @@ int main(int argc, char **argv, char * const *envp) {
return -1;
}
// If the program doesn't explicitly call exit, we will need the Exit
// function later on to make an explicit call, so get the function now.
Constant *Exit = Mod->getOrInsertFunction("exit", Type::VoidTy,
Type::Int32Ty, NULL);
// Run static constructors.
EE->runStaticConstructorsDestructors(false);
@ -133,14 +137,12 @@ int main(int argc, char **argv, char * const *envp) {
// Run static destructors.
EE->runStaticConstructorsDestructors(true);
// If the program didn't explicitly call exit, call exit now, for the
// program. This ensures that any atexit handlers get called correctly.
Constant *Exit = Mod->getOrInsertFunction("exit", Type::VoidTy,
Type::Int32Ty, NULL);
// If the program didn't call exit explicitly, we should call it now.
// This ensures that any atexit handlers get called correctly.
if (Function *ExitF = dyn_cast<Function>(Exit)) {
std::vector<GenericValue> Args;
GenericValue ResultGV;
ResultGV.Int32Val = Result;
ResultGV.IntVal = APInt(32, Result);
Args.push_back(ResultGV);
EE->runFunction(ExitF, Args);
std::cerr << "ERROR: exit(" << Result << ") returned!\n";