[clang] [CIR] Upstream support for name mangling (PR #137094)
Andy Kaylor via cfe-commits
cfe-commits at lists.llvm.org
Thu Apr 24 09:17:27 PDT 2025
================
@@ -639,13 +674,82 @@ cir::FuncOp CIRGenModule::getAddrOfFunction(clang::GlobalDecl gd,
funcType = convertType(fd->getType());
}
- assert(!cir::MissingFeatures::mangledNames());
- cir::FuncOp func = getOrCreateCIRFunction(
- cast<NamedDecl>(gd.getDecl())->getIdentifier()->getName(), funcType, gd,
- forVTable, dontDefer, /*isThunk=*/false, isForDefinition);
+ StringRef mangledName = getMangledName(gd);
+ cir::FuncOp func =
+ getOrCreateCIRFunction(mangledName, funcType, gd, forVTable, dontDefer,
+ /*isThunk=*/false, isForDefinition);
return func;
}
+static std::string getMangledNameImpl(CIRGenModule &cgm, GlobalDecl gd,
+ const NamedDecl *nd) {
+ SmallString<256> buffer;
+
+ llvm::raw_svector_ostream out(buffer);
+ MangleContext &mc = cgm.getCXXABI().getMangleContext();
+
+ assert(!cir::MissingFeatures::moduleNameHash());
+
+ if (mc.shouldMangleDeclName(nd)) {
+ mc.mangleName(gd.getWithDecl(nd), out);
+ } else {
+ IdentifierInfo *ii = nd->getIdentifier();
+ assert(ii && "Attempt to mangle unnamed decl.");
+
+ const auto *fd = dyn_cast<FunctionDecl>(nd);
+ if (fd &&
+ fd->getType()->castAs<FunctionType>()->getCallConv() == CC_X86RegCall) {
+ cgm.errorNYI(nd->getSourceRange(), "getMangledName: X86RegCall");
+ out << ii->getName();
+ } else if (fd && fd->hasAttr<CUDAGlobalAttr>() &&
+ gd.getKernelReferenceKind() == KernelReferenceKind::Stub) {
+ out << "__device_stub__" << ii->getName();
----------------
andykaylor wrote:
Agreed. I don't think we can hit this yet. I'll make it NYI.
https://github.com/llvm/llvm-project/pull/137094
More information about the cfe-commits
mailing list