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

Don't set pure for const functions [refs #12696] #6383

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

Conversation

chrchr-github
Copy link
Collaborator

No description provided.

@chrchr-github chrchr-github changed the title Don't set pure for const functions Don't set pure for const functions [refs #12696] May 4, 2024
@chrchr-github chrchr-github marked this pull request as ready for review May 4, 2024 18:26
@chrchr-github
Copy link
Collaborator Author

FWIW here's a reduced example:

class QModelIndex;

struct ResultsTree {   
    void copy();
    QStandardItemModel mModel;
    QItemSelectionModel mSelectionModel{};
};

void ResultsTree::copy()
{
    QString text;
    for (QModelIndex index : mSelectionModel.selectedRows()) {
        QStandardItem* item = mModel.itemFromIndex(index);
        if (!item->parent()) {
            text += item->text() + '\n';
            continue;
        }
    }
}

Before this change, the valueflow was

Line 14
  ! always {!<=-1,!>=2}
  item always symbolic=(mModel.itemFromIndex(index))
Line 15
  item always symbolic=(mModel.itemFromIndex(index))
  '\n' always 10

Those symbolic values disappear without pure, affecting isAliasOf() and ultimaltely isVariableChanged().

@@ -694,8 +694,7 @@ Library::Error Library::loadFunction(const tinyxml2::XMLElement * const node, co
} else if (functionnodename == "pure")
func.ispure = true;
else if (functionnodename == "const") {
func.ispure = true;
func.isconst = true; // a constant function is pure
Copy link
Owner

Choose a reason for hiding this comment

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

as I understand a const function is always pure. does valueflow assume that the function reads from global memory if it's pure?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm not sure how ValueFlow uses these attributes.
We also need to figure out what const is supposed to mean in the library, see #6385

@chrchr-github chrchr-github marked this pull request as draft May 22, 2024 09:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants