From ce8e506a782a6f4780b81862038a23bf9bfce633 Mon Sep 17 00:00:00 2001 From: Yichao Yu Date: Mon, 27 Oct 2025 14:47:57 -0400 Subject: [PATCH] Fix ArrayRef(std::nullopt_t) deprecation --- src/cgutils.cpp | 15 ++++---- src/codegen.cpp | 64 +++++++++++++++++------------------ src/llvm-codegen-shared.h | 2 +- src/llvm-late-gc-lowering.cpp | 2 +- src/llvm-multiversioning.cpp | 4 +-- src/llvm-ptls.cpp | 8 ++--- 6 files changed, 47 insertions(+), 48 deletions(-) diff --git a/src/cgutils.cpp b/src/cgutils.cpp index 88b869fd5df28..8a7c8746aca3b 100644 --- a/src/cgutils.cpp +++ b/src/cgutils.cpp @@ -284,7 +284,7 @@ void jl_debugcache_t::initialize(Module *m) { jl_di_func_sig = dbuilder.createSubroutineType( dbuilder.getOrCreateTypeArray(diargs)); jl_di_func_null_sig = dbuilder.createSubroutineType( - dbuilder.getOrCreateTypeArray(None)); + dbuilder.getOrCreateTypeArray({})); } static Value *emit_pointer_from_objref(jl_codectx_t &ctx, Value *V) @@ -418,7 +418,7 @@ static Constant *julia_pgv(jl_codegen_params_t ¶ms, Module *M, const char *c // since the load at the new location satisfy the same condition as the original one. // Mark the global as constant to LLVM code using our own metadata // which is much less likely to be striped. - gv->setMetadata("julia.constgv", MDNode::get(gv->getContext(), None)); + gv->setMetadata("julia.constgv", MDNode::get(gv->getContext(), {})); assert(localname == gv->getName()); assert(!gv->hasInitializer()); return gv; @@ -536,7 +536,7 @@ static inline Instruction *maybe_mark_load_dereferenceable(Instruction *LI, bool if (isa(LI->getType())) { if (!can_be_null) // The `dereferenceable` below does not imply `nonnull` for non addrspace(0) pointers. - LI->setMetadata(LLVMContext::MD_nonnull, MDNode::get(LI->getContext(), None)); + LI->setMetadata(LLVMContext::MD_nonnull, MDNode::get(LI->getContext(), {})); if (size) { Metadata *OP = ConstantAsMetadata::get(ConstantInt::get(getInt64Ty(LI->getContext()), size)); LI->setMetadata(can_be_null ? LLVMContext::MD_dereferenceable_or_null : LLVMContext::MD_dereferenceable, @@ -1762,7 +1762,7 @@ static Value *emit_typeof(jl_codectx_t &ctx, Value *v, bool maybenull, bool just Value *smallp = emit_ptrgep(ctx, prepare_global_in(M, jl_small_typeof_var), tag); jl_aliasinfo_t ai = jl_aliasinfo_t::fromTBAA(ctx, ctx.tbaa().tbaa_const); auto small = ctx.builder.CreateAlignedLoad(typetag->getType(), smallp, M->getDataLayout().getPointerABIAlignment(0)); - small->setMetadata(LLVMContext::MD_nonnull, MDNode::get(M->getContext(), None)); + small->setMetadata(LLVMContext::MD_nonnull, MDNode::get(M->getContext(), {})); return ai.decorateInst(small); }); }); @@ -2463,8 +2463,7 @@ static jl_cgval_t typed_store(jl_codectx_t &ctx, FunctionType::get(StructType::get(elty, elty), {ptr->getType(), ctx.builder.getPtrTy(), ctx.builder.getInt8Ty(), ctx.builder.getInt8Ty()}, true), AttributeList::get(elty->getContext(), Attributes(elty->getContext(), {Attribute::NoMerge}), // prevent llvm from merging calls to different functions - AttributeSet(), - None)); + AttributeSet(), {})); SmallVector Args = {ptr, op, ctx.builder.getInt8((unsigned)Order), ctx.builder.getInt8(SyncScope::System)}; if (rhs.V) Args.push_back(rhs.V); @@ -3389,7 +3388,7 @@ static Value *emit_genericmemoryptr(jl_codectx_t &ctx, Value *mem, const jl_data PointerType *PPT = cast(ctx.types().T_jlgenericmemory->getElementType(1)); LoadInst *LI = ctx.builder.CreateAlignedLoad(PPT, addr, Align(sizeof(char*))); LI->setOrdering(AtomicOrdering::NotAtomic); - LI->setMetadata(LLVMContext::MD_nonnull, MDNode::get(ctx.builder.getContext(), None)); + LI->setMetadata(LLVMContext::MD_nonnull, MDNode::get(ctx.builder.getContext(), {})); jl_aliasinfo_t aliasinfo = jl_aliasinfo_t::fromTBAA(ctx, ctx.tbaa().tbaa_memoryptr); aliasinfo.decorateInst(LI); Value *ptr = LI; @@ -3408,7 +3407,7 @@ static Value *emit_genericmemoryowner(jl_codectx_t &ctx, Value *t) Type *T_data = ctx.types().T_jlgenericmemory->getElementType(1); LoadInst *LI = ctx.builder.CreateAlignedLoad(T_data, addr, Align(sizeof(char*))); LI->setOrdering(AtomicOrdering::NotAtomic); - LI->setMetadata(LLVMContext::MD_nonnull, MDNode::get(ctx.builder.getContext(), None)); + LI->setMetadata(LLVMContext::MD_nonnull, MDNode::get(ctx.builder.getContext(), {})); jl_aliasinfo_t aliasinfo_mem = jl_aliasinfo_t::fromTBAA(ctx, ctx.tbaa().tbaa_memoryown); aliasinfo_mem.decorateInst(LI); addr = emit_ptrgep(ctx, m, JL_SMALL_BYTE_ALIGNMENT); diff --git a/src/codegen.cpp b/src/codegen.cpp index 71dd815548358..11dbc67f72fb4 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -625,7 +625,7 @@ static AttributeList get_attrs_noreturn(LLVMContext &C) return AttributeList::get(C, Attributes(C, {Attribute::NoReturn}), AttributeSet(), - None); + {}); } static AttributeList get_attrs_basic(LLVMContext &C) @@ -633,7 +633,7 @@ static AttributeList get_attrs_basic(LLVMContext &C) return AttributeList::get(C, AttributeSet(), Attributes(C, {Attribute::NonNull}), - None); + {}); } static AttributeList get_attrs_box_float(LLVMContext &C, unsigned nbytes) @@ -649,7 +649,7 @@ static AttributeList get_attrs_box_float(LLVMContext &C, unsigned nbytes) return AttributeList::get(C, AttributeSet::get(C, FnAttrs), AttributeSet::get(C, RetAttrs), - None); + {}); } static AttributeList get_attrs_box_sext(LLVMContext &C, unsigned nbytes) @@ -936,7 +936,7 @@ static const auto jltopeval_func = new JuliaFunction<>{ [](LLVMContext &C) { return AttributeList::get(C, AttributeSet(), Attributes(C, {Attribute::NonNull}), - None); }, + {}); }, }; static const auto jlcopyast_func = new JuliaFunction<>{ XSTR(jl_copy_ast), @@ -948,7 +948,7 @@ static const auto jlcopyast_func = new JuliaFunction<>{ [](LLVMContext &C) { return AttributeList::get(C, AttributeSet(), Attributes(C, {Attribute::NonNull}), - None); }, + {}); }, }; static const auto jlapplygeneric_func = new JuliaFunction<>{ XSTR(jl_apply_generic), @@ -1054,7 +1054,7 @@ static const auto jlleave_func = new JuliaFunction<>{ return AttributeList::get(C, AttributeSet::get(C, FnAttrs), AttributeSet(), - None); + {}); }, }; static const auto jlleave_noexcept_func = new JuliaFunction<>{ @@ -1071,7 +1071,7 @@ static const auto jlleave_noexcept_func = new JuliaFunction<>{ return AttributeList::get(C, AttributeSet::get(C, FnAttrs), AttributeSet(), - None); + {}); }, }; static const auto jl_restore_excstack_func = new JuliaFunction{ @@ -1101,7 +1101,7 @@ static const auto jlegalx_func = new JuliaFunction{ return AttributeList::get(C, AttributeSet::get(C, FnAttrs), AttributeSet(), - None); }, + {}); }, }; static const auto jl_alloc_obj_func = new JuliaFunction{ "julia.gc_alloc_obj", @@ -1125,7 +1125,7 @@ static const auto jl_alloc_obj_func = new JuliaFunction{ return AttributeList::get(C, AttributeSet::get(C, FnAttrs), AttributeSet::get(C, RetAttrs), - None); + {}); }, }; static const auto jl_alloc_genericmemory_unchecked_func = new JuliaFunction{ @@ -1149,7 +1149,7 @@ static const auto jl_alloc_genericmemory_unchecked_func = new JuliaFunction{ @@ -1162,7 +1162,7 @@ static const auto jl_newbits_func = new JuliaFunction<>{ [](LLVMContext &C) { return AttributeList::get(C, AttributeSet(), Attributes(C, {Attribute::NonNull}), - None); }, + {}); }, }; // `julia.typeof` does read memory, but it is effectively readnone before we lower // the allocation function. This is OK as long as we lower `julia.typeof` no later than @@ -1182,7 +1182,7 @@ static const auto jl_typeof_func = new JuliaFunction<>{ return AttributeList::get(C, AttributeSet::get(C, FnAttrs), Attributes(C, {Attribute::NonNull}), - None); }, + {}); }, }; static const auto jl_write_barrier_func = new JuliaFunction<>{ @@ -1234,7 +1234,7 @@ static const auto jlapplytype_func = new JuliaFunction<>{ AttributeSet(), AttributeSet::get(C, ArrayRef({Attribute::get(C, Attribute::NonNull), Attribute::getWithAlignment(C, Align(16))})), - None); + {}); }, }; static const auto jl_object_id__func = new JuliaFunction{ @@ -1255,7 +1255,7 @@ static const auto setjmp_func = new JuliaFunction{ [](LLVMContext &C) { return AttributeList::get(C, Attributes(C, {Attribute::ReturnsTwice}), AttributeSet(), - None); }, + {}); }, }; static const auto memcmp_func = new JuliaFunction{ XSTR(memcmp), @@ -1268,7 +1268,7 @@ static const auto memcmp_func = new JuliaFunction{ return AttributeList::get(C, AttributeSet::get(C, FnAttrs), AttributeSet(), - None); }, + {}); }, // TODO: inferLibFuncAttributes(*memcmp_func, TLI); }; static const auto jldlsym_func = new JuliaFunction<>{ @@ -1302,7 +1302,7 @@ static const auto jlgetnthfieldchecked_func = new JuliaFunction{ XSTR(jl_field_index), @@ -1319,7 +1319,7 @@ static const auto jlfieldindex_func = new JuliaFunction<>{ return AttributeList::get(C, AttributeSet::get(C, FnAttrs), AttributeSet(), - None); }, // This function can error if the third argument is 1 so don't do that. + {}); }, // This function can error if the third argument is 1 so don't do that. }; static const auto jlfieldisdefinedchecked_func = new JuliaFunction{ XSTR(jl_field_isdefined_checked), @@ -1331,7 +1331,7 @@ static const auto jlfieldisdefinedchecked_func = new JuliaFunction{ XSTR(jl_get_cfunction_trampoline), @@ -1353,7 +1353,7 @@ static const auto jlgetcfunctiontrampoline_func = new JuliaFunction<>{ [](LLVMContext &C) { return AttributeList::get(C, AttributeSet(), Attributes(C, {Attribute::NonNull}), - None); }, + {}); }, }; static const auto jlgetabiconverter_func = new JuliaFunction{ XSTR(jl_get_abi_converter), @@ -1393,7 +1393,7 @@ static const auto jl_allocgenericmemory = new JuliaFunction{ \ @@ -1435,7 +1435,7 @@ static const auto jldnd_func = new JuliaFunction<>{ return AttributeList::get(C, AttributeSet::get(C, FnAttrs), Attributes(C, {}), - None); + {}); }, }; @@ -1470,7 +1470,7 @@ static const auto pointer_from_objref_func = new JuliaFunction<>{ return AttributeList::get(C, AttributeSet::get(C, FnAttrs), Attributes(C, {Attribute::NonNull}), - None); }, + {}); }, }; static const auto gc_loaded_func = new JuliaFunction<>{ "julia.gc_loaded", @@ -1665,7 +1665,7 @@ struct jl_aliasinfo_t { MDNode *operand = cast(this->scope->getOperand(0)); auto scope_name = cast(operand->getOperand(0))->getString(); if (scope_name == "jnoalias_const") - inst->setMetadata(LLVMContext::MD_invariant_load, MDNode::get(inst->getContext(), None)); + inst->setMetadata(LLVMContext::MD_invariant_load, MDNode::get(inst->getContext(), {})); } } @@ -2017,7 +2017,7 @@ jl_aliasinfo_t jl_aliasinfo_t::fromTBAA(jl_codectx_t &ctx, MDNode *tbaa) { static Type *julia_type_to_llvm(jl_codectx_t &ctx, jl_value_t *jt, bool *isboxed = NULL); static jl_returninfo_t get_specsig_function(jl_codegen_params_t &ctx, Module *M, Value *fval, StringRef name, jl_value_t *sig, jl_value_t *jlrettype, bool is_opaque_closure, - ArrayRef ArgNames=None, unsigned nreq=0); + ArrayRef ArgNames={}, unsigned nreq=0); static jl_cgval_t emit_expr(jl_codectx_t &ctx, jl_value_t *expr, ssize_t ssaval = -1); static jl_cgval_t emit_checked_var(jl_codectx_t &ctx, Value *bp, jl_sym_t *name, jl_value_t *scope, bool isvol, MDNode *tbaa); static jl_cgval_t emit_sparam(jl_codectx_t &ctx, size_t i); @@ -2195,7 +2195,7 @@ static inline jl_cgval_t ghostValue(jl_codectx_t &ctx, jl_value_t *typ) if (jl_is_type_type(typ)) { assert(is_uniquerep_Type(typ)); // replace T::Type{T} with T, by assuming that T must be a leaftype of some sort - jl_cgval_t constant(NULL, true, typ, NULL, best_tbaa(ctx.tbaa(), typ), None); + jl_cgval_t constant(NULL, true, typ, NULL, best_tbaa(ctx.tbaa(), typ), ArrayRef()); constant.constant = jl_tparam0(typ); if (typ == (jl_value_t*)jl_typeofbottom_type->super) constant.isghost = true; @@ -2219,13 +2219,13 @@ static inline jl_cgval_t mark_julia_const(jl_codectx_t &ctx, jl_value_t *jv) if (jl_is_datatype_singleton((jl_datatype_t*)typ)) return ghostValue(ctx, typ); } - jl_cgval_t constant(NULL, true, typ, NULL, best_tbaa(ctx.tbaa(), typ), None); + jl_cgval_t constant(NULL, true, typ, NULL, best_tbaa(ctx.tbaa(), typ), ArrayRef()); constant.constant = jv; return constant; } -static inline jl_cgval_t mark_julia_slot(Value *v, jl_value_t *typ, Value *tindex, MDNode *tbaa, ArrayRef inline_roots=None) +static inline jl_cgval_t mark_julia_slot(Value *v, jl_value_t *typ, Value *tindex, MDNode *tbaa, ArrayRef inline_roots={}) { // this enables lazy-copying of immutable values and stack or argument slots jl_cgval_t tagval(v, false, typ, tindex, tbaa, inline_roots); @@ -2311,7 +2311,7 @@ static inline jl_cgval_t mark_julia_type(jl_codectx_t &ctx, Value *v, bool isbox return value_to_pointer(ctx, v, typ, NULL); } if (isboxed) - return jl_cgval_t(v, isboxed, typ, NULL, best_tbaa(ctx.tbaa(), typ), None); + return jl_cgval_t(v, isboxed, typ, NULL, best_tbaa(ctx.tbaa(), typ), ArrayRef()); return jl_cgval_t(v, typ, NULL); } @@ -2590,7 +2590,7 @@ static jl_cgval_t convert_julia_type_union(jl_codectx_t &ctx, const jl_cgval_t & } } else { - return jl_cgval_t(boxed(ctx, v), true, typ, NULL, best_tbaa(ctx.tbaa(), typ), None); + return jl_cgval_t(boxed(ctx, v), true, typ, NULL, best_tbaa(ctx.tbaa(), typ), ArrayRef()); } return jl_cgval_t(v, typ, new_tindex); } @@ -5641,7 +5641,7 @@ static jl_cgval_t emit_varinfo(jl_codectx_t &ctx, jl_varinfo_t &vi, jl_sym_t *va Value *tindex = NULL; if (vi.pTIndex) tindex = ctx.builder.CreateAlignedLoad(getInt8Ty(ctx.builder.getContext()), vi.pTIndex, Align(1), vi.isVolatile); - v = mark_julia_slot(ssaslot, vi.value.typ, tindex, ctx.tbaa().tbaa_stack, None); + v = mark_julia_slot(ssaslot, vi.value.typ, tindex, ctx.tbaa().tbaa_stack); } if (vi.inline_roots) { AllocaInst *varslot = vi.inline_roots; @@ -6599,7 +6599,7 @@ static jl_cgval_t emit_expr(jl_codectx_t &ctx, jl_value_t *expr, ssize_t ssaidx_ SmallVector MDs; // Reserve first location for self reference to the LoopID metadata node. - TempMDTuple TempNode = MDNode::getTemporary(ctx.builder.getContext(), None); + TempMDTuple TempNode = MDNode::getTemporary(ctx.builder.getContext(), {}); MDs.push_back(TempNode.get()); for (int i = 0, ie = nargs; i < ie; ++i) { @@ -8634,7 +8634,7 @@ static jl_llvm_functions_t AllocaInst *roots = sizes.second > 0 ? emit_static_roots(ctx, sizes.second) : nullptr; if (bits) bits->setName(jl_symbol_name(s)); if (roots) roots->setName(StringRef(".roots.") + jl_symbol_name(s)); - varinfo.value = mark_julia_slot(bits, jt, NULL, ctx.tbaa().tbaa_stack, None); + varinfo.value = mark_julia_slot(bits, jt, NULL, ctx.tbaa().tbaa_stack, {}); varinfo.inline_roots = roots; alloc_def_flag(ctx, varinfo); if (debug_enabled && varinfo.dinfo) { diff --git a/src/llvm-codegen-shared.h b/src/llvm-codegen-shared.h index d5d7ae3d50113..f1324ddf2c6b3 100644 --- a/src/llvm-codegen-shared.h +++ b/src/llvm-codegen-shared.h @@ -158,7 +158,7 @@ static inline llvm::Instruction *tbaa_decorate(llvm::MDNode *md, llvm::Instructi using namespace llvm; inst->setMetadata(llvm::LLVMContext::MD_tbaa, md); if (llvm::isa(inst) && md && md == get_tbaa_const(md->getContext())) { - inst->setMetadata(llvm::LLVMContext::MD_invariant_load, llvm::MDNode::get(md->getContext(), std::nullopt)); + inst->setMetadata(llvm::LLVMContext::MD_invariant_load, llvm::MDNode::get(md->getContext(), {})); } return inst; } diff --git a/src/llvm-late-gc-lowering.cpp b/src/llvm-late-gc-lowering.cpp index ae1351ae41ca1..8b4afbeedc68c 100644 --- a/src/llvm-late-gc-lowering.cpp +++ b/src/llvm-late-gc-lowering.cpp @@ -2291,7 +2291,7 @@ bool LateLowerGCFrame::CleanupIR(Function &F, State *S, bool *CFGModified) { } else { // remove all operand bundles #if JL_LLVM_VERSION >= 200000 - CallInst *NewCall = CallInst::Create(CI, None, CI->getIterator()); + CallInst *NewCall = CallInst::Create(CI, {}, CI->getIterator()); #else CallInst *NewCall = CallInst::Create(CI, None, CI); #endif diff --git a/src/llvm-multiversioning.cpp b/src/llvm-multiversioning.cpp index e9276526ef263..0c60bd56832d4 100644 --- a/src/llvm-multiversioning.cpp +++ b/src/llvm-multiversioning.cpp @@ -687,7 +687,7 @@ void CloneCtx::rewrite_alias(GlobalAlias *alias, Function *F) auto ptr = irbuilder.CreateLoad(F->getType(), slot); ptr->setMetadata(llvm::LLVMContext::MD_tbaa, tbaa_const); - ptr->setMetadata(llvm::LLVMContext::MD_invariant_load, MDNode::get(F->getContext(), None)); + ptr->setMetadata(llvm::LLVMContext::MD_invariant_load, MDNode::get(F->getContext(), {})); SmallVector Args; for (auto &arg : trampoline->args()) @@ -846,7 +846,7 @@ static void replaceUsesWithLoad(Function &F, Type *T_size, I2GV should_replace, #endif Instruction *ptr = new LoadInst(F.getType(), slot, "", false, insert_before); ptr->setMetadata(llvm::LLVMContext::MD_tbaa, tbaa_const); - ptr->setMetadata(llvm::LLVMContext::MD_invariant_load, MDNode::get(ptr->getContext(), None)); + ptr->setMetadata(llvm::LLVMContext::MD_invariant_load, MDNode::get(ptr->getContext(), {})); use_i->setOperand(info.use->getOperandNo(), rewrite_inst_use(uses.get_stack(), T_size, ptr, insert_before)); diff --git a/src/llvm-ptls.cpp b/src/llvm-ptls.cpp index a7bc79afd3eb4..3929ecbb0e64e 100644 --- a/src/llvm-ptls.cpp +++ b/src/llvm-ptls.cpp @@ -225,7 +225,7 @@ void LowerPTLS::fix_pgcstack_use(CallInst *pgcstack, Function *pgcstack_getter, // pgcstack = getter(); // slow auto offset = builder.CreateLoad(T_size, pgcstack_offset); offset->setMetadata(llvm::LLVMContext::MD_tbaa, tbaa_const); - offset->setMetadata(llvm::LLVMContext::MD_invariant_load, MDNode::get(pgcstack->getContext(), None)); + offset->setMetadata(llvm::LLVMContext::MD_invariant_load, MDNode::get(pgcstack->getContext(), {})); auto cmp = builder.CreateICmpNE(offset, Constant::getNullValue(offset->getType())); MDBuilder MDB(pgcstack->getContext()); SmallVector Weights{9, 1}; @@ -250,7 +250,7 @@ void LowerPTLS::fix_pgcstack_use(CallInst *pgcstack, Function *pgcstack_getter, builder.SetInsertPoint(pgcstack); auto getter = builder.CreateLoad(T_pgcstack_getter, pgcstack_func_slot); getter->setMetadata(llvm::LLVMContext::MD_tbaa, tbaa_const); - getter->setMetadata(llvm::LLVMContext::MD_invariant_load, MDNode::get(pgcstack->getContext(), None)); + getter->setMetadata(llvm::LLVMContext::MD_invariant_load, MDNode::get(pgcstack->getContext(), {})); pgcstack->setCalledFunction(pgcstack->getFunctionType(), getter); set_pgcstack_attrs(pgcstack); @@ -265,11 +265,11 @@ void LowerPTLS::fix_pgcstack_use(CallInst *pgcstack, Function *pgcstack_getter, // since we may not know which getter function to use ahead of time. auto getter = builder.CreateLoad(T_pgcstack_getter, pgcstack_func_slot); getter->setMetadata(llvm::LLVMContext::MD_tbaa, tbaa_const); - getter->setMetadata(llvm::LLVMContext::MD_invariant_load, MDNode::get(pgcstack->getContext(), None)); + getter->setMetadata(llvm::LLVMContext::MD_invariant_load, MDNode::get(pgcstack->getContext(), {})); if (TargetTriple.isOSDarwin()) { auto key = builder.CreateLoad(T_size, pgcstack_key_slot); key->setMetadata(llvm::LLVMContext::MD_tbaa, tbaa_const); - key->setMetadata(llvm::LLVMContext::MD_invariant_load, MDNode::get(pgcstack->getContext(), None)); + key->setMetadata(llvm::LLVMContext::MD_invariant_load, MDNode::get(pgcstack->getContext(), {})); auto new_pgcstack = builder.CreateCall(FT_pgcstack_getter, getter, {key}); new_pgcstack->takeName(pgcstack); pgcstack->replaceAllUsesWith(new_pgcstack);