Avoid spurious clone emission for (void)-discarded function pointer casts in refcount model#289
Open
nunoplopes with Copilot wants to merge 5 commits into
Open
Avoid spurious clone emission for (void)-discarded function pointer casts in refcount model#289nunoplopes with Copilot wants to merge 5 commits into
(void)-discarded function pointer casts in refcount model#289nunoplopes with Copilot wants to merge 5 commits into
Conversation
Copilot
AI
changed the title
[WIP] Fix spurious clone for cast'ed function pointers
Avoid spurious clone emission for Jul 25, 2026
(void)-discarded function pointer casts in refcount model
…-cast no-clone fix
nunoplopes
marked this pull request as ready for review
July 25, 2026 20:37
lucic71
reviewed
Jul 25, 2026
| // Variable references to fn-ptrs still need .clone() because FnPtr is | ||
| // non-Copy and (*var.borrow()) would otherwise attempt a move. | ||
| auto *inner = expr->getSubExpr()->IgnoreParenImpCasts(); | ||
| bool is_fn_ptr_var_ref = clang::isa<clang::DeclRefExpr>(inner) && |
Contributor
There was a problem hiding this comment.
I think this entire check is focusing only on DeclRefExpr, while missing other AST shapes
The correct solution is probably to do computed_expr_type_ = ComputedExprType::FreshPointer in ConvertFunctionToFunctionPointer
Then the check in VisitExplicitCastExpr becomes: !TypeIsCopyable(sub->getType()) && !isFresh()
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.
(void)-discarded expressions involving casted function pointers were translated with an unnecessary.clone()in refcount output (e.g.(void)(static_cast<int (*)()>(&f))). This change removes that extra clone while preserving discard semantics.Refcount converter: void-cast emission
ConverterRefCount::VisitExplicitCastExprto keep existing clone behavior for non-copyable discarded expressions, but skip clone when the discarded subexpression type is a function pointer.(void)cast handling only.Golden output update (unit regression coverage)
tests/unit/out/refcount/void_cast.rsexpected output to remove clone emission for discarded function-pointer expressions and discarded casted function-pointer expressions.Before/after behavior