Skip to content

Commit 2024f32

Browse files
committed
C++: Add an example with missing flow.
1 parent 47ab307 commit 2024f32

File tree

5 files changed

+39
-0
lines changed

5 files changed

+39
-0
lines changed

cpp/ql/test/library-tests/dataflow/fields/dataflow-consistency.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ postWithInFlow
142142
| simple.cpp:92:7:92:7 | i [post update] | PostUpdateNode should not be the target of local flow. |
143143
| simple.cpp:118:7:118:7 | i [post update] | PostUpdateNode should not be the target of local flow. |
144144
| simple.cpp:124:5:124:6 | * ... [post update] | PostUpdateNode should not be the target of local flow. |
145+
| simple.cpp:167:9:167:9 | x [post update] | PostUpdateNode should not be the target of local flow. |
145146
viableImplInCallContextTooLarge
146147
uniqueParameterNodeAtPosition
147148
uniqueParameterNodePosition

cpp/ql/test/library-tests/dataflow/fields/partial-definition-diff.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,3 +308,5 @@ WARNING: module 'DataFlow' has been deprecated and may be removed in future (par
308308
| simple.cpp:124:5:124:6 | * ... | AST only |
309309
| simple.cpp:131:14:131:14 | a | IR only |
310310
| simple.cpp:136:10:136:10 | a | IR only |
311+
| simple.cpp:167:9:167:9 | x | AST only |
312+
| simple.cpp:168:8:168:12 | u_int | IR only |

cpp/ql/test/library-tests/dataflow/fields/partial-definition-ir.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -670,6 +670,8 @@
670670
| simple.cpp:131:14:131:14 | a |
671671
| simple.cpp:135:20:135:20 | q |
672672
| simple.cpp:136:10:136:10 | a |
673+
| simple.cpp:167:3:167:7 | u_int |
674+
| simple.cpp:168:8:168:12 | u_int |
673675
| struct_init.c:15:8:15:9 | ab |
674676
| struct_init.c:15:12:15:12 | a |
675677
| struct_init.c:16:8:16:9 | ab |

cpp/ql/test/library-tests/dataflow/fields/partial-definition.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,8 @@ WARNING: module 'DataFlow' has been deprecated and may be removed in future (par
597597
| simple.cpp:118:7:118:7 | i |
598598
| simple.cpp:124:5:124:6 | * ... |
599599
| simple.cpp:135:20:135:20 | q |
600+
| simple.cpp:167:3:167:7 | u_int |
601+
| simple.cpp:167:9:167:9 | x |
600602
| struct_init.c:15:8:15:9 | ab |
601603
| struct_init.c:15:12:15:12 | a |
602604
| struct_init.c:16:8:16:9 | ab |

cpp/ql/test/library-tests/dataflow/fields/simple.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,4 +136,36 @@ void alias_with_fields(bool b) {
136136
sink(a.i); // $ MISSING: ast,ir
137137
}
138138

139+
template<typename T>
140+
union U_with_two_instantiations_of_different_size {
141+
int x;
142+
T y;
143+
};
144+
145+
struct LargeStruct {
146+
int data[64];
147+
};
148+
149+
void test_union_with_two_instantiations_of_different_sizes() {
150+
// A union's fields is partitioned into "chunks" for field-flow in order to
151+
// improve performance (so that a write to a field of a union does not flow
152+
// to too many reads that don't happen at runtime). The partitioning is based
153+
// the size of the types in the union. So a write to a field of size k only
154+
// flows to a read of size k.
155+
// Since field-flow is based on uninstantiated types a field can have
156+
// multiple sizes if the union is instantiated with types of
157+
// different sizes. So to compute the partition we pick the maximum size.
158+
// Because of this there are `Content`s corresponding to the union
159+
// `U_with_two_instantiations_of_different_size<T>`: The one for size
160+
// `sizeof(int)`, and the one for size `sizeof(LargeStruct)` (because
161+
// `LargeStruct` is larger than `int`). So the write to `x` writes to the
162+
// `Content` for size `sizeof(int)`, and the read of `y` reads from the
163+
// `Content` for size `sizeof(LargeStruct)`.
164+
U_with_two_instantiations_of_different_size<int> u_int;
165+
U_with_two_instantiations_of_different_size<LargeStruct> u_very_large;
166+
167+
u_int.x = user_input();
168+
sink(u_int.y); // $ MISSING: ir
169+
}
170+
139171
} // namespace Simple

0 commit comments

Comments
 (0)