Drop support for LLVM < 3.5 and fix compile errors with 3.5

LLVM older that 3.6 has a bug that cause assertions when compiling certain
constructs. For 3.5 there's still a chance that the bug might get fixed
in 3.5.2, so let's keep allowing to compile with it for it for now.
This commit is contained in:
Björn Steinbrink 2015-03-14 13:14:04 +01:00
parent 9eb69abad8
commit bb18a3cfe7
2 changed files with 14 additions and 110 deletions

4
configure vendored
View File

@ -823,11 +823,11 @@ then
LLVM_VERSION=$($LLVM_CONFIG --version)
case $LLVM_VERSION in
(3.[2-6]*)
(3.[5-6]*)
msg "found ok version of LLVM: $LLVM_VERSION"
;;
(*)
err "bad LLVM version: $LLVM_VERSION, need >=3.0svn"
err "bad LLVM version: $LLVM_VERSION, need >=3.5"
;;
esac
fi

View File

@ -14,11 +14,7 @@
#include "llvm/IR/DiagnosticInfo.h"
#include "llvm/IR/DiagnosticPrinter.h"
#if LLVM_VERSION_MINOR >= 5
#include "llvm/IR/CallSite.h"
#else
#include "llvm/Support/CallSite.h"
#endif
//===----------------------------------------------------------------------===
//
@ -33,7 +29,6 @@ using namespace llvm::object;
static char *LastError;
#if LLVM_VERSION_MINOR >= 5
extern "C" LLVMMemoryBufferRef
LLVMRustCreateMemoryBufferWithContentsOfFile(const char *Path) {
ErrorOr<std::unique_ptr<MemoryBuffer>> buf_or = MemoryBuffer::getFile(Path,
@ -45,18 +40,6 @@ LLVMRustCreateMemoryBufferWithContentsOfFile(const char *Path) {
}
return wrap(buf_or.get().release());
}
#else
extern "C" LLVMMemoryBufferRef
LLVMRustCreateMemoryBufferWithContentsOfFile(const char *Path) {
OwningPtr<MemoryBuffer> buf;
error_code err = MemoryBuffer::getFile(Path, buf, -1, false);
if (err) {
LLVMRustSetLastError(err.message().c_str());
return NULL;
}
return wrap(buf.take());
}
#endif
extern "C" char *LLVMRustGetLastError(void) {
char *ret = LastError;
@ -116,7 +99,6 @@ extern "C" void LLVMAddCallSiteAttribute(LLVMValueRef Instr, unsigned index, uin
}
#if LLVM_VERSION_MINOR >= 5
extern "C" void LLVMAddDereferenceableCallSiteAttr(LLVMValueRef Instr, unsigned idx, uint64_t b) {
CallSite Call = CallSite(unwrap<Instruction>(Instr));
AttrBuilder B;
@ -126,9 +108,6 @@ extern "C" void LLVMAddDereferenceableCallSiteAttr(LLVMValueRef Instr, unsigned
AttributeSet::get(Call->getContext(),
idx, B)));
}
#else
extern "C" void LLVMAddDereferenceableCallSiteAttr(LLVMValueRef, unsigned, uint64_t) {}
#endif
extern "C" void LLVMAddFunctionAttribute(LLVMValueRef Fn, unsigned index, uint64_t Val) {
Function *A = unwrap<Function>(Fn);
@ -137,16 +116,12 @@ extern "C" void LLVMAddFunctionAttribute(LLVMValueRef Fn, unsigned index, uint64
A->addAttributes(index, AttributeSet::get(A->getContext(), index, B));
}
#if LLVM_VERSION_MINOR >= 5
extern "C" void LLVMAddDereferenceableAttr(LLVMValueRef Fn, unsigned index, uint64_t bytes) {
Function *A = unwrap<Function>(Fn);
AttrBuilder B;
B.addDereferenceableAttr(bytes);
A->addAttributes(index, AttributeSet::get(A->getContext(), index, B));
}
#else
extern "C" void LLVMAddDereferenceableAttr(LLVMValueRef, unsigned, uint64_t) {}
#endif
extern "C" void LLVMAddFunctionAttrString(LLVMValueRef Fn, unsigned index, const char *Name) {
Function *F = unwrap<Function>(Fn);
@ -199,10 +174,8 @@ extern "C" LLVMValueRef LLVMBuildAtomicCmpXchg(LLVMBuilderRef B,
AtomicOrdering order,
AtomicOrdering failure_order) {
return wrap(unwrap(B)->CreateAtomicCmpXchg(unwrap(target), unwrap(old),
unwrap(source), order
#if LLVM_VERSION_MINOR >= 5
, failure_order
#endif
unwrap(source), order,
failure_order
));
}
extern "C" LLVMValueRef LLVMBuildAtomicFence(LLVMBuilderRef B, AtomicOrdering order) {
@ -247,11 +220,7 @@ DIT unwrapDI(LLVMMetadataRef ref) {
return DIT(ref ? unwrap<MDNode>(ref) : NULL);
}
#if LLVM_VERSION_MINOR >= 5
extern "C" const uint32_t LLVMRustDebugMetadataVersion = DEBUG_METADATA_VERSION;
#else
extern "C" const uint32_t LLVMRustDebugMetadataVersion = 1;
#endif
extern "C" void LLVMRustAddModuleFlag(LLVMModuleRef M,
const char *name,
@ -383,10 +352,8 @@ extern "C" LLVMMetadataRef LLVMDIBuilderCreateStructType(
unwrapDI<DIType>(DerivedFrom),
unwrapDI<DIArray>(Elements),
RunTimeLang,
unwrapDI<DIType>(VTableHolder)
#if LLVM_VERSION_MINOR >= 4
,UniqueId
#endif
unwrapDI<DIType>(VTableHolder),
UniqueId
));
}
@ -465,8 +432,8 @@ extern "C" LLVMMetadataRef LLVMDIBuilderCreateVariable(
#if LLVM_VERSION_MINOR < 6
if (AddrOpsCount > 0) {
SmallVector<llvm::Value *, 16> addr_ops;
llvm::Type *Int64Ty = Type::getInt64Ty(VMContext);
for (int i = 0; i < AddrOpsCount; ++i)
llvm::Type *Int64Ty = Type::getInt64Ty(unwrap<MDNode>(Scope)->getContext());
for (unsigned i = 0; i < AddrOpsCount; ++i)
addr_ops.push_back(ConstantInt::get(Int64Ty, AddrOps[i]));
return wrap(Builder->createComplexVariable(
@ -522,7 +489,11 @@ extern "C" LLVMMetadataRef LLVMDIBuilderGetOrCreateArray(
LLVMMetadataRef* Ptr,
unsigned Count) {
return wrap(Builder->getOrCreateArray(
#if LLVM_VERSION_MINOR >= 6
ArrayRef<Metadata*>(unwrap(Ptr), Count)));
#else
ArrayRef<Value*>(reinterpret_cast<Value**>(Ptr), Count)));
#endif
}
extern "C" LLVMValueRef LLVMDIBuilderInsertDeclareAtEnd(
@ -627,19 +598,11 @@ extern "C" LLVMMetadataRef LLVMDIBuilderCreateUnionType(
AlignInBits,
Flags,
unwrapDI<DIArray>(Elements),
RunTimeLang
#if LLVM_VERSION_MINOR >= 4
,UniqueId
#endif
RunTimeLang,
UniqueId
));
}
#if LLVM_VERSION_MINOR < 5
extern "C" void LLVMSetUnnamedAddr(LLVMValueRef Value, LLVMBool Unnamed) {
unwrap<GlobalValue>(Value)->setUnnamedAddr(Unnamed);
}
#endif
extern "C" LLVMMetadataRef LLVMDIBuilderCreateTemplateTypeParameter(
DIBuilderRef Builder,
LLVMMetadataRef Scope,
@ -730,7 +693,6 @@ extern "C" void LLVMWriteValueToString(LLVMValueRef Value, RustStringRef str) {
os << ")";
}
#if LLVM_VERSION_MINOR >= 5
extern "C" bool
LLVMRustLinkInExternalBitcode(LLVMModuleRef dst, char *bc, size_t len) {
Module *Dst = unwrap(dst);
@ -763,28 +725,7 @@ LLVMRustLinkInExternalBitcode(LLVMModuleRef dst, char *bc, size_t len) {
}
return true;
}
#else
extern "C" bool
LLVMRustLinkInExternalBitcode(LLVMModuleRef dst, char *bc, size_t len) {
Module *Dst = unwrap(dst);
MemoryBuffer* buf = MemoryBuffer::getMemBufferCopy(StringRef(bc, len));
std::string Err;
Module *Src = llvm::getLazyBitcodeModule(buf, Dst->getContext(), &Err);
if (!Src) {
LLVMRustSetLastError(Err.c_str());
delete buf;
return false;
}
if (Linker::LinkModules(Dst, Src, Linker::DestroySource, &Err)) {
LLVMRustSetLastError(Err.c_str());
return false;
}
return true;
}
#endif
#if LLVM_VERSION_MINOR >= 5
extern "C" void*
LLVMRustOpenArchive(char *path) {
ErrorOr<std::unique_ptr<MemoryBuffer>> buf_or = MemoryBuffer::getFile(path,
@ -817,23 +758,6 @@ LLVMRustOpenArchive(char *path) {
return ret;
}
#else
extern "C" void*
LLVMRustOpenArchive(char *path) {
OwningPtr<MemoryBuffer> buf;
error_code err = MemoryBuffer::getFile(path, buf, -1, false);
if (err) {
LLVMRustSetLastError(err.message().c_str());
return NULL;
}
Archive *ret = new Archive(buf.take(), err);
if (err) {
LLVMRustSetLastError(err.message().c_str());
return NULL;
}
return ret;
}
#endif
extern "C" const char*
#if LLVM_VERSION_MINOR >= 6
@ -844,21 +768,12 @@ LLVMRustArchiveReadSection(OwningBinary<Archive> *ob, char *name, size_t *size)
LLVMRustArchiveReadSection(Archive *ar, char *name, size_t *size) {
#endif
#if LLVM_VERSION_MINOR >= 5
Archive::child_iterator child = ar->child_begin(),
end = ar->child_end();
for (; child != end; ++child) {
ErrorOr<StringRef> name_or_err = child->getName();
if (name_or_err.getError()) continue;
StringRef sect_name = name_or_err.get();
#else
Archive::child_iterator child = ar->begin_children(),
end = ar->end_children();
for (; child != end; ++child) {
StringRef sect_name;
error_code err = child->getName(sect_name);
if (err) continue;
#endif
if (sect_name.trim(" ") == name) {
StringRef buf = child->getBuffer();
*size = buf.size();
@ -877,18 +792,11 @@ LLVMRustDestroyArchive(Archive *ar) {
delete ar;
}
#if LLVM_VERSION_MINOR >= 5
extern "C" void
LLVMRustSetDLLExportStorageClass(LLVMValueRef Value) {
GlobalValue *V = unwrap<GlobalValue>(Value);
V->setDLLStorageClass(GlobalValue::DLLExportStorageClass);
}
#else
extern "C" void
LLVMRustSetDLLExportStorageClass(LLVMValueRef Value) {
LLVMSetLinkage(Value, LLVMDLLExportLinkage);
}
#endif
extern "C" int
LLVMVersionMinor() {
@ -918,11 +826,7 @@ inline section_iterator *unwrap(LLVMSectionIteratorRef SI) {
extern "C" int
LLVMRustGetSectionName(LLVMSectionIteratorRef SI, const char **ptr) {
StringRef ret;
#if LLVM_VERSION_MINOR >= 5
if (std::error_code ec = (*unwrap(SI))->getName(ret))
#else
if (error_code ec = (*unwrap(SI))->getName(ret))
#endif
report_fatal_error(ec.message());
*ptr = ret.data();
return ret.size();