Skip to content
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

[clang-tidy] [dataflow] Cache reference accessors for bugprone-unchecked-optional-access #128437

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

BaLiKfromUA
Copy link
Contributor

Fixes #126283

Extending #112605 to cache const getters which return references.

This should fix false positive cases when we check optional via the chain of const getter calls.

@BaLiKfromUA
Copy link
Contributor Author

TODO: update release notes and clang-tools-extra/docs/clang-tidy/checks/bugprone/unchecked-optional-access.rst if needed

StorageLocation &Loc =
State.Lattice.getOrCreateConstMethodReturnStorageLocation(
*RecordLoc, DirectCallee, State.Env, [&](StorageLocation &Loc) {
// no-op
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure if anything should be here so decided to make it no-op for now


bool isReference =
DirectCallee->getReturnType().getTypePtr()->isReferenceType();
if (isReference) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe this check is redundant

}

TEST_P(UncheckedOptionalAccessTest,
ConstRefToOptionalSavedAsTemporaryVariable) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added this test to check that the existing workaround still works. maybe redundant test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant