-
Notifications
You must be signed in to change notification settings - Fork 1.7k
C++: fix typedef resolution in ArrayType
#19805
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
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.
Pull Request Overview
This PR ensures that ArrayType
typedefs are correctly resolved by overriding its resolveTypedefs
predicate, updates corresponding tests, and adds a change note.
- Override
resolveTypedefs
inArrayType
to return a correctly resolved base type and size. - Add a CodeQL test (
ArrayTypedefs.ql
) and update expected outputs to cover array typedef resolution. - Record the behavior change in a change-note.
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
Show a summary per file
File | Description |
---|---|
cpp/ql/lib/semmle/code/cpp/Type.qll | Added resolveTypedefs override in ArrayType to fix typedef resolution. |
cpp/ql/test/library-tests/typedefs/ArrayTypedefs.ql | New query selecting ArrayType with resolved typedefs. |
cpp/ql/test/library-tests/typedefs/ArrayTypedefs.expected | Updated expected results for array typedef resolution. |
cpp/ql/test/library-tests/typedefs/Typedefs1.expected | Extended expected output to include array typedefs in simple cases. |
cpp/ql/test/library-tests/typedefs/Typedefs3.expected | Added entries for int_t and float_t resolutions in existing tests. |
cpp/ql/lib/change-notes/2025-06-17-arraytype-typedefs.md | Documented the fix for ArrayType typedef resolution. |
Comments suppressed due to low confidence (1)
cpp/ql/lib/semmle/code/cpp/Type.qll:1593
- The override for
resolveTypedefs
inArrayType
sets only the base type and array size but does not propagate qualifiers (e.g.,const
/volatile
) or the VLA flag. Consider invokingsuper.resolveTypedefs()
or explicitly copying qualifiers andisVla()
to ensure all modifiers are retained.
override Type resolveTypedefs() {
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.
Two small comments, otherwise LGTM
typedef int int_t; | ||
int_t g1[10]; | ||
int_t g2[2][4]; | ||
|
||
typedef float float_t; | ||
float_t arr1[5]; | ||
float_t (*a_pointer)[10]; |
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 would prefer if we move this test to its own directory, as it's testing resolveTypedefs
and not typedefs per se. Given that we don't have any tests for resolveTypedefs
, I would just use that for the directory name, so we can add other kinds of resolveTypedefs
tests in the future.
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.
Good point! Thank you. I saw different naming conventions for test folders, and I opted for snake_case, as it seems to be the most commonly used.
c220844
to
72559d5
Compare
This PR fixes typedef resolution for
ArrayType
by overriding theresolveTypedefs
predicate to correctly resolve typedefs.The new tests use
type.getATypeNameUse()
to restrict output to type names explicitly present in the test source. Without this, the output would include duplicated lines for eachArrayType
encountered, such asint[10]
, increasing test output size unnecessarily and making it "hard" to debug.The PR includes a change note.