Repository navigation
Fix ICE in GVN that interns allocation containing provenance - #162463
Conversation
|
Some changes occurred to MIR optimizations cc @rust-lang/wg-mir-opt |
|
r? @folkertdev rustbot has assigned @folkertdev. Use Why was this reviewer chosen?The reviewer was selected based on:
|
This comment has been minimized.
This comment has been minimized.
|
r? mir-opt |
hmm, that means it applies less often now, even if it could apply by just interning the part of the alloc that is needed. We could create a new alloc for just the needed part and copy over that memory region. I guess that could be problematic if someone relies on the other memory lying right next to the now-copied memory. Thoughts? |
That's actually the first option came into my head, and yeah, in the situation you described, we might have to do something like track and merge allocation blocks in the global memory, which can be expensive and unnecessarily complex for a "hack" IMO. Maybe another option is to clear the provenance from the allocation before interning it, in that case we can just check the needed part. This should also avoid triggering ICE, but I am not sure if there is any subsequent phase relies on that provenance to work correctly. |
| // Due to https://github.com/rust-lang/rust/issues/128775, doing so could lead to bugs. | ||
| // FIXME: remove this hack once that issue is fixed. | ||
| let size = ecx.get_alloc_info(alloc_id).size; | ||
| let alloc_ref = ecx.get_ptr_alloc(mplace.ptr(), size).discard_err()??; |
There was a problem hiding this comment.
doesn't this mean that if there is provenance before where the pointer points, we'd still get the ICE?.
I think you'd just want to do the GlobalAlloc::Memory check below real early and then work off the alloc directly, as that's what we're going to be interning.
There was a problem hiding this comment.
doesn't this mean that if there is provenance before where the pointer points, we'd still get the ICE?.
You are right. I forgot that a pointer also contains an offset and treated it as a reference to an allocation 😅. I think this is likely the reason that failed the CI.
I think you'd just want to do the
GlobalAlloc::Memorycheck below real early
Does this mean to move the GlobalAlloc::Memory check before even the call to intern_const_alloc_for_constprop? From my understanding this won't make sense if we haven't intern the allocation into the global memory yet, and it will trigger ICE in that case. Please correct me if I misunderstand something.
There was a problem hiding this comment.
Oh right 🤦 yea, unsure how to load the entire alloc first, but there should be sth for loading it
There was a problem hiding this comment.
I think we can make a copy of the pointer inside mplace and set its offset to zero, then we can access the full allocation with the pointer copy and the allocation size by calling ecx.get_ptr_alloc().
There was a problem hiding this comment.
Hmm, maybe just add a method to Memory that checks if an alloc has any relocations. That method can access the alloc directly without exposing such a capability to everyone
There was a problem hiding this comment.
That works for me. How about add it to InterpCx so that it is directly accesible under ecx? I just took a quick glance at the current APIs and felt that such method will go there.
There was a problem hiding this comment.
If that has enough access and there are similar existing methods, then yes
|
Reminder, once the PR becomes ready for a review, use |
|
rust/compiler/rustc_const_eval/src/interpret/intern.rs Lines 359 to 364 in c26ce70 BTW, I am wondering if we shall also update the documentation of |
7c47a76 to
661aeba
Compare
This comment has been minimized.
This comment has been minimized.
|
@rustbot ready |
GVN only checked whether the portion of allocation referred by `MPlaceTy` contains provenance, but we then intern the whole allocation. This causes ICE if the unchecked part contains provenance. This commit extends the check to the whole allocation. Also, removes a check for unsized local in `try_as_evaluated_constant` which seems to duplicate with the one in `op_to_prop_const`.
We only checked the provenance for a part of the allocation that will be interned. Fixed by adding a method under `InterpCx` to check the whole allocation.
661aeba to
2cfd6c5
Compare
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
Rollup merge of #162463 - cclfmht:issue-160750, r=oli-obk Fix ICE in GVN that interns allocation containing provenance While trying to intern an allocation into the global memory, GVN only checked if the portion of the allocation referred by the `MPlaceTy` from const eval contains provenance, but then it interned the whole allocation instead of just that portion. This causes ICE if the unchecked part contains provenance, as in #160750. This PR extends the check to the whole allocation so that we won't accidentally intern an allocation with provenance. Also, the check for unsized local in `try_as_evaluated_constant` seems to be redundant with the one in `op_to_prop_const`, this PR removes it.
View all comments
While trying to intern an allocation into the global memory, GVN only checked if the portion of the allocation referred by the
MPlaceTyfrom const eval contains provenance, but then it interned the whole allocation instead of just that portion. This causes ICE if the unchecked part contains provenance, as in #160750.This PR extends the check to the whole allocation so that we won't accidentally intern an allocation with provenance.
Also, the check for unsized local in
try_as_evaluated_constantseems to be redundant with the one inop_to_prop_const, this PR removes it.