aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorJohn Criswell <criswell@uiuc.edu>2003-11-04 15:22:26 +0000
committerJohn Criswell <criswell@uiuc.edu>2003-11-04 15:22:26 +0000
commit700867bb69ae1469f2b20005a79fd133e83fd552 (patch)
treef31982a78f11201edef9d74f9c917ffb4df5d24f /lib
parent62a7cc8661c551bdddca174426f79514a594dc33 (diff)
downloadexternal_llvm-700867bb69ae1469f2b20005a79fd133e83fd552.zip
external_llvm-700867bb69ae1469f2b20005a79fd133e83fd552.tar.gz
external_llvm-700867bb69ae1469f2b20005a79fd133e83fd552.tar.bz2
Checking in Chris's suggestions:
Added assert() to ensure symbol table is well formed. Added code to remember the value that was found; resolving types can change the symbol table and invalidate the value of the iterator. Added comments to the ResolveTypes() function (mainly for my own benefit). Please feel free to correct the comments if they are not accurate. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@9693 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/Linker/LinkModules.cpp35
-rw-r--r--lib/Transforms/Utils/Linker.cpp35
-rw-r--r--lib/VMCore/Linker.cpp35
3 files changed, 96 insertions, 9 deletions
diff --git a/lib/Linker/LinkModules.cpp b/lib/Linker/LinkModules.cpp
index 7bab1af..98dbacc 100644
--- a/lib/Linker/LinkModules.cpp
+++ b/lib/Linker/LinkModules.cpp
@@ -31,8 +31,23 @@ static inline bool Error(std::string *E, const std::string &Message) {
return true;
}
-// ResolveTypes - Attempt to link the two specified types together. Return true
-// if there is an error and they cannot yet be linked.
+//
+// Function: ResolveTypes()
+//
+// Description:
+// Attempt to link the two specified types together.
+//
+// Inputs:
+// DestTy - The type to which we wish to resolve.
+// SrcTy - The original type which we want to resolve.
+// Name - The name of the type.
+//
+// Outputs:
+// DestST - The symbol table in which the new type should be placed.
+//
+// Return value:
+// true - There is an error and the types cannot yet be linked.
+// false - No errors.
//
static bool ResolveTypes(const Type *DestTy, const Type *SrcTy,
SymbolTable *DestST, const std::string &Name) {
@@ -356,13 +371,27 @@ static GlobalValue *FindGlobalNamed(const std::string &Name, const Type *Ty,
for (SymbolTable::iterator I = ST->begin(), E = ST->end(); I != E; ++I)
if (I->first != Type::TypeTy) {
SymbolTable::VarMap &VM = I->second;
+
// Does this type plane contain an entry with the specified name?
SymbolTable::type_iterator TI = VM.find(Name);
if (TI != VM.end()) {
+ //
+ // Ensure that this type if placed correctly into the symbol table.
+ //
+ assert(TI->second->getType() == I->first && "Type conflict!");
+
+ //
+ // Save a reference to the new type. Resolving the type can modify the
+ // symbol table, invalidating the TI variable.
+ //
+ Value *ValPtr = TI->second;
+
+ //
// Determine whether we can fold the two types together, resolving them.
// If so, we can use this value.
+ //
if (!RecursiveResolveTypes(Ty, I->first, ST, ""))
- return cast<GlobalValue>(TI->second);
+ return cast<GlobalValue>(ValPtr);
}
}
return 0; // Otherwise, nothing could be found.
diff --git a/lib/Transforms/Utils/Linker.cpp b/lib/Transforms/Utils/Linker.cpp
index 7bab1af..98dbacc 100644
--- a/lib/Transforms/Utils/Linker.cpp
+++ b/lib/Transforms/Utils/Linker.cpp
@@ -31,8 +31,23 @@ static inline bool Error(std::string *E, const std::string &Message) {
return true;
}
-// ResolveTypes - Attempt to link the two specified types together. Return true
-// if there is an error and they cannot yet be linked.
+//
+// Function: ResolveTypes()
+//
+// Description:
+// Attempt to link the two specified types together.
+//
+// Inputs:
+// DestTy - The type to which we wish to resolve.
+// SrcTy - The original type which we want to resolve.
+// Name - The name of the type.
+//
+// Outputs:
+// DestST - The symbol table in which the new type should be placed.
+//
+// Return value:
+// true - There is an error and the types cannot yet be linked.
+// false - No errors.
//
static bool ResolveTypes(const Type *DestTy, const Type *SrcTy,
SymbolTable *DestST, const std::string &Name) {
@@ -356,13 +371,27 @@ static GlobalValue *FindGlobalNamed(const std::string &Name, const Type *Ty,
for (SymbolTable::iterator I = ST->begin(), E = ST->end(); I != E; ++I)
if (I->first != Type::TypeTy) {
SymbolTable::VarMap &VM = I->second;
+
// Does this type plane contain an entry with the specified name?
SymbolTable::type_iterator TI = VM.find(Name);
if (TI != VM.end()) {
+ //
+ // Ensure that this type if placed correctly into the symbol table.
+ //
+ assert(TI->second->getType() == I->first && "Type conflict!");
+
+ //
+ // Save a reference to the new type. Resolving the type can modify the
+ // symbol table, invalidating the TI variable.
+ //
+ Value *ValPtr = TI->second;
+
+ //
// Determine whether we can fold the two types together, resolving them.
// If so, we can use this value.
+ //
if (!RecursiveResolveTypes(Ty, I->first, ST, ""))
- return cast<GlobalValue>(TI->second);
+ return cast<GlobalValue>(ValPtr);
}
}
return 0; // Otherwise, nothing could be found.
diff --git a/lib/VMCore/Linker.cpp b/lib/VMCore/Linker.cpp
index 7bab1af..98dbacc 100644
--- a/lib/VMCore/Linker.cpp
+++ b/lib/VMCore/Linker.cpp
@@ -31,8 +31,23 @@ static inline bool Error(std::string *E, const std::string &Message) {
return true;
}
-// ResolveTypes - Attempt to link the two specified types together. Return true
-// if there is an error and they cannot yet be linked.
+//
+// Function: ResolveTypes()
+//
+// Description:
+// Attempt to link the two specified types together.
+//
+// Inputs:
+// DestTy - The type to which we wish to resolve.
+// SrcTy - The original type which we want to resolve.
+// Name - The name of the type.
+//
+// Outputs:
+// DestST - The symbol table in which the new type should be placed.
+//
+// Return value:
+// true - There is an error and the types cannot yet be linked.
+// false - No errors.
//
static bool ResolveTypes(const Type *DestTy, const Type *SrcTy,
SymbolTable *DestST, const std::string &Name) {
@@ -356,13 +371,27 @@ static GlobalValue *FindGlobalNamed(const std::string &Name, const Type *Ty,
for (SymbolTable::iterator I = ST->begin(), E = ST->end(); I != E; ++I)
if (I->first != Type::TypeTy) {
SymbolTable::VarMap &VM = I->second;
+
// Does this type plane contain an entry with the specified name?
SymbolTable::type_iterator TI = VM.find(Name);
if (TI != VM.end()) {
+ //
+ // Ensure that this type if placed correctly into the symbol table.
+ //
+ assert(TI->second->getType() == I->first && "Type conflict!");
+
+ //
+ // Save a reference to the new type. Resolving the type can modify the
+ // symbol table, invalidating the TI variable.
+ //
+ Value *ValPtr = TI->second;
+
+ //
// Determine whether we can fold the two types together, resolving them.
// If so, we can use this value.
+ //
if (!RecursiveResolveTypes(Ty, I->first, ST, ""))
- return cast<GlobalValue>(TI->second);
+ return cast<GlobalValue>(ValPtr);
}
}
return 0; // Otherwise, nothing could be found.