[clang] [CIR] Implement weak ref and alias attribute handling (PR #195972)
Andy Kaylor via cfe-commits
cfe-commits at lists.llvm.org
Wed May 6 09:42:57 PDT 2026
================
@@ -3374,10 +3379,93 @@ void CIRGenModule::release() {
emitLLVMUsed();
+ // Classic codegen calls `checkAliases` here to validate any alias
+ // definitions emitted during codegen.
+ assert(!cir::MissingFeatures::checkAliases());
+
// There's a lot of code that is not implemented yet.
assert(!cir::MissingFeatures::cgmRelease());
}
+void CIRGenModule::emitAliasDefinition(GlobalDecl gd) {
+ const auto *d = cast<ValueDecl>(gd.getDecl());
+ const AliasAttr *aa = d->getAttr<AliasAttr>();
+ assert(aa && "Not an alias?");
+
+ StringRef mangledName = getMangledName(gd);
+
+ if (aa->getAliasee() == mangledName) {
+ diags.Report(aa->getLocation(), diag::err_cyclic_alias) << 0;
+ return;
+ }
+
+ // If there is a definition in the module, then it wins over the alias.
+ // This is dubious, but allow it to be safe. Just ignore the alias.
+ mlir::Operation *entry = getGlobalValue(mangledName);
+ if (entry) {
+ auto entryGV = mlir::dyn_cast<cir::CIRGlobalValueInterface>(entry);
+ if (entryGV && !entryGV.isDeclaration())
----------------
andykaylor wrote:
Unfortuantely, `isDeclaration` comes from MLIR's `SymbolOpInterface` so it would be a big lift to change that. We don't have an `isDefinition` method, but I suppose it's easy enough to add one.
https://github.com/llvm/llvm-project/pull/195972
More information about the cfe-commits
mailing list