Index: include/llvm/IR/Metadata.h =================================================================== --- include/llvm/IR/Metadata.h +++ include/llvm/IR/Metadata.h @@ -1277,6 +1277,8 @@ if (!Use) return; *Use = MD; + if(*Use) + MetadataTracking::track(*Use); Use = nullptr; } }; Index: test/ThinLTO/X86/Inputs/lazy-load-temporaries-cleanup.a.ll =================================================================== --- test/ThinLTO/X86/Inputs/lazy-load-temporaries-cleanup.a.ll +++ test/ThinLTO/X86/Inputs/lazy-load-temporaries-cleanup.a.ll @@ -0,0 +1,9 @@ +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +define void @tinkywinky() { + tail call void @patatino() + ret void +} + +declare void @patatino() Index: test/ThinLTO/X86/Inputs/lazy-load-temporaries-cleanup.b.ll =================================================================== --- test/ThinLTO/X86/Inputs/lazy-load-temporaries-cleanup.b.ll +++ test/ThinLTO/X86/Inputs/lazy-load-temporaries-cleanup.b.ll @@ -0,0 +1,23 @@ +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +define void @patatino() { + ret void +} + +!named = !{!0, !2, !4, !6, !8, !10, !12} + +!0 = distinct !{!1} +!1 = !{i8 1} +!2 = distinct !{!3} +!3 = !{i8 2} +!4 = distinct !{!5} +!5 = !{i8 3} +!6 = distinct !{!7} +!7 = !{i8 4, i8 5} +!8 = distinct !{!9} +!9 = !{i8 6, i8 7} +!10 = distinct !{!11} +!11 = !{i8 8, i8 9} +!12 = distinct !{!13, i8 0} +!13 = !{i8 10, i8 11} Index: test/ThinLTO/X86/lazy-load-temporaries-cleanup.ll =================================================================== --- test/ThinLTO/X86/lazy-load-temporaries-cleanup.ll +++ test/ThinLTO/X86/lazy-load-temporaries-cleanup.ll @@ -0,0 +1,5 @@ +; This test ensures that metadata temporaries are properly tracked, then cleaned up + +; RUN: opt -module-summary %S/Inputs/lazy-load-temporaries-cleanup.a.ll -o %t.1.o +; RUN: opt -module-summary %S/Inputs/lazy-load-temporaries-cleanup.b.ll -o %t.2.o +; RUN: ld.lld %t.1.o %t.2.o