Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5014432

Browse files
committed
CPP: Tests: Add a test of NewArrayExpr.getAllocatedType() and NewArrayExpr.getExtent().
1 parent d6cbc67 commit 5014432

3 files changed

Lines changed: 25 additions & 13 deletions

File tree

cpp/ql/test/library-tests/allocators/allocators.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,3 +137,9 @@ int overloadedNew() {
137137

138138
return five;
139139
}
140+
141+
void multidimensionalNew(int x, int y) {
142+
auto p1 = new char[x][10];
143+
auto p2 = new char[20][20];
144+
auto p3 = new char[x][30][30];
145+
}

cpp/ql/test/library-tests/allocators/allocators.expected

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,18 @@ newExprs
1111
| allocators.cpp:129:3:129:21 | new | int | operator new(size_t, void *) -> void * | 4 | 4 | |
1212
| allocators.cpp:135:3:135:26 | new | int | operator new(size_t, const nothrow_t &) -> void * | 4 | 4 | |
1313
newArrayExprs
14-
| allocators.cpp:68:3:68:12 | new[] | int | operator new[](unsigned long) -> void * | 4 | 4 | |
15-
| allocators.cpp:69:3:69:18 | new[] | int | operator new[](size_t, float) -> void * | 4 | 4 | |
16-
| allocators.cpp:70:3:70:15 | new[] | String | operator new[](unsigned long) -> void * | 8 | 8 | |
17-
| allocators.cpp:71:3:71:20 | new[] | Overaligned | operator new[](unsigned long, align_val_t) -> void * | 256 | 128 | aligned |
18-
| allocators.cpp:72:3:72:16 | new[] | String | operator new[](unsigned long) -> void * | 8 | 8 | |
19-
| allocators.cpp:108:3:108:19 | new[] | FailedInit | FailedInit::operator new[](size_t) -> void * | 1 | 1 | |
20-
| allocators.cpp:110:3:110:37 | new[] | FailedInitOveraligned | FailedInitOveraligned::operator new[](size_t, align_val_t, float) -> void * | 128 | 128 | aligned |
21-
| allocators.cpp:132:3:132:17 | new[] | int | operator new[](size_t, void *) -> void * | 4 | 4 | |
22-
| allocators.cpp:136:3:136:26 | new[] | int | operator new[](size_t, const nothrow_t &) -> void * | 4 | 4 | |
14+
| allocators.cpp:68:3:68:12 | new[] | int[] | int | operator new[](unsigned long) -> void * | 4 | 4 | | n |
15+
| allocators.cpp:69:3:69:18 | new[] | int[] | int | operator new[](size_t, float) -> void * | 4 | 4 | | n |
16+
| allocators.cpp:70:3:70:15 | new[] | String[] | String | operator new[](unsigned long) -> void * | 8 | 8 | | n |
17+
| allocators.cpp:71:3:71:20 | new[] | Overaligned[] | Overaligned | operator new[](unsigned long, align_val_t) -> void * | 256 | 128 | aligned | n |
18+
| allocators.cpp:72:3:72:16 | new[] | String[10] | String | operator new[](unsigned long) -> void * | 8 | 8 | | |
19+
| allocators.cpp:108:3:108:19 | new[] | FailedInit[] | FailedInit | FailedInit::operator new[](size_t) -> void * | 1 | 1 | | n |
20+
| allocators.cpp:110:3:110:37 | new[] | FailedInitOveraligned[10] | FailedInitOveraligned | FailedInitOveraligned::operator new[](size_t, align_val_t, float) -> void * | 128 | 128 | aligned | |
21+
| allocators.cpp:132:3:132:17 | new[] | int[1] | int | operator new[](size_t, void *) -> void * | 4 | 4 | | |
22+
| allocators.cpp:136:3:136:26 | new[] | int[2] | int | operator new[](size_t, const nothrow_t &) -> void * | 4 | 4 | | |
23+
| allocators.cpp:142:13:142:27 | new[] | char[][10] | char[10] | operator new[](unsigned long) -> void * | 10 | 1 | | x |
24+
| allocators.cpp:143:13:143:28 | new[] | char[20][20] | char[20] | operator new[](unsigned long) -> void * | 20 | 1 | | |
25+
| allocators.cpp:144:13:144:31 | new[] | char[][30][30] | char[30][30] | operator new[](unsigned long) -> void * | 900 | 1 | | x |
2326
newExprDeallocators
2427
| allocators.cpp:52:3:52:14 | new | String | operator delete(void *, unsigned long) -> void | 8 | 8 | sized |
2528
| allocators.cpp:53:3:53:27 | new | String | operator delete(void *, float) -> void | 8 | 8 | |

cpp/ql/test/library-tests/allocators/allocators.ql

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,19 @@ query predicate newExprs(NewExpr expr, string type, string sig, int size, int al
1313
}
1414

1515
query predicate newArrayExprs(
16-
NewArrayExpr expr, string type, string sig, int size, int alignment, string form
16+
NewArrayExpr expr, string t1, string t2, string sig, int size, int alignment, string form, string extents
1717
) {
18-
exists(Function allocator, Type elementType |
18+
exists(Function allocator, Type arrayType, Type elementType |
1919
expr.getAllocator() = allocator and
2020
sig = allocator.getFullSignature() and
21+
arrayType = expr.getAllocatedType() and
22+
t1 = arrayType.toString() and
2123
elementType = expr.getAllocatedElementType() and
22-
type = elementType.toString() and
24+
t2 = elementType.toString() and
2325
size = elementType.getSize() and
2426
alignment = elementType.getAlignment() and
25-
if expr.hasAlignedAllocation() then form = "aligned" else form = ""
27+
if expr.hasAlignedAllocation() then form = "aligned" else form = "" and
28+
extents = concat(Expr e | e = expr.getExtent() | e.toString(), ", ")
2629
)
2730
}
2831

0 commit comments

Comments
 (0)