Skip to content

Commit 0cb7d4c

Browse files
committed
C++: Add an explicit test of AllocationFunction and AllocationExpr.
1 parent b634b59 commit 0cb7d4c

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,28 @@ deleteArrayExprs
4646
| allocators.cpp:81:3:81:45 | delete[] | Overaligned | operator delete[](void *, unsigned long, align_val_t) -> void | 256 | 128 | sized aligned |
4747
| allocators.cpp:82:3:82:49 | delete[] | PolymorphicBase | operator delete[](void *, unsigned long) -> void | 8 | 8 | sized |
4848
| allocators.cpp:83:3:83:23 | delete[] | int | operator delete[](void *, unsigned long) -> void | 4 | 4 | sized |
49+
allocationFunctions
50+
allocationExprs
51+
| allocators.cpp:49:3:49:9 | new | getSizeBytes = 4, requiresDealloc |
52+
| allocators.cpp:50:3:50:15 | new | getSizeBytes = 4, requiresDealloc |
53+
| allocators.cpp:51:3:51:11 | new | getSizeBytes = 4, requiresDealloc |
54+
| allocators.cpp:52:3:52:14 | new | getSizeBytes = 8, requiresDealloc |
55+
| allocators.cpp:53:3:53:27 | new | getSizeBytes = 8, requiresDealloc |
56+
| allocators.cpp:54:3:54:17 | new | getSizeBytes = 256, requiresDealloc |
57+
| allocators.cpp:55:3:55:25 | new | getSizeBytes = 256, requiresDealloc |
58+
| allocators.cpp:68:3:68:12 | new[] | getSizeExpr = n, getSizeMult = 4, requiresDealloc |
59+
| allocators.cpp:69:3:69:18 | new[] | getSizeExpr = n, getSizeMult = 4, requiresDealloc |
60+
| allocators.cpp:70:3:70:15 | new[] | getSizeExpr = n, getSizeMult = 8, requiresDealloc |
61+
| allocators.cpp:71:3:71:20 | new[] | getSizeExpr = n, getSizeMult = 256, requiresDealloc |
62+
| allocators.cpp:72:3:72:16 | new[] | getSizeBytes = 80, requiresDealloc |
63+
| allocators.cpp:107:3:107:18 | new | getSizeBytes = 1, requiresDealloc |
64+
| allocators.cpp:108:3:108:19 | new[] | getSizeExpr = n, getSizeMult = 1, requiresDealloc |
65+
| allocators.cpp:109:3:109:35 | new | getSizeBytes = 128, requiresDealloc |
66+
| allocators.cpp:110:3:110:37 | new[] | getSizeBytes = 1280, requiresDealloc |
67+
| allocators.cpp:129:3:129:21 | new | getSizeBytes = 4 |
68+
| allocators.cpp:132:3:132:17 | new[] | getSizeBytes = 4 |
69+
| allocators.cpp:135:3:135:26 | new | getSizeBytes = 4, requiresDealloc |
70+
| allocators.cpp:136:3:136:26 | new[] | getSizeBytes = 8, requiresDealloc |
71+
| allocators.cpp:142:13:142:27 | new[] | getSizeExpr = x, getSizeMult = 10, requiresDealloc |
72+
| allocators.cpp:143:13:143:28 | new[] | getSizeBytes = 400, requiresDealloc |
73+
| allocators.cpp:144:13:144:31 | new[] | getSizeExpr = x, getSizeMult = 900, requiresDealloc |

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

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,39 @@ query predicate deleteArrayExprs(
103103
)
104104
)
105105
}
106+
107+
string describeAllocationFunction(AllocationFunction f) {
108+
result = "getSizeArg = " + f.getSizeArg().toString()
109+
or
110+
result = "getSizeMult = " + f.getSizeMult().toString()
111+
or
112+
result = "getReallocPtrArg = " + f.getReallocPtrArg().toString()
113+
or
114+
(
115+
f.requiresDealloc() and
116+
result = "requiresDealloc"
117+
)
118+
}
119+
120+
query predicate allocationFunctions(AllocationFunction f, string descr) {
121+
descr = concat(describeAllocationFunction(f), ", ")
122+
}
123+
124+
string describeAllocationExpr(AllocationExpr e) {
125+
result = "getSizeExpr = " + e.getSizeExpr().toString()
126+
or
127+
result = "getSizeMult = " + e.getSizeMult().toString()
128+
or
129+
result = "getSizeBytes = " + e.getSizeBytes().toString()
130+
or
131+
result = "getReallocPtr = " + e.getReallocPtr().toString()
132+
or
133+
(
134+
e.requiresDealloc() and
135+
result = "requiresDealloc"
136+
)
137+
}
138+
139+
query predicate allocationExprs(AllocationExpr e, string descr) {
140+
descr = concat(describeAllocationExpr(e), ", ")
141+
}

0 commit comments

Comments
 (0)