Author: Reid Kleckner
Date: 2025-04-23T22:09:02Z
New Revision: cd826d6e840ed33ad88458c862da5f9fcc6e908c

URL: 
https://github.com/llvm/llvm-project/commit/cd826d6e840ed33ad88458c862da5f9fcc6e908c
DIFF: 
https://github.com/llvm/llvm-project/commit/cd826d6e840ed33ad88458c862da5f9fcc6e908c.diff

LOG: Revert "[Clang,debuginfo] added vtt parameter in destructor 
DISubroutineType (#130674)"

This reverts commit 27c1aa9b9cf9e0b14211758ff8f7d3aaba24ffcf.

See comments on PR. After this change, Clang now asserts like this:

clang: ../llvm/include/llvm/IR/Metadata.h:1435: const MDOperand 
&llvm::MDNode::getOperand(unsigned int) const: Assertion `I < getNumOperands() 
&& "Out of range"' failed.
...
 #8 0x000055f345c4e4cb 
clang::CodeGen::CGDebugInfo::getOrCreateInstanceMethodType()
 #9 0x000055f345c5ba4f clang::CodeGen::CGDebugInfo::EmitFunctionDecl()
 #10 0x000055f345b52519 
clang::CodeGen::CodeGenModule::EmitExternalFunctionDeclaration()

This is due to pre-existing jankiness in the way BPF emits extra
declarations for debug info, but we should rollback and then fix forward.

Added: 
    

Modified: 
    clang/lib/CodeGen/CGDebugInfo.cpp
    clang/lib/CodeGen/CGDebugInfo.h
    clang/lib/CodeGen/CodeGenModule.cpp

Removed: 
    clang/test/CodeGenCXX/debug-info-dtor-implicit-args.cpp


################################################################################
diff  --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 1582d911ba052..f3ec498d4064b 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -2018,17 +2018,8 @@ CGDebugInfo::getOrCreateMethodType(const CXXMethodDecl 
*Method,
   return getOrCreateInstanceMethodType(ThisType, Func, 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) 
{
+llvm::DISubroutineType *CGDebugInfo::getOrCreateInstanceMethodType(
+    QualType ThisPtr, const FunctionProtoType *Func, llvm::DIFile *Unit) {
   FunctionProtoType::ExtProtoInfo EPI = Func->getExtProtoInfo();
   Qualifiers &Qc = EPI.TypeQuals;
   Qc.removeConst();
@@ -2068,7 +2059,7 @@ CGDebugInfo::getOrCreateInstanceMethodType(QualType 
ThisPtr,
   }
 
   // Copy rest of the arguments.
-  for (unsigned i = (SkipFirst ? 2 : 1), e = Args.size(); i != e; ++i)
+  for (unsigned i = 1, e = Args.size(); i != e; ++i)
     Elts.push_back(Args[i]);
 
   // Attach FlagObjectPointer to the explicit "this" parameter.
@@ -4381,12 +4372,6 @@ 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)) {
-    // Read method type from 'FnType' because 'D.getType()' does not cover
-    // implicit arguments for destructors.
-    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 771c129230eea..b287ce7b92eee 100644
--- a/clang/lib/CodeGen/CGDebugInfo.h
+++ b/clang/lib/CodeGen/CGDebugInfo.h
@@ -249,14 +249,9 @@ 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, bool SkipFirst = false);
+                                llvm::DIFile *Unit);
   llvm::DISubroutineType *
   getOrCreateFunctionType(const Decl *D, QualType FnType, llvm::DIFile *F);
   /// \return debug info descriptor for vtable.

diff  --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 83d8d4f758195..a073c5d54f8ab 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -5837,15 +5837,24 @@ void CodeGenModule::EmitExternalVarDeclaration(const 
VarDecl *D) {
     }
 }
 
+static GlobalDecl getBaseVariantGlobalDecl(const FunctionDecl *FD) {
+  if (auto const *CD = dyn_cast<const CXXConstructorDecl>(FD))
+    return GlobalDecl(CD, CXXCtorType::Ctor_Base);
+  else if (auto const *DD = dyn_cast<const CXXDestructorDecl>(FD))
+    return GlobalDecl(DD, CXXDtorType::Dtor_Base);
+  return GlobalDecl(FD);
+}
+
 void CodeGenModule::EmitExternalFunctionDeclaration(const FunctionDecl *FD) {
   if (CGDebugInfo *DI = getModuleDebugInfo())
     if (getCodeGenOpts().hasReducedDebugInfo()) {
+      GlobalDecl GD = getBaseVariantGlobalDecl(FD);
       auto *Ty = getTypes().ConvertType(FD->getType());
-      StringRef MangledName = getMangledName(FD);
+      StringRef MangledName = getMangledName(GD);
       auto *Fn = cast<llvm::Function>(
-          GetOrCreateLLVMFunction(MangledName, Ty, FD, /* ForVTable */ false));
+          GetOrCreateLLVMFunction(MangledName, Ty, GD, /* ForVTable */ false));
       if (!Fn->getSubprogram())
-        DI->EmitFunctionDecl(FD, FD->getLocation(), FD->getType(), Fn);
+        DI->EmitFunctionDecl(GD, FD->getLocation(), FD->getType(), Fn);
     }
 }
 

diff  --git a/clang/test/CodeGenCXX/debug-info-dtor-implicit-args.cpp 
b/clang/test/CodeGenCXX/debug-info-dtor-implicit-args.cpp
deleted file mode 100644
index 4bb51dcc4da51..0000000000000
--- a/clang/test/CodeGenCXX/debug-info-dtor-implicit-args.cpp
+++ /dev/null
@@ -1,24 +0,0 @@
-// RUN: %clang_cc1 -triple x86_64-none-linux-gnu -emit-llvm 
-debug-info-kind=limited %s -o - | FileCheck %s
-// RUN: %clang_cc1 -triple x86_64-pc-windows-msvc -emit-llvm 
-debug-info-kind=limited %s -o - | FileCheck --check-prefix MSVC %s
-
-struct B {
-    virtual ~B() {}
-};
-
-struct A : virtual B {
-};
-
-A a;
-
-
-// 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]]}
-
-// MSVC-DAG: ![[inttype:[0-9]+]] = !DIBasicType(name: "int", size: 32, 
encoding: DW_ATE_signed)
-// MSVC-DAG: ![[voidpointertype:[0-9]+]] = !DIDerivedType(tag: 
DW_TAG_pointer_type, baseType: null, size: 64)
-// MSVC-DAG: ![[destructor:[0-9]+]] = distinct !DISubprogram(name: "~A", 
linkageName: "??_GA@@UEAAPEAXI@Z", {{.*}}, type: ![[subroutinetype:[0-9]+]]
-// MSVC-DAG: !{{[0-9]+}} = !DILocalVariable(name: "should_call_delete", arg: 
2, scope: ![[destructor]], type: ![[inttype]], flags: DIFlagArtificial)
-// MSVC-DAG: ![[subroutinetype]] = !DISubroutineType(types: ![[types:[0-9]+]])
-// MSVC-DAG: [[types]] = !{![[voidpointertype]], !{{[0-9]+}}, ![[inttype]]}


        
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to