[clang] [Clang] Add -fhash-mangled-names to shorten Itanium C++ symbol names (PR #241482)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Nov 11 12:14:18 PST 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang-driver
Author: Vy Nguyen (oontvoo)
<details>
<summary>Changes</summary>
Nested templates and long param lists can produce extremely long mangled names (eg., we've seen 760K character-long symbols in our codebase). These resulted in very large .strtab (and .dynstr)(eg., some reaching 35% of our total binaries size).
This patch provides an option to use custom mangling scheme via -fhash-mangled-names (-fno-hash-mangled-names by default) on ELF targets (May consider MachO, et al, later).
Format: Replaces template arguments, function parameters/return types, method qualifiers, and ABI tags with a .h.<uint64> suffix (64-bit BLAKE3 hash of the full mangled name) after a scope-only Itanium mangling whenever the hashed form is strictly shorter.
Demangler compat: Because .h.<digits> matches the standard .<alpha>+.<digit>+ clone-suffix grammar after a complete _Z encoding, existing Itanium demanglers should continue to work without issues.
Profile & special-case list support: Emits "sample-profile-suffix-elision-policy"="selected" so SamplePGO preserves .h.<digits> across distinct specializations while still stripping .llvm./.part. suffixes, and matches canonical unhashed mangled names in -fsanitize-ignorelist, -fxray-attr-list, and -fprofile-list.
---
Patch is 58.46 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/241482.diff
14 Files Affected:
- (modified) clang/docs/ReleaseNotes.md (+8)
- (modified) clang/docs/UsersManual.md (+26)
- (modified) clang/include/clang/AST/Mangle.h (+7)
- (modified) clang/include/clang/Basic/LangOptions.def (+3)
- (modified) clang/include/clang/Basic/NoSanitizeList.h (+6-3)
- (modified) clang/include/clang/Options/Options.td (+9)
- (modified) clang/lib/AST/ItaniumMangle.cpp (+255-15)
- (modified) clang/lib/Basic/NoSanitizeList.cpp (+15-5)
- (modified) clang/lib/CodeGen/CGCall.cpp (+3)
- (modified) clang/lib/CodeGen/CodeGenModule.cpp (+41-6)
- (modified) clang/lib/CodeGen/CodeGenModule.h (+3)
- (modified) clang/lib/Driver/ToolChains/Clang.cpp (+2)
- (added) clang/test/CodeGenCXX/mangle-hash-names.cpp (+388)
- (added) clang/test/Driver/fhash-mangled-names.c (+6)
``````````diff
diff --git a/clang/docs/ReleaseNotes.md b/clang/docs/ReleaseNotes.md
index 7205fd4ab2968..a0f10f7919e3e 100644
--- a/clang/docs/ReleaseNotes.md
+++ b/clang/docs/ReleaseNotes.md
@@ -373,6 +373,14 @@ documentation](CIR/index.md) for more information regarding ClangIR's status and
### New Compiler Flags
+- Added `-fhash-mangled-names` (and `-fno-hash-mangled-names`, the default) on
+ ELF targets to shorten long Itanium C++ mangled symbol names by emitting a
+ scope-only Itanium mangling followed by a `.h.<uint64>` clone-style suffix
+ computed from the 64-bit BLAKE3 hash of the full mangled name whenever that
+ is strictly shorter. Because `.h.<digits>` conforms to the standard
+ supported grammar after a complete `_Z` encoding, existing demanglers
+ should be able to demangle those new hashed symbols without any issue.
+
- New option `-fmodules-validate-directory-dependencies` makes an implicitly
built module out of date when a header is added to a directory it enumerated,
such as an umbrella directory or the directory of an umbrella header, after it
diff --git a/clang/docs/UsersManual.md b/clang/docs/UsersManual.md
index 96d1c4e009c71..9e0ee8be7f9b9 100644
--- a/clang/docs/UsersManual.md
+++ b/clang/docs/UsersManual.md
@@ -2835,6 +2835,32 @@ $ cd $P && clang foo/name_conflict.o && bar/name_conflict.o
```
:::
+(fhash_mangled_names)=
+(fhash-mangled-names)=
+
+:::{option} -f[no-]hash-mangled-names
+
+Shorten long Itanium C++ mangled symbol names on ELF targets by replacing
+template arguments, function parameter/return types, method qualifiers, and ABI
+tags with a `.h.<uint64>` suffix derived from the 64-bit BLAKE3 hash of the full
+mangled name whenever the hashed form is strictly shorter than the original
+mangled name. Because `.h.<digits>` conforms to the standard grammar
+after a valid scope-only `_Z` encoding, existing C++ demanglers and symbolizers
+should be able to demangle these without any issue.
+
+Declarations in top-level standard/runtime namespaces (`std`, `__gnu_cxx`,
+`__gnu_debug`, `__cxxabiv1`), global allocation/deallocation operators,
+typeinfo name strings (`_ZTS`), CUDA/HIP/OpenCL device symbols and kernel entry
+points, and non-ELF targets keep standard unhashed Itanium manglings.
+Sanitizer ignorelists (`-fsanitize-ignorelist`), XRay attribute lists
+(`-fxray-attr-list`), and profile lists (`-fprofile-list`) match both the
+hashed symbol name and the canonical unhashed mangled name.
+
+Note that `-fhash-mangled-names` changes emitted C++ symbol names; translation
+units that share hashed C++ symbols across object or library boundaries must be
+compiled consistently with the same setting. Off by default.
+:::
+
:::{option} -f[no-]keep-inline-functions
Force inline functions to be emitted into the object file, even when they
diff --git a/clang/include/clang/AST/Mangle.h b/clang/include/clang/AST/Mangle.h
index 0e0bfef9053f9..48488d8d81573 100644
--- a/clang/include/clang/AST/Mangle.h
+++ b/clang/include/clang/AST/Mangle.h
@@ -66,6 +66,7 @@ class MangleContext {
/// For aux target. If true, uses mangling number for aux target from
/// ASTContext.
bool IsAux = false;
+ bool SuppressHashMangledNames = false;
llvm::DenseMap<const BlockDecl *, unsigned> GlobalBlockIds;
llvm::DenseMap<const BlockDecl *, unsigned> LocalBlockIds;
@@ -77,6 +78,12 @@ class MangleContext {
bool isAux() const { return IsAux; }
+ bool isHashMangledNamesSuppressed() const { return SuppressHashMangledNames; }
+
+ void setSuppressHashMangledNames(bool Suppress) {
+ SuppressHashMangledNames = Suppress;
+ }
+
explicit MangleContext(ASTContext &Context, DiagnosticsEngine &Diags,
ManglerKind Kind, bool IsAux = false)
: Context(Context), Diags(Diags), Kind(Kind), IsAux(IsAux) {}
diff --git a/clang/include/clang/Basic/LangOptions.def b/clang/include/clang/Basic/LangOptions.def
index b4a57a9c0944b..b3e16bfdfea04 100644
--- a/clang/include/clang/Basic/LangOptions.def
+++ b/clang/include/clang/Basic/LangOptions.def
@@ -540,6 +540,9 @@ LANGOPT(Reflection , 1, 0, NotCompatible, "C++26 Reflection")
LANGOPT(StablePointerSubtraction, 1, 0, NotCompatible, "Make unaligned pointer subtraction stable")
+LANGOPT(HashMangledNames, 1, 0, Benign,
+ "hash template and function parameters in C++ mangled names")
+
#undef LANGOPT
#undef ENUM_LANGOPT
#undef VALUE_LANGOPT
diff --git a/clang/include/clang/Basic/NoSanitizeList.h b/clang/include/clang/Basic/NoSanitizeList.h
index a7a7a29d50a9a..9e6a20bf0e72d 100644
--- a/clang/include/clang/Basic/NoSanitizeList.h
+++ b/clang/include/clang/Basic/NoSanitizeList.h
@@ -30,17 +30,20 @@ class NoSanitizeList {
std::unique_ptr<SanitizerSpecialCaseList> SSCL;
SourceManager &SM;
bool containsPrefix(SanitizerMask Mask, StringRef Prefix, StringRef Name,
- StringRef Category) const;
+ StringRef Category,
+ StringRef AltName = StringRef()) const;
public:
NoSanitizeList(const std::vector<std::string> &NoSanitizeListPaths,
SourceManager &SM);
~NoSanitizeList();
bool containsGlobal(SanitizerMask Mask, StringRef GlobalName,
- StringRef Category = StringRef()) const;
+ StringRef Category = StringRef(),
+ StringRef AltGlobalName = StringRef()) const;
bool containsType(SanitizerMask Mask, StringRef MangledTypeName,
StringRef Category = StringRef()) const;
- bool containsFunction(SanitizerMask Mask, StringRef FunctionName) const;
+ bool containsFunction(SanitizerMask Mask, StringRef FunctionName,
+ StringRef AltFunctionName = StringRef()) const;
bool containsFile(SanitizerMask Mask, StringRef FileName,
StringRef Category = StringRef()) const;
bool containsMainFile(SanitizerMask Mask, StringRef FileName,
diff --git a/clang/include/clang/Options/Options.td b/clang/include/clang/Options/Options.td
index db1648c2d55d8..f650556f5db17 100644
--- a/clang/include/clang/Options/Options.td
+++ b/clang/include/clang/Options/Options.td
@@ -5149,6 +5149,15 @@ defm unique_internal_linkage_names : BoolFOption<"unique-internal-linkage-names"
"Uniqueify Internal Linkage Symbol Names by appending"
" the MD5 hash of the module path">,
NegFlag<SetFalse, [], [ClangOption, CC1Option, FlangOption]>>;
+defm hash_mangled_names : BoolFOption<"hash-mangled-names",
+ LangOpts<"HashMangledNames">, DefaultFalse,
+ PosFlag<SetTrue, [], [ClangOption, CC1Option],
+ "Shorten C++ mangled names by hashing template and function parameters (ELF Only)">,
+ NegFlag<SetFalse>>,
+ DocBrief<[{When enabled on ELF targets, shorten long Itanium C++ mangled names by
+emitting a scope-only mangling followed by a ``.h.<uint64>`` suffix computed from the
+64-bit BLAKE3 hash of the full mangled name whenever that representation is strictly
+shorter. Off by default.}]>;
defm unique_section_names : BoolFOption<"unique-section-names",
CodeGenOpts<"UniqueSectionNames">, DefaultTrue,
NegFlag<SetFalse, [], [ClangOption, CC1Option],
diff --git a/clang/lib/AST/ItaniumMangle.cpp b/clang/lib/AST/ItaniumMangle.cpp
index 6ebbdbd536924..cffc02b3b7e04 100644
--- a/clang/lib/AST/ItaniumMangle.cpp
+++ b/clang/lib/AST/ItaniumMangle.cpp
@@ -33,7 +33,10 @@
#include "clang/Basic/TargetInfo.h"
#include "clang/Basic/Thunk.h"
#include "llvm/ADT/StringExtras.h"
+#include "llvm/Support/BLAKE3.h"
+#include "llvm/Support/Endian.h"
#include "llvm/Support/ErrorHandling.h"
+#include "llvm/Support/SaveAndRestore.h"
#include "llvm/Support/raw_ostream.h"
#include <optional>
@@ -210,6 +213,9 @@ class ItaniumMangleContextImpl : public ItaniumMangleContext {
bool isInternalLinkageDecl(const NamedDecl *ND);
+ bool InHashMangle = false;
+ bool ScopeOnly = false;
+
/// @}
};
@@ -228,6 +234,8 @@ class CXXNameMangler {
/// Also it is required to avoid infinite recursion in some cases.
bool DisableDerivedAbiTags = false;
+ bool isScopeOnly() const { return Context.ScopeOnly; }
+
/// The "structor" is the top-level declaration being mangled, if
/// that's not a template specialization; otherwise it's the pattern
/// for that specialization.
@@ -810,6 +818,8 @@ bool ItaniumMangleContextImpl::shouldMangleCXXName(const NamedDecl *D) {
void CXXNameMangler::writeAbiTags(const NamedDecl *ND,
ArrayRef<StringRef> AdditionalAbiTags) {
+ if (isScopeOnly())
+ return;
assert(AbiTags && "require AbiTagState");
AbiTags->write(Out, ND,
DisableDerivedAbiTags ? ArrayRef<StringRef>{}
@@ -849,6 +859,12 @@ void CXXNameMangler::mangleFunctionEncoding(GlobalDecl GD) {
return;
}
+ if (isScopeOnly()) {
+ mangleName(GD);
+ Out << 'v';
+ return;
+ }
+
AbiTagList ReturnTypeAbiTags = makeFunctionReturnTypeTags(FD);
if (ReturnTypeAbiTags.empty()) {
// There are no tags for return type, the simplest case. Enter the function
@@ -1019,6 +1035,10 @@ static TemplateName asTemplateName(GlobalDecl GD) {
}
void CXXNameMangler::mangleName(GlobalDecl GD) {
+ if (isScopeOnly()) {
+ mangleNameWithAbiTags(GD);
+ return;
+ }
const NamedDecl *ND = cast<NamedDecl>(GD.getDecl());
if (const VarDecl *VD = dyn_cast<VarDecl>(ND)) {
// Variables should have implicit tags from its type.
@@ -1197,7 +1217,7 @@ void CXXNameMangler::mangleUnscopedTemplateName(
const TemplateDecl *ND = cast<TemplateDecl>(GD.getDecl());
// <unscoped-template-name> ::= <unscoped-name>
// ::= <substitution>
- if (mangleSubstitution(ND))
+ if (!isScopeOnly() && mangleSubstitution(ND))
return;
// <template-template-param> ::= <template-param>
@@ -1212,7 +1232,8 @@ void CXXNameMangler::mangleUnscopedTemplateName(
AdditionalAbiTags);
}
- addSubstitution(ND);
+ if (!isScopeOnly())
+ addSubstitution(ND);
}
void CXXNameMangler::mangleFloat(const llvm::APFloat &f) {
@@ -1591,8 +1612,11 @@ void CXXNameMangler::mangleUnqualifiedName(
if (auto *TPO = dyn_cast<TemplateParamObjectDecl>(ND)) {
// Proposed in https://github.com/itanium-cxx-abi/cxx-abi/issues/63.
Out << "TA";
- mangleValueInTemplateArg(TPO->getType().getUnqualifiedType(),
- TPO->getValue(), /*TopLevel=*/true);
+ if (isScopeOnly())
+ mangleType(TPO->getType().getUnqualifiedType());
+ else
+ mangleValueInTemplateArg(TPO->getType().getUnqualifiedType(),
+ TPO->getValue(), /*TopLevel=*/true);
break;
}
@@ -1873,7 +1897,8 @@ void CXXNameMangler::mangleNestedName(GlobalDecl GD, const DeclContext *DC,
// <template-args> E
Out << 'N';
- if (const CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(ND)) {
+ if (const CXXMethodDecl *Method =
+ !isScopeOnly() ? dyn_cast<CXXMethodDecl>(ND) : nullptr) {
Qualifiers MethodQuals = Method->getMethodQualifiers();
// We do not consider restrict a distinguishing attribute for overloading
// purposes so we must not mangle it.
@@ -1886,7 +1911,9 @@ void CXXNameMangler::mangleNestedName(GlobalDecl GD, const DeclContext *DC,
// Check if we have a template.
const TemplateArgumentList *TemplateArgs = nullptr;
- if (GlobalDecl TD = isTemplate(GD, TemplateArgs)) {
+ if (GlobalDecl TD = (isScopeOnly() && isa<CXXConversionDecl>(ND))
+ ? GlobalDecl()
+ : isTemplate(GD, TemplateArgs)) {
mangleTemplatePrefix(TD, NoFunction);
mangleTemplateArgs(asTemplateName(TD), *TemplateArgs);
} else {
@@ -2245,6 +2272,10 @@ void CXXNameMangler::mangleLambda(const CXXRecordDecl *Lambda) {
}
void CXXNameMangler::mangleLambdaSig(const CXXRecordDecl *Lambda) {
+ if (isScopeOnly()) {
+ Out << 'v';
+ return;
+ }
// Proposed on https://github.com/itanium-cxx-abi/cxx-abi/issues/31.
for (auto *D : Lambda->getLambdaExplicitTemplateParameters())
mangleTemplateParamDecl(D);
@@ -2362,12 +2393,12 @@ void CXXNameMangler::mangleTemplatePrefix(TemplateName Template) {
// Clang 11 and before mangled the substitution for a dependent template name
// after already having emitted (a substitution for) the prefix.
bool Clang11Compat = isCompatibleWith(LangOptions::ClangABI::Ver11);
- if (!Clang11Compat && mangleSubstitution(Template))
+ if (!isScopeOnly() && !Clang11Compat && mangleSubstitution(Template))
return;
manglePrefix(Dependent->getQualifier());
- if (Clang11Compat && mangleSubstitution(Template))
+ if (!isScopeOnly() && Clang11Compat && mangleSubstitution(Template))
return;
if (IdentifierOrOverloadedOperator Name = Dependent->getName();
@@ -2376,7 +2407,8 @@ void CXXNameMangler::mangleTemplatePrefix(TemplateName Template) {
else
mangleOperatorName(Name.getOperator(), UnknownArity);
- addSubstitution(Template);
+ if (!isScopeOnly())
+ addSubstitution(Template);
}
void CXXNameMangler::mangleTemplatePrefix(GlobalDecl GD,
@@ -2388,7 +2420,7 @@ void CXXNameMangler::mangleTemplatePrefix(GlobalDecl GD,
// <template-template-param> ::= <template-param>
// <substitution>
- if (mangleSubstitution(ND))
+ if (!isScopeOnly() && mangleSubstitution(ND))
return;
// <template-template-param> ::= <template-param>
@@ -2403,7 +2435,8 @@ void CXXNameMangler::mangleTemplatePrefix(GlobalDecl GD,
mangleUnqualifiedName(GD.getWithDecl(ND->getTemplatedDecl()), DC);
}
- addSubstitution(ND);
+ if (!isScopeOnly())
+ addSubstitution(ND);
}
const NamedDecl *CXXNameMangler::getClosurePrefix(const Decl *ND) {
@@ -2735,7 +2768,10 @@ void CXXNameMangler::mangleOperatorName(DeclarationName Name, unsigned Arity) {
case DeclarationName::CXXConversionFunctionName:
// <operator-name> ::= cv <type> # (cast)
Out << "cv";
- mangleType(Name.getCXXNameType());
+ if (isScopeOnly() && Name.getCXXNameType()->isDependentType())
+ Out << 'v';
+ else
+ mangleType(Name.getCXXNameType());
break;
case DeclarationName::CXXLiteralOperatorName:
@@ -4546,7 +4582,7 @@ void CXXNameMangler::mangleType(const ObjCObjectType *T) {
mangleType(T->getBaseType());
- if (T->isSpecialized()) {
+ if (!isScopeOnly() && T->isSpecialized()) {
// Mangle type arguments as I <type>+ E
Out << 'I';
for (auto typeArg : T->getTypeArgs())
@@ -6417,6 +6453,8 @@ struct CXXNameMangler::TemplateArgManglingInfo {
void CXXNameMangler::mangleTemplateArgs(TemplateName TN,
const TemplateArgumentLoc *TemplateArgs,
unsigned NumTemplateArgs) {
+ if (isScopeOnly())
+ return;
// <template-args> ::= I <template-arg>+ [Q <requires-clause expr>] E
Out << 'I';
TemplateArgManglingInfo Info(*this, TN);
@@ -6429,6 +6467,8 @@ void CXXNameMangler::mangleTemplateArgs(TemplateName TN,
void CXXNameMangler::mangleTemplateArgs(TemplateName TN,
const TemplateArgumentList &AL) {
+ if (isScopeOnly())
+ return;
// <template-args> ::= I <template-arg>+ [Q <requires-clause expr>] E
Out << 'I';
TemplateArgManglingInfo Info(*this, TN);
@@ -6441,6 +6481,8 @@ void CXXNameMangler::mangleTemplateArgs(TemplateName TN,
void CXXNameMangler::mangleTemplateArgs(TemplateName TN,
ArrayRef<TemplateArgument> Args) {
+ if (isScopeOnly())
+ return;
// <template-args> ::= I <template-arg>+ [Q <requires-clause expr>] E
Out << 'I';
TemplateArgManglingInfo Info(*this, TN);
@@ -7295,6 +7337,9 @@ bool CXXNameMangler::mangleStandardSubstitution(const NamedDecl *ND) {
return false;
}
+ if (isScopeOnly())
+ return false;
+
if (const ClassTemplateDecl *TD = dyn_cast<ClassTemplateDecl>(ND)) {
if (!isStdNamespace(Context.getEffectiveDeclContext(TD)))
return false;
@@ -7435,6 +7480,156 @@ bool CXXNameMangler::shouldHaveAbiTags(ItaniumMangleContextImpl &C,
return TrackAbiTags.AbiTagsRoot.getUsedAbiTags().size();
}
+/// Declarations inside top-level C++ standard/runtime namespaces (`std`,
+/// `__gnu_cxx`, `__gnu_debug`, `__cxxabiv1`, including inline namespaces such
+/// as `std::__1` and `std::__cxx11`) are kept unhashed to preserve ABI
+/// compatibility with prebuilt C++ standard and runtime libraries. Functions
+/// and types outside `std` that take `std::*` parameters are hashed normally.
+static bool isInStdOrRuntimeNamespace(ItaniumMangleContextImpl &Ctx,
+ const NamedDecl *D) {
+ if (!D)
+ return false;
+ for (const DeclContext *DC = Ctx.getEffectiveDeclContext(D);
+ DC && !DC->isTranslationUnit(); DC = Ctx.getEffectiveParentContext(DC)) {
+ if (const auto *NS = dyn_cast<NamespaceDecl>(DC)) {
+ if (Ctx.getEffectiveParentContext(NS)->isTranslationUnit()) {
+ if (const IdentifierInfo *II = NS->getFirstDecl()->getIdentifier()) {
+ if (II->isStr("std") || II->isStr("__gnu_cxx") ||
+ II->isStr("__gnu_debug") || II->isStr("__cxxabiv1"))
+ return true;
+ }
+ }
+ }
+ }
+ return false;
+}
+
+static const NamedDecl *getRTTIDecl(QualType Ty) {
+ while (!Ty.isNull()) {
+ if (const auto *Tag = Ty->getAsTagDecl())
+ return Tag;
+ QualType Pointee = Ty->getPointeeType();
+ if (!Pointee.isNull()) {
+ Ty = Pointee;
+ continue;
+ }
+ if (const auto *AT = Ty->getAsArrayTypeUnsafe()) {
+ Ty = AT->getElementType();
+ continue;
+ }
+ break;
+ }
+ return nullptr;
+}
+
+/// CUDA/HIP `__global__` and OpenCL/device `__attribute__((device_kernel))`
+/// entry points (and device variables / nested local entities) must keep
+/// standard Itanium manglings so host launch stubs match device toolchains
+/// such as `nvcc` that do not pass `-fhash-mangled-names`.
+static bool isDeviceKernelOrVarDecl(const NamedDecl *D) {
+ if (!D)
+ return false;
+ if (D->hasAttr<CUDAGlobalAttr>() || D->hasAttr<DeviceKernelAttr>())
+ return true;
+ if (isa<VarDecl>(D) &&
+ (D->hasAttr<CUDADeviceAttr>() || D->hasAttr<CUDAConstantAttr>()))
+ return true;
+ for (const DeclContext *DC = D->getDeclContext();
+ DC && !DC->isTranslationUnit(); DC = DC->getParent()) {
+ if (const auto *FD = dyn_cast<FunctionDecl>(DC)) {
+ if (FD->hasAttr<CUDAGlobalAttr>() || FD->hasAttr<DeviceKernelAttr>())
+ return true;
+ }
+ }
+ return false;
+}
+
+/// Global ::operator new / ::operator new[] / ::operator delete /
+/// ::operator delete[] overloads (including C++17 aligned/nothrow and custom
+/// global placement/tagged forms) are ABI/runtime entry points matched by
+/// literal symbol name in LLVM TargetLibraryInfo, MemProf/AllocToken passes,
+/// sanitizer interceptors, and C++ allocator libraries. Keep their standard
+/// Itanium manglings unhashed.
+static bool isGlobalAllocationFunction(ItaniumMangleContextImpl &Ctx,
+ const NamedDecl *D) {
+ const auto *FD = dyn_cast<FunctionDecl>(D);
+ if (!FD)
+ return false;
+ switch (FD->getOverloadedOperator()) {
+ case OO_New:
+ case OO_Array_New:
+ case OO_Delete:
+ case OO_Array_Delete:
+ return Ctx.getEffectiveDeclContext(FD)->isTranslationUnit();
+ default:
+ return false;
+ }
+}
+
+static bool shouldTryHashMangle(ItaniumMangleContextImpl &Ctx,
+ const NamedDecl *D, bool AllowHash = true) {
+ // Non-ELF object formats (e.g. NVPTX PTX where '.' is a syntax error in
+ // ptxas, Mach-O, COFF, WASM, SPIR-V) and CUDA/HIP device or auxiliary device
+ // manglings must keep standard dot-free Itanium manglings.
+ return AllowHash && !Ctx.InHashMangle &&
+ !Ctx.isHashMangledNamesSuppressed() &&
+ Ctx.getASTContext().getLangOpts().HashMangledNames && !Ctx.isAux() &&
+ !Ctx.getASTContext().getLangOpts().CUDAIsDevice &&
+ Ctx.getASTContext().getTargetInfo().getTriple().isOSBinFormatELF() &&
+ !isDeviceKernelOrVarDecl(D) && !isInStdOrRuntimeNamespace(Ctx, D);
+}
+
+template <typename Fn>
+static void mangleWithOptionalHash(ItaniumMangleContextImpl &Ctx,
+ raw_ostream &Out, Fn &&MangleFn) {
+ llvm::SaveAndRes...
[truncated]
``````````
</details>
https://github.com/llvm/llvm-project/pull/241482
More information about the cfe-commits
mailing list