[clang] [compiler-rt] [Clang][CodeGen] Report when an alias points to an incompatible target (PR #192397)
Eli Friedman via cfe-commits
cfe-commits at lists.llvm.org
Sun Apr 19 11:37:26 PDT 2026
================
@@ -804,6 +804,49 @@ void CodeGenModule::checkAliases() {
continue;
}
+ if (!IsIFunc) {
+ GlobalDecl AliaseeGD;
+ lookupRepresentativeDecl(GV->getName(), AliaseeGD);
+ assert(AliaseeGD);
+ // Function declarations can only alias functions (including IFUNCs).
+ // Similarly, variable declarations can only alias variables.
+ if (isa<FunctionDecl>(D) != isa<llvm::Function, llvm::GlobalIFunc>(GV)) {
+ Diags.Report(Location, diag::err_alias_between_function_and_variable)
+ << isa<FunctionDecl>(D);
+ Diags.Report(AliaseeGD.getDecl()->getLocation(),
+ diag::note_aliasee_declaration);
+ Error = true;
+ continue;
+ }
+
+ auto shouldReportTypeMismatch = [&]() {
+ QualType AliasQTy = D->getType().getCanonicalType();
+ QualType AliaseeQTy =
+ cast<ValueDecl>(AliaseeGD.getDecl())->getType().getCanonicalType();
+
+ // Same types, nothing to report.
+ if (AliasQTy == AliaseeQTy)
+ return false;
----------------
efriedma-quic wrote:
Do we want to check for compatible types, instead of straight equality? It doesn't make a big difference it most cases, but the compatible type infrastructure does handle FunctionNoProtoType for you.
https://github.com/llvm/llvm-project/pull/192397
More information about the cfe-commits
mailing list