Skip to content

Conversation

@wsmoses
Copy link
Member

@wsmoses wsmoses commented Aug 31, 2025

No description provided.

@wsmoses
Copy link
Member Author

wsmoses commented Aug 31, 2025

currently this results in an inserted instruction (bitcast) without a parent -- and is used in a memset:

Thread 2 received signal SIGSEGV, Segmentation fault.
[Switching to Thread 1354226.1354226]
<signal handler called>
(rr) bt
#0  <signal handler called>
#1  llvm::Instruction::insertBefore (this=0x644400c31e10, InsertPos=0x0)
    at /home/wmoses/git/julia11/deps/srccache/llvm-julia-16.0.6-3/llvm/include/llvm/IR/Instruction.h:91
#2  0x00007adc233fd6d7 in propagateJuliaAddrspaces (F=...) at /home/wmoses/git/julia11/src/llvm-propagate-addrspaces.cpp:290
#3  0x00007adc233fd7f4 in PropagateJuliaAddrspacesPass::run (this=0x644402a23778, F=..., AM=...)
    at /home/wmoses/git/julia11/src/llvm-propagate-addrspaces.cpp:300
#4  0x00007adc2348b136 in llvm::detail::PassModel<llvm::Function, PropagateJuliaAddrspacesPass, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (this=0x644402a23770, IR=..., AM=...)
    at /home/wmoses/git/julia11/usr/include/llvm/IR/PassManagerInternal.h:89
#5  0x00007adc1fe12405 in llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (AM=..., IR=..., this=<optimized out>) at /home/wmoses/git/julia11/deps/srccache/llvm-julia-16.0.6-3/llvm/include/llvm/IR/PassManager.h:517
#6  llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (this=<optimized out>, IR=..., AM=...)
    at /home/wmoses/git/julia11/deps/srccache/llvm-julia-16.0.6-3/llvm/include/llvm/IR/PassManagerInternal.h:89
#7  0x00007adc1da89901 in llvm::ModuleToFunctionPassAdaptor::run (this=<optimized out>, M=..., AM=...)
    at /home/wmoses/git/julia11/deps/srccache/llvm-julia-16.0.6-3/llvm/lib/IR/PassManager.cpp:124
#8  0x00007adc1fe03515 in llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (this=<optimized out>, IR=..., AM=...)
    at /home/wmoses/git/julia11/deps/srccache/llvm-julia-16.0.6-3/llvm/include/llvm/IR/PassManagerInternal.h:89
#9  0x00007adc1676b1ca in llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (
    AM=..., IR=..., this=0x7ffed0db39b0) at /opt/x86_64-linux-gnu/x86_64-linux-gnu/sys-root/usr/local/include/llvm/IR/PassManager.h:517
#10 runJuliaPasses (Mod=0x644401cb21d0, Fun=<optimized out>, Passes=<optimized out>, Machine=<optimized out>, PassOpts=<optimized out>, 
    PassExts=<optimized out>) at /workspace/srcdir/LLVM.jl/deps/LLVMExtra/lib/NewPM.cpp:217
#11 0x00007adbf1bb11d1 in julia_LLVMRunJuliaPasses_18057 (M=..., Passes=<error reading variable: Cannot access memory at address 0x0>, TM=<optimized out>, 
    Options=135085088173584, Extensions=110243209596432) at /home/wmoses/.julia/packages/LLVM/UFrs4/lib/16/libLLVM_extra.jl:397
#12 0x00007adbf1ac4547 in macro expansion () at /home/wmoses/.julia/packages/LLVM/UFrs4/src/executionengine/utils.jl:25
#13 julia_run!_17968 (pb=..., target=..., tm=...) at /home/wmoses/.julia/packages/LLVM/UFrs4/src/newpm.jl:291
#14 0x00007adbe956d89b in run! () at /home/wmoses/.julia/packages/LLVM/UFrs4/src/newpm.jl:252
#15 macro expansion () at /mnt3/wmoses/git/Enzyme.jl/src/compiler/optimize.jl:111
#16 macro expansion () at /home/wmoses/.julia/packages/LLVM/UFrs4/src/base.jl:97
#17 julia_prop_julia_addr_29938 (mod=...) at /mnt3/wmoses/git/Enzyme.jl/src/compiler/optimize.jl:105
#18 0x00007adbe943d03f in jfptr_prop_julia_addr_29939 () from /home/wmoses/.julia/compiled/v1.11/Enzyme/G1p5n_AGSw1.so
#19 0x00007adc24454141 in _jl_invoke (F=0x7adbe9918b60 <jl_system_image_data+1787296>, args=0x7ffed0db5168, nargs=1, 
    mfunc=0x7adbe9e0b6c0 <jl_system_image_data+6975744>, world=26770) at /home/wmoses/git/julia11/src/gf.c:2929
#20 0x00007adc24454ca9 in ijl_apply_generic (F=0x7adbe9918b60 <jl_system_image_data+1787296>, args=0x7ffed0db5168, nargs=1)
    at /home/wmoses/git/julia11/src/gf.c:3125
#21 0x00007adc241ced9a in julia_module_pass_callback_12823 (ptr=110243250643408, data=<optimized out>)
    at /home/wmoses/.julia/packages/LLVM/UFrs4/src/pass.jl:19
#22 0x00007adc241cee61 in jfptr_module_pass_callback_12824 ()
#23 0x00007adc24454141 in _jl_invoke (F=0x7adbfc01b270 <jl_system_image_data+4149808>, args=0x7ffed0db52e0, nargs=2, mfunc=0x7adc19c9e310, world=26770)
    at /home/wmoses/git/julia11/src/gf.c:2929
#24 0x00007adc24454ca9 in ijl_apply_generic (F=0x7adbfc01b270 <jl_system_image_data+4149808>, args=0x7ffed0db52e0, nargs=2)
    at /home/wmoses/git/julia11/src/gf.c:3125
#25 0x00007adbe95f01bf in jlcapi_module_pass_callback_30225 () from /home/wmoses/.julia/compiled/v1.11/Enzyme/G1p5n_AGSw1.so
#26 0x00007adc1675c6a1 in (anonymous namespace)::JuliaModulePass::runOnModule (this=<optimized out>, M=...)
    at /workspace/srcdir/LLVM.jl/deps/LLVMExtra/lib/Core.cpp:195
#27 0x00007adc1da3febe in (anonymous namespace)::MPPassManager::runOnModule (M=..., this=<optimized out>)
    at /home/wmoses/git/julia11/deps/srccache/llvm-julia-16.0.6-3/llvm/lib/IR/LegacyPassManager.cpp:1545
#28 llvm::legacy::PassManagerImpl::run (this=0x644401c6e0d0, M=...)
    at /home/wmoses/git/julia11/deps/srccache/llvm-julia-16.0.6-3/llvm/lib/IR/LegacyPassManager.cpp:535
#29 0x00007adc1d95dd62 in LLVMRunPassManager (PM=<optimized out>, M=<optimized out>)
--Type <RET> for more, q to quit, c to continue without paging--q
Quit
(rr) b propagateJuliaAddrspaces
Breakpoint 1 at 0x7adc233fd63a: file /home/wmoses/git/julia11/src/llvm-propagate-addrspaces.cpp, line 287.
(rr) rc
Continuing.

instruction was created here

(rr) finish
Run till exit from #0  0x00007adc233fd06b in PropagateJuliaAddrspacesVisitor::LiftPointer (this=0x7ffed0db3520, M=0x644401cb21d0, V=0x6444000c3f80, 
    InsertPt=0x0) at /home/wmoses/git/julia11/src/llvm-propagate-addrspaces.cpp:216
0x00007adc233fd2f7 in PropagateJuliaAddrspacesVisitor::visitMemSetInst (this=0x7ffed0db3520, MI=...)
    at /home/wmoses/git/julia11/src/llvm-propagate-addrspaces.cpp:250
250	    Value *Replacement = LiftPointer(MI.getModule(), MI.getRawDest());
Value returned is $11 = (llvm::Value *) 0x644400c31e10
(rr) n
251	    if (!Replacement)
(rr) p Replacement->dump()
  <badref> = bitcast i64* <badref> to i8*
$12 = void
(rr) b LiftPointer
Breakpoint 3 at 0x7adc233fc660: file /home/wmoses/git/julia11/src/llvm-propagate-addrspaces.cpp, line 83.
(rr) rc
Continuing.

Thread 2 hit Hardware watchpoint 2: *((llvm::BasicBlock **) 0x644400c31e38)

Old value = (llvm::BasicBlock *) 0x0
New value = (llvm::BasicBlock *) 0x7adc2314ccec <(anonymous namespace)::BreakCriticalEdges::ID>
llvm::Instruction::Instruction (this=0x644400c31e10, ty=<optimized out>, it=<optimized out>, Ops=<optimized out>, NumOps=<optimized out>, InsertBefore=0x0)
    at /home/wmoses/git/julia11/deps/srccache/llvm-julia-16.0.6-3/llvm/lib/IR/Instruction.cpp:26
26	  : User(ty, Value::InstructionVal + it, Ops, NumOps), Parent(nullptr) {
(rr) up
#1  0x00007adc1da0e765 in llvm::UnaryInstruction::UnaryInstruction (IB=<optimized out>, V=<optimized out>, iType=49, Ty=<optimized out>, 
    this=0x644400c31e10) at /home/wmoses/git/julia11/deps/srccache/llvm-julia-16.0.6-3/llvm/include/llvm/IR/OperandTraits.h:31
31	  static Use *op_begin(SubClass* U) {
(rr) 
#2  llvm::CastInst::CastInst (InsertBefore=<optimized out>, NameStr=..., S=<optimized out>, iType=49, Ty=<optimized out>, this=0x644400c31e10)
    at /home/wmoses/git/julia11/deps/srccache/llvm-julia-16.0.6-3/llvm/include/llvm/IR/InstrTypes.h:433
433	    : UnaryInstruction(Ty, iType, S, InsertBefore) {
(rr) 
#3  llvm::BitCastInst::BitCastInst (this=0x644400c31e10, S=0x6444023f23a0, Ty=0x6443fa3b7b80, Name=..., InsertBefore=<optimized out>)
    at /home/wmoses/git/julia11/deps/srccache/llvm-julia-16.0.6-3/llvm/lib/IR/Instructions.cpp:3971
3971	) : CastInst(Ty, BitCast, S, Name, InsertBefore) {
(rr) 
#4  0x00007adc233fc5cc in operator() (__closure=0x7ffed0db3230, CurrentV=0x6444023f23a0, InsertPt=0x0)
    at /home/wmoses/git/julia11/src/llvm-propagate-addrspaces.cpp:190
190	            auto *BCI = new BitCastInst(CurrentV, TargetType);
(rr) 
#5  0x00007adc233fd06b in PropagateJuliaAddrspacesVisitor::LiftPointer (this=0x7ffed0db3520, M=0x644401cb21d0, V=0x6444000c3f80, InsertPt=0x0)
    at /home/wmoses/git/julia11/src/llvm-propagate-addrspaces.cpp:216
216	    return CollapseCastsAndLift(V, InsertPt);
(rr) l
211	        } else {
212	            assert(false && "Shouldn't have reached here");
213	        }
214	    }
215	
216	    return CollapseCastsAndLift(V, InsertPt);
217	}
218	
219	void PropagateJuliaAddrspacesVisitor::visitMemop(Instruction &I, Type *T, unsigned OpIndex) {
220	    Value *Original = I.getOperand(OpIndex);
(rr) p InsertPt
$13 = (llvm::Instruction *) 0x0
(rr) up
#6  0x00007adc233fd2f7 in PropagateJuliaAddrspacesVisitor::visitMemSetInst (this=0x7ffed0db3520, MI=...)
    at /home/wmoses/git/julia11/src/llvm-propagate-addrspaces.cpp:250
250	    Value *Replacement = LiftPointer(MI.getModule(), MI.getRawDest());
(rr) down
#5  0x00007adc233fd06b in PropagateJuliaAddrspacesVisitor::LiftPointer (this=0x7ffed0db3520, M=0x644401cb21d0, V=0x6444000c3f80, InsertPt=0x0)
    at /home/wmoses/git/julia11/src/llvm-propagate-addrspaces.cpp:216
216	    return CollapseCastsAndLift(V, InsertPt);
(rr) up
#6  0x00007adc233fd2f7 in PropagateJuliaAddrspacesVisitor::visitMemSetInst (this=0x7ffed0db3520, MI=...)
    at /home/wmoses/git/julia11/src/llvm-propagate-addrspaces.cpp:250
250	    Value *Replacement = LiftPointer(MI.getModule(), MI.getRawDest());
(rr) l
245	
246	void PropagateJuliaAddrspacesVisitor::visitMemSetInst(MemSetInst &MI) {
247	    unsigned AS = MI.getDestAddressSpace();
248	    if (!isSpecialAS(AS))
249	        return;
250	    Value *Replacement = LiftPointer(MI.getModule(), MI.getRawDest());
251	    if (!Replacement)
252	        return;
253	    Function *TheFn = Intrinsic::getDeclaration(MI.getModule(), Intrinsic::memset,
254	        {Replacement->getType(), MI.getOperand(1)->getType()});
(rr) l
255	    MI.setCalledFunction(TheFn);
256	    MI.setArgOperand(0, Replacement);
257	}
258	
259	void PropagateJuliaAddrspacesVisitor::visitMemTransferInst(MemTransferInst &MTI) {
260	    unsigned DestAS = MTI.getDestAddressSpace();
261	    unsigned SrcAS = MTI.getSourceAddressSpace();
262	    if (!isSpecialAS(DestAS) && !isSpecialAS(SrcAS))
263	        return;
264	    Value *Dest = MTI.getRawDest();

@wsmoses wsmoses added backport 1.10 Change should be backported to the 1.10 release backport 1.11 Change should be backported to release-1.11 backport 1.12 Change should be backported to release-1.12 labels Aug 31, 2025
@vchuravy
Copy link
Member

Can you audit other uses of LiftPointer and perhaps we could remove the default Nullpointer argument and always require an insertion point?

@gbaraldi
Copy link
Member

gbaraldi commented Sep 1, 2025

It also could do with a test

This was referenced Sep 24, 2025
@oscardssmith oscardssmith assigned gbaraldi and unassigned oscardssmith Oct 4, 2025
@KristofferC KristofferC mentioned this pull request Oct 21, 2025
35 tasks
DilumAluthge added a commit that referenced this pull request Nov 3, 2025
Backported PRs:
- [x] #57523 <!-- Remove usages of weak symbols -->
- [x] #58127 <!-- [DOC] Update installation docs: /downloads/ =>
/install/ -->
- [x] #58202 <!-- [release-1.11] malloc: use jl_get_current_task to fix
null check -->
- [x] #58554 <!-- remove workaround for controlling terminal behavior in
repl_cmd -->
- [x] #58584 <!-- Make `Ptr` values static-show w/ type-information -->
- [x] #59062 <!-- remove a testset from MMAP that might cause CI to now
fail on Windows -->
- [x] #59300 <!-- Update the developer docs to reflect the use of
JuliaSyntax.jl -->
- [x] #57604 <!-- `@nospecialize` for `string_index_err` -->
- [x] #59329 <!-- aotcompile: destroy LLVM context after serializing
combined module -->
- [x] #59418 <!-- Fix startup when history file is bad -->
- [x] #56890 <!-- Enable getting non-boxed LLVM type from Julia Type -->
- [x] #59559 <!-- codegen: mark write barrier field load as volatile -->
- [x] #59572 <!-- Only apply Base.Sort.SubArrayOptimization when
iszero(v.offset1) -->

Need manual backport:
- [ ] #56329 <!-- loading: clean up more concurrency issues -->
- [ ] #56956 <!-- Add "mea culpa" to foreign module assignment error.
-->
- [ ] #57035 <!-- linux: workaround to avoid deadlock inside
dl_iterate_phdr in glibc -->
- [ ] #57089 <!-- Block thread from receiving profile signal with
stackwalk lock -->
- [ ] #57249 <!-- restore non-freebsd-unix fix for profiling -->
- [ ] #58011 <!-- Remove try-finally scope from `@time_imports`
`@trace_compile` `@trace_dispatch` -->
- [ ] #58062 <!-- remove unnecessary edge from `exp_impl` to `pow` -->
- [ ] #58157 <!-- add showing a string to REPL precompile workload -->
- [ ] #58209 <!-- Specialize `one` for the `SizedArray` test helper -->
- [ ] #58356 <!-- codegen: remove readonly from abstract type calling
convention -->
- [ ] #58415 <!-- [REPL] more reliable extension loading -->
- [ ] #58510 <!-- Don't filter `Core` methods from newly-inferred list
-->
- [ ] #58110 <!-- relax dispatch for the `IteratorSize` method for
`Generator` -->
- [ ] #58965 <!-- Fix `hygienic-scope`s in inner macro expansions -->
- [ ] #58971 <!-- Fix alignment of failed precompile jobs on CI -->
- [ ] #59066 <!-- build: Also pass -fno-strict-aliasing for C++ -->
- [ ] #59428 <!-- Correctly set the variant bits of uuid1 -->

Contains multiple commits, manual intervention needed:
- [ ] #55877 <!-- fix FileWatching designs and add workaround for a stat
bug on Apple -->
- [ ] #56755 <!-- docs: fix scope type of a `struct` to hard -->
- [ ] #57809 <!-- Fix fptrunc Float64 -> Float16 rounding through
Float32 -->
- [ ] #57398 <!-- Make remaining float intrinsics require float
arguments -->
- [ ] #56351 <!-- Fix `--project=@script` when outside script directory
-->
- [ ] #57129 <!-- clarify that time_ns is monotonic -->
- [ ] #58134 <!-- Note annotated string API is experimental in Julia
1.11 in HISTORY.md -->
- [ ] #58401 <!-- check that hashing of types does not foreigncall
(`jl_type_hash` is concrete evaluated) -->
- [ ] #58435 <!-- Fix layout flags for types that have oddly sized
primitive type fields -->
- [ ] #58483 <!-- Fix tbaa usage when storing into heap allocated
immutable structs -->
- [ ] #58512 <!-- Make more types jl_static_show readably -->
- [ ] #58012 <!-- Re-enable tab completion of kwargs for large method
tables -->
- [ ] #58683 <!-- Add 0 predecessor to entry basic block and handle it
in inlining -->
- [ ] #59112 <!-- Add builtin function name to add methods error -->
- [ ] #56823 <!-- Make version of opaque closure constructor in world
-->
- [ ] #59467 <!-- `CoreLogging`: prevent some `Annotated*`-related
instability -->

Non-merged PRs with backport label:
- [ ] #59450 <!-- Propagate Addrspaces: fix lift of memset -->
- [ ] #58848 <!-- Set array size only when safe to do so -->
- [ ] #55958 <!-- also redirect JL_STDERR etc. when redirecting to
devnull -->
- [ ] #55956 <!-- Make threadcall gc safe -->
- [ ] #55534 <!-- Set stdlib sources as read-only during installation
-->
- [ ] #55499 <!-- propagate the terminal's `displaysize` to the
`IOContext` used by the REPL -->
- [ ] #55458 <!-- Allow for generically extracting unannotated string
-->
- [ ] #55457 <!-- Make AnnotateChar equality consider annotations -->
- [ ] #55220 <!-- `isfile_casesensitive` fixes on Windows -->
- [ ] #53957 <!-- tweak how filtering is done for what packages should
be precompiled -->
- [ ] #51479 <!-- prevent code loading from lookin in the versioned
environment when building Julia -->
- [ ] #50813 <!-- More doctests for Sockets and capitalization fix -->
- [ ] #50157 <!-- improve docs for `@inbounds` and
`Base.@propagate_inbounds` -->

---------

Co-authored-by: Dilum Aluthge <[email protected]>
Co-authored-by: Sam Schweigel <[email protected]>
Co-authored-by: Cody Tapscott <[email protected]>
Co-authored-by: Jameson Nash <[email protected]>
Co-authored-by: Adam Wheeler <[email protected]>
Co-authored-by: Neven Sajko <[email protected]>
Co-authored-by: Shuhei Kadowaki <[email protected]>
Co-authored-by: Ian Butterworth <[email protected]>
Co-authored-by: William Moses <[email protected]>
Co-authored-by: Valentin Churavy <[email protected]>
Co-authored-by: Lilith Orion Hafner <[email protected]>
@fingolfin fingolfin added needs tests Unit tests are required for this change status: waiting for PR author labels Nov 10, 2025
@fingolfin
Copy link
Member

@wsmoses ping?

@KristofferC KristofferC mentioned this pull request Nov 24, 2025
22 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport 1.10 Change should be backported to the 1.10 release backport 1.11 Change should be backported to release-1.11 backport 1.12 Change should be backported to release-1.12 needs tests Unit tests are required for this change status: waiting for PR author

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants