llvm.org GIT mirror llvm / 6891050
fix PR11464 by preventing the linker from mapping two different struct types from the source module onto the same opaque destination type. An opaque type can only be resolved to one thing or another after all. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@146929 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 8 years ago
2 changed file(s) with 46 addition(s) and 12 deletion(s). Raw diff Collapse all Expand all
3737 /// case we need to roll back.
3838 SmallVector SpeculativeTypes;
3939
40 /// DefinitionsToResolve - This is a list of non-opaque structs in the source
41 /// module that are mapped to an opaque struct in the destination module.
42 SmallVector DefinitionsToResolve;
40 /// SrcDefinitionsToResolve - This is a list of non-opaque structs in the
41 /// source module that are mapped to an opaque struct in the destination
42 /// module.
43 SmallVector SrcDefinitionsToResolve;
44
45 /// DstResolvedOpaqueTypes - This is the set of opaque types in the
46 /// destination modules who are getting a body from the source module.
47 SmallPtrSet DstResolvedOpaqueTypes;
4348 public:
4449
4550 /// addTypeMapping - Indicate that the specified type in the destination
117122 return true;
118123 }
119124
120 // Mapping a non-opaque source type to an opaque dest. Keep the dest, but
121 // fill it in later. This doesn't need to be speculative.
125 // Mapping a non-opaque source type to an opaque dest. If this is the first
126 // type that we're mapping onto this destination type then we succeed. Keep
127 // the dest, but fill it in later. This doesn't need to be speculative. If
128 // this is the second (different) type that we're trying to map onto the
129 // same opaque type then we fail.
122130 if (cast(DstTy)->isOpaque()) {
131 // We can only map one source type onto the opaque destination type.
132 if (!DstResolvedOpaqueTypes.insert(cast(DstTy)))
133 return false;
134 SrcDefinitionsToResolve.push_back(SSTy);
123135 Entry = DstTy;
124 DefinitionsToResolve.push_back(SSTy);
125136 return true;
126137 }
127138 }
173184 SmallString<16> TmpName;
174185
175186 // Note that processing entries in this loop (calling 'get') can add new
176 // entries to the DefinitionsToResolve vector.
177 while (!DefinitionsToResolve.empty()) {
178 StructType *SrcSTy = DefinitionsToResolve.pop_back_val();
187 // entries to the SrcDefinitionsToResolve vector.
188 while (!SrcDefinitionsToResolve.empty()) {
189 StructType *SrcSTy = SrcDefinitionsToResolve.pop_back_val();
179190 StructType *DstSTy = cast(MappedTypes[SrcSTy]);
180191
181192 // TypeMap is a many-to-one mapping, if there were multiple types that
203214 TmpName.clear();
204215 }
205216 }
217
218 DstResolvedOpaqueTypes.clear();
206219 }
207220
208221
212225 Type *Result = getImpl(Ty);
213226
214227 // If this caused a reference to any struct type, resolve it before returning.
215 if (!DefinitionsToResolve.empty())
228 if (!SrcDefinitionsToResolve.empty())
216229 linkDefinedTypeBodies();
217230 return Result;
218231 }
303316
304317 // Otherwise we create a new type and resolve its body later. This will be
305318 // resolved by the top level of get().
306 DefinitionsToResolve.push_back(STy);
307 return *Entry = StructType::create(STy->getContext());
319 SrcDefinitionsToResolve.push_back(STy);
320 StructType *DTy = StructType::create(STy->getContext());
321 DstResolvedOpaqueTypes.insert(DTy);
322 return *Entry = DTy;
308323 }
309324
310325
0 ; RUN: echo {%bug_type = type opaque \
1 ; RUN: declare i32 @bug_a(%bug_type*) \
2 ; RUN: declare i32 @bug_b(%bug_type*) } > %t.ll
3 ; RUN: llvm-link %t.ll %s
4 ; PR11464
5
6 %bug_type = type { %bug_type* }
7 %bar = type { i32 }
8
9 define i32 @bug_a(%bug_type* %fp) nounwind uwtable {
10 entry:
11 %d_stream = getelementptr inbounds %bug_type* %fp, i64 0, i32 0
12 ret i32 0
13 }
14
15 define i32 @bug_b(%bar* %a) nounwind uwtable {
16 entry:
17 ret i32 0
18 }