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) LLVM_VERSION=$($LLVM_CONFIG --version)
case $LLVM_VERSION in case $LLVM_VERSION in
(3.[2-6]*) (3.[5-6]*)
msg "found ok version of LLVM: $LLVM_VERSION" 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 esac
fi fi

View file

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