[clang] [compiler-rt] [Clang][CodeGen] Report when an alias points to an incompatible target (PR #192397)

Igor Kudrin via cfe-commits cfe-commits at lists.llvm.org
Thu Apr 16 23:07:58 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();
----------------
igorkudrin wrote:

The similar check in GCC is quite permissive. It doesn't trigger on `int(enum A)` vs. `int(enum B)` or `int(char, float)` vs. `void(...)`. So, I thought that we also should not be too strict. Besides, I haven't found a good way to get `QualType` for the target: `getMangledNameDecl()` is too slow. Could you give me a hint?

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


More information about the cfe-commits mailing list