VStudio compiler errors and placing Function*->ExFunc map under ManagedStatic control.

This commit fixes two things.  One is a pair of VStudio compiler errors stemming from variables
which defined within the for loop statement and also within the body of the for loop.  I fixed these 
by renaming one of the two variables.  Additionally, I've made the Function*->ExFunc map in 
ExternalFunctions.cpp a ManagedStatic object, so that cleanup will be done on llvm_shutdown.  In repeated
uses of the interpreter, where the same Function* address may get used for completely differnet functions,
this was causing a crash.

llvm-svn: 40558
This commit is contained in:
Chuck Rose III 2007-07-27 18:26:35 +00:00
parent 8e9869716c
commit 1a39a2d13d
3 changed files with 10 additions and 9 deletions

View File

@ -25,6 +25,7 @@
#include "llvm/Support/Streams.h" #include "llvm/Support/Streams.h"
#include "llvm/System/DynamicLibrary.h" #include "llvm/System/DynamicLibrary.h"
#include "llvm/Target/TargetData.h" #include "llvm/Target/TargetData.h"
#include "llvm/Support/ManagedStatic.h"
#include <csignal> #include <csignal>
#include <map> #include <map>
#include <cmath> #include <cmath>
@ -33,7 +34,7 @@ using std::vector;
using namespace llvm; using namespace llvm;
typedef GenericValue (*ExFunc)(FunctionType *, const vector<GenericValue> &); typedef GenericValue (*ExFunc)(FunctionType *, const vector<GenericValue> &);
static std::map<const Function *, ExFunc> Functions; static ManagedStatic<std::map<const Function *, ExFunc> > Functions;
static std::map<std::string, ExFunc> FuncNames; static std::map<std::string, ExFunc> FuncNames;
static Interpreter *TheInterpreter; static Interpreter *TheInterpreter;
@ -80,7 +81,7 @@ static ExFunc lookupFunction(const Function *F) {
FnPtr = (ExFunc)(intptr_t) FnPtr = (ExFunc)(intptr_t)
sys::DynamicLibrary::SearchForAddressOfSymbol(F->getName()); sys::DynamicLibrary::SearchForAddressOfSymbol(F->getName());
if (FnPtr != 0) if (FnPtr != 0)
Functions.insert(std::make_pair(F, FnPtr)); // Cache for later Functions->insert(std::make_pair(F, FnPtr)); // Cache for later
return FnPtr; return FnPtr;
} }
@ -90,8 +91,8 @@ GenericValue Interpreter::callExternalFunction(Function *F,
// Do a lookup to see if the function is in our cache... this should just be a // Do a lookup to see if the function is in our cache... this should just be a
// deferred annotation! // deferred annotation!
std::map<const Function *, ExFunc>::iterator FI = Functions.find(F); std::map<const Function *, ExFunc>::iterator FI = Functions->find(F);
ExFunc Fn = (FI == Functions.end()) ? lookupFunction(F) : FI->second; ExFunc Fn = (FI == Functions->end()) ? lookupFunction(F) : FI->second;
if (Fn == 0) { if (Fn == 0) {
cerr << "Tried to execute an unknown external function: " cerr << "Tried to execute an unknown external function: "
<< F->getType()->getDescription() << " " << F->getName() << "\n"; << F->getType()->getDescription() << " " << F->getName() << "\n";

View File

@ -482,9 +482,9 @@ void CloneDomInfo(BasicBlock *NewBB, BasicBlock *Orig,
for (DominanceFrontier::DomSetType::iterator I = S.begin(), E = S.end(); for (DominanceFrontier::DomSetType::iterator I = S.begin(), E = S.end();
I != E; ++I) { I != E; ++I) {
BasicBlock *BB = *I; BasicBlock *BB = *I;
DenseMap<const Value*, Value*>::iterator I = VM.find(BB); DenseMap<const Value*, Value*>::iterator IDM = VM.find(BB);
if (I != VM.end()) if (IDM != VM.end())
NewDFSet.insert(cast<BasicBlock>(I->second)); NewDFSet.insert(cast<BasicBlock>(IDM->second));
else else
NewDFSet.insert(BB); NewDFSet.insert(BB);
} }

View File

@ -240,8 +240,8 @@ void RegisterInfoEmitter::run(std::ostream &OS) {
bool Empty = true; bool Empty = true;
for (unsigned subrc = 0, e2 = RC.SubRegClasses.size(); for (unsigned subrc = 0, subrcMax = RC.SubRegClasses.size();
subrc != e2; ++subrc) { subrc != subrcMax; ++subrc) {
unsigned rc2 = 0, e2 = RegisterClasses.size(); unsigned rc2 = 0, e2 = RegisterClasses.size();
for (; rc2 != e2; ++rc2) { for (; rc2 != e2; ++rc2) {
const CodeGenRegisterClass &RC2 = RegisterClasses[rc2]; const CodeGenRegisterClass &RC2 = RegisterClasses[rc2];