-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
C++: Resolve typedef
s when matching MaD parameters
#18386
base: main
Are you sure you want to change the base?
Conversation
…d-write' by about 8%.
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.
Copilot wasn't able to review any files in this pull request.
Files not reviewed (6)
- cpp/ql/lib/semmle/code/cpp/dataflow/ExternalFlow.qll: Language not supported
- cpp/ql/test/library-tests/dataflow/models-as-data/FlowSummaryNode.expected: Language not supported
- cpp/ql/test/library-tests/dataflow/models-as-data/SummaryCall.expected: Language not supported
- cpp/ql/test/library-tests/dataflow/models-as-data/testModels.qll: Language not supported
- cpp/ql/test/library-tests/dataflow/models-as-data/tests.cpp: Language not supported
- cpp/ql/test/library-tests/dataflow/taint-tests/test_mad-signatures.expected: Language not supported
Tip: Copilot only keeps its highest confidence comments to reduce noise and keep you focused. Learn more
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.
LGTM, some very minor corrections.
} | ||
|
||
/** | ||
* Returns `s` prefixed with appropriate speciiers from `t`, or `s` if `t` has |
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.
* Returns `s` prefixed with appropriate speciiers from `t`, or `s` if `t` has | |
* Returns `s` prefixed with appropriate specifiers from `t`, or `s` if `t` has |
} | ||
|
||
/** | ||
* Gets the string version of `t`. The boolean `needsSpace` is `true` |
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.
I think we can be a bit more precise here.
* Gets the string version of `t`. The boolean `needsSpace` is `true` | |
* Gets the string version of `t`, after resolving typedefs. The boolean `needsSpace` is `true` |
) | ||
or | ||
not t instanceof DerivedType and | ||
not t instanceof TypedefType and |
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.
I'm trying to convince myself ArrayType
doesn't need to be a special case here. Because getName
already handles it adequately???
exists(string s, string base, string specifiers, Type t | | ||
t = f.getParameter(n).getType() and | ||
// The name of the string can either be the possibly typedefed name | ||
// or an alternartive name where typedefs has been resolved. |
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.
// or an alternartive name where typedefs has been resolved. | |
// or an alternative name where typedefs has been resolved. |
// The name of the string can either be the possibly typedefed name | ||
// or an alternartive name where typedefs has been resolved. | ||
// `getTypeName(t, _)` is almost equal to `t.resolveTypedefs().getName()`, | ||
// except that `t.resolveTypedefs()` doesn't have a result when the |
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.
// except that `t.resolveTypedefs()` doesn't have a result when the | |
// except that `t.resolveTypedefs()` doesn't have a result when the |
The various implementations of the STL differ on the exact name of the types of some of the parameters. For example, some implementations specify
std::vector::insert
as:while others do this instead:
these are completely identical since containers are required to declare
value_type
as a synonym forT
. However, until this PR we would match the parameter type name against whatever type name is specified. With the current MaD models, this meant we only matched against the implementations that pickedconst T&
, but not the ones that pickedconst value_type&
.This PR fixes this by allowing both the unresolved and the typedef-resolved type name. This ensures that we can continue to use the typedef'ed name when it's convenient (for example, when a parameter must have type
size_type
which is platform dependent).Our
Type
class actually comes with a perfectly reasonable predicate for resolving typedefs while retaining whatever specifiers are attached to the type:codeql/cpp/ql/lib/semmle/code/cpp/Type.qll
Lines 279 to 284 in f23e56b
Commit-by-commit review recommended: