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,13 @@ 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); + if (GV->hasAvailableExternallyLinkage()) { + Check(GA.hasAvailableExternallyLinkage(), + "available_externally aliasee requires available_externally alias", + &GA); + } else { + Check(!GV->isDeclaration(), "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); @@ -846,7 +851,7 @@ void Verifier::visitGlobalAlias(const GlobalAlias &GA) { Check(GlobalAlias::isValidLinkage(GA.getLinkage()), "Alias should have private, internal, linkonce, weak, linkonce_odr, " - "weak_odr, or external linkage!", + "weak_odr, external, or available_externally linkage!", &GA); const Constant *Aliasee = GA.getAliasee(); Check(Aliasee, "Aliasee cannot be NULL!", &GA); 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 --implicit-check-not=Alias declare void @f() @@ -15,7 +15,7 @@ ret void } @fa2 = alias void(), void()* @f2 -; CHECK: Alias must point to a definition +; CHECK: available_externally aliasee requires available_externally alias ; CHECK-NEXT: @fa2 @test2_a = alias i32, i32* @test2_b @@ -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