[clang] de132b2 - [Clang][CodeGen] Fix demangler invariant comment assertion (#130522)

via cfe-commits cfe-commits at lists.llvm.org
Sun Mar 9 19:56:44 PDT 2025


Author: Aiden Grossman
Date: 2025-03-09T19:56:40-07:00
New Revision: de132b2a0c344729703358a1c3ac90fb28fdb130

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

LOG: [Clang][CodeGen] Fix demangler invariant comment assertion (#130522)

This patch makes the assertion (that is currently in a comment) that
validates that names mangled by clang can be demangled by LLVM actually
compile/work. There were some minor issues that needed to be fixed (like
starts_with not being available on std::string and needing to call
getDecl() on GD), and a logic issue that should be fixed in this patch.
This enables just uncommenting the assertion to enable it within the
compiler (minus needing to add the header file).

Added: 
    

Modified: 
    clang/lib/CodeGen/CodeGenModule.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp
index d2c97ce501b03..1f6321a5908e6 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -2068,9 +2068,10 @@ StringRef CodeGenModule::getMangledName(GlobalDecl GD) {
   // Prior work:
   // https://discourse.llvm.org/t/rfc-clang-diagnostic-for-demangling-failures/82835/8
   // https://github.com/llvm/llvm-project/issues/111345
-  // assert((MangledName.startswith("_Z") || MangledName.startswith("?")) &&
-  //        !GD->hasAttr<AsmLabelAttr>() &&
-  //        llvm::demangle(MangledName) != MangledName &&
+  // assert(!((StringRef(MangledName).starts_with("_Z") ||
+  //           StringRef(MangledName).starts_with("?")) &&
+  //          !GD.getDecl()->hasAttr<AsmLabelAttr>() &&
+  //          llvm::demangle(MangledName) == MangledName) &&
   //        "LLVM demangler must demangle clang-generated names");
 
   auto Result = Manglings.insert(std::make_pair(MangledName, GD));


        


More information about the cfe-commits mailing list