Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Union split can cause assertion in debug mode #50964

Closed
Keno opened this issue Aug 17, 2023 · 9 comments · Fixed by #50998
Closed

Union split can cause assertion in debug mode #50964

Keno opened this issue Aug 17, 2023 · 9 comments · Fixed by #50998
Labels
compiler:codegen Generation of LLVM IR and native code

Comments

@Keno
Copy link
Member

Keno commented Aug 17, 2023

@noinline bar(x::Core.Const) = Base.inferencebarrier(1)
@noinline bar(x::DataType) = Base.inferencebarrier(2)
foo(x) = bar(Base.inferencebarrier(Core.Const(x)))

With assertions enabled:

julia: /home/keno/julia/src/codegen.cpp:1550: jl_cgval_t::jl_cgval_t(const jl_cgval_t&, jl_value_t*, llvm::Value*): Assertion `isboxed || v.typ == typ || tindex' failed.

[3749451] signal (6.-6): Aborted
in expression starting at REPL[13]:1
gsignal at /lib/x86_64-linux-gnu/libc.so.6 (unknown line)
abort at /lib/x86_64-linux-gnu/libc.so.6 (unknown line)
unknown function (ip: 0x7f5d34112728)
__assert_fail at /lib/x86_64-linux-gnu/libc.so.6 (unknown line)
jl_cgval_t at /home/keno/julia/src/codegen.cpp:1550
convert_julia_type at /home/keno/julia/src/codegen.cpp:2343
emit_expr at /home/keno/julia/src/codegen.cpp:5472

Reported-by: @oscardssmith

@oscardssmith
Copy link
Member

Was this in the RR I sent you?

@Keno
Copy link
Member Author

Keno commented Aug 17, 2023

Same test case

@gbaraldi
Copy link
Member

Did this regress? Or has it always been broken?

@Keno
Copy link
Member Author

Keno commented Aug 17, 2023

I don't know, we don't usually run with assertions enabled.

@DilumAluthge
Copy link
Member

We do have one CI job that runs the Base test suite with Julia assertions and LLVM assertions enabled. It only runs on x86_64-linux-gnu. It does not have debug symbols, i.e. it's just make FORCE_ASSERTIONS=1 LLVM_ASSERTIONS=1.

@vtjnash
Copy link
Sponsor Member

vtjnash commented Aug 18, 2023

Looks like it should be detecting this is dead code and skipping emission of this statement (the assertion is semi-correct at detecting, but not handling, this). Usually this gets handled by the jl_is_concrete_type check in convert_julia_type, but we skip that for KindType (whereas we should only skip it for kinds that are isboxed, or where otherwise the conversion is even possible between different Kind and Type representations).

julia> code_typed(foo, (Int,))
1-element Vector{Any}:
 CodeInfo(
    @ REPL[3]:1 within `foo`
   ┌ @ boot.jl:430 within `Const`
1 ─│ %1  = %new(Core.Const, x)::Core.Const
│  └
│   %2  = Main.bar::typeof(bar)
│   %3  = (isa)(%1, Core.Const)::Bool
└──       goto #3 if not %3
2%5  = invoke %2(%1::Core.Const)::Any
└──       goto #6
3%7  = (isa)(%1, DataType)::Bool
└──       goto #5 if not %7
4%9  = π (%1, DataType) # failure occurs here, `x::Core.Const`%10 = invoke %2(%9::DataType)::Any
└──       goto #6
5%12 = Main.bar(%1)::Any
└──       goto #6
6%14 = φ (#2 => %5, #4 => %10, #5 => %12)::Any
└──       return %14
) => Any

@vtjnash vtjnash added the compiler:codegen Generation of LLVM IR and native code label Aug 18, 2023
@gbaraldi
Copy link
Member

So this regressed in #44512 but I guess it doesn't really matter?

@gbaraldi
Copy link
Member

So we should enter this branch

        if (jl_is_concrete_type(v.typ) && !jl_is_kind(v.typ)) {
            if (jl_is_concrete_type(typ) && !jl_is_kind(typ)) {
                // type mismatch: changing from one leaftype to another
                if (skip)
                    *skip = ConstantInt::get(getInt1Ty(ctx.builder.getContext()), 1);
                else
                    CreateTrap(ctx.builder);
                return jl_cgval_t();
            }
        }

@vtjnash
Copy link
Sponsor Member

vtjnash commented Aug 21, 2023

Yes, that is the expectation of that code. The tests for jl_is_kind can be deleted, since they are not accurate here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler:codegen Generation of LLVM IR and native code
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants