[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
Fri Apr 17 11:40:50 PDT 2026


================
@@ -804,6 +804,48 @@ void CodeGenModule::checkAliases() {
       continue;
     }
 
+    if (!IsIFunc) {
+      // 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)) {
+        GlobalDecl AliaseeGD = getMangledNameDecl(GV->getName());
+        assert(AliaseeGD);
+        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 = [&]() {
+        llvm::Type *AliasTy = Alias->getValueType();
+        llvm::Type *AliaseeTy = GV->getValueType();
----------------
efriedma-quic wrote:

Looking a little more, I guess we don't really keep any usable mapping.

We could potentially add some sort of map (either mangled name->Decl, or GlobalValue->Decl), but we'd need to weight the cost of the map, and whether anything else could benefit from those maps.

https://github.com/llvm/llvm-project/pull/192397


More information about the cfe-commits mailing list