-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
False positives from invalid_reference_casting #124685
Comments
Under the memory model checked by Miri by default, a @rustbot label -regression-from-stable-to-stable -C-bug -I-prioritize +C-discussion |
Miri also agrees that the code as written contains undefined behavior, in the top right of the page select "Tools > Miri" to run and you'll see that it says that there's undefined behavior. The important bit from the error message is that the code is trying to access |
Your comment and the lint are misleading. There is no accepted memory model. And the lint message is pointing to code which does not create an allocation, so at best the lint has grabbed the wrong span. If this lint is supposed to engage in provenance-based reasoning, it would need to indicate that. Otherwise it is simply buggy. |
True, "the current" is not quite right. "The memory model currently checked by Miri by default" is perhaps a better wording for what I wanted to say, I will edit my comment. Agreed that the lint is definitely sketchy wording at best, and I'm suspicious of its implementation given the incorrect wording. |
The lint is not supposed to engage in "provenance-based reasoning", it is just supposed to peel all the reference/raw pointer casting until it finds an allocation, and then it should compare the size of type and report an error if the target is bigger than the source. Nothing else, nothing more. I tried describing the intent of the change in #118983 (comment). So as @saethlin correctly mentions it, nothing in this code creates an "allocation", so I think the lint shouldn't have fired here. (whenever there is actual UB or not is irrelevant here) |
Rollup merge of rust-lang#124761 - Urgau:ref-casting_bigger_slice_index, r=jieyouxu Fix insufficient logic when searching for the underlying allocation This PR fixes the logic inside the `invalid_reference_casting` lint, when trying to lint on bigger memory layout casts. More specifically when looking for the "underlying allocation" we were wrongly assuming that when we got `&mut slice[index]` that `slice[index]` was the allocation, but it's not. Fixes rust-lang#124685
Starting with rustc 1.78.0 (because of #118983) this produces the following
Perhaps I'm missing something but this is not undefined behavior as far as I can tell. The lint is wrong about the backing allocation and I suspect the false warning is downstream from that?
The text was updated successfully, but these errors were encountered: