summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2003-08-23 21:25:54 +0000
committerChris Lattner <sabre@nondot.org>2003-08-23 21:25:54 +0000
commite3092c94ad2e3af96f37a0a8186149acbbd9700a (patch)
treeac4557884429a791881c12ad2b1c5e05b307bacb /lib
parent8d8523b27a15dd733bfb2e880fba9e667bfe7e2b (diff)
downloadllvm-e3092c94ad2e3af96f37a0a8186149acbbd9700a.tar.gz
llvm-e3092c94ad2e3af96f37a0a8186149acbbd9700a.tar.bz2
llvm-e3092c94ad2e3af96f37a0a8186149acbbd9700a.tar.xz
Fix bug: Linker/2003-08-23-RecursiveOpaqueTypeResolve.ll
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@8083 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/Linker/LinkModules.cpp53
-rw-r--r--lib/Transforms/Utils/Linker.cpp53
-rw-r--r--lib/VMCore/Linker.cpp53
3 files changed, 117 insertions, 42 deletions
diff --git a/lib/Linker/LinkModules.cpp b/lib/Linker/LinkModules.cpp
index f6b1916db4..24449ea9f6 100644
--- a/lib/Linker/LinkModules.cpp
+++ b/lib/Linker/LinkModules.cpp
@@ -59,9 +59,10 @@ static const StructType *getST(const PATypeHolder &TH) {
// recurses down into derived types, merging the used types if the parent types
// are compatible.
//
-static bool RecursiveResolveTypes(const PATypeHolder &DestTy,
- const PATypeHolder &SrcTy,
- SymbolTable *DestST, const std::string &Name){
+static bool RecursiveResolveTypesI(const PATypeHolder &DestTy,
+ const PATypeHolder &SrcTy,
+ SymbolTable *DestST, const std::string &Name,
+ std::vector<std::pair<PATypeHolder, PATypeHolder> > &Pointers) {
const Type *SrcTyT = SrcTy.get();
const Type *DestTyT = DestTy.get();
if (DestTyT == SrcTyT) return false; // If already equal, noop
@@ -81,8 +82,9 @@ static bool RecursiveResolveTypes(const PATypeHolder &DestTy,
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, ""))
+ if (RecursiveResolveTypesI(getFT(DestTy)->getContainedType(i),
+ getFT(SrcTy)->getContainedType(i), DestST, "",
+ Pointers))
return true;
return false;
}
@@ -90,8 +92,9 @@ static bool RecursiveResolveTypes(const PATypeHolder &DestTy,
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, ""))
+ if (RecursiveResolveTypesI(getST(DestTy)->getContainedType(i),
+ getST(SrcTy)->getContainedType(i), DestST, "",
+ Pointers))
return true;
return false;
}
@@ -99,18 +102,40 @@ static bool RecursiveResolveTypes(const PATypeHolder &DestTy,
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, "");
+ return RecursiveResolveTypesI(DAT->getElementType(), SAT->getElementType(),
+ DestST, "", Pointers);
+ }
+ case Type::PointerTyID: {
+ // If this is a pointer type, check to see if we have already seen it. If
+ // so, we are in a recursive branch. Cut off the search now. We cannot use
+ // an associative container for this search, because the type pointers (keys
+ // in the container) change whenever types get resolved...
+ //
+ for (unsigned i = 0, e = Pointers.size(); i != e; ++i)
+ if (Pointers[i].first == DestTy)
+ return Pointers[i].second != SrcTy;
+
+ // Otherwise, add the current pointers to the vector to stop recursion on
+ // this pair.
+ Pointers.push_back(std::make_pair(DestTyT, SrcTyT));
+ bool Result =
+ RecursiveResolveTypesI(cast<PointerType>(DestTy.get())->getElementType(),
+ cast<PointerType>(SrcTy.get())->getElementType(),
+ DestST, "", Pointers);
+ Pointers.pop_back();
+ return Result;
}
- case Type::PointerTyID:
- return RecursiveResolveTypes(
- cast<PointerType>(DestTy.get())->getElementType(),
- cast<PointerType>(SrcTy.get())->getElementType(),
- DestST, "");
default: assert(0 && "Unexpected type!"); return true;
}
}
+static bool RecursiveResolveTypes(const PATypeHolder &DestTy,
+ const PATypeHolder &SrcTy,
+ SymbolTable *DestST, const std::string &Name){
+ std::vector<std::pair<PATypeHolder, PATypeHolder> > PointerTypes;
+ return RecursiveResolveTypesI(DestTy, SrcTy, DestST, Name, PointerTypes);
+}
+
// LinkTypes - Go through the symbol table of the Src module and see if any
// types are named in the src module that are not named in the Dst module.
diff --git a/lib/Transforms/Utils/Linker.cpp b/lib/Transforms/Utils/Linker.cpp
index f6b1916db4..24449ea9f6 100644
--- a/lib/Transforms/Utils/Linker.cpp
+++ b/lib/Transforms/Utils/Linker.cpp
@@ -59,9 +59,10 @@ static const StructType *getST(const PATypeHolder &TH) {
// recurses down into derived types, merging the used types if the parent types
// are compatible.
//
-static bool RecursiveResolveTypes(const PATypeHolder &DestTy,
- const PATypeHolder &SrcTy,
- SymbolTable *DestST, const std::string &Name){
+static bool RecursiveResolveTypesI(const PATypeHolder &DestTy,
+ const PATypeHolder &SrcTy,
+ SymbolTable *DestST, const std::string &Name,
+ std::vector<std::pair<PATypeHolder, PATypeHolder> > &Pointers) {
const Type *SrcTyT = SrcTy.get();
const Type *DestTyT = DestTy.get();
if (DestTyT == SrcTyT) return false; // If already equal, noop
@@ -81,8 +82,9 @@ static bool RecursiveResolveTypes(const PATypeHolder &DestTy,
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, ""))
+ if (RecursiveResolveTypesI(getFT(DestTy)->getContainedType(i),
+ getFT(SrcTy)->getContainedType(i), DestST, "",
+ Pointers))
return true;
return false;
}
@@ -90,8 +92,9 @@ static bool RecursiveResolveTypes(const PATypeHolder &DestTy,
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, ""))
+ if (RecursiveResolveTypesI(getST(DestTy)->getContainedType(i),
+ getST(SrcTy)->getContainedType(i), DestST, "",
+ Pointers))
return true;
return false;
}
@@ -99,18 +102,40 @@ static bool RecursiveResolveTypes(const PATypeHolder &DestTy,
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, "");
+ return RecursiveResolveTypesI(DAT->getElementType(), SAT->getElementType(),
+ DestST, "", Pointers);
+ }
+ case Type::PointerTyID: {
+ // If this is a pointer type, check to see if we have already seen it. If
+ // so, we are in a recursive branch. Cut off the search now. We cannot use
+ // an associative container for this search, because the type pointers (keys
+ // in the container) change whenever types get resolved...
+ //
+ for (unsigned i = 0, e = Pointers.size(); i != e; ++i)
+ if (Pointers[i].first == DestTy)
+ return Pointers[i].second != SrcTy;
+
+ // Otherwise, add the current pointers to the vector to stop recursion on
+ // this pair.
+ Pointers.push_back(std::make_pair(DestTyT, SrcTyT));
+ bool Result =
+ RecursiveResolveTypesI(cast<PointerType>(DestTy.get())->getElementType(),
+ cast<PointerType>(SrcTy.get())->getElementType(),
+ DestST, "", Pointers);
+ Pointers.pop_back();
+ return Result;
}
- case Type::PointerTyID:
- return RecursiveResolveTypes(
- cast<PointerType>(DestTy.get())->getElementType(),
- cast<PointerType>(SrcTy.get())->getElementType(),
- DestST, "");
default: assert(0 && "Unexpected type!"); return true;
}
}
+static bool RecursiveResolveTypes(const PATypeHolder &DestTy,
+ const PATypeHolder &SrcTy,
+ SymbolTable *DestST, const std::string &Name){
+ std::vector<std::pair<PATypeHolder, PATypeHolder> > PointerTypes;
+ return RecursiveResolveTypesI(DestTy, SrcTy, DestST, Name, PointerTypes);
+}
+
// LinkTypes - Go through the symbol table of the Src module and see if any
// types are named in the src module that are not named in the Dst module.
diff --git a/lib/VMCore/Linker.cpp b/lib/VMCore/Linker.cpp
index f6b1916db4..24449ea9f6 100644
--- a/lib/VMCore/Linker.cpp
+++ b/lib/VMCore/Linker.cpp
@@ -59,9 +59,10 @@ static const StructType *getST(const PATypeHolder &TH) {
// recurses down into derived types, merging the used types if the parent types
// are compatible.
//
-static bool RecursiveResolveTypes(const PATypeHolder &DestTy,
- const PATypeHolder &SrcTy,
- SymbolTable *DestST, const std::string &Name){
+static bool RecursiveResolveTypesI(const PATypeHolder &DestTy,
+ const PATypeHolder &SrcTy,
+ SymbolTable *DestST, const std::string &Name,
+ std::vector<std::pair<PATypeHolder, PATypeHolder> > &Pointers) {
const Type *SrcTyT = SrcTy.get();
const Type *DestTyT = DestTy.get();
if (DestTyT == SrcTyT) return false; // If already equal, noop
@@ -81,8 +82,9 @@ static bool RecursiveResolveTypes(const PATypeHolder &DestTy,
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, ""))
+ if (RecursiveResolveTypesI(getFT(DestTy)->getContainedType(i),
+ getFT(SrcTy)->getContainedType(i), DestST, "",
+ Pointers))
return true;
return false;
}
@@ -90,8 +92,9 @@ static bool RecursiveResolveTypes(const PATypeHolder &DestTy,
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, ""))
+ if (RecursiveResolveTypesI(getST(DestTy)->getContainedType(i),
+ getST(SrcTy)->getContainedType(i), DestST, "",
+ Pointers))
return true;
return false;
}
@@ -99,18 +102,40 @@ static bool RecursiveResolveTypes(const PATypeHolder &DestTy,
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, "");
+ return RecursiveResolveTypesI(DAT->getElementType(), SAT->getElementType(),
+ DestST, "", Pointers);
+ }
+ case Type::PointerTyID: {
+ // If this is a pointer type, check to see if we have already seen it. If
+ // so, we are in a recursive branch. Cut off the search now. We cannot use
+ // an associative container for this search, because the type pointers (keys
+ // in the container) change whenever types get resolved...
+ //
+ for (unsigned i = 0, e = Pointers.size(); i != e; ++i)
+ if (Pointers[i].first == DestTy)
+ return Pointers[i].second != SrcTy;
+
+ // Otherwise, add the current pointers to the vector to stop recursion on
+ // this pair.
+ Pointers.push_back(std::make_pair(DestTyT, SrcTyT));
+ bool Result =
+ RecursiveResolveTypesI(cast<PointerType>(DestTy.get())->getElementType(),
+ cast<PointerType>(SrcTy.get())->getElementType(),
+ DestST, "", Pointers);
+ Pointers.pop_back();
+ return Result;
}
- case Type::PointerTyID:
- return RecursiveResolveTypes(
- cast<PointerType>(DestTy.get())->getElementType(),
- cast<PointerType>(SrcTy.get())->getElementType(),
- DestST, "");
default: assert(0 && "Unexpected type!"); return true;
}
}
+static bool RecursiveResolveTypes(const PATypeHolder &DestTy,
+ const PATypeHolder &SrcTy,
+ SymbolTable *DestST, const std::string &Name){
+ std::vector<std::pair<PATypeHolder, PATypeHolder> > PointerTypes;
+ return RecursiveResolveTypesI(DestTy, SrcTy, DestST, Name, PointerTypes);
+}
+
// LinkTypes - Go through the symbol table of the Src module and see if any
// types are named in the src module that are not named in the Dst module.