================
@@ -3374,10 +3382,92 @@ 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.isDefinition())
+ return;
+ }
+
+ // Classic codegen pushes the alias onto an `Aliases` list at this point so
+ // that `checkAliases` can later validate the alias and recover on error.
+ assert(!cir::MissingFeatures::checkAliases());
+
+ mlir::Location loc = getLoc(d->getSourceRange());
+ bool isFunction = isa<FunctionDecl>(d);
+
+ // Get the linkage and the type of the alias.
+ cir::GlobalLinkageKind linkage;
+ mlir::Type declTy;
+ if (isFunction) {
+ declTy = getTypes().getFunctionType(gd);
+ linkage = getFunctionLinkage(gd);
+ } else {
+ declTy = getTypes().convertTypeForMem(d->getType());
+ if (const auto *vd = dyn_cast<VarDecl>(d))
+ linkage = getCIRLinkageVarDefinition(vd);
+ else
+ linkage = getFunctionLinkage(gd);
----------------
erichkeane wrote:
TBH, I'm a bit confused here. We're calling 'getFunctionLinkage' on a thing
that isn't a function? Is this reproducable/have something that gets here?
I looked into it, the FIRST thing that `getFunctionLinkage` seems to do is cast
`g->getDecl` to a `FunctionDecl`. So since our `isFunction` above checked
that, this seems dead? Can we just switch that to a `cast<VarDecl>`?
https://github.com/llvm/llvm-project/pull/195972
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits