[clang] [libcxxabi] [lldb] [llvm] [WIP][lldb] Alternative implementation of more reliable function call infrastructure (PR #115245)

2025-09-03 Thread Michael Buch via cfe-commits

Michael137 wrote:

Landed in https://github.com/llvm/llvm-project/pull/148877

https://github.com/llvm/llvm-project/pull/115245
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [libcxxabi] [lldb] [llvm] [WIP][lldb] Alternative implementation of more reliable function call infrastructure (PR #115245)

2025-09-03 Thread Michael Buch via cfe-commits

https://github.com/Michael137 closed 
https://github.com/llvm/llvm-project/pull/115245
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [libcxxabi] [lldb] [llvm] [WIP][lldb] Alternative implementation of more reliable function call infrastructure (PR #115245)

2025-04-04 Thread Michael Buch via cfe-commits

https://github.com/Michael137 edited 
https://github.com/llvm/llvm-project/pull/115245
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [libcxxabi] [lldb] [llvm] [WIP][lldb] Alternative implementation of more reliable function call infrastructure (PR #115245)

2025-04-04 Thread Michael Buch via cfe-commits

https://github.com/Michael137 updated 
https://github.com/llvm/llvm-project/pull/115245

>From 63ca211312cd9dcbf28d30866a429262b504bdb3 Mon Sep 17 00:00:00 2001
From: Michael Buch 
Date: Tue, 5 Nov 2024 00:22:07 +
Subject: [PATCH] Init

---
 clang/include/clang/Basic/Attr.td |   7 +
 clang/include/clang/Basic/AttrDocs.td |   5 +
 clang/lib/AST/Mangle.cpp  |  16 +-
 clang/lib/Sema/SemaDeclAttr.cpp   |  11 ++
 libcxxabi/src/demangle/ItaniumDemangle.h  |   2 +
 lldb/source/Expression/IRExecutionUnit.cpp| 186 ++
 .../SymbolFile/DWARF/DWARFASTParserClang.cpp  |  29 ++-
 .../TypeSystem/Clang/TypeSystemClang.cpp  |  12 +-
 llvm/include/llvm/Demangle/Demangle.h |   1 +
 llvm/include/llvm/Demangle/ItaniumDemangle.h  |   2 +
 llvm/lib/Demangle/ItaniumDemangle.cpp |  17 +-
 11 files changed, 275 insertions(+), 13 deletions(-)

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index fd9e686485552..d72ae1fd80e81 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -812,6 +812,13 @@ def AbiTag : Attr {
   let Documentation = [AbiTagsDocs];
 }
 
+def StructorName : Attr {
+let Spellings = [Clang<"structor_name">];
+let Args = [StringArgument<"Name">];
+let Subjects = SubjectList<[Function], ErrorDiag>;
+let Documentation = [StructorNameDocs];
+}
+
 def AddressSpace : TypeAttr {
   let Spellings = [Clang<"address_space">];
   let Args = [IntArgument<"AddressSpace">];
diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index c8b371280e35d..32eec4d2f8b79 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -4067,6 +4067,11 @@ manipulating bits of the enumerator when issuing 
warnings.
   }];
 }
 
+def StructorNameDocs : Documentation {
+let Category = DocCatDecl;
+let Content = [{ TODO }];
+}
+
 def AsmLabelDocs : Documentation {
   let Category = DocCatDecl;
   let Content = [{
diff --git a/clang/lib/AST/Mangle.cpp b/clang/lib/AST/Mangle.cpp
index b44ab23f1d0e1..124b06a430e69 100644
--- a/clang/lib/AST/Mangle.cpp
+++ b/clang/lib/AST/Mangle.cpp
@@ -125,7 +125,7 @@ bool MangleContext::shouldMangleDeclName(const NamedDecl 
*D) {
 
   // Any decl can be declared with __asm("foo") on it, and this takes 
precedence
   // over all other naming in the .o file.
-  if (D->hasAttr())
+  if (D->hasAttr() || D->hasAttr())
 return true;
 
   // Declarations that don't have identifier names always need to be mangled.
@@ -139,6 +139,20 @@ void MangleContext::mangleName(GlobalDecl GD, raw_ostream 
&Out) {
   const ASTContext &ASTContext = getASTContext();
   const NamedDecl *D = cast(GD.getDecl());
 
+  if (const auto *SNA = D->getAttr()) {
+Out << SNA->getName() << ':';
+
+if (isa(D)) {
+  Out << 'C';
+  Out << GD.getCtorType();
+} else {
+  Out << 'D';
+  Out << GD.getDtorType();
+}
+
+return;
+  }
+
   // Any decl can be declared with __asm("foo") on it, and this takes 
precedence
   // over all other naming in the .o file.
   if (const AsmLabelAttr *ALA = D->getAttr()) {
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index 0b844b44930b9..9906131c684bc 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -1730,6 +1730,14 @@ static void handleIFuncAttr(Sema &S, Decl *D, const 
ParsedAttr &AL) {
   D->addAttr(::new (S.Context) IFuncAttr(S.Context, AL, Str));
 }
 
+static void handleStructorNameAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
+  StringRef Str;
+  if (!S.checkStringLiteralArgumentAttr(AL, 0, Str))
+return;
+
+  D->addAttr(::new (S.Context) StructorNameAttr(S.Context, AL, Str));
+}
+
 static void handleAliasAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
   StringRef Str;
   if (!S.checkStringLiteralArgumentAttr(AL, 0, Str))
@@ -7532,6 +7540,9 @@ ProcessDeclAttribute(Sema &S, Scope *scope, Decl *D, 
const ParsedAttr &AL,
 S.HLSL().handleParamModifierAttr(D, AL);
 break;
 
+  case ParsedAttr::AT_StructorName:
+handleStructorNameAttr(S, D, AL);
+break;
   case ParsedAttr::AT_AbiTag:
 handleAbiTagAttr(S, D, AL);
 break;
diff --git a/libcxxabi/src/demangle/ItaniumDemangle.h 
b/libcxxabi/src/demangle/ItaniumDemangle.h
index 3df41b5f4d7d0..9ae7c1160d2e9 100644
--- a/libcxxabi/src/demangle/ItaniumDemangle.h
+++ b/libcxxabi/src/demangle/ItaniumDemangle.h
@@ -1750,6 +1750,8 @@ class CtorDtorName final : public Node {
 
   template void match(Fn F) const { F(Basename, IsDtor, Variant); 
}
 
+  int getVariant() const { return Variant; }
+
   void printLeft(OutputBuffer &OB) const override {
 if (IsDtor)
   OB += "~";
diff --git a/lldb/source/Expression/IRExecutionUnit.cpp 
b/lldb/source/Expression/IRExecutionUnit.cpp
index 06b0cb7769f64..1056195b108fb 100644
--- a/lldb/source/Expression/IRExecutionUnit.cpp
+++ 

[clang] [libcxxabi] [lldb] [llvm] [WIP][lldb] Alternative implementation of more reliable function call infrastructure (PR #115245)

2025-04-04 Thread via cfe-commits

github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff HEAD~1 HEAD --extensions h,cpp -- 
clang/lib/AST/Mangle.cpp clang/lib/Sema/SemaDeclAttr.cpp 
libcxxabi/src/demangle/ItaniumDemangle.h 
lldb/source/Expression/IRExecutionUnit.cpp 
lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp 
lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp 
llvm/include/llvm/Demangle/Demangle.h 
llvm/include/llvm/Demangle/ItaniumDemangle.h 
llvm/lib/Demangle/ItaniumDemangle.cpp
``





View the diff from clang-format here.


``diff
diff --git a/lldb/source/Expression/IRExecutionUnit.cpp 
b/lldb/source/Expression/IRExecutionUnit.cpp
index 1056195b1..f864b0f38 100644
--- a/lldb/source/Expression/IRExecutionUnit.cpp
+++ b/lldb/source/Expression/IRExecutionUnit.cpp
@@ -892,43 +892,44 @@ static std::string FindStructorLinkageName(DWARFDIE die,
   return {};
 }
 
-static lldb::addr_t FindSpecialLinkageName(
-LoadAddressResolver &resolver,ConstString name, llvm::StringRef 
symbol) {
+static lldb::addr_t FindSpecialLinkageName(LoadAddressResolver &resolver,
+   ConstString name,
+   llvm::StringRef symbol) {
   uintptr_t module_ptr;
   if (symbol.consumeInteger(0, module_ptr))
 return LLDB_INVALID_ADDRESS;
-  
+
   if (module_ptr == 0) {
 // TODO: log this case. We should ever be putting a null module pointer
 // here
 return LLDB_INVALID_ADDRESS;
   }
-  
+
   auto *mod = (lldb_private::Module *)module_ptr;
   assert(mod);
   auto *sym = mod->GetSymbolFile();
   assert(sym);
-  
+
   if (!symbol.consume_front(":"))
 return LLDB_INVALID_ADDRESS;
-  
+
   lldb::user_id_t die_id;
   if (symbol.consumeInteger(10, die_id))
 return LLDB_INVALID_ADDRESS;
-  
+
   auto *dwarf = llvm::dyn_cast(sym);
   if (!dwarf)
 return LLDB_INVALID_ADDRESS;
-  
+
   auto die = dwarf->GetDIE(die_id);
   if (!die.IsValid())
 return LLDB_INVALID_ADDRESS;
-  
+
   // TODO: account for MS-ABI (where there are no ctor variants in the
   // mangling)
   if (!symbol.consume_front(":"))
 return LLDB_INVALID_ADDRESS;
-  
+
   auto structor_variant_or_err = MakeStructorVariant(symbol);
   if (!structor_variant_or_err) {
 LLDB_LOG_ERROR(GetLog(LLDBLog::Expressions),
@@ -937,13 +938,12 @@ static lldb::addr_t FindSpecialLinkageName(
name.GetStringRef());
 return LLDB_INVALID_ADDRESS;
   }
-  
-  ConstString mangled(
-  FindStructorLinkageName(die, *structor_variant_or_err));
-  
-  Module::LookupInfo lookup_info(
-  mangled, lldb::FunctionNameType::eFunctionNameTypeAny,
-  lldb::LanguageType::eLanguageTypeC_plus_plus);
+
+  ConstString mangled(FindStructorLinkageName(die, *structor_variant_or_err));
+
+  Module::LookupInfo lookup_info(mangled,
+ lldb::FunctionNameType::eFunctionNameTypeAny,
+ lldb::LanguageType::eLanguageTypeC_plus_plus);
   SymbolContextList sc_list;
   dwarf->FindFunctions(lookup_info, {}, false, sc_list);
   if (auto load_addr = resolver.Resolve(sc_list))

``




https://github.com/llvm/llvm-project/pull/115245
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [libcxxabi] [lldb] [llvm] [WIP][lldb] Alternative implementation of more reliable function call infrastructure (PR #115245)

2024-11-06 Thread Michael Buch via cfe-commits

https://github.com/Michael137 edited 
https://github.com/llvm/llvm-project/pull/115245
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [libcxxabi] [lldb] [llvm] [WIP][lldb] Alternative implementation of more reliable function call infrastructure (PR #115245)

2024-11-06 Thread Michael Buch via cfe-commits

https://github.com/Michael137 edited 
https://github.com/llvm/llvm-project/pull/115245
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits