Skip to content

Commit 5141aa3

Browse files
committed
Retain compatibility with LLVM 6, 7, 8 and 9
1 parent 0812eeb commit 5141aa3

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

src/rustllvm/PassWrapper.cpp

+21-4
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,19 @@
1818
#include "llvm/Transforms/IPO/PassManagerBuilder.h"
1919
#include "llvm/Transforms/IPO/AlwaysInliner.h"
2020
#include "llvm/Transforms/IPO/FunctionImport.h"
21-
#include "llvm/Transforms/Instrumentation/AddressSanitizer.h"
22-
#include "llvm/Transforms/Instrumentation/MemorySanitizer.h"
23-
#include "llvm/Transforms/Instrumentation/ThreadSanitizer.h"
2421
#include "llvm/Transforms/Utils/FunctionImportUtils.h"
2522
#include "llvm/LTO/LTO.h"
26-
2723
#include "llvm-c/Transforms/PassManagerBuilder.h"
2824

25+
#include "llvm/Transforms/Instrumentation.h"
26+
#if LLVM_VERSION_GE(9, 0)
27+
#include "llvm/Transforms/Instrumentation/AddressSanitizer.h"
28+
#endif
29+
#if LLVM_VERSION_GE(8, 0)
30+
#include "llvm/Transforms/Instrumentation/ThreadSanitizer.h"
31+
#include "llvm/Transforms/Instrumentation/MemorySanitizer.h"
32+
#endif
33+
2934
using namespace llvm;
3035
using namespace llvm::legacy;
3136

@@ -88,18 +93,30 @@ extern "C" LLVMPassRef LLVMRustCreateAddressSanitizerFunctionPass(bool Recover)
8893
extern "C" LLVMPassRef LLVMRustCreateModuleAddressSanitizerPass(bool Recover) {
8994
const bool CompileKernel = false;
9095

96+
#if LLVM_VERSION_GE(9, 0)
9197
return wrap(createModuleAddressSanitizerLegacyPassPass(CompileKernel, Recover));
98+
#else
99+
return wrap(createAddressSanitizerModulePass(CompileKernel, Recover));
100+
#endif
92101
}
93102

94103
extern "C" LLVMPassRef LLVMRustCreateMemorySanitizerPass(int TrackOrigins, bool Recover) {
104+
#if LLVM_VERSION_GE(8, 0)
95105
const bool CompileKernel = false;
96106

97107
return wrap(createMemorySanitizerLegacyPassPass(
98108
MemorySanitizerOptions{TrackOrigins, Recover, CompileKernel}));
109+
#else
110+
return wrap(createMemorySanitizerPass(TrackOrigins, Recover));
111+
#endif
99112
}
100113

101114
extern "C" LLVMPassRef LLVMRustCreateThreadSanitizerPass() {
115+
#if LLVM_VERSION_GE(8, 0)
102116
return wrap(createThreadSanitizerLegacyPassPass());
117+
#else
118+
return wrap(createThreadSanitizerPass());
119+
#endif
103120
}
104121

105122
extern "C" LLVMRustPassKind LLVMRustPassKind(LLVMPassRef RustPass) {

0 commit comments

Comments
 (0)