Markus =?utf-8?q?Gschoßmann?= <markus.gschossm...@tum.de>, Markus =?utf-8?q?Gschoßmann?= <markus.gschossm...@tum.de> Message-ID: In-Reply-To: <llvm.org/llvm/llvm-project/pull/130...@github.com>
https://github.com/mgschossmann updated https://github.com/llvm/llvm-project/pull/130674 >From 017a07e4912c0d06b625207a8465ed2f8d8aac5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20Gscho=C3=9Fmann?= <markus.gschossm...@tum.de> Date: Mon, 10 Mar 2025 22:03:40 +0000 Subject: [PATCH 1/3] [Clang,debuginfo] added vtt parameter in DISubroutineType for virtual destructors --- clang/lib/CodeGen/CGDebugInfo.cpp | 19 ++++++++++++++++--- clang/lib/CodeGen/CGDebugInfo.h | 7 ++++++- clang/test/CodeGenCXX/debug-info-vtt.cpp | 16 ++++++++++++++++ 3 files changed, 38 insertions(+), 4 deletions(-) create mode 100644 clang/test/CodeGenCXX/debug-info-vtt.cpp diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp index 0e6daa42ee7bf..ae1ce18ee1831 100644 --- a/clang/lib/CodeGen/CGDebugInfo.cpp +++ b/clang/lib/CodeGen/CGDebugInfo.cpp @@ -2003,8 +2003,17 @@ CGDebugInfo::getOrCreateMethodType(const CXXMethodDecl *Method, return getOrCreateInstanceMethodType(ThisType, Func, Unit); } -llvm::DISubroutineType *CGDebugInfo::getOrCreateInstanceMethodType( - QualType ThisPtr, const FunctionProtoType *Func, llvm::DIFile *Unit) { +llvm::DISubroutineType *CGDebugInfo::getOrCreateMethodTypeForDestructor( + const CXXMethodDecl *Method, llvm::DIFile *Unit, QualType FNType) { + const FunctionProtoType *Func = FNType->getAs<FunctionProtoType>(); + // skip the first param since it is also this + return getOrCreateInstanceMethodType(Method->getThisType(), Func, Unit, true); +} + +llvm::DISubroutineType * +CGDebugInfo::getOrCreateInstanceMethodType(QualType ThisPtr, + const FunctionProtoType *Func, + llvm::DIFile *Unit, bool SkipFirst) { FunctionProtoType::ExtProtoInfo EPI = Func->getExtProtoInfo(); Qualifiers &Qc = EPI.TypeQuals; Qc.removeConst(); @@ -2044,7 +2053,7 @@ llvm::DISubroutineType *CGDebugInfo::getOrCreateInstanceMethodType( } // Copy rest of the arguments. - for (unsigned i = 1, e = Args.size(); i != e; ++i) + for (unsigned i = (SkipFirst ? 2 : 1), e = Args.size(); i != e; ++i) Elts.push_back(Args[i]); // Attach FlagObjectPointer to the explicit "this" parameter. @@ -4352,6 +4361,10 @@ llvm::DISubroutineType *CGDebugInfo::getOrCreateFunctionType(const Decl *D, // subprogram DIE will miss DW_AT_decl_file and DW_AT_decl_line fields. return DBuilder.createSubroutineType(DBuilder.getOrCreateTypeArray({})); + if (const auto *Method = dyn_cast<CXXDestructorDecl>(D)) { + return getOrCreateMethodTypeForDestructor(Method, F, FnType); + } + if (const auto *Method = dyn_cast<CXXMethodDecl>(D)) return getOrCreateMethodType(Method, F); diff --git a/clang/lib/CodeGen/CGDebugInfo.h b/clang/lib/CodeGen/CGDebugInfo.h index 38f73eca561b7..8d7591da0f518 100644 --- a/clang/lib/CodeGen/CGDebugInfo.h +++ b/clang/lib/CodeGen/CGDebugInfo.h @@ -249,9 +249,14 @@ class CGDebugInfo { /// to get a method type which includes \c this pointer. llvm::DISubroutineType *getOrCreateMethodType(const CXXMethodDecl *Method, llvm::DIFile *F); + + llvm::DISubroutineType * + getOrCreateMethodTypeForDestructor(const CXXMethodDecl *Method, + llvm::DIFile *F, QualType FNType); + llvm::DISubroutineType * getOrCreateInstanceMethodType(QualType ThisPtr, const FunctionProtoType *Func, - llvm::DIFile *Unit); + llvm::DIFile *Unit, bool SkipFirst = false); llvm::DISubroutineType * getOrCreateFunctionType(const Decl *D, QualType FnType, llvm::DIFile *F); /// \return debug info descriptor for vtable. diff --git a/clang/test/CodeGenCXX/debug-info-vtt.cpp b/clang/test/CodeGenCXX/debug-info-vtt.cpp new file mode 100644 index 0000000000000..f888994d08d53 --- /dev/null +++ b/clang/test/CodeGenCXX/debug-info-vtt.cpp @@ -0,0 +1,16 @@ +// RUN: %clang -g -c -emit-llvm %s -o - | llvm-dis | FileCheck %s + +struct B { + virtual ~B() {} +}; + +struct A : virtual B { +}; + +A a; + +// CHECK-DAG: distinct !DISubprogram(name: "~A", linkageName: "_ZN1AD2Ev", {{.*}}, type: ![[subroutinetype:[0-9]+]] +// CHECK-DAG: ![[subroutinetype]] = !DISubroutineType(types: ![[types:[0-9]+]]) +// CHECK-DAG: [[types]] = !{null, !{{[0-9]+}}, !{{[0-9]+}}} + + >From cdd8eb8bf144483ddc0724652dcf5c2eab929e84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20Gscho=C3=9Fmann?= <markus.gschossm...@tum.de> Date: Mon, 10 Mar 2025 22:39:17 +0000 Subject: [PATCH 2/3] fixed test --- clang/test/CodeGenCXX/debug-info-vtt.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/clang/test/CodeGenCXX/debug-info-vtt.cpp b/clang/test/CodeGenCXX/debug-info-vtt.cpp index f888994d08d53..ead81b464a530 100644 --- a/clang/test/CodeGenCXX/debug-info-vtt.cpp +++ b/clang/test/CodeGenCXX/debug-info-vtt.cpp @@ -9,8 +9,8 @@ struct A : virtual B { A a; -// CHECK-DAG: distinct !DISubprogram(name: "~A", linkageName: "_ZN1AD2Ev", {{.*}}, type: ![[subroutinetype:[0-9]+]] -// CHECK-DAG: ![[subroutinetype]] = !DISubroutineType(types: ![[types:[0-9]+]]) -// CHECK-DAG: [[types]] = !{null, !{{[0-9]+}}, !{{[0-9]+}}} - +// CHECK-DAG: !{{[0-9]+}} = !DILocalVariable(name: "vtt", arg: 2, scope: ![[destructor:[0-9]+]], type: ![[vtttype:[0-9]+]], flags: DIFlagArtificial) +// CHECK-DAG: ![[destructor]] = distinct !DISubprogram(name: "~A", {{.*}}, type: ![[subroutinetype:[0-9]+]] +// CHECK-DAG: ![[subroutinetype]] = !DISubroutineType(types: ![[types:[0-9]+]]) +// CHECK-DAG: [[types]] = !{null, !{{[0-9]+}}, ![[vtttype]]} >From 803460d95cdd496ce9f1822d89292af0ff89a8f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20Gscho=C3=9Fmann?= <markus.gschossm...@tum.de> Date: Mon, 10 Mar 2025 23:45:20 +0000 Subject: [PATCH 3/3] test: fixed target triple to x86_64-none-linux-gnu (vtt not generated for i686-pc-windows-msvc) --- clang/test/CodeGenCXX/debug-info-vtt.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/test/CodeGenCXX/debug-info-vtt.cpp b/clang/test/CodeGenCXX/debug-info-vtt.cpp index ead81b464a530..ab7c9d90d7f25 100644 --- a/clang/test/CodeGenCXX/debug-info-vtt.cpp +++ b/clang/test/CodeGenCXX/debug-info-vtt.cpp @@ -1,4 +1,4 @@ -// RUN: %clang -g -c -emit-llvm %s -o - | llvm-dis | FileCheck %s +// RUN: %clang_cc1 -triple x86_64-none-linux-gnu -emit-llvm -debug-info-kind=limited %s -o - | FileCheck %s struct B { virtual ~B() {} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits