diff --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst --- a/llvm/docs/LangRef.rst +++ b/llvm/docs/LangRef.rst @@ -886,8 +886,9 @@ [, partition "name"] The linkage must be one of ``private``, ``internal``, ``linkonce``, ``weak``, -``linkonce_odr``, ``weak_odr``, ``external``. Note that some system linkers -might not correctly handle dropping a weak symbol that is aliased. +``linkonce_odr``, ``weak_odr``, ``external``, ``available_externally``. Note +that some system linkers might not correctly handle dropping a weak symbol that +is aliased. Aliases that are not ``unnamed_addr`` are guaranteed to have the same address as the aliasee expression. ``unnamed_addr`` ones are only guaranteed to point diff --git a/llvm/include/llvm/IR/GlobalAlias.h b/llvm/include/llvm/IR/GlobalAlias.h --- a/llvm/include/llvm/IR/GlobalAlias.h +++ b/llvm/include/llvm/IR/GlobalAlias.h @@ -93,8 +93,8 @@ } static bool isValidLinkage(LinkageTypes L) { - return isExternalLinkage(L) || isLocalLinkage(L) || - isWeakLinkage(L) || isLinkOnceLinkage(L); + return isExternalLinkage(L) || isLocalLinkage(L) || isWeakLinkage(L) || + isLinkOnceLinkage(L) || isAvailableExternallyLinkage(L); } // Methods for support type inquiry through isa, cast, and dyn_cast: diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp --- a/llvm/lib/IR/Verifier.cpp +++ b/llvm/lib/IR/Verifier.cpp @@ -816,8 +816,8 @@ void Verifier::visitAliaseeSubExpr(SmallPtrSetImpl &Visited, const GlobalAlias &GA, const Constant &C) { if (const auto *GV = dyn_cast(&C)) { - Check(!GV->isDeclarationForLinker(), "Alias must point to a definition", - &GA); + Check(GA.hasAvailableExternallyLinkage() || !GV->isDeclarationForLinker(), + "Alias must point to a definition", &GA); if (const auto *GA2 = dyn_cast(GV)) { Check(Visited.insert(GA2).second, "Aliases cannot form a cycle", &GA); @@ -844,8 +844,10 @@ } void Verifier::visitGlobalAlias(const GlobalAlias &GA) { - Check(GlobalAlias::isValidLinkage(GA.getLinkage()), - "Alias should have private, internal, linkonce, weak, linkonce_odr, " + Check(GlobalAlias::isValidLinkage(GA.getLinkage()) || + GA.hasAvailableExternallyLinkage(), + "Alias should have available_externally, private, internal, linkonce, " + "weak, linkonce_odr, " "weak_odr, or external linkage!", &GA); const Constant *Aliasee = GA.getAliasee(); diff --git a/llvm/test/Verifier/alias.ll b/llvm/test/Verifier/alias.ll --- a/llvm/test/Verifier/alias.ll +++ b/llvm/test/Verifier/alias.ll @@ -1,4 +1,4 @@ -; RUN: not llvm-as %s -o /dev/null 2>&1 | FileCheck %s +; RUN: not llvm-as %s -o /dev/null 2>&1 | FileCheck %s --implicit-check-not=Alias declare void @f() @@ -31,3 +31,7 @@ @test3_c = alias i32, i32* @test3_b ; CHECK: Alias cannot point to an interposable alias ; CHECK-NEXT: i32* @test3_c + +@test4_a = available_externally alias i32, i32* @test3_a +@test4_b = available_externally alias void(), void()* @f2 +@test4_c = available_externally alias i32, i32* @test4_a