valueflow.cpp: avoid some copies related to ErrorPath#4160
Merged
Conversation
firewave
commented
Jun 1, 2022
| ErrorPath er = v.errorPath; | ||
| const Variable *var = getLifetimeVariable(tok2, er); | ||
| // TODO: the inserted data is never used | ||
| er.insert(er.end(), errorPath.begin(), errorPath.end()); |
Collaborator
Author
There was a problem hiding this comment.
@pfultz2
Please take a look. Seems like this is inserted the wrong way.
Would be great if we could detect this but I guess it's a variant of https://trac.cppcheck.net/ticket/4593.
Collaborator
Author
There was a problem hiding this comment.
@pfultz2 Please take a look.
Feel free to merge as well.
firewave
commented
Jun 1, 2022
| value.lifetimeScope = ValueFlow::Value::LifetimeScope::ThisValue; | ||
| value.tokvalue = tok2; | ||
| value.errorPath.push_back({tok2, "Lambda captures the 'this' variable here."}); | ||
| value.errorPath.emplace_back(tok2, "Lambda captures the 'this' variable here."); |
Collaborator
Author
There was a problem hiding this comment.
I would have expected for clang-tidy to detect this but maybe that check is still in review.
Collaborator
Author
There was a problem hiding this comment.
Turns out we have modernize-use-emplace disabled in our .clang-tidy config.
The detection of unnecessary temporary object was to clang-tidy just today: llvm/llvm-project@987f9cb
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.
Testing an
-O2build with--enable=all --inconclusiveonmame_regtestcode (with some additional local speed hacks and BoostSmallVectorapplied):Clang 13
18,349,224,671->18,347,635,685We might also be able to use
std::move()inaddErrorPath()andreanalyze().