[llvm-branch-commits] [llvm] 03d030b - [CodeGen] Filter out available_externally aliases

Tom Stellard via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Tue Feb 7 17:16:29 PST 2023


Author: Jonas Hahnfeld
Date: 2023-02-07T17:15:55-08:00
New Revision: 03d030be087a38b9671dabd6953e86d7756775fa

URL: https://github.com/llvm/llvm-project/commit/03d030be087a38b9671dabd6953e86d7756775fa
DIFF: https://github.com/llvm/llvm-project/commit/03d030be087a38b9671dabd6953e86d7756775fa.diff

LOG: [CodeGen] Filter out available_externally aliases

The Language Reference says that aliases can have available_externally
linkage if their aliasee is an available_externally global value. Using
this kind of aliases resulted in crashes during code generation, filter
them out (the same that the AsmPrinter also filters out GlobalVariables
in emitSpecialLLVMGlobal(); Functions are discarded in the machine pass
infrastructure).

Differential Revision: https://reviews.llvm.org/D142352

(cherry picked from commit f1c4f927f7c15b5efdc3589c050fd0513bf6b303)

Added: 
    llvm/test/CodeGen/Generic/available_externally_alias.ll

Modified: 
    llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
index 8c126d20fc9a6..0b1e32c87fc34 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -2235,6 +2235,8 @@ bool AsmPrinter::doFinalization(Module &M) {
   SmallVector<const GlobalAlias *, 16> AliasStack;
   SmallPtrSet<const GlobalAlias *, 16> AliasVisited;
   for (const auto &Alias : M.aliases()) {
+    if (Alias.hasAvailableExternallyLinkage())
+      continue;
     for (const GlobalAlias *Cur = &Alias; Cur;
          Cur = dyn_cast<GlobalAlias>(Cur->getAliasee())) {
       if (!AliasVisited.insert(Cur).second)

diff  --git a/llvm/test/CodeGen/Generic/available_externally_alias.ll b/llvm/test/CodeGen/Generic/available_externally_alias.ll
new file mode 100644
index 0000000000000..90b289ff393e6
--- /dev/null
+++ b/llvm/test/CodeGen/Generic/available_externally_alias.ll
@@ -0,0 +1,11 @@
+; RUN: llc < %s
+
+ at v = available_externally global i32 42, align 4
+ at va = available_externally alias i32, ptr @v
+
+define available_externally i32 @f() {
+entry:
+  ret i32 0
+}
+
+ at fa = available_externally alias i32(), ptr @f


        


More information about the llvm-branch-commits mailing list