[llvm] [GlobalOpt] Don't replace aliasee with alias that has weak linkage (PR #91483)

Eli Friedman via llvm-commits llvm-commits at lists.llvm.org
Wed May 15 10:41:15 PDT 2024


================
@@ -2242,6 +2253,13 @@ static bool hasUsesToReplace(GlobalAlias &GA, const LLVMUsed &U,
   //   define ... @a(...)
   Constant *Aliasee = GA.getAliasee();
   GlobalValue *Target = cast<GlobalValue>(Aliasee->stripPointerCasts());
+  // Don't perform the transform if the alias may be replaced at link time while
+  // someone is using the aliasee (e.g., multiple aliases potentially target it
+  // or someone calls it).
+  if (GA.isWeakForLinker())
+    Ret = false;
+  if (hasMoreThanOneUseOtherThanLLVMUsed(*Target, U))
----------------
efriedma-quic wrote:

Since there's a stripPointerCasts() earlier, do we need to check for other uses of a cast ConstantExpr, in addition to other uses of the global itself?

Or maybe we can just drop the whole pointer-cast-stripping thing... with opaque pointer types, not sure if there's any legitimate cast that can show up here.  (An addressspacecast would be allowed by the verifier, but not sure it's something we can actually generate code for.)

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


More information about the llvm-commits mailing list