generated from amazon-archives/__template_Apache-2.0
-
Notifications
You must be signed in to change notification settings - Fork 142
Remove slow find_by_pretty_name vtable search #193
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
Merged
danielsn
merged 6 commits into
model-checking:main-152-2021-06-07
from
avanhatt:symbol-vtable-lookup
Jun 11, 2021
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
14e74b8
Replace slower lookup by pretty name with symbol name
avanhatt 305a493
Add nonnull fn call assertion (with new utility fn)
avanhatt 5e9855a
Kill pretty_name_from_instance
avanhatt b791f08
Remove fixme from boxmuttrait test that now works
avanhatt 94dc4ff
Pipe pretty_name through Symbol::function constructor
avanhatt 37fefbf
Don't pass non-specific pretty names
avanhatt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -278,10 +278,8 @@ impl<'tcx> GotocCtx<'tcx> { | |
| return Stmt::goto(self.find_label(&target), Location::none()); | ||
| } | ||
|
|
||
| // Mutable so that we can override it in case of a virtual function call | ||
| // TODO is there a better way to do this without needing the mut? | ||
| let mut funce = self.codegen_operand(func); | ||
| if let InstanceDef::Virtual(def_id, size) = instance.def { | ||
| // Handle the case of a virtual function call via vtable lookup. | ||
| let mut stmts = if let InstanceDef::Virtual(def_id, size) = instance.def { | ||
| debug!( | ||
| "Codegen a call through a virtual function. def_id: {:?} size: {:?}", | ||
| def_id, size | ||
|
|
@@ -299,21 +297,39 @@ impl<'tcx> GotocCtx<'tcx> { | |
| let vtable_ref = trait_fat_ptr.to_owned().member("vtable", &self.symbol_table); | ||
| let vtable = vtable_ref.dereference(); | ||
| let fn_ptr = vtable.member(&vtable_field_name, &self.symbol_table); | ||
| funce = fn_ptr.dereference(); | ||
|
|
||
| //Update the argument from arg0 to arg0.data | ||
| // Update the argument from arg0 to arg0.data | ||
| fargs[0] = trait_fat_ptr.to_owned().member("data", &self.symbol_table); | ||
| } | ||
|
|
||
| // Actually generate the function call, and store the return value, if any. | ||
| Stmt::block( | ||
| // For soundness, add an assertion that the vtable function call is not null. | ||
| // Otherwise, CBMC might treat this as an assert(0) and later user-added assertions | ||
| // could be vacuously true. | ||
| let call_is_nonnull = fn_ptr.clone().is_nonnull(); | ||
| let assert_msg = | ||
| format!("Non-null virtual function call for {:?}", vtable_field_name); | ||
| let assert_nonnull = Stmt::assert(call_is_nonnull, &assert_msg, loc.clone()); | ||
|
|
||
| // Virtual function call and corresponding nonnull assertion. | ||
| let func_exp: Expr = fn_ptr.dereference(); | ||
| vec![ | ||
| self.codegen_expr_to_place(&p, funce.call(fargs)) | ||
| assert_nonnull, | ||
| self.codegen_expr_to_place(&p, func_exp.call(fargs)) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not for this PR, but |
||
| .with_location(loc.clone()), | ||
| Stmt::goto(self.find_label(&target), loc.clone()), | ||
| ], | ||
| loc, | ||
| ) | ||
| ] | ||
| } else { | ||
| // Non-virtual function call. | ||
| let func_exp = self.codegen_operand(func); | ||
| vec![ | ||
| self.codegen_expr_to_place(&p, func_exp.call(fargs)) | ||
| .with_location(loc.clone()), | ||
| ] | ||
| }; | ||
|
|
||
| // Add return jump. | ||
| stmts.push(Stmt::goto(self.find_label(&target), loc.clone())); | ||
|
|
||
| // Produce the full function call block. | ||
| Stmt::block(stmts, loc) | ||
| } | ||
| ty::FnPtr(_) => { | ||
| let (p, target) = destination.unwrap(); | ||
|
|
||
File renamed without changes.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a better pretty-name to use here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above, removing.