diff --git a/clang/lib/CodeGen/CGVTables.cpp b/clang/lib/CodeGen/CGVTables.cpp index e14e883a55ac5..3fbac308a9178 100644 --- a/clang/lib/CodeGen/CGVTables.cpp +++ b/clang/lib/CodeGen/CGVTables.cpp @@ -125,6 +125,11 @@ static void resolveTopLevelMetadata(llvm::Function *Fn, if (!DIS) return; auto *NewDIS = llvm::MDNode::replaceWithDistinct(DIS->clone()); + // As DISubprogram remapping is avoided, clear retained nodes list of + // cloned DISubprogram from retained nodes local to original DISubprogram. + // FIXME: Thunk function signature is produced wrong in DWARF, as retained + // nodes are not remapped. + NewDIS->replaceRetainedNodes(llvm::MDTuple::get(Fn->getContext(), {})); VMap.MD()[DIS].reset(NewDIS); // Find all llvm.dbg.declare intrinsics and resolve the DILocalVariable nodes diff --git a/clang/test/CodeGenCXX/tmp-md-nodes1.cpp b/clang/test/CodeGenCXX/tmp-md-nodes1.cpp index 524b2c08c1ad5..f39dca3edaed1 100644 --- a/clang/test/CodeGenCXX/tmp-md-nodes1.cpp +++ b/clang/test/CodeGenCXX/tmp-md-nodes1.cpp @@ -2,6 +2,14 @@ // RUN: %clang_cc1 -O0 -triple %itanium_abi_triple -debug-info-kind=limited -emit-llvm %s -o - | \ // RUN: FileCheck %s +// Trigger GenerateVarArgsThunk. +// RUN: %clang_cc1 -O0 -triple riscv64-linux-gnu -debug-info-kind=limited -emit-llvm %s -o - | \ +// RUN: FileCheck %s + +// Check that retainedNodes are properly maintained at function cloning. +// RUN: %clang_cc1 -O1 -triple riscv64-linux-gnu -debug-info-kind=limited -emit-llvm %s -o - | \ +// RUN: FileCheck %s --check-prefixes=CHECK,CHECK-DI + // This test simply checks that the varargs thunk is created. The failing test // case asserts. @@ -16,3 +24,11 @@ struct CharlieImpl : Charlie, Alpha { } delta; // CHECK: define {{.*}} void @_ZThn{{[48]}}_N11CharlieImpl5bravoEz( + +// CHECK-DI: distinct !DISubprogram({{.*}}, linkageName: "_ZN11CharlieImpl5bravoEz", {{.*}}, retainedNodes: [[RN1:![0-9]+]] +// A non-empty retainedNodes list of original DISubprogram. +// CHECK-DI: [[RN1]] = !{!{{.*}}} + +// CHECK-DI: distinct !DISubprogram({{.*}}, linkageName: "_ZN11CharlieImpl5bravoEz", {{.*}}, retainedNodes: [[EMPTY:![0-9]+]] +// An empty retainedNodes list of cloned DISubprogram. +// CHECK-DI: [[EMPTY]] = !{} diff --git a/clang/test/CodeGenCXX/tmp-md-nodes2.cpp b/clang/test/CodeGenCXX/tmp-md-nodes2.cpp index 8500cf3c42393..0c323ae4f58aa 100644 --- a/clang/test/CodeGenCXX/tmp-md-nodes2.cpp +++ b/clang/test/CodeGenCXX/tmp-md-nodes2.cpp @@ -2,6 +2,14 @@ // RUN: %clang_cc1 -O0 -triple %itanium_abi_triple -debug-info-kind=limited -emit-llvm %s -o - | \ // RUN: FileCheck %s +// Trigger GenerateVarArgsThunk. +// RUN: %clang_cc1 -O0 -triple riscv64-linux-gnu -debug-info-kind=limited -emit-llvm %s -o - | \ +// RUN: FileCheck %s + +// Check that retainedNodes are properly maintained at function cloning. +// RUN: %clang_cc1 -O1 -triple riscv64-linux-gnu -debug-info-kind=limited -emit-llvm %s -o - | \ +// RUN: FileCheck %s --check-prefixes=CHECK,CHECK-DI + // This test simply checks that the varargs thunk is created. The failing test // case asserts. @@ -31,3 +39,11 @@ BOOL CBdVfsImpl::ReqCacheHint( CMsgAgent* p_ma, CACHE_HINT hint, ... ) { } // CHECK: define {{.*}} @_ZThn{{[48]}}_N10CBdVfsImpl12ReqCacheHintEP9CMsgAgentN3CFs10CACHE_HINTEz( + +// An empty retainedNodes list of cloned DISubprogram. +// CHECK-DI: [[EMPTY:![0-9]+]] = !{} +// CHECK-DI: distinct !DISubprogram({{.*}}, linkageName: "_ZN10CBdVfsImpl12ReqCacheHintEP9CMsgAgentN3CFs10CACHE_HINTEz", {{.*}}, retainedNodes: [[RN1:![0-9]+]] +// A non-empty retainedNodes list of original DISubprogram. +// CHECK-DI: [[RN1]] = !{!{{.*}}} + +// CHECK-DI: distinct !DISubprogram({{.*}}, linkageName: "_ZN10CBdVfsImpl12ReqCacheHintEP9CMsgAgentN3CFs10CACHE_HINTEz", {{.*}}, retainedNodes: [[EMPTY]]