Skip to content

Commit 56fe1eb

Browse files
committed
[clang] Replace $_ fallback with ABI mangling Ul for all lambda and Ut for all unamed
1 parent 38318dd commit 56fe1eb

File tree

3 files changed

+17
-35
lines changed

3 files changed

+17
-35
lines changed

clang/lib/AST/ItaniumMangle.cpp

Lines changed: 10 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1640,46 +1640,23 @@ void CXXNameMangler::mangleUnqualifiedName(
16401640
UnsignedOrNone DeviceNumber =
16411641
Context.getDiscriminatorOverride()(Context.getASTContext(), Record);
16421642

1643-
// If we have a device-number via the discriminator, use that to mangle
1644-
// the lambda, otherwise use the typical lambda-mangling-number. In either
1645-
// case, a '0' should be mangled as a normal unnamed class instead of as a
1646-
// lambda.
1647-
if (Record->isLambda() &&
1648-
((DeviceNumber && *DeviceNumber > 0) ||
1649-
(!DeviceNumber && Record->getLambdaManglingNumber() > 0))) {
1643+
if (Record->isLambda()) {
1644+
assert(!DeviceNumber && Record->getLambdaManglingNumber() > 0 &&
1645+
"Lambda mangling number should be already set");
16501646
assert(!AdditionalAbiTags &&
16511647
"Lambda type cannot have additional abi tags");
16521648
mangleLambda(Record);
16531649
break;
16541650
}
16551651
}
16561652

1657-
if (TD->isExternallyVisible()) {
1658-
unsigned UnnamedMangle =
1659-
getASTContext().getManglingNumber(TD, Context.isAux());
1660-
Out << "Ut";
1661-
if (UnnamedMangle > 1)
1662-
Out << UnnamedMangle - 2;
1663-
Out << '_';
1664-
writeAbiTags(TD, AdditionalAbiTags);
1665-
break;
1666-
}
1667-
1668-
// Get a unique id for the anonymous struct. If it is not a real output
1669-
// ID doesn't matter so use fake one.
1670-
unsigned AnonStructId =
1671-
NullOut ? 0
1672-
: Context.getAnonymousStructId(TD, dyn_cast<FunctionDecl>(DC));
1673-
1674-
// Mangle it as a source name in the form
1675-
// [n] $_<id>
1676-
// where n is the length of the string.
1677-
SmallString<8> Str;
1678-
Str += "$_";
1679-
Str += llvm::utostr(AnonStructId);
1680-
1681-
Out << Str.size();
1682-
Out << Str;
1653+
unsigned UnnamedMangle =
1654+
getASTContext().getManglingNumber(TD, Context.isAux());
1655+
Out << "Ut";
1656+
if (UnnamedMangle > 1)
1657+
Out << UnnamedMangle - 2;
1658+
Out << '_';
1659+
writeAbiTags(TD, AdditionalAbiTags);
16831660
break;
16841661
}
16851662

clang/lib/Sema/SemaDecl.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4914,6 +4914,11 @@ void Sema::handleTagNumbering(const TagDecl *Tag, Scope *TagScope) {
49144914
Decl *ManglingContextDecl;
49154915
std::tie(MCtx, ManglingContextDecl) =
49164916
getCurrentMangleNumberContext(Tag->getDeclContext());
4917+
4918+
// If no existing context and this tag is anonymous, use the TU context
4919+
if (!MCtx && !Tag->getIdentifier())
4920+
MCtx = &Context.getManglingNumberContext(nullptr);
4921+
49174922
if (MCtx) {
49184923
Context.setManglingNumber(
49194924
Tag, MCtx->getManglingNumber(

clang/lib/Sema/SemaLambda.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -501,8 +501,7 @@ void Sema::handleLambdaNumbering(
501501
MangleNumberingContext *MCtx;
502502
std::tie(MCtx, Numbering.ContextDecl) =
503503
getCurrentMangleNumberContext(Class->getDeclContext());
504-
if (!MCtx && (getLangOpts().CUDA || getLangOpts().SYCLIsDevice ||
505-
getLangOpts().SYCLIsHost)) {
504+
if (!MCtx) {
506505
// Force lambda numbering in CUDA/HIP as we need to name lambdas following
507506
// ODR. Both device- and host-compilation need to have a consistent naming
508507
// on kernel functions. As lambdas are potential part of these `__global__`
@@ -514,6 +513,7 @@ void Sema::handleLambdaNumbering(
514513
assert(MCtx && "Retrieving mangle numbering context failed!");
515514
Numbering.HasKnownInternalLinkage = true;
516515
}
516+
517517
if (MCtx) {
518518
Numbering.IndexInContext = MCtx->getNextLambdaIndex();
519519
Numbering.ManglingNumber = MCtx->getManglingNumber(Method);

0 commit comments

Comments
 (0)