@@ -107,6 +107,7 @@ static LLVMRustPassKind toRust(PassKind Kind) {
107107}
108108
109109extern " C" LLVMPassRef LLVMRustFindAndCreatePass (const char *PassName) {
110+ #if LLVM_VERSION_LT(15, 0)
110111 StringRef SR (PassName);
111112 PassRegistry *PR = PassRegistry::getPassRegistry ();
112113
@@ -115,36 +116,59 @@ extern "C" LLVMPassRef LLVMRustFindAndCreatePass(const char *PassName) {
115116 return wrap (PI->createPass ());
116117 }
117118 return nullptr ;
119+ #else
120+ report_fatal_error (" Legacy PM not supported with LLVM 15" );
121+ #endif
118122}
119123
120124extern " C" LLVMPassRef LLVMRustCreateAddressSanitizerFunctionPass (bool Recover) {
125+ #if LLVM_VERSION_LT(15, 0)
121126 const bool CompileKernel = false ;
122127 const bool UseAfterScope = true ;
123128
124129 return wrap (createAddressSanitizerFunctionPass (CompileKernel, Recover, UseAfterScope));
130+ #else
131+ report_fatal_error (" Legacy PM not supported with LLVM 15" );
132+ #endif
125133}
126134
127135extern " C" LLVMPassRef LLVMRustCreateModuleAddressSanitizerPass (bool Recover) {
136+ #if LLVM_VERSION_LT(15, 0)
128137 const bool CompileKernel = false ;
129138
130139 return wrap (createModuleAddressSanitizerLegacyPassPass (CompileKernel, Recover));
140+ #else
141+ report_fatal_error (" Legacy PM not supported with LLVM 15" );
142+ #endif
131143}
132144
133145extern " C" LLVMPassRef LLVMRustCreateMemorySanitizerPass (int TrackOrigins, bool Recover) {
146+ #if LLVM_VERSION_LT(15, 0)
134147 const bool CompileKernel = false ;
135148
136149 return wrap (createMemorySanitizerLegacyPassPass (
137150 MemorySanitizerOptions{TrackOrigins, Recover, CompileKernel}));
151+ #else
152+ report_fatal_error (" Legacy PM not supported with LLVM 15" );
153+ #endif
138154}
139155
140156extern " C" LLVMPassRef LLVMRustCreateThreadSanitizerPass () {
157+ #if LLVM_VERSION_LT(15, 0)
141158 return wrap (createThreadSanitizerLegacyPassPass ());
159+ #else
160+ report_fatal_error (" Legacy PM not supported with LLVM 15" );
161+ #endif
142162}
143163
144164extern " C" LLVMPassRef LLVMRustCreateHWAddressSanitizerPass (bool Recover) {
165+ #if LLVM_VERSION_LT(15, 0)
145166 const bool CompileKernel = false ;
146167
147168 return wrap (createHWAddressSanitizerLegacyPassPass (CompileKernel, Recover));
169+ #else
170+ report_fatal_error (" Legacy PM not supported with LLVM 15" );
171+ #endif
148172}
149173
150174extern " C" LLVMRustPassKind LLVMRustPassKind (LLVMPassRef RustPass) {
@@ -154,23 +178,40 @@ extern "C" LLVMRustPassKind LLVMRustPassKind(LLVMPassRef RustPass) {
154178}
155179
156180extern " C" void LLVMRustAddPass (LLVMPassManagerRef PMR, LLVMPassRef RustPass) {
181+ #if LLVM_VERSION_LT(15, 0)
157182 assert (RustPass);
158183 Pass *Pass = unwrap (RustPass);
159184 PassManagerBase *PMB = unwrap (PMR);
160185 PMB->add (Pass);
186+ #else
187+ report_fatal_error (" Legacy PM not supported with LLVM 15" );
188+ #endif
189+ }
190+ extern " C" void LLVMRustPassManagerBuilderPopulateLTOPassManager (
191+ LLVMPassManagerBuilderRef PMB, LLVMPassManagerRef PM, bool Internalize, bool RunInliner) {
192+ #if LLVM_VERSION_LT(15, 0)
193+ LLVMPassManagerBuilderPopulateLTOPassManager (PMB, PM, Internalize, RunInliner);
194+ #else
195+ report_fatal_error (" Legacy PM not supported with LLVM 15" );
196+ #endif
161197}
162198
163199extern " C"
164200void LLVMRustPassManagerBuilderPopulateThinLTOPassManager (
165201 LLVMPassManagerBuilderRef PMBR,
166202 LLVMPassManagerRef PMR
167203) {
204+ #if LLVM_VERSION_LT(15, 0)
168205 unwrap (PMBR)->populateThinLTOPassManager (*unwrap (PMR));
206+ #else
207+ report_fatal_error (" Legacy PM not supported with LLVM 15" );
208+ #endif
169209}
170210
171211extern " C"
172212void LLVMRustAddLastExtensionPasses (
173213 LLVMPassManagerBuilderRef PMBR, LLVMPassRef *Passes, size_t NumPasses) {
214+ #if LLVM_VERSION_LT(15, 0)
174215 auto AddExtensionPasses = [Passes, NumPasses](
175216 const PassManagerBuilder &Builder, PassManagerBase &PM) {
176217 for (size_t I = 0 ; I < NumPasses; I++) {
@@ -183,6 +224,9 @@ void LLVMRustAddLastExtensionPasses(
183224 AddExtensionPasses);
184225 unwrap (PMBR)->addExtension (PassManagerBuilder::EP_EnabledOnOptLevel0,
185226 AddExtensionPasses);
227+ #else
228+ report_fatal_error (" Legacy PM not supported with LLVM 15" );
229+ #endif
186230}
187231
188232#ifdef LLVM_COMPONENT_X86
0 commit comments