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

Segfault with one(::Type) and Base.checked_add on Julia 1.0 #32203

Closed
sostock opened this issue May 31, 2019 · 3 comments
Closed

Segfault with one(::Type) and Base.checked_add on Julia 1.0 #32203

sostock opened this issue May 31, 2019 · 3 comments

Comments

@sostock
Copy link
Contributor

sostock commented May 31, 2019

The following code segfaults on Julia 1.0.4 (it works on 1.1.1 and 1.2.0-rc1):

struct HalfInt <: Real
    twice::Int8
    function HalfInt(x)
        i = Int8(x)
        twice = Base.checked_add(i, i)
        new(twice)
    end
end

convert(HalfInt, 1) # this works
one(HalfInt) # this segfaults, even though it should just call convert(HalfInt, 1)

The segfault also happens when Int8 is replaced by Int16, UInt8 or UInt16 (it works correctly for the other integer types). The segfault also doesn’t happen when Base.checked_add is replaced by +.

@KristofferC
Copy link
Member

KristofferC commented May 31, 2019

Would be good if someone could do a bisect and find the commit that fixed it. Then we might be able to backport it to the next 1.0 release.

@JeffBezanson JeffBezanson added this to the 1.0.x milestone Jun 2, 2019
@sostock
Copy link
Contributor Author

sostock commented Jun 3, 2019

I did a bisect, the relevant commit is 500d669:

500d669e84cad3ce8d1af90e79c9390396a464c7 is the first new commit
commit 500d669e84cad3ce8d1af90e79c9390396a464c7
Author: Jameson Nash <[email protected]>
Date:   Wed Oct 17 17:22:44 2018 -0400

    runtime: fix definition of checked-intrinsics
    
    Handle case where runtime_nbits is not a power of two,
    and be more careful to avoid C compiler undefined behavior
    and tricky promotion rules when defining these.

:040000 040000 fbc7f85db5b6626a19764fc0d3296f03f1c6016b 90610b2bc79f343ab771494088e2e48c38b0d521 M      src

This is part of #29721, which apparently cannot be backported so easily? At least that’s how I interpret the discussion there.

@vtjnash vtjnash closed this as completed Aug 18, 2021
@vtjnash
Copy link
Member

vtjnash commented Aug 18, 2021

Closing as this was only a 1.0.x issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants