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/Linker/Inputs/lazy-load-temporaries-cleanup.a.ll =================================================================== --- test/Linker/Inputs/lazy-load-temporaries-cleanup.a.ll +++ test/Linker/Inputs/lazy-load-temporaries-cleanup.a.ll @@ -0,0 +1,6 @@ +define void @tinkywinky() { + tail call void @patatino() + ret void +} + +declare void @patatino() Index: test/Linker/Inputs/lazy-load-temporaries-cleanup.b.ll =================================================================== --- test/Linker/Inputs/lazy-load-temporaries-cleanup.b.ll +++ test/Linker/Inputs/lazy-load-temporaries-cleanup.b.ll @@ -0,0 +1,20 @@ +define void @patatino() { + ret void +} + +!llvm.asan.globals = !{!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/Linker/lazy-load-temporaries-cleanup.ll =================================================================== --- test/Linker/lazy-load-temporaries-cleanup.ll +++ test/Linker/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: llvm-link %t.1.o %t.2.o