[clang] [compiler-rt] Reland "[Clang][CodeGen] Report when an alias points to an incompatible target" (PR #195550)
Eli Friedman via cfe-commits
cfe-commits at lists.llvm.org
Tue May 5 22:00:19 PDT 2026
================
@@ -804,6 +804,70 @@ void CodeGenModule::checkAliases() {
continue;
}
+ if (!IsIFunc) {
+ GlobalDecl AliaseeGD;
+ if (!lookupRepresentativeDecl(GV->getName(), AliaseeGD) ||
+ !isa<VarDecl, FunctionDecl>(AliaseeGD.getDecl())) {
+ Diags.Report(Location, diag::err_alias_to_undefined)
+ << IsIFunc << IsIFunc;
+ Error = true;
+ continue;
+ }
+
+ bool aliasIsFuncDecl = isa<FunctionDecl>(D);
+ bool aliaseeIsFunc = isa<llvm::Function, llvm::GlobalIFunc>(GV);
+ // Function declarations can only alias functions (including IFUNCs).
+ // Similarly, variable declarations can only alias variables.
+ if (aliasIsFuncDecl != aliaseeIsFunc) {
+ Diags.Report(Location, diag::err_alias_between_function_and_variable)
+ << aliasIsFuncDecl;
+ Diags.Report(AliaseeGD.getDecl()->getLocation(),
+ diag::note_aliasee_declaration);
+ Error = true;
+ continue;
+ }
+
+ // Only report functions.
+ // Type mismatches for variables can be intentional.
+ if (aliasIsFuncDecl && aliaseeIsFunc) {
+ QualType AliasTy = D->getType();
+ QualType AliaseeTy = cast<ValueDecl>(AliaseeGD.getDecl())->getType();
+ auto shouldReportTypeMismatch = [&]() {
+ const auto *AliasFTy =
+ AliasTy.getCanonicalType()->getAs<FunctionType>();
+ const auto *AliaseeFTy =
+ AliaseeTy.getCanonicalType()->getAs<FunctionType>();
+ assert(AliasFTy && AliaseeFTy);
+ if (!Context.typesAreCompatible(AliasFTy->getReturnType(),
+ AliaseeFTy->getReturnType()))
+ return true;
+ const auto *AliasFPTy = dyn_cast<FunctionProtoType>(AliasFTy);
+ // Do not report aliases with unspecified parameter lists.
+ if (!AliasFPTy)
+ return false;
----------------
efriedma-quic wrote:
Unprototyped functions are never variadic. (Variadic function can have a different calling convention from non-variadic functions, so it's undefined behavior to use an unprototyped declaration to call a variadic function. It sort of works on certain Linux/BSD targets, but it explodes on Windows and OS X.)
https://github.com/llvm/llvm-project/pull/195550
More information about the cfe-commits
mailing list