Merge pull request #19805 from github/idrissrio/namespace-attributes

C++: fix typedef resolution in `ArrayType`
This commit is contained in:
Idriss Riouak
2025-06-18 10:21:21 +02:00
committed by GitHub
5 changed files with 25 additions and 0 deletions

View File

@@ -0,0 +1,4 @@
---
category: fix
---
* `resolveTypedefs` now properly resolves typedefs for `ArrayType`s.

View File

@@ -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()
}
}
/**

View File

@@ -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];

View File

@@ -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 |

View File

@@ -0,0 +1,4 @@
import cpp
from ArrayType type
select type, type.resolveTypedefs(), type.getATypeNameUse()