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

Aiden Grossman via cfe-commits cfe-commits at lists.llvm.org
Sun Mar 9 15:45:25 PDT 2025


https://github.com/boomanaiden154 created https://github.com/llvm/llvm-project/pull/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).

>From 182393b7b1aeb8fff68cc9efb9fadd2d16840487 Mon Sep 17 00:00:00 2001
From: Aiden Grossman <aidengrossman at google.com>
Date: Sun, 9 Mar 2025 22:38:34 +0000
Subject: [PATCH] [Clang][CodeGen] Fix demangler invariant comment assertion

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.
---
 clang/lib/CodeGen/CodeGenModule.cpp | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp
index bca0a932b3495..d851a97a4ec78 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