-
Notifications
You must be signed in to change notification settings - Fork 11.1k
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
altera-id-dependent-backward-branch
mass false positive: all variables assigned/initialized with a variable are considered id-dependent
#52790
Comments
@ffrankies I see that you're the original author, would you mind taking a look? |
(I got here from the same stack overflow question. Hoping for a fix.) |
Bump, also came here from the so question, hoping for a quick fix |
@njames93, as the owner of I've resolved the issue and wrote some tests in a branch: https://github.com/yeputons/llvm-project/commits/fix-altera-id-dependent-backward-branch . I've also added some minor quality-of-life improvements. Although I personally don't use this check, they're hopefully useful and break no workflows. Anyway, most of them are separate commits and can be easily omitted. |
@yeputons: See https://llvm.org/docs/Phabricator.html for patch process. |
@EugeneZelenko Thank you. I will create a series of small patches then. |
For the record, here is the first batch of patches, ones related to fixing this specific issue: I suppose all further communication is to happen in that Phabricator |
…iables Mark variables/fields as ID-dependent when initializing from ID-dependent expressions only, not any expressions. Fixes llvm#52790
Inspired by this StackOverflow question.
Steps to reproduce
a.cpp
:clang-tidy-13 --checks=altera-id-dependent-backward-branch a.cpp
I'm running on Ubuntu 20.04.3 LTS:
Expected outcome
There are no warnings, except maybe "this loop is never executed".
Real outcome
Comments
This look completely unrelated to the
altera-id-dependent-backward-branch
check's docs: there is noget_local_id
or anything like this in sight.If I remove the
x = y
assignment, the warning goes away.There is also no note on why exactly
x
is considered id-dependent, while there should be one. Maybe I need some extra flags or it's a separate issue?Probable cause
I'm not familiar with LLVM's source code, but it seems to me that the bug is in
saveIdDepVarFromReference
at the very least: it saves all potentially id-dependent variables inIdDepVarsMap
regardless of whether the right-hand side of the assignment/initialization is id-dependent itself. Looks like some early returns are missing. Similar bug probably happens insaveIdDepFieldFromReference
as well.More high-level picture is as follows:
IdDepVar
is found in theIdDepVarsMap
map.x
is marked as id-dependent by one ofIdDependentBackwardBranchCheck::saveIdDep*
methods from here (they're the only place modifyingIdDepVarsMap
).if
s. In particular, if there is aPotentialVar
(pot_tid_var
match) andRefExpr
(assign_ref_var
match),saveIdDepVarFromReference
is called.pot_tid_var
matches either a variable initialized from a variable or a field (because the latter may be id-dependent) or a similar assignment. In both cases, eitherassign_ref_var
orassign_ref_field
is matches as well viaRefVarOrField
depending on whether the initializer is a variable or a field.saveIdDepVarFromReference
is called on thex = y
assignment as well withassign_ref_var = y
andpot_tid_var = x
.saveIdDepVarFromReference
checks that the right hand side is inIdDepFieldsMap
, it does not do anything to with knowledge and assumes thatPotentialVar
is always id-dependent.Btw, here is a code review
Suggested fix
saveIdDepVarFromReference
ifRefVar
/RefField
(there should be only one, an assertion would be nice to have) is not found inIdDepVarsMap
.saveIdDepVarFromReference
andsaveIdDepFieldFromReference
to something likepotentiallySaveIdDepVarFromReference
to highlight that it performs some checks itself. It's easy to assume that the variable is already established to be id-dependent while reviewingsaveIdDepVarFromReference
.PotentialVar
andpot_tid_var
to something likePossiblyIdDependentVar
/possibly_iddep_var
to highlight that it's not necessary id-dependent even more.PotentialVar
is more open to interpretation and the erroneoussaveIdDepVarFromReference(RefExpr, MemExpr, PotentialVar);
line does not immediately stand out as "save only a possible id dependent variable as really id-dependent". However, I'm not sure if that would really help, as the line is already inside some if-statement which looks somewhat reasonable.The text was updated successfully, but these errors were encountered: