[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:12:04 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:

It's extremely permissive (anything that gets passed/returned indirectly is the same, and it can even confuse return values with arguments), and also messy because the LLVM IR type is target-specific.

If getMangledNameDecl() isn't usable here, I'm not sure I have any better suggestion for getting the actual type here, off the top of my head.

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


More information about the cfe-commits mailing list