Treat pointer and Box locals of function items as ordinary variables - #4892
Open
srivatsansamraj wants to merge 1 commit into
Open
srivatsansamraj wants to merge 1 commit into
srivatsansamraj wants to merge 1 commit into
Conversation
codegen_local_fndef replaced a local of type *const FnDef, *mut FnDef or Box<FnDef> with &f::FnDefSingleton, or a Box literal around it. A pointer holds whatever was assigned to it, so reads ignored the stored value, writes assigned to a non-lvalue (model-checking#4857, model-checking#1257), and naming the singleton needed a function symbol that reachability had not declared (model-checking#2255). Keep only the FnDef arm, which is zero-sized, and delete box_value, whose only caller was the Box arm.
Contributor
Author
|
@CYJ904 @Tianshu-Huang @wodex1nhaoIeng @acearyanarun for review. In Kani, a function item ( This PR removes the shortcut for pointers and boxes, so they are ordinary variables. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
codegen_local_fndefreplaced a local whose type is a raw pointer to a function item, or aBoxof one, with a fixed expression:&f::FnDefSingleton, or aBoxliteral around it. That is only right for the function item itself, which is zero-sized, so all its values are the same. A pointer holds whatever was assigned to it. The substitution caused three failures:Function should've been declared before usage, was:Can't take address of Expr#2255: building&f::FnDefSingletonneedsf's symbol, which reachability does not declare whenfis only pointed to ({:p}of&foo), so codegen panics atoperand.rs:697.Box<dyn Fn>: l2_rename_rvalues case address_of not handled #4857 and Kani fails withl2_rename_values casestruct' not handled` #1257: a write to such a local assigns to&f::FnDefSingletonor to a struct literal, neither of which is an lvalue, and CBMC stops withl2_rename_rvalues case `address_of' not handled.*const Fto a function item reads as non-null and an assertion that it is non-null verifies.This keeps only the
FnDefarm, so pointer andBoxlocals of function items are ordinary variables, and deletesbox_value, whose only caller was theBoxarm.The new test
FunctionSymbols/fn_item_address.rscovers the #2255 program, the value of a pointer to a function item, and ashould_panicharness that fails if a null one reads as non-null.DynTrait/boxed_fn_item.rsdrops--only-codegenand now verifies. The programs from #4857 and #1257 verify, and variants with a wrong expected value fail. Calls throughBox<dyn Fn>,Box<dyn FnMut>andBox<dyn FnOnce>of a function item, and reads and calls through a dangling pointer to one, verify. Thekaniandexpectedsuites pass, apart from twoQuantifierstests that fail the same way onmainon this machine.This replaces #4860.
Resolves #2255
Resolves #4857
Resolves #1257
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.