Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove (incorrect) C API fixes from llvm-api and patch LLVM instead #25794

Merged
merged 2 commits into from
Jan 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions deps/llvm.mk
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,7 @@ $(eval $(call LLVM_PATCH,llvm-3.9.0-D37576-NVPTX-sm_70)) # NVPTX, Remove for 6.0
$(eval $(call LLVM_PATCH,llvm-D37939-Mem2Reg-Also-handle-memcpy))
$(eval $(call LLVM_PATCH,llvm-D31524-sovers_4.0)) # Remove for 4.0
$(eval $(call LLVM_PATCH,llvm-D42262-jumpthreading-not-i1))
$(eval $(call LLVM_PATCH,llvm-3.9-c_api_nullptr))
ifeq ($(BUILD_LLVM_CLANG),1)
$(eval $(call LLVM_PATCH,compiler_rt-3.9-glibc_2.25.90)) # Remove for 5.0
endif
Expand Down
39 changes: 39 additions & 0 deletions deps/patches/llvm-3.9-c_api_nullptr.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
diff --git a/lib/IR/Core.cpp b/lib/IR/Core.cpp
index 1cf17b1f311..a969e08cabc 100644
--- a/lib/IR/Core.cpp
+++ b/lib/IR/Core.cpp
@@ -1842,12 +1842,16 @@ void LLVMAddAttributeAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx,

unsigned LLVMGetAttributeCountAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx) {
auto *ASN = AttributeSetNode::get(unwrap<Function>(F)->getAttributes(), Idx);
+ if (!ASN)
+ return 0;
return ASN->getNumAttributes();
}

void LLVMGetAttributesAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx,
LLVMAttributeRef *Attrs) {
auto *ASN = AttributeSetNode::get(unwrap<Function>(F)->getAttributes(), Idx);
+ if (!ASN)
+ return;
for (auto A: make_range(ASN->begin(), ASN->end()))
*Attrs++ = wrap(A);
}
@@ -2173,6 +2177,8 @@ unsigned LLVMGetCallSiteAttributeCount(LLVMValueRef C,
LLVMAttributeIndex Idx) {
auto CS = CallSite(unwrap<Instruction>(C));
auto *ASN = AttributeSetNode::get(CS.getAttributes(), Idx);
+ if (!ASN)
+ return 0;
return ASN->getNumAttributes();
}

@@ -2180,6 +2186,8 @@ void LLVMGetCallSiteAttributes(LLVMValueRef C, LLVMAttributeIndex Idx,
LLVMAttributeRef *Attrs) {
auto CS = CallSite(unwrap<Instruction>(C));
auto *ASN = AttributeSetNode::get(CS.getAttributes(), Idx);
+ if (!ASN)
+ return;
for (auto A: make_range(ASN->begin(), ASN->end()))
*Attrs++ = wrap(A);
}
29 changes: 0 additions & 29 deletions src/llvm-api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,35 +200,6 @@ LLVMExtraCreateBasicBlockPass(const char *Name, jl_value_t *Callback)
}


// Bugfixes

#if JL_LLVM_VERSION < 40000

// D26392
extern "C" JL_DLLEXPORT unsigned
LLVMExtraGetAttributeCountAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx)
{
auto Fn = unwrap<Function>(F);
if (Fn->getAttributes().isEmpty())
return 0;
else
return LLVMGetAttributeCountAtIndex(F, Idx);
}

// D26392
extern "C" JL_DLLEXPORT unsigned LLVMExtraGetCallSiteAttributeCount(
LLVMValueRef C, LLVMAttributeIndex Idx)
{
CallSite CS(unwrap<Instruction>(C));
if (CS.getAttributes().isEmpty())
return 0;
else
return LLVMGetCallSiteAttributeCount(C, Idx);
}

#endif


// Various missing functions

extern "C" JL_DLLEXPORT unsigned int LLVMExtraGetDebugMDVersion()
Expand Down