diff --git a/llvm/include/llvm-c/Core.h b/llvm/include/llvm-c/Core.h --- a/llvm/include/llvm-c/Core.h +++ b/llvm/include/llvm-c/Core.h @@ -2377,9 +2377,20 @@ * * @{ */ + +/** 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 --- a/llvm/lib/IR/Core.cpp +++ b/llvm/lib/IR/Core.cpp @@ -2266,6 +2266,14 @@ 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 --- a/llvm/tools/llvm-c-test/echo.cpp +++ b/llvm/tools/llvm-c-test/echo.cpp @@ -1056,9 +1056,11 @@ 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 --- a/llvm/unittests/IR/ConstantsTest.cpp +++ b/llvm/unittests/IR/ConstantsTest.cpp @@ -404,7 +404,7 @@ 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); }