[llvm-c] Make LLVMAddAlias opaque pointer compatible

Deprecate LLVMAddAlias in favor of LLVMAddAlias2, which accepts a
value type and an address space. Previously these were extracted
from the pointer type.

Differential Revision: https://reviews.llvm.org/D114860
This commit is contained in:
Nikita Popov 2021-12-01 12:12:35 +01:00
parent bc61e5e90b
commit 55d392cc30
4 changed files with 24 additions and 3 deletions

View File

@ -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.
*

View File

@ -2266,6 +2266,14 @@ LLVMValueRef LLVMAddAlias(LLVMModuleRef M, LLVMTypeRef Ty, LLVMValueRef Aliasee,
unwrap<Constant>(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<Constant>(Aliasee), unwrap(M)));
}
LLVMValueRef LLVMGetNamedGlobalAlias(LLVMModuleRef M,
const char *Name, size_t NameLen) {
return wrap(unwrap(M)->getNamedAlias(Name));

View File

@ -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) {

View File

@ -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<GlobalAlias>(AliasRef)->getAliasee(), Aliasee);
}