llvm.org GIT mirror llvm / 1014f0f
Merging r287353: ------------------------------------------------------------------------ r287353 | hans | 2016-11-18 09:33:05 -0800 (Fri, 18 Nov 2016) | 12 lines IRMover: Avoid accidentally mapping types from the destination module (PR30799) During Module linking, it's possible for SrcM->getIdentifiedStructTypes(); to return types that are actually defined in the destination module (DstM). Depending on how the bitcode file was read, getIdentifiedStructTypes() might do a walk over all values, including metadata nodes, looking for types. In my case, a debug info metadata node was shared between the two modules, and it referred to a type defined in the destination module (see test case). Differential Revision: https://reviews.llvm.org/D26212 ------------------------------------------------------------------------ git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_39@287906 91177308-0d34-0410-b5e6-96231b3b80d8 Tom Stellard 2 years ago
3 changed file(s) with 78 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
693693 if (!ST->hasName())
694694 continue;
695695
696 if (TypeMap.DstStructTypesSet.hasType(ST)) {
697 // This is actually a type from the destination module.
698 // getIdentifiedStructTypes() can have found it by walking debug info
699 // metadata nodes, some of which get linked by name when ODR Type Uniquing
700 // is enabled on the Context, from the source to the destination module.
701 continue;
702 }
703
696704 // Check to see if there is a dot in the name followed by a digit.
697705 size_t DotPos = ST->getName().rfind('.');
698706 if (DotPos == 0 || DotPos == StringRef::npos ||
0 target triple = "x86_64-pc-windows-msvc18.0.0"
1
2 %SrcType = type { i8 }
3 @x = external global %SrcType
4
5 %CommonStruct = type opaque
6 @bar = internal global %CommonStruct* null, !dbg !0
7
8
9 !llvm.dbg.cu = !{!1}
10 !llvm.module.flags = !{!12}
11 !0 = distinct !DIGlobalVariable(name: "bar", linkageName: "bar", scope: !1, file: !2, line: 2, type: !5, isLocal: false, isDefinition: true)
12 !1 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !2, producer: "", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !3, globals: !4)
13 !2 = !DIFile(filename: "b", directory: "/")
14 !3 = !{}
15 !4 = !{!0}
16 !5 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !6, size: 64)
17 !6 = !DICompositeType(tag: DW_TAG_structure_type, name: "S", file: !2, line: 1, flags: DIFlagFwdDecl, identifier: ".?AUS@@")
18 !12 = !{i32 2, !"Debug Info Version", i32 3}
19
0 ; RUN: llvm-as -o %t.dst.bc %s
1 ; RUN: llvm-as -o %t.src.bc %S/Inputs/type-mapping-src.ll
2 ; RUN: llvm-lto %t.dst.bc %t.src.bc -o=/dev/null
3
4 target triple = "x86_64-pc-windows-msvc18.0.0"
5
6 ; @x in Src will be linked with this @x, causing SrcType in Src to be mapped
7 ; to %DstType.
8 %DstType = type { i8 }
9 @x = global %DstType zeroinitializer
10
11 ; The Src module will re-use our DINode for this type.
12 %CommonStruct = type { i32 }
13 @foo = internal global %CommonStruct zeroinitializer, !dbg !5
14
15 ; That DINode will refer to this value, casted to %Tricky.1* (!11),
16 ; which will then show up in Src's getIdentifiedStructTypes().
17 @templateValueParam = global i8 zeroinitializer
18
19 ; Because of the names, we would try to map %Tricky.1 to %Tricky --
20 ; mapping a Dst type to another Dst type! This would assert when
21 ; getting a mapping from %DstType, which has previously used as
22 ; a destination type. Since these types are not in the source module,
23 ; there should be no attempt to create a mapping involving them;
24 ; both types should be left as they are.
25 %Tricky = type opaque
26 %Tricky.1 = type { %DstType* }
27
28
29 ; Mark %Tricky used.
30 @use = global %Tricky* zeroinitializer
31
32 !llvm.dbg.cu = !{!1}
33 !llvm.module.flags = !{!19}
34 !1 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !2, producer: "", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !3, globals: !4)
35 !2 = !DIFile(filename: "a", directory: "/")
36 !3 = !{}
37 !4 = !{!5}
38 !5 = distinct !DIGlobalVariable(name: "foo", linkageName: "foo", scope: !1, file: !2, line: 5, type: !6, isLocal: false, isDefinition: true)
39 !6 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "S", file: !2, line: 5, size: 8, elements: !7, identifier: ".?AUS@@")
40 !7 = !{!8}
41 !8 = !DIDerivedType(tag: DW_TAG_inheritance, scope: !6, baseType: !9)
42 !9 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "Template<&x>", file: !2, line: 3, size: 8, elements: !3, templateParams: !10, identifier: ".?AU?$Template@$1?x@@3UX@@A@@")
43 !10 = !{!11}
44
45 !11 = !DITemplateValueParameter(type: !12, value: %Tricky.1* bitcast (i8* @templateValueParam to %Tricky.1*))
46
47 !12 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !13, size: 64)
48 !13 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "X", file: !2, line: 1, size: 8, elements: !3, identifier: ".?AUX@@")
49 !19 = !{i32 2, !"Debug Info Version", i32 3}