LLVM backends: work around poorly designed C API
As part of the Opaque Pointers upgrade documentation, LLVM says that the function LLVMGetGEPSourceElementType() can be used to obtain element type information in lieu of LLVMGetElementType(), however, this function actually returns the struct type, not the field type. The GEP instruction does store the information we need, however, this is not exposed in the C API. It seems like they accidentally exposed the wrong field, because one would never need the struct type since one must already pass it directly to the GEP instruction, so one will always have it handy, whereas one will usually not have the field type handy.
This commit is contained in:
@@ -1195,6 +1195,10 @@ void ZigLLVMSetCallElemTypeAttr(LLVMValueRef Call, size_t arg_index, LLVMTypeRef
|
||||
Attribute::get(call_inst->getContext(), Attribute::ElementType, llvm_type));
|
||||
}
|
||||
|
||||
LLVMTypeRef ZigLLVMGetGEPResultElementType(LLVMValueRef GEP) {
|
||||
return wrap(unwrap<GEPOperator>(GEP)->getResultElementType());
|
||||
}
|
||||
|
||||
void ZigLLVMFunctionSetPrefixData(LLVMValueRef function, LLVMValueRef data) {
|
||||
unwrap<Function>(function)->setPrefixData(unwrap<Constant>(data));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user