-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Fix an off-by-one error in interpreter's do_invoke
#54443
Conversation
Does this need a test? |
30729e9
to
b1b2857
Compare
Especially since there have been multiple pushes after the pull request was accepted, showing that (1) that version wasn't ready and (2) there are no tests making sure the code works as expected. |
The previous version did OOB indexing and so was UB. |
One possible test could try to call |
Here is an attempt to generate a test case: # segfault.jl
macro generate_test_case(n)
as = [ Symbol("a$i") for i in 1:n ]
compute = Meta.parse(join(as, '+'))
return esc(quote
@noinline function sum_54443($(as...))
return $compute
end
@noinline function wrapped_sum_54443($(as...))
return sum_54443($(as...))
end
end)
end
macro call_test_case(n)
unpack_as = [ :(as[$i]) for i in 1:n ]
return esc(quote
as = [ randn() for _ in 1:$n ]
wrapped_sum_54443($(unpack_as...))
end)
end
@generate_test_case(10)
@call_test_case(10) This generates what I think is a problematic julia> code_typed(wrapped_sum_54443, NTuple{10,Int64}; optimize=true) # note optimize=true!!
1-element Vector{Any}:
CodeInfo(
1 ─ %1 = invoke Main.sum_54443(a1::Int64, a2::Int64, a3::Int64, a4::Int64, a5::Int64, a6::Int64, a7::Int64, a8::Int64, a9::Int64, a10::Int64)::Int64
└── return %1
) => Int64 However, I have the problem that I don't even know how to call into Adding more
I am really just guessing here ... |
It actually ends up in |
According to the embedding section of the docs the @vtjnash May I ask you for another review and a decision on whether this needs a test or not? |
OOB indexing is not UB. Anyways, this version also looks fine |
In theory we would use a static analyzer type of test here, but I don't think we provide the bounds information to the analyzer right now, or if it would try to reason about the symbolic bound here if we did |
The ASAN build tests in CI also should fail if this code ever got used, but we have no tests currently written for it specifically |
Why?
Nice. So I just need to figure out how to call into |
Julia unlike C bounds-checks by default, so it's just an error, not UB. |
Access is UB, but indexing is generally valid (and, as a special case, indexing one past the last element is always considered valid) |
Thanks. Very interesting, I did not know about that. |
Deref when
That's the first I'm hearing of this; could you share the relevant section of the standard? To clarify, are you talking about something like
Note that the SO post is specifically about See also this SO post about the situation in C++. |
This fixed #54054 apparently if you want to use it as a test. |
Ah, the test checking #54054 already exists, but no one noticed it because aarch64-linux-gnu is allowed to fail (and it has been failing for way too long). |
Fix #54054