[clang] [Clang] Avoid assertion failure for initialized extern aliases (PR #223124)
Aaron Ballman via cfe-commits
cfe-commits at lists.llvm.org
Wed Sep 23 06:29:45 PDT 2026
================
@@ -14127,6 +14093,15 @@ void Sema::AddInitializerToDecl(Decl *RealDecl, Expr *Init, bool DirectInit) {
return;
}
+ // handleAliasAttr() runs before the initializer is attached to the VarDecl,
+ // so it cannot determine that an extern declaration with an initializer is a
+ // definition. Diagnose the conflict now that an initializer is present and
+ // remove the attribute before the post-initialization checks.
+ if (const auto *Attr = VDecl->getAttr<AliasAttr>()) {
+ Diag(Attr->getLocation(), diag::err_alias_is_definition) << VDecl << 0;
+ VDecl->dropAttr<AliasAttr>();
----------------
AaronBallman wrote:
I was thinking we'd set it as invalid and then early return to skip the error recovery path. My primary reason for thinking we want to mark it as invalid is so that we don't attempt to codegen it, but given that we're dropping the attribute, codegen won't be a problem. But other code paths in this function do mark the declaration as being invalid, so doing it for consistency makes sense to me (and the other paths also early return).
https://github.com/llvm/llvm-project/pull/223124
More information about the cfe-commits
mailing list