Index: llvm/include/llvm-c/Core.h =================================================================== --- llvm/include/llvm-c/Core.h +++ 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. * Index: llvm/lib/IR/Core.cpp =================================================================== --- llvm/lib/IR/Core.cpp +++ 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)); Index: llvm/tools/llvm-c-test/echo.cpp =================================================================== --- llvm/tools/llvm-c-test/echo.cpp +++ 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) { Index: llvm/unittests/IR/ConstantsTest.cpp =================================================================== --- llvm/unittests/IR/ConstantsTest.cpp +++ 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); }