llvm.org GIT mirror llvm / 8103208
Linker: Fix references to uniqued nodes after r243883 r243883 started moving 'distinct' nodes instead of duplicated them in lib/Linker. This had the side-effect of sometimes not cloning uniqued nodes that reference them. I missed a corner case: !named = !{!0} !0 = !{!1} !1 = distinct !{!0} !0 is the entry point for "remapping", and a temporary clone (say, !0-temp) is created and mapped in case we need to model a uniquing cycle. Recursive descent into !1. !1 is distinct, so we leave it alone, but update its operand to !0-temp. Pop back out to !0. Its only operand, !1, hasn't changed, so we don't need to use !0-temp. !0-temp goes out of scope, and we're finished remapping, but we're left with: !named = !{!0} !0 = !{!1} !1 = distinct !{null} ; uh oh... Previously, if !0 and !0-temp ended up with identical operands, then !0-temp couldn't have been referenced at all. Now that distinct nodes don't get duplicated, that assumption is invalid. We need to !0-temp->replaceAllUsesWith(!0) before freeing !0-temp. I found this while running an internal `-flto -g` bootstrap. Strangely, there was no case of this in the open source bootstrap I'd done before commit... git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@243961 91177308-0d34-0410-b5e6-96231b3b80d8 Duncan P. N. Exon Smith 5 years ago
2 changed file(s) with 17 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
257257
258258 // Create a temporary node upfront in case we have a metadata cycle.
259259 auto ClonedMD = Node->clone();
260 if (!remap(Node, ClonedMD.get(), Cycles, VM, Flags, TypeMapper, Materializer))
260 if (!remap(Node, ClonedMD.get(), Cycles, VM, Flags, TypeMapper, Materializer)) {
261261 // No operands changed, so use the identity mapping.
262 ClonedMD->replaceAllUsesWith(const_cast(Node));
262263 return mapToSelf(VM, Node);
264 }
263265
264266 // At least one operand has changed, so uniquify the cloned node.
265267 return mapToMetadata(VM, Node,
0 ; RUN: llvm-link -o - %s | llvm-dis | FileCheck %s
1
2 ; CHECK: !named = !{!0, !2}
3 !named = !{!0, !2}
4
5 ; CHECK: !0 = !{!1}
6 ; CHECK-NEXT: !1 = distinct !{!0}
7 !0 = !{!1}
8 !1 = distinct !{!0}
9
10 ; CHECK-NEXT: !2 = distinct !{!3}
11 ; CHECK-NEXT: !3 = !{!2}
12 !2 = distinct !{!3}
13 !3 = !{!2}