[clang] [CIR] Implement 'weak-ref' lowering (PR #238538)
Erich Keane via cfe-commits
cfe-commits at lists.llvm.org
Wed Nov 4 13:00:37 PST 2026
================
@@ -1194,8 +1196,17 @@ LValue CIRGenFunction::emitDeclRefLValue(const DeclRefExpr *e) {
!e->getLocation().isValid()) &&
"Should not use decl without marking it used!");
- if (nd->hasAttr<WeakRefAttr>())
- cgm.errorNYI(nd->getSourceRange(), "emitGlobal: WeakRefAttr");
+ // A weakref variable refers to its alias target. Weakref functions are
+ // handled by emitFunctionDeclPointer.
+ if (const auto *vd = dyn_cast<VarDecl>(nd);
+ vd && vd->hasAttr<WeakRefAttr>()) {
+ auto aliasee = mlir::cast<cir::GlobalOp>(cgm.getWeakRefReference(vd));
----------------
erichkeane wrote:
I think i handled all cases here reasonably? I added tests for the NYI to make sure we capture them/that they were caught.
https://github.com/llvm/llvm-project/pull/238538
More information about the cfe-commits
mailing list