Obtain the exit function before execution just in case the module
authorReid Spencer <rspencer@reidspencer.com>
Tue, 6 Mar 2007 03:12:55 +0000 (03:12 +0000)
committerReid Spencer <rspencer@reidspencer.com>
Tue, 6 Mar 2007 03:12:55 +0000 (03:12 +0000)
disappears before we get to calling the exit function.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34953 91177308-0d34-0410-b5e6-96231b3b80d8

tools/lli/lli.cpp

index c02d2a441929b1904d705b4fe457decddee0236e..225180b8caed3ba94ca68b3da8f9156fa1686dc4 100644 (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";