diff --git a/llvm/include/llvm-c/Core.h b/llvm/include/llvm-c/Core.h index d170eff17951..f2183ff52bfb 100644 --- a/llvm/include/llvm-c/Core.h +++ b/llvm/include/llvm-c/Core.h @@ -2377,9 +2377,20 @@ void LLVMSetExternallyInitialized(LLVMValueRef GlobalVar, LLVMBool IsExtInit); * * @{ */ + +/** Deprecated: Use LLVMAddAlias2 instead. */ LLVMValueRef LLVMAddAlias(LLVMModuleRef M, LLVMTypeRef Ty, LLVMValueRef Aliasee, const char *Name); +/** + * Add a GlobalAlias with the given value type, address space and aliasee. + * + * @see llvm::GlobalAlias::create() + */ +LLVMValueRef LLVMAddAlias2(LLVMModuleRef M, LLVMTypeRef ValueTy, + unsigned AddrSpace, LLVMValueRef Aliasee, + const char *Name); + /** * Obtain a GlobalAlias value from a Module by its name. * diff --git a/llvm/lib/IR/Core.cpp b/llvm/lib/IR/Core.cpp index 905372982dc2..2c396ae97499 100644 --- a/llvm/lib/IR/Core.cpp +++ b/llvm/lib/IR/Core.cpp @@ -2266,6 +2266,14 @@ LLVMValueRef LLVMAddAlias(LLVMModuleRef M, LLVMTypeRef Ty, LLVMValueRef Aliasee, unwrap(Aliasee), unwrap(M))); } +LLVMValueRef LLVMAddAlias2(LLVMModuleRef M, LLVMTypeRef ValueTy, + unsigned AddrSpace, LLVMValueRef Aliasee, + const char *Name) { + return wrap(GlobalAlias::create(unwrap(ValueTy), AddrSpace, + GlobalValue::ExternalLinkage, Name, + unwrap(Aliasee), unwrap(M))); +} + LLVMValueRef LLVMGetNamedGlobalAlias(LLVMModuleRef M, const char *Name, size_t NameLen) { return wrap(unwrap(M)->getNamedAlias(Name)); diff --git a/llvm/tools/llvm-c-test/echo.cpp b/llvm/tools/llvm-c-test/echo.cpp index fe570f057c98..4475cbedc414 100644 --- a/llvm/tools/llvm-c-test/echo.cpp +++ b/llvm/tools/llvm-c-test/echo.cpp @@ -1056,9 +1056,11 @@ AliasDecl: const char *Name = LLVMGetValueName2(Cur, &NameLen); if (LLVMGetNamedGlobalAlias(M, Name, NameLen)) report_fatal_error("Global alias already cloned"); - LLVMTypeRef CurType = TypeCloner(M).Clone(Cur); + LLVMTypeRef PtrType = TypeCloner(M).Clone(Cur); + LLVMTypeRef ValType = TypeCloner(M).Clone(LLVMGlobalGetValueType(Cur)); + unsigned AddrSpace = LLVMGetPointerAddressSpace(PtrType); // FIXME: Allow NULL aliasee. - LLVMAddAlias(M, CurType, LLVMGetUndef(CurType), Name); + LLVMAddAlias2(M, ValType, AddrSpace, LLVMGetUndef(PtrType), Name); Next = LLVMGetNextGlobalAlias(Cur); if (Next == nullptr) { diff --git a/llvm/unittests/IR/ConstantsTest.cpp b/llvm/unittests/IR/ConstantsTest.cpp index 41cfb9d5c04f..061b633c32e2 100644 --- a/llvm/unittests/IR/ConstantsTest.cpp +++ b/llvm/unittests/IR/ConstantsTest.cpp @@ -404,7 +404,7 @@ TEST(ConstantsTest, AliasCAPI) { Type *I16PTy = PointerType::get(I16Ty, 0); Constant *Aliasee = ConstantExpr::getBitCast(G, I16PTy); LLVMValueRef AliasRef = - LLVMAddAlias(wrap(M.get()), wrap(I16PTy), wrap(Aliasee), "a"); + LLVMAddAlias2(wrap(M.get()), wrap(I16Ty), 0, wrap(Aliasee), "a"); ASSERT_EQ(unwrap(AliasRef)->getAliasee(), Aliasee); }