@@ -54,7 +54,7 @@ void decision::operator()(decision_node *entry) {
5454 " _1" , getvalue_type ({sort_category::Symbol, 0 }, module_)));
5555 fail_subject_->addIncoming (
5656 new llvm::BitCastInst (
57- val, llvm::Type::getInt8PtrTy (ctx_), " " , current_block_),
57+ val, llvm::PointerType::getUnqual (ctx_), " " , current_block_),
5858 current_block_);
5959 fail_pattern_->addIncoming (
6060 string_literal (" \\ bottom{SortGeneratedTopCell{}}()" ), current_block_);
@@ -72,7 +72,7 @@ llvm::Value *decision::ptr_term(llvm::Value *val) {
7272 val = allocate_term (val->getType (), current_block_, " kore_alloc_always_gc" );
7373 }
7474 return new llvm::BitCastInst (
75- val, llvm::Type::getInt8PtrTy (ctx_), " " , current_block_);
75+ val, llvm::PointerType::getUnqual (ctx_), " " , current_block_);
7676}
7777
7878bool decision_node::begin_node (decision *d, std::string const &name) {
@@ -490,16 +490,16 @@ void function_node::codegen(decision *d) {
490490 function_args.push_back (d->string_literal (str));
491491 }
492492 function_args.push_back (
493- llvm::ConstantPointerNull::get (llvm::Type::getInt8PtrTy (d->ctx_ )));
493+ llvm::ConstantPointerNull::get (llvm::PointerType::getUnqual (d->ctx_ )));
494494
495495 auto *call = llvm::CallInst::Create (
496496 get_or_insert_function (
497497 d->module_ , " add_match_function" ,
498498 llvm::FunctionType::get (
499499 llvm::Type::getVoidTy (d->ctx_ ),
500- {llvm::Type::getInt8PtrTy (d->ctx_ ),
501- llvm::Type::getInt8PtrTy (d->ctx_ ),
502- llvm::Type::getInt8PtrTy (d->ctx_ )},
500+ {llvm::PointerType::getUnqual (d->ctx_ ),
501+ llvm::PointerType::getUnqual (d->ctx_ ),
502+ llvm::PointerType::getUnqual (d->ctx_ )},
503503 true )),
504504 function_args, " " , d->current_block_ );
505505 set_debug_loc (call);
@@ -709,7 +709,7 @@ static void init_choice_buffer(
709709 std::unordered_set<leaf_node *> leaves;
710710 dt->preprocess (leaves);
711711 auto *ty = llvm::ArrayType::get (
712- llvm::Type::getInt8PtrTy (module ->getContext ()),
712+ llvm::PointerType::getUnqual (module ->getContext ()),
713713 dt->get_choice_depth () + 1 );
714714 auto *choice_buffer = new llvm::AllocaInst (ty, 0 , " choiceBuffer" , block);
715715 auto *choice_depth = new llvm::AllocaInst (
@@ -928,7 +928,7 @@ static void store_ptrs_for_gc(
928928 auto *zero
929929 = llvm::ConstantInt::get (llvm::Type::getInt64Ty (module ->getContext ()), 0 );
930930 llvm::Type *voidptrptr = llvm::PointerType::getUnqual (
931- llvm::Type::getInt8PtrTy (module ->getContext ()));
931+ llvm::PointerType::getUnqual (module ->getContext ()));
932932 for (unsigned i = 0 ; i < nroots; i++) {
933933 auto *ptr = llvm::GetElementPtrInst::CreateInBounds (
934934 root_ty, arr,
@@ -1031,7 +1031,7 @@ static void load_ptrs_for_gc(
10311031 std::vector<value_type> const &types,
10321032 std::vector<llvm::Value *> const &are_block) {
10331033 llvm::Type *voidptrptr = llvm::PointerType::getUnqual (
1034- llvm::Type::getInt8PtrTy (module ->getContext ()));
1034+ llvm::PointerType::getUnqual (module ->getContext ()));
10351035 unsigned i = 0 ;
10361036 for (auto [ptr, pointee_ty] : root_ptrs) {
10371037 llvm::Value *loaded = nullptr ;
@@ -1130,24 +1130,18 @@ std::pair<std::vector<llvm::Value *>, llvm::BasicBlock *> step_function_header(
11301130 i++;
11311131 }
11321132 auto *root_ty = llvm::ArrayType::get (
1133- llvm::Type::getInt8PtrTy (module ->getContext ()), 256 );
1133+ llvm::PointerType::getUnqual (module ->getContext ()), 256 );
11341134 auto *arr = module ->getOrInsertGlobal (" gc_roots" , root_ty);
11351135 std::vector<std::pair<llvm::Value *, llvm::Type *>> root_ptrs;
11361136 std::vector<llvm::Value *> are_block;
1137- llvm::Instruction *are_block_val = llvm::CallInst::CreateMalloc (
1137+ auto *are_block_val = create_malloc (
11381138 collect, llvm::Type::getInt64Ty (block->getContext ()),
11391139 llvm::Type::getInt1Ty (module ->getContext ()),
11401140 llvm::ConstantInt::get (llvm::Type::getInt64Ty (module ->getContext ()), 1 ),
11411141 llvm::ConstantInt::get (
11421142 llvm::Type::getInt64Ty (module ->getContext ()), nroots),
11431143 nullptr );
11441144
1145- #if LLVM_VERSION_MAJOR < 16
1146- are_block_val->insertAfter (&collect->back ());
1147- #else
1148- are_block_val->insertInto (collect, collect->end ());
1149- #endif
1150-
11511145 store_ptrs_for_gc (
11521146 nroots, module , root_ty, arr, are_block_val, collect, roots, types,
11531147 ptr_types, root_ptrs, are_block);
@@ -1198,7 +1192,7 @@ std::pair<std::vector<llvm::Value *>, llvm::BasicBlock *> step_function_header(
11981192 llvm::FunctionType::get (
11991193 llvm::Type::getVoidTy (module ->getContext ()),
12001194 {arr->getType (), llvm::Type::getInt8Ty (module ->getContext ()), ptr_ty,
1201- llvm::Type::getInt1PtrTy (module ->getContext ())},
1195+ llvm::PointerType::getUnqual (module ->getContext ())},
12021196 false ));
12031197 auto *call = llvm::CallInst::Create (
12041198 kore_collect,
@@ -1379,11 +1373,22 @@ void make_match_reason_function(
13791373 llvm::BasicBlock *fail
13801374 = llvm::BasicBlock::Create (module ->getContext (), " fail" , match_func);
13811375 llvm::PHINode *fail_subject = llvm::PHINode::Create (
1382- llvm::Type::getInt8PtrTy (module ->getContext ()), 0 , " subject" , fail);
1376+ llvm::PointerType::getUnqual (module ->getContext ()), 0 , " subject" , fail);
1377+
1378+ // The pointer types created here for the failure pattern and sort need to be
1379+ // given an explicit element type on LLVM 15 (LLVM_VERSION_MAJOR <= 15). This
1380+ // is because the constants that eventually flow into the Phi nodes still get
1381+ // type `i8*` on LLVM 15, rather than `ptr` as would be assigned here.
1382+ //
1383+ // In newer versions, the string constants also get type `ptr` and these
1384+ // explicit element types become no-ops that we can remove.
13831385 llvm::PHINode *fail_pattern = llvm::PHINode::Create (
1384- llvm::Type::getInt8PtrTy (module ->getContext ()), 0 , " pattern" , fail);
1386+ llvm::PointerType::getUnqual (llvm::Type::getInt8Ty (module ->getContext ())),
1387+ 0 , " pattern" , fail);
13851388 llvm::PHINode *fail_sort = llvm::PHINode::Create (
1386- llvm::Type::getInt8PtrTy (module ->getContext ()), 0 , " sort" , fail);
1389+ llvm::PointerType::getUnqual (llvm::Type::getInt8Ty (module ->getContext ())),
1390+ 0 , " sort" , fail);
1391+
13871392 auto *call = llvm::CallInst::Create (
13881393 get_or_insert_function (
13891394 module , " add_match_fail_reason" ,
0 commit comments