Skip to content

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

Merged
merged 6 commits into from
Jun 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions cpp/ql/lib/change-notes/2025-06-17-arraytype-typedefs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
category: fix
---
* `resolveTypedefs` now properly resolves typedefs for `ArrayType`s.
5 changes: 5 additions & 0 deletions cpp/ql/lib/semmle/code/cpp/Type.qll
Original file line number Diff line number Diff line change
Expand Up @@ -1589,6 +1589,11 @@ class ArrayType extends DerivedType {
* Holds if this array is a variable-length array (VLA).
*/
predicate isVla() { type_is_vla(underlyingElement(this)) }

override Type resolveTypedefs() {
result.(ArrayType).getBaseType() = this.getBaseType().resolveTypedefs() and
result.(ArrayType).getArraySize() = this.getArraySize()
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
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];
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
| file://:0:0:0:0 | float_t[5] | file://:0:0:0:0 | float[5] | ArrayTypedefs.cpp:6:9:6:12 | definition of arr1 |
| file://:0:0:0:0 | float_t[10] | file://:0:0:0:0 | float[10] | ArrayTypedefs.cpp:7:11:7:19 | definition of a_pointer |
| file://:0:0:0:0 | int_t[2][4] | file://:0:0:0:0 | int[2][4] | ArrayTypedefs.cpp:3:7:3:8 | definition of g2 |
| file://:0:0:0:0 | int_t[4] | file://:0:0:0:0 | int[4] | ArrayTypedefs.cpp:3:7:3:8 | definition of g2 |
| file://:0:0:0:0 | int_t[10] | file://:0:0:0:0 | int[10] | ArrayTypedefs.cpp:2:7:2:8 | definition of g1 |
4 changes: 4 additions & 0 deletions cpp/ql/test/library-tests/resolve_typedefs/ArrayTypedefs.ql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import cpp

from ArrayType type
select type, type.resolveTypedefs(), type.getATypeNameUse()