@@ -82,7 +82,11 @@ static void debug_printf(Module *mod, IRBuilder<> &B, const string &fmt, vector<
8282 args.insert (args.begin (), B.getInt64 ((uintptr_t )stderr));
8383 Function *fprintf_fn = mod->getFunction (" fprintf" );
8484 if (!fprintf_fn) {
85+ #if LLVM_VERSION_MAJOR >= 18
86+ vector<Type *> fprintf_fn_args ({B.getInt64Ty (), B.getPtrTy ()});
87+ #else
8588 vector<Type *> fprintf_fn_args ({B.getInt64Ty (), B.getInt8PtrTy ()});
89+ #endif
8690 FunctionType *fprintf_fn_type = FunctionType::get (B.getInt32Ty (), fprintf_fn_args, /* isvarArg=*/ true );
8791 fprintf_fn = Function::Create (fprintf_fn_type, GlobalValue::ExternalLinkage, " fprintf" , mod);
8892 fprintf_fn->setCallingConv (CallingConv::C);
@@ -267,7 +271,11 @@ string BPFModule::make_reader(Module *mod, Type *type) {
267271 IRBuilder<> B (*ctx_);
268272
269273 FunctionType *sscanf_fn_type = FunctionType::get (
274+ #if LLVM_VERSION_MAJOR >= 18
275+ B.getInt32Ty (), {B.getPtrTy (), B.getPtrTy ()}, /* isVarArg=*/ true );
276+ #else
270277 B.getInt32Ty (), {B.getInt8PtrTy (), B.getInt8PtrTy ()}, /* isVarArg=*/ true );
278+ #endif
271279 Function *sscanf_fn = mod->getFunction (" sscanf" );
272280 if (!sscanf_fn) {
273281 sscanf_fn = Function::Create (sscanf_fn_type, GlobalValue::ExternalLinkage,
@@ -277,7 +285,11 @@ string BPFModule::make_reader(Module *mod, Type *type) {
277285 }
278286
279287 string name = " reader" + std::to_string (readers_.size ());
288+ #if LLVM_VERSION_MAJOR >= 18
289+ vector<Type *> fn_args ({B.getPtrTy (), PointerType::getUnqual (type)});
290+ #else
280291 vector<Type *> fn_args ({B.getInt8PtrTy (), PointerType::getUnqual (type)});
292+ #endif
281293 FunctionType *fn_type = FunctionType::get (B.getInt32Ty (), fn_args, /* isVarArg=*/ false );
282294 Function *fn =
283295 Function::Create (fn_type, GlobalValue::ExternalLinkage, name, mod);
@@ -293,7 +305,11 @@ string BPFModule::make_reader(Module *mod, Type *type) {
293305 B.SetInsertPoint (label_entry);
294306
295307 Value *nread = B.CreateAlloca (B.getInt32Ty ());
308+ #if LLVM_VERSION_MAJOR >= 18
309+ Value *sptr = B.CreateAlloca (B.getPtrTy ());
310+ #else
296311 Value *sptr = B.CreateAlloca (B.getInt8PtrTy ());
312+ #endif
297313 map<string, Value *> locals{{" nread" , nread}, {" sptr" , sptr}};
298314 B.CreateStore (arg_in, sptr);
299315 vector<Value *> args ({nullptr , nullptr });
@@ -337,7 +353,11 @@ string BPFModule::make_writer(Module *mod, Type *type) {
337353 IRBuilder<> B (*ctx_);
338354
339355 string name = " writer" + std::to_string (writers_.size ());
356+ #if LLVM_VERSION_MAJOR >= 18
357+ vector<Type *> fn_args ({B.getPtrTy (), B.getInt64Ty (), PointerType::getUnqual (type)});
358+ #else
340359 vector<Type *> fn_args ({B.getInt8PtrTy (), B.getInt64Ty (), PointerType::getUnqual (type)});
360+ #endif
341361 FunctionType *fn_type = FunctionType::get (B.getInt32Ty (), fn_args, /* isVarArg=*/ false );
342362 Function *fn =
343363 Function::Create (fn_type, GlobalValue::ExternalLinkage, name, mod);
@@ -369,7 +389,11 @@ string BPFModule::make_writer(Module *mod, Type *type) {
369389 if (0 )
370390 debug_printf (mod, B, " %d %p %p\n " , vector<Value *>({arg_len, arg_out, arg_in}));
371391
392+ #if LLVM_VERSION_MAJOR >= 18
393+ vector<Type *> snprintf_fn_args ({B.getPtrTy (), B.getInt64Ty (), B.getPtrTy ()});
394+ #else
372395 vector<Type *> snprintf_fn_args ({B.getInt8PtrTy (), B.getInt64Ty (), B.getInt8PtrTy ()});
396+ #endif
373397 FunctionType *snprintf_fn_type = FunctionType::get (B.getInt32Ty (), snprintf_fn_args, /* isVarArg=*/ true );
374398 Function *snprintf_fn = mod->getFunction (" snprintf" );
375399 if (!snprintf_fn)
0 commit comments