summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonas Hahnfeld <jonas.hahnfeld@cern.ch>2023-01-23 14:09:48 +0100
committerTom Stellard <tstellar@redhat.com>2023-02-07 17:15:55 -0800
commit03d030be087a38b9671dabd6953e86d7756775fa (patch)
tree474acec90a6cc545f7939fa446c4beabdf41997e
parentaa2bbfaee2d5b352f7ab1a990c1e40535c6fb51b (diff)
downloadllvm-03d030be087a38b9671dabd6953e86d7756775fa.tar.gz
[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)
-rw-r--r--llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp2
-rw-r--r--llvm/test/CodeGen/Generic/available_externally_alias.ll11
2 files changed, 13 insertions, 0 deletions
diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
index 8c126d20fc9a..0b1e32c87fc3 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 000000000000..90b289ff393e
--- /dev/null
+++ b/llvm/test/CodeGen/Generic/available_externally_alias.ll
@@ -0,0 +1,11 @@
+; RUN: llc < %s
+
+@v = available_externally global i32 42, align 4
+@va = available_externally alias i32, ptr @v
+
+define available_externally i32 @f() {
+entry:
+ ret i32 0
+}
+
+@fa = available_externally alias i32(), ptr @f