From bb18a3cfe7554143622af4911028605e89c80104 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Steinbrink?= Date: Sat, 14 Mar 2015 13:14:04 +0100 Subject: [PATCH] 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. --- configure | 4 +- src/rustllvm/RustWrapper.cpp | 120 ++++------------------------------- 2 files changed, 14 insertions(+), 110 deletions(-) diff --git a/configure b/configure index 73e09158539aa..760203ae5cf4e 100755 --- a/configure +++ b/configure @@ -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 diff --git a/src/rustllvm/RustWrapper.cpp b/src/rustllvm/RustWrapper.cpp index aaf6d8df29cad..9a87c03f1c407 100644 --- a/src/rustllvm/RustWrapper.cpp +++ b/src/rustllvm/RustWrapper.cpp @@ -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> 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 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(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(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(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(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(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(DerivedFrom), unwrapDI(Elements), RunTimeLang, - unwrapDI(VTableHolder) -#if LLVM_VERSION_MINOR >= 4 - ,UniqueId -#endif + unwrapDI(VTableHolder), + UniqueId )); } @@ -465,8 +432,8 @@ extern "C" LLVMMetadataRef LLVMDIBuilderCreateVariable( #if LLVM_VERSION_MINOR < 6 if (AddrOpsCount > 0) { SmallVector addr_ops; - llvm::Type *Int64Ty = Type::getInt64Ty(VMContext); - for (int i = 0; i < AddrOpsCount; ++i) + llvm::Type *Int64Ty = Type::getInt64Ty(unwrap(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(unwrap(Ptr), Count))); +#else + ArrayRef(reinterpret_cast(Ptr), Count))); +#endif } extern "C" LLVMValueRef LLVMDIBuilderInsertDeclareAtEnd( @@ -627,19 +598,11 @@ extern "C" LLVMMetadataRef LLVMDIBuilderCreateUnionType( AlignInBits, Flags, unwrapDI(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(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> buf_or = MemoryBuffer::getFile(path, @@ -817,23 +758,6 @@ LLVMRustOpenArchive(char *path) { return ret; } -#else -extern "C" void* -LLVMRustOpenArchive(char *path) { - OwningPtr 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 *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 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(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();