Skip to content

Commit cb4f10c

Browse files
committed
C++: Move the union field check to the IPA branch of 'TFieldContent'.
1 parent 8a569da commit cb4f10c

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/DataFlowPrivate.qll

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,6 @@ predicate jumpStep(Node n1, Node n2) { none() }
189189
*/
190190
predicate storeStep(StoreNode node1, FieldContent f, StoreNode node2) {
191191
exists(FieldAddressInstruction fai |
192-
not fai.getObjectAddress().getResultType().stripType() instanceof Union and
193192
node1.getInstruction() = fai and
194193
node2.getInstruction() = fai.getObjectAddress() and
195194
f.getField() = fai.getField()
@@ -203,7 +202,6 @@ predicate storeStep(StoreNode node1, FieldContent f, StoreNode node2) {
203202
*/
204203
predicate readStep(ReadNode node1, FieldContent f, ReadNode node2) {
205204
exists(FieldAddressInstruction fai |
206-
not fai.getObjectAddress().getResultType().stripType() instanceof Union and
207205
node1.getInstruction() = fai.getObjectAddress() and
208206
node2.getInstruction() = fai and
209207
f.getField() = fai.getField()

cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/DataFlowUtil.qll

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -972,7 +972,11 @@ predicate localInstructionFlow(Instruction e1, Instruction e2) {
972972
predicate localExprFlow(Expr e1, Expr e2) { localFlow(exprNode(e1), exprNode(e2)) }
973973

974974
private newtype TContent =
975-
TFieldContent(Field f) or
975+
TFieldContent(Field f) {
976+
// As reads and writes to union fields can create flow even though the reads and writes
977+
// target different fields, we don't want a read (write) to create a read (write) step.
978+
not f.getDeclaringType() instanceof Union
979+
} or
976980
TCollectionContent() or // Not used in C/C++
977981
TArrayContent() // Not used in C/C++.
978982

cpp/ql/test/library-tests/syntax-zoo/dataflow-ir-consistency.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1959,6 +1959,7 @@ postWithInFlow
19591959
| ir.cpp:522:9:522:10 | VariableAddress [post update] | PostUpdateNode should not be the target of local flow. |
19601960
| ir.cpp:522:16:522:21 | PointerAdd [post update] | PostUpdateNode should not be the target of local flow. |
19611961
| ir.cpp:522:16:522:21 | PointerAdd [post update] | PostUpdateNode should not be the target of local flow. |
1962+
| ir.cpp:531:7:531:8 | VariableAddress [post update] | PostUpdateNode should not be the target of local flow. |
19621963
| ir.cpp:531:11:531:16 | FieldAddress [post update] | PostUpdateNode should not be the target of local flow. |
19631964
| ir.cpp:540:5:540:5 | y [post update] | PostUpdateNode should not be the target of local flow. |
19641965
| ir.cpp:545:9:545:17 | VariableAddress [post update] | PostUpdateNode should not be the target of local flow. |

0 commit comments

Comments
 (0)