aboutsummaryrefslogtreecommitdiffstats
path: root/lib/VMCore
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2003-08-22 19:12:55 +0000
committerChris Lattner <sabre@nondot.org>2003-08-22 19:12:55 +0000
commit43f4ba8c7d19664bb5de73a7b391b67061f25d22 (patch)
tree12c8229b211fc61dca0f20af2e01e35d94d872c3 /lib/VMCore
parentc28c1d3cd19bbfcc8eec44f25c5890f8e3ed8bdc (diff)
downloadexternal_llvm-43f4ba8c7d19664bb5de73a7b391b67061f25d22.zip
external_llvm-43f4ba8c7d19664bb5de73a7b391b67061f25d22.tar.gz
external_llvm-43f4ba8c7d19664bb5de73a7b391b67061f25d22.tar.bz2
The process of linking types can cause their addresses to become invalid. For this reason, we must use TypeHandles!
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@8057 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/VMCore')
-rw-r--r--lib/VMCore/Linker.cpp57
1 files changed, 33 insertions, 24 deletions
diff --git a/lib/VMCore/Linker.cpp b/lib/VMCore/Linker.cpp
index a38d2c0..e6e89c3 100644
--- a/lib/VMCore/Linker.cpp
+++ b/lib/VMCore/Linker.cpp
@@ -48,55 +48,64 @@ static bool ResolveTypes(const Type *DestTy, const Type *SrcTy,
return false;
}
+static const FunctionType *getFT(const PATypeHolder &TH) {
+ return cast<FunctionType>(TH.get());
+}
+static const StructType *getsT(const PATypeHolder &TH) {
+ return cast<StructType>(TH.get());
+}
// RecursiveResolveTypes - This is just like ResolveTypes, except that it
// recurses down into derived types, merging the used types if the parent types
// are compatible.
//
-static bool RecursiveResolveTypes(const Type *DestTy, const Type *SrcTy,
+static bool RecursiveResolveTypes(const PATypeHolder &DestTy,
+ const PATypeHolder &SrcTy,
SymbolTable *DestST, const std::string &Name){
- if (DestTy == SrcTy) return false; // If already equal, noop
+ const Type *SrcTyT = SrcTy.get();
+ const Type *DestTyT = DestTy.get();
+ if (DestTyT == SrcTyT) return false; // If already equal, noop
// If we found our opaque type, resolve it now!
- if (isa<OpaqueType>(DestTy) || isa<OpaqueType>(SrcTy))
- return ResolveTypes(DestTy, SrcTy, DestST, Name);
+ if (isa<OpaqueType>(DestTyT) || isa<OpaqueType>(SrcTyT))
+ return ResolveTypes(DestTyT, SrcTyT, DestST, Name);
// Two types cannot be resolved together if they are of different primitive
// type. For example, we cannot resolve an int to a float.
- if (DestTy->getPrimitiveID() != SrcTy->getPrimitiveID()) return true;
+ if (DestTyT->getPrimitiveID() != SrcTyT->getPrimitiveID()) return true;
// Otherwise, resolve the used type used by this derived type...
- switch (DestTy->getPrimitiveID()) {
+ switch (DestTyT->getPrimitiveID()) {
case Type::FunctionTyID: {
- const FunctionType *DFT = cast<FunctionType>(DestTy);
- const FunctionType *SFT = cast<FunctionType>(SrcTy);
- if (DFT->isVarArg() != SFT->isVarArg()) return true;
- for (unsigned i = 0, e = DFT->getNumContainedTypes(); i != e; ++i)
- if (RecursiveResolveTypes(DFT->getContainedType(i),
- SFT->getContainedType(i), DestST, Name))
+ if (cast<FunctionType>(DestTyT)->isVarArg() !=
+ cast<FunctionType>(SrcTyT)->isVarArg())
+ return true;
+ for (unsigned i = 0, e = getFT(DestTy)->getNumContainedTypes(); i != e; ++i)
+ if (RecursiveResolveTypes(getFT(DestTy)->getContainedType(i),
+ getFT(SrcTy)->getContainedType(i), DestST,Name))
return true;
return false;
}
case Type::StructTyID: {
- const StructType *DST = cast<StructType>(DestTy);
- const StructType *SST = cast<StructType>(SrcTy);
- if (DST->getNumContainedTypes() != SST->getNumContainedTypes()) return 1;
- for (unsigned i = 0, e = DST->getNumContainedTypes(); i != e; ++i)
- if (RecursiveResolveTypes(DST->getContainedType(i),
- SST->getContainedType(i), DestST, Name))
+ if (getST(DestTy)->getNumContainedTypes() !=
+ getST(SrcTy)->getNumContainedTypes()) return 1;
+ for (unsigned i = 0, e = getST(DestTy)->getNumContainedTypes(); i != e; ++i)
+ if (RecursiveResolveTypes(getST(DestTy)->getContainedType(i),
+ getST(SrcTy)->getContainedType(i), DestST,Name))
return true;
return false;
}
case Type::ArrayTyID: {
- const ArrayType *DAT = cast<ArrayType>(DestTy);
- const ArrayType *SAT = cast<ArrayType>(SrcTy);
+ const ArrayType *DAT = cast<ArrayType>(DestTy.get());
+ const ArrayType *SAT = cast<ArrayType>(SrcTy.get());
if (DAT->getNumElements() != SAT->getNumElements()) return true;
return RecursiveResolveTypes(DAT->getElementType(), SAT->getElementType(),
DestST, Name);
}
case Type::PointerTyID:
- return RecursiveResolveTypes(cast<PointerType>(DestTy)->getElementType(),
- cast<PointerType>(SrcTy)->getElementType(),
+ return RecursiveResolveTypes(
+ cast<PointerType>(DestTy.get())->getElementType(),
+ cast<PointerType>(SrcTy.get())->getElementType(),
DestST, Name);
default: assert(0 && "Unexpected type!"); return true;
}
@@ -158,8 +167,8 @@ static bool LinkTypes(Module *Dest, const Module *Src, std::string *Err) {
// two types: { int* } and { opaque* }
for (unsigned i = 0, e = DelayedTypesToResolve.size(); i != e; ++i) {
const std::string &Name = DelayedTypesToResolve[i];
- Type *T1 = cast<Type>(VM.find(Name)->second);
- Type *T2 = cast<Type>(DestST->lookup(Type::TypeTy, Name));
+ PATypeHolder T1(cast<Type>(VM.find(Name)->second));
+ PATypeHolder T2(cast<Type>(DestST->lookup(Type::TypeTy, Name)));
if (!RecursiveResolveTypes(T2, T1, DestST, Name)) {
// We are making progress!