Skip to content

Commit bb18a3c

Browse files
committed
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.
1 parent 9eb69ab commit bb18a3c

File tree

2 files changed

+14
-110
lines changed

2 files changed

+14
-110
lines changed

configure

+2-2
Original file line numberDiff line numberDiff line change
@@ -823,11 +823,11 @@ then
823823
LLVM_VERSION=$($LLVM_CONFIG --version)
824824

825825
case $LLVM_VERSION in
826-
(3.[2-6]*)
826+
(3.[5-6]*)
827827
msg "found ok version of LLVM: $LLVM_VERSION"
828828
;;
829829
(*)
830-
err "bad LLVM version: $LLVM_VERSION, need >=3.0svn"
830+
err "bad LLVM version: $LLVM_VERSION, need >=3.5"
831831
;;
832832
esac
833833
fi

src/rustllvm/RustWrapper.cpp

+12-108
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,7 @@
1414
#include "llvm/IR/DiagnosticInfo.h"
1515
#include "llvm/IR/DiagnosticPrinter.h"
1616

17-
#if LLVM_VERSION_MINOR >= 5
1817
#include "llvm/IR/CallSite.h"
19-
#else
20-
#include "llvm/Support/CallSite.h"
21-
#endif
2218

2319
//===----------------------------------------------------------------------===
2420
//
@@ -33,7 +29,6 @@ using namespace llvm::object;
3329

3430
static char *LastError;
3531

36-
#if LLVM_VERSION_MINOR >= 5
3732
extern "C" LLVMMemoryBufferRef
3833
LLVMRustCreateMemoryBufferWithContentsOfFile(const char *Path) {
3934
ErrorOr<std::unique_ptr<MemoryBuffer>> buf_or = MemoryBuffer::getFile(Path,
@@ -45,18 +40,6 @@ LLVMRustCreateMemoryBufferWithContentsOfFile(const char *Path) {
4540
}
4641
return wrap(buf_or.get().release());
4742
}
48-
#else
49-
extern "C" LLVMMemoryBufferRef
50-
LLVMRustCreateMemoryBufferWithContentsOfFile(const char *Path) {
51-
OwningPtr<MemoryBuffer> buf;
52-
error_code err = MemoryBuffer::getFile(Path, buf, -1, false);
53-
if (err) {
54-
LLVMRustSetLastError(err.message().c_str());
55-
return NULL;
56-
}
57-
return wrap(buf.take());
58-
}
59-
#endif
6043

6144
extern "C" char *LLVMRustGetLastError(void) {
6245
char *ret = LastError;
@@ -116,7 +99,6 @@ extern "C" void LLVMAddCallSiteAttribute(LLVMValueRef Instr, unsigned index, uin
11699
}
117100

118101

119-
#if LLVM_VERSION_MINOR >= 5
120102
extern "C" void LLVMAddDereferenceableCallSiteAttr(LLVMValueRef Instr, unsigned idx, uint64_t b) {
121103
CallSite Call = CallSite(unwrap<Instruction>(Instr));
122104
AttrBuilder B;
@@ -126,9 +108,6 @@ extern "C" void LLVMAddDereferenceableCallSiteAttr(LLVMValueRef Instr, unsigned
126108
AttributeSet::get(Call->getContext(),
127109
idx, B)));
128110
}
129-
#else
130-
extern "C" void LLVMAddDereferenceableCallSiteAttr(LLVMValueRef, unsigned, uint64_t) {}
131-
#endif
132111

133112
extern "C" void LLVMAddFunctionAttribute(LLVMValueRef Fn, unsigned index, uint64_t Val) {
134113
Function *A = unwrap<Function>(Fn);
@@ -137,16 +116,12 @@ extern "C" void LLVMAddFunctionAttribute(LLVMValueRef Fn, unsigned index, uint64
137116
A->addAttributes(index, AttributeSet::get(A->getContext(), index, B));
138117
}
139118

140-
#if LLVM_VERSION_MINOR >= 5
141119
extern "C" void LLVMAddDereferenceableAttr(LLVMValueRef Fn, unsigned index, uint64_t bytes) {
142120
Function *A = unwrap<Function>(Fn);
143121
AttrBuilder B;
144122
B.addDereferenceableAttr(bytes);
145123
A->addAttributes(index, AttributeSet::get(A->getContext(), index, B));
146124
}
147-
#else
148-
extern "C" void LLVMAddDereferenceableAttr(LLVMValueRef, unsigned, uint64_t) {}
149-
#endif
150125

151126
extern "C" void LLVMAddFunctionAttrString(LLVMValueRef Fn, unsigned index, const char *Name) {
152127
Function *F = unwrap<Function>(Fn);
@@ -199,10 +174,8 @@ extern "C" LLVMValueRef LLVMBuildAtomicCmpXchg(LLVMBuilderRef B,
199174
AtomicOrdering order,
200175
AtomicOrdering failure_order) {
201176
return wrap(unwrap(B)->CreateAtomicCmpXchg(unwrap(target), unwrap(old),
202-
unwrap(source), order
203-
#if LLVM_VERSION_MINOR >= 5
204-
, failure_order
205-
#endif
177+
unwrap(source), order,
178+
failure_order
206179
));
207180
}
208181
extern "C" LLVMValueRef LLVMBuildAtomicFence(LLVMBuilderRef B, AtomicOrdering order) {
@@ -247,11 +220,7 @@ DIT unwrapDI(LLVMMetadataRef ref) {
247220
return DIT(ref ? unwrap<MDNode>(ref) : NULL);
248221
}
249222

250-
#if LLVM_VERSION_MINOR >= 5
251223
extern "C" const uint32_t LLVMRustDebugMetadataVersion = DEBUG_METADATA_VERSION;
252-
#else
253-
extern "C" const uint32_t LLVMRustDebugMetadataVersion = 1;
254-
#endif
255224

256225
extern "C" void LLVMRustAddModuleFlag(LLVMModuleRef M,
257226
const char *name,
@@ -383,10 +352,8 @@ extern "C" LLVMMetadataRef LLVMDIBuilderCreateStructType(
383352
unwrapDI<DIType>(DerivedFrom),
384353
unwrapDI<DIArray>(Elements),
385354
RunTimeLang,
386-
unwrapDI<DIType>(VTableHolder)
387-
#if LLVM_VERSION_MINOR >= 4
388-
,UniqueId
389-
#endif
355+
unwrapDI<DIType>(VTableHolder),
356+
UniqueId
390357
));
391358
}
392359

@@ -465,8 +432,8 @@ extern "C" LLVMMetadataRef LLVMDIBuilderCreateVariable(
465432
#if LLVM_VERSION_MINOR < 6
466433
if (AddrOpsCount > 0) {
467434
SmallVector<llvm::Value *, 16> addr_ops;
468-
llvm::Type *Int64Ty = Type::getInt64Ty(VMContext);
469-
for (int i = 0; i < AddrOpsCount; ++i)
435+
llvm::Type *Int64Ty = Type::getInt64Ty(unwrap<MDNode>(Scope)->getContext());
436+
for (unsigned i = 0; i < AddrOpsCount; ++i)
470437
addr_ops.push_back(ConstantInt::get(Int64Ty, AddrOps[i]));
471438

472439
return wrap(Builder->createComplexVariable(
@@ -522,7 +489,11 @@ extern "C" LLVMMetadataRef LLVMDIBuilderGetOrCreateArray(
522489
LLVMMetadataRef* Ptr,
523490
unsigned Count) {
524491
return wrap(Builder->getOrCreateArray(
492+
#if LLVM_VERSION_MINOR >= 6
525493
ArrayRef<Metadata*>(unwrap(Ptr), Count)));
494+
#else
495+
ArrayRef<Value*>(reinterpret_cast<Value**>(Ptr), Count)));
496+
#endif
526497
}
527498

528499
extern "C" LLVMValueRef LLVMDIBuilderInsertDeclareAtEnd(
@@ -627,19 +598,11 @@ extern "C" LLVMMetadataRef LLVMDIBuilderCreateUnionType(
627598
AlignInBits,
628599
Flags,
629600
unwrapDI<DIArray>(Elements),
630-
RunTimeLang
631-
#if LLVM_VERSION_MINOR >= 4
632-
,UniqueId
633-
#endif
601+
RunTimeLang,
602+
UniqueId
634603
));
635604
}
636605

637-
#if LLVM_VERSION_MINOR < 5
638-
extern "C" void LLVMSetUnnamedAddr(LLVMValueRef Value, LLVMBool Unnamed) {
639-
unwrap<GlobalValue>(Value)->setUnnamedAddr(Unnamed);
640-
}
641-
#endif
642-
643606
extern "C" LLVMMetadataRef LLVMDIBuilderCreateTemplateTypeParameter(
644607
DIBuilderRef Builder,
645608
LLVMMetadataRef Scope,
@@ -730,7 +693,6 @@ extern "C" void LLVMWriteValueToString(LLVMValueRef Value, RustStringRef str) {
730693
os << ")";
731694
}
732695

733-
#if LLVM_VERSION_MINOR >= 5
734696
extern "C" bool
735697
LLVMRustLinkInExternalBitcode(LLVMModuleRef dst, char *bc, size_t len) {
736698
Module *Dst = unwrap(dst);
@@ -763,28 +725,7 @@ LLVMRustLinkInExternalBitcode(LLVMModuleRef dst, char *bc, size_t len) {
763725
}
764726
return true;
765727
}
766-
#else
767-
extern "C" bool
768-
LLVMRustLinkInExternalBitcode(LLVMModuleRef dst, char *bc, size_t len) {
769-
Module *Dst = unwrap(dst);
770-
MemoryBuffer* buf = MemoryBuffer::getMemBufferCopy(StringRef(bc, len));
771-
std::string Err;
772-
Module *Src = llvm::getLazyBitcodeModule(buf, Dst->getContext(), &Err);
773-
if (!Src) {
774-
LLVMRustSetLastError(Err.c_str());
775-
delete buf;
776-
return false;
777-
}
778-
779-
if (Linker::LinkModules(Dst, Src, Linker::DestroySource, &Err)) {
780-
LLVMRustSetLastError(Err.c_str());
781-
return false;
782-
}
783-
return true;
784-
}
785-
#endif
786728

787-
#if LLVM_VERSION_MINOR >= 5
788729
extern "C" void*
789730
LLVMRustOpenArchive(char *path) {
790731
ErrorOr<std::unique_ptr<MemoryBuffer>> buf_or = MemoryBuffer::getFile(path,
@@ -817,23 +758,6 @@ LLVMRustOpenArchive(char *path) {
817758

818759
return ret;
819760
}
820-
#else
821-
extern "C" void*
822-
LLVMRustOpenArchive(char *path) {
823-
OwningPtr<MemoryBuffer> buf;
824-
error_code err = MemoryBuffer::getFile(path, buf, -1, false);
825-
if (err) {
826-
LLVMRustSetLastError(err.message().c_str());
827-
return NULL;
828-
}
829-
Archive *ret = new Archive(buf.take(), err);
830-
if (err) {
831-
LLVMRustSetLastError(err.message().c_str());
832-
return NULL;
833-
}
834-
return ret;
835-
}
836-
#endif
837761

838762
extern "C" const char*
839763
#if LLVM_VERSION_MINOR >= 6
@@ -844,21 +768,12 @@ LLVMRustArchiveReadSection(OwningBinary<Archive> *ob, char *name, size_t *size)
844768
LLVMRustArchiveReadSection(Archive *ar, char *name, size_t *size) {
845769
#endif
846770

847-
#if LLVM_VERSION_MINOR >= 5
848771
Archive::child_iterator child = ar->child_begin(),
849772
end = ar->child_end();
850773
for (; child != end; ++child) {
851774
ErrorOr<StringRef> name_or_err = child->getName();
852775
if (name_or_err.getError()) continue;
853776
StringRef sect_name = name_or_err.get();
854-
#else
855-
Archive::child_iterator child = ar->begin_children(),
856-
end = ar->end_children();
857-
for (; child != end; ++child) {
858-
StringRef sect_name;
859-
error_code err = child->getName(sect_name);
860-
if (err) continue;
861-
#endif
862777
if (sect_name.trim(" ") == name) {
863778
StringRef buf = child->getBuffer();
864779
*size = buf.size();
@@ -877,18 +792,11 @@ LLVMRustDestroyArchive(Archive *ar) {
877792
delete ar;
878793
}
879794

880-
#if LLVM_VERSION_MINOR >= 5
881795
extern "C" void
882796
LLVMRustSetDLLExportStorageClass(LLVMValueRef Value) {
883797
GlobalValue *V = unwrap<GlobalValue>(Value);
884798
V->setDLLStorageClass(GlobalValue::DLLExportStorageClass);
885799
}
886-
#else
887-
extern "C" void
888-
LLVMRustSetDLLExportStorageClass(LLVMValueRef Value) {
889-
LLVMSetLinkage(Value, LLVMDLLExportLinkage);
890-
}
891-
#endif
892800

893801
extern "C" int
894802
LLVMVersionMinor() {
@@ -918,11 +826,7 @@ inline section_iterator *unwrap(LLVMSectionIteratorRef SI) {
918826
extern "C" int
919827
LLVMRustGetSectionName(LLVMSectionIteratorRef SI, const char **ptr) {
920828
StringRef ret;
921-
#if LLVM_VERSION_MINOR >= 5
922829
if (std::error_code ec = (*unwrap(SI))->getName(ret))
923-
#else
924-
if (error_code ec = (*unwrap(SI))->getName(ret))
925-
#endif
926830
report_fatal_error(ec.message());
927831
*ptr = ret.data();
928832
return ret.size();

0 commit comments

Comments
 (0)