-
Notifications
You must be signed in to change notification settings - Fork 1.8k
C++: Abstractions for treating qualifiers as parameters in IR #4702
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
Conversation
CPP-difference started: https://jenkins.internal.semmle.com/job/Changes/job/CPP-Differences/1563/ |
I think we want to guide users towards using these predicates by default, which usually means giving them names that are simpler than their alternatives. Could |
…uide users to use these predicates by default.
… own implementation of getArgument already (which didn't handle qualifiers). The predicate wasn't used anywhere, so I simply removed it, as a better predicate is now available on the base class of DataFlowCall.
I think those are some excellent names! I've changed the names to match your suggestions now. I had to get rid of an unused predicate on DataFlowCall in |
CPP-difference looks good (for some reason there's a 10% reduction in build/extraction/import time on openjdk?) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! I'm happy with the names too.
final predicate hasIndex(int index) { | ||
index >= 0 and index = this.getParameter().getIndex() | ||
or | ||
index = -1 and this.isThisIndirection() | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The implementation of this predicate looks a lot like getArgumentOperand
, but only the latter has pragma[noinline]
on it. Is there a good reason to put pragma[noinline]
on one but not the other?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, no. I suspect the pragma[noinline]
is an artifact of me copy/pasting from getPositionalArgumentOperand
. I'll just double-check that I can safely remove the new pragma[noinline]
s.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm... looking at this comment you made, I'd actually feel more comfortable adding a pragma[noinline]
to the hasIndex
predicates. It doesn't seem to be necessary right now, but if it avoids a future bad join-order we might as well put it there now. Would that be reasonable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes.
Fixes https://github.com/github/codeql-c-analysis-team/issues/186.
In #3571 we made it possible to treat
this
as an argument, but there are still a couple of places where we need to distinguish between qualifiers and parameters (and betweenthis
and arguments). These places are:CallInstruction
(which has agetPositionalArgument
andgetThisArgument
predicates)getParameter
predicate, but instructions initializingthis
need to refer to theIRVariable
). The same problem also exists forReturnIndirectionInstruction
.This PR adds a new predicate for each of these scenarios:
CallInstruction
now has agetPositionalOrThisArgumentOperand
(andgetPositionalOrThisArgument
) predicates that, given an index, gives back the argumentoperand
(andinstruction
) with the given index, or when the index is-1
, gives back the operand used as the qualifier.InitializeParameterInstruction
andInitializeIndirectionInstruction
now have anisParameterOrQualifierIndex
predicate that holds if the instruction initializes a positional parameter with a given index, or initializethis
with the index-1
.Similarly,
ReturnIndirectionInstruction
has a new predicateisParameterOrThisIndirection
with similar semantics.