Skip to content

segfault on Julia 1.11 for list comprehension on function with nested parameterized struct #58806

Open
@haakon-e

Description

@haakon-e

The following code causes a segfault for me on Julia v1.11, but not v1.10:

haakon@dhcp-72-242 src % julia --startup=no failure.jl 

[18432] signal 11 (2): Segmentation fault: 11
in expression starting at /Users/me/failure.jl:49
_ZL13getSameOpcodeN4llvm8ArrayRefIPNS_5ValueEEERKNS_17TargetLibraryInfoEj at /Users/me/.julia/juliaup/julia-1.11.5+0.aarch64.apple.darwin14/lib/julia/libLLVM.dylib (unknown line)
Allocations: 1 (Pool: 1; Big: 0); GC: 0
zsh: segmentation fault  julia --startup=no failure.jl

where failure.jl is:

# failure.jl
struct NestedStruct{FT, I1, I2}
    inner1::I1
    inner2::I2
    a::FT
    b::FT
    c::FT
    d::FT
    e::FT
end

function NestedStruct()
    inner1 = Inner1(1.0, 1.0, 1.0, 1.0, 1.0)
    inner2 = Inner2(1.0)
    return NestedStruct{Float64, Inner1{Float64}, Inner2{Float64}}(inner1, inner2, 1.0, 1.0, 1.0, 1.0, 1.0)
end

struct Inner1{FT}
    a::FT
    b::FT
    c::FT
    d::FT
    e::FT
end

struct Inner2{FT}
    n0::FT
end

struct FlatStruct{FT}
    a::FT
    b::FT
    c::FT
    function FlatStruct(a::FT, b::FT, c::FT) where {FT}
        a_safe = max(a, 0)
        b_safe = max(b, 0)
        c_safe = max(c, 0)
        return new{FT}(a_safe, b_safe, c_safe)
    end
end

func(ice_params::NestedStruct, q::FlatStruct) = 0


ns = NestedStruct()
a = 20e-3
c_range = (1e-8, 1e-7)

# FAILS
[func(ns, FlatStruct(a, 0.0, c)) for c in c_range]
versioninfo()
julia> versioninfo()
Julia Version 1.11.5
Commit 760b2e5b739 (2025-04-14 06:53 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: macOS (arm64-apple-darwin24.0.0)
  CPU: 14 × Apple M4 Pro
  WORD_SIZE: 64
  LLVM: libLLVM-16.0.6 (ORCJIT, apple-m1)
Threads: 10 default, 0 interactive, 5 GC (on 10 virtual cores)
Environment:
  JULIA_EDITOR = cursor
  JULIA_NUM_THREADS = auto
  JULIA_MAX_NUM_PRECOMPILE_FILES = 50

A mouthful of a PR title, and I certainly do not claim to understand why this fails. I originally posted this on #helpdesk in the julialang slack (Jun 23 2025, 2:29pm PT). The not simplified version of this code that originally led me to discover this issue can be run if you:

  1. clone https://github.com/CliMA/CloudMicrophysics.jl
  2. checkout main (d3a8ae2)
  3. instantiate the primary project environment
  4. instantiate the ./docs environment (you may need to dev . to get the right CloudMicrophysics.jl dependency)
  5. run julia --startup=no --proj=docs docs/src/plots/Microphysics1M_plots.jl
  6. This fails on L80, specifically: [CM1.conv_q_ice_to_q_sno(ice, aps, tps, TD.PhasePartition(q_tot, 0.0, q_ice), q_rai, q_sno, ρ_air, T - 5) for q_ice in q_ice_range]

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions