Skip to content

Commit a45a6e4

Browse files
committed
C++: remove side effect operands from non-reads
1 parent 9f20cb8 commit a45a6e4

File tree

10 files changed

+104
-96
lines changed

10 files changed

+104
-96
lines changed

cpp/ql/src/semmle/code/cpp/ir/implementation/aliased_ssa/Instruction.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ module InstructionSanity {
4848
or
4949
(
5050
opcode instanceof ReadSideEffectOpcode or
51-
opcode instanceof MayWriteSideEffectOpcode or
52-
opcode instanceof Opcode::InlineAsm
51+
opcode instanceof Opcode::InlineAsm or
52+
opcode instanceof Opcode::CallSideEffect
5353
) and
5454
tag instanceof SideEffectOperandTag
5555
)

cpp/ql/src/semmle/code/cpp/ir/implementation/raw/Instruction.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ module InstructionSanity {
4848
or
4949
(
5050
opcode instanceof ReadSideEffectOpcode or
51-
opcode instanceof MayWriteSideEffectOpcode or
52-
opcode instanceof Opcode::InlineAsm
51+
opcode instanceof Opcode::InlineAsm or
52+
opcode instanceof Opcode::CallSideEffect
5353
) and
5454
tag instanceof SideEffectOperandTag
5555
)

cpp/ql/src/semmle/code/cpp/ir/implementation/raw/internal/TranslatedCall.qll

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -449,12 +449,7 @@ class TranslatedSideEffect extends TranslatedElement, TTranslatedArgumentSideEff
449449
or
450450
tag instanceof OnlyInstructionTag and
451451
operandTag instanceof SideEffectOperandTag and
452-
not call.getTarget().(SideEffectFunction).hasSpecificWriteSideEffect(index, _, true) and
453-
result = getEnclosingFunction().getUnmodeledDefinitionInstruction()
454-
or
455-
tag instanceof OnlyInstructionTag and
456-
operandTag instanceof SideEffectOperandTag and
457-
call.getTarget().(SideEffectFunction).hasSpecificReadSideEffect(index, _) and
452+
not isWrite() and
458453
result = getEnclosingFunction().getUnmodeledDefinitionInstruction()
459454
or
460455
tag instanceof OnlyInstructionTag and

cpp/ql/src/semmle/code/cpp/ir/implementation/unaliased_ssa/Instruction.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ module InstructionSanity {
4848
or
4949
(
5050
opcode instanceof ReadSideEffectOpcode or
51-
opcode instanceof MayWriteSideEffectOpcode or
52-
opcode instanceof Opcode::InlineAsm
51+
opcode instanceof Opcode::InlineAsm or
52+
opcode instanceof Opcode::CallSideEffect
5353
) and
5454
tag instanceof SideEffectOperandTag
5555
)

cpp/ql/test/library-tests/ir/ir/raw_ir.expected

Lines changed: 77 additions & 77 deletions
Large diffs are not rendered by default.

cpp/ql/test/library-tests/ir/ssa/aliased_ssa_ir.expected

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ ssa.cpp:
328328
# 97| m0_14(unknown) = ^CallSideEffect : ~m0_5
329329
# 97| m0_15(unknown) = Chi : total:m0_5, partial:m0_14
330330
# 97| v0_16(void) = ^IndirectReadSideEffect[0] : &:r0_12, ~m0_15
331-
# 97| m0_17(unknown) = ^BufferMayWriteSideEffect[0] : &:r0_12, ~m0_15
331+
# 97| m0_17(unknown) = ^BufferMayWriteSideEffect[0] : &:r0_12
332332
# 97| m0_18(unknown) = Chi : total:m0_15, partial:m0_17
333333
# 98| v0_19(void) = NoOp :
334334
# 95| v0_20(void) = ReturnVoid :
@@ -382,7 +382,7 @@ ssa.cpp:
382382
# 108| m0_20(unknown) = ^CallSideEffect : ~m0_5
383383
# 108| m0_21(unknown) = Chi : total:m0_5, partial:m0_20
384384
# 108| v0_22(void) = ^IndirectReadSideEffect[0] : &:r0_18, ~m0_21
385-
# 108| m0_23(unknown) = ^BufferMayWriteSideEffect[0] : &:r0_18, ~m0_21
385+
# 108| m0_23(unknown) = ^BufferMayWriteSideEffect[0] : &:r0_18
386386
# 108| m0_24(unknown) = Chi : total:m0_21, partial:m0_23
387387
# 109| v0_25(void) = NoOp :
388388
# 105| v0_26(void) = ReturnVoid :
@@ -452,7 +452,7 @@ ssa.cpp:
452452
# 119| m0_28(unknown) = ^CallSideEffect : ~m0_19
453453
# 119| m0_29(unknown) = Chi : total:m0_19, partial:m0_28
454454
# 119| v0_30(void) = ^IndirectReadSideEffect[0] : &:r0_26, ~m0_29
455-
# 119| m0_31(unknown) = ^BufferMayWriteSideEffect[0] : &:r0_26, ~m0_29
455+
# 119| m0_31(unknown) = ^BufferMayWriteSideEffect[0] : &:r0_26
456456
# 119| m0_32(unknown) = Chi : total:m0_29, partial:m0_31
457457
# 120| v0_33(void) = NoOp :
458458
# 116| v0_34(void) = ReturnVoid :

cpp/ql/test/library-tests/ir/ssa/unaliased_ssa_ir.expected

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ ssa.cpp:
327327
# 97| v0_12(void) = Call : func:r0_9, 0:r0_11
328328
# 97| mu0_13(unknown) = ^CallSideEffect : ~mu0_2
329329
# 97| v0_14(void) = ^IndirectReadSideEffect[0] : &:r0_11, ~mu0_2
330-
# 97| mu0_15(unknown) = ^BufferMayWriteSideEffect[0] : &:r0_11, ~mu0_2
330+
# 97| mu0_15(unknown) = ^BufferMayWriteSideEffect[0] : &:r0_11
331331
# 98| v0_16(void) = NoOp :
332332
# 95| v0_17(void) = ReturnVoid :
333333
# 95| v0_18(void) = UnmodeledUse : mu*
@@ -378,7 +378,7 @@ ssa.cpp:
378378
# 108| v0_18(void) = Call : func:r0_15, 0:r0_17
379379
# 108| mu0_19(unknown) = ^CallSideEffect : ~mu0_2
380380
# 108| v0_20(void) = ^IndirectReadSideEffect[0] : &:r0_17, ~mu0_2
381-
# 108| mu0_21(unknown) = ^BufferMayWriteSideEffect[0] : &:r0_17, ~mu0_2
381+
# 108| mu0_21(unknown) = ^BufferMayWriteSideEffect[0] : &:r0_17
382382
# 109| v0_22(void) = NoOp :
383383
# 105| v0_23(void) = ReturnVoid :
384384
# 105| v0_24(void) = UnmodeledUse : mu*
@@ -441,7 +441,7 @@ ssa.cpp:
441441
# 119| v0_24(void) = Call : func:r0_21, 0:r0_23
442442
# 119| mu0_25(unknown) = ^CallSideEffect : ~mu0_2
443443
# 119| v0_26(void) = ^IndirectReadSideEffect[0] : &:r0_23, ~mu0_2
444-
# 119| mu0_27(unknown) = ^BufferMayWriteSideEffect[0] : &:r0_23, ~mu0_2
444+
# 119| mu0_27(unknown) = ^BufferMayWriteSideEffect[0] : &:r0_23
445445
# 120| v0_28(void) = NoOp :
446446
# 116| v0_29(void) = ReturnVoid :
447447
# 116| v0_30(void) = UnmodeledUse : mu*

cpp/ql/test/library-tests/syntax-zoo/aliased_ssa_sanity.expected

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
missingOperand
22
| misc.c:125:5:125:11 | CopyValue: (statement expression) | Instruction 'CopyValue' is missing an expected operand with tag 'Unary' in function '$@'. | misc.c:97:6:97:10 | IR: misc3 | void misc3() |
3+
| parameterinitializer.cpp:27:3:27:6 | IndirectReadSideEffect: my_c | Instruction 'IndirectReadSideEffect' is missing an expected operand with tag 'SideEffect' in function '$@'. | allocators.cpp:14:5:14:8 | IR: main | int main() |
4+
| parameterinitializer.cpp:27:3:27:6 | IndirectReadSideEffect: my_c | Instruction 'IndirectReadSideEffect' is missing an expected operand with tag 'SideEffect' in function '$@'. | no_dynamic_init.cpp:9:5:9:8 | IR: main | int main() |
5+
| parameterinitializer.cpp:27:3:27:6 | IndirectReadSideEffect: my_c | Instruction 'IndirectReadSideEffect' is missing an expected operand with tag 'SideEffect' in function '$@'. | parameterinitializer.cpp:18:5:18:8 | IR: main | int main() |
6+
| parameterinitializer.cpp:27:3:27:6 | IndirectReadSideEffect: my_c | Instruction 'IndirectReadSideEffect' is missing an expected operand with tag 'SideEffect' in function '$@'. | stream_it.cpp:16:5:16:8 | IR: main | int main() |
37
| try_catch.cpp:13:5:13:16 | ThrowValue: throw ... | Instruction 'ThrowValue' is missing an expected operand with tag 'Load' in function '$@'. | try_catch.cpp:11:6:11:17 | IR: bypass_catch | void bypass_catch() |
48
unexpectedOperand
59
duplicateOperand

cpp/ql/test/library-tests/syntax-zoo/raw_sanity.expected

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ instructionWithoutSuccessor
2727
| assume0.cpp:7:2:7:2 | CallSideEffect: call to f |
2828
| assume0.cpp:9:11:9:11 | Constant: (bool)... |
2929
| condition_decls.cpp:16:19:16:20 | CallSideEffect: call to BoxedInt |
30-
| condition_decls.cpp:26:19:26:19 | CallSideEffect: call to operator int |
30+
| condition_decls.cpp:26:19:26:20 | IndirectMayWriteSideEffect: bi |
3131
| condition_decls.cpp:26:23:26:24 | CallSideEffect: call to BoxedInt |
3232
| condition_decls.cpp:41:22:41:23 | CallSideEffect: call to BoxedInt |
3333
| condition_decls.cpp:48:52:48:53 | CallSideEffect: call to BoxedInt |
@@ -614,12 +614,14 @@ useNotDominatedByDefinition
614614
| assume0.cpp:11:2:11:2 | Operand | Operand 'Operand' is not dominated by its definition in function '$@'. | assume0.cpp:5:6:5:6 | IR: h | void h() |
615615
| condition_decls.cpp:16:15:16:15 | Operand | Operand 'Operand' is not dominated by its definition in function '$@'. | condition_decls.cpp:15:6:15:17 | IR: if_decl_bind | void if_decl_bind(int) |
616616
| condition_decls.cpp:16:15:16:16 | Load | Operand 'Load' is not dominated by its definition in function '$@'. | condition_decls.cpp:15:6:15:17 | IR: if_decl_bind | void if_decl_bind(int) |
617+
| condition_decls.cpp:16:15:16:16 | Operand | Operand 'Operand' is not dominated by its definition in function '$@'. | condition_decls.cpp:15:6:15:17 | IR: if_decl_bind | void if_decl_bind(int) |
617618
| condition_decls.cpp:17:5:17:15 | Load | Operand 'Load' is not dominated by its definition in function '$@'. | condition_decls.cpp:15:6:15:17 | IR: if_decl_bind | void if_decl_bind(int) |
618619
| condition_decls.cpp:17:11:17:15 | Load | Operand 'Load' is not dominated by its definition in function '$@'. | condition_decls.cpp:15:6:15:17 | IR: if_decl_bind | void if_decl_bind(int) |
619620
| condition_decls.cpp:20:5:20:15 | Load | Operand 'Load' is not dominated by its definition in function '$@'. | condition_decls.cpp:15:6:15:17 | IR: if_decl_bind | void if_decl_bind(int) |
620621
| condition_decls.cpp:20:11:20:15 | Load | Operand 'Load' is not dominated by its definition in function '$@'. | condition_decls.cpp:15:6:15:17 | IR: if_decl_bind | void if_decl_bind(int) |
621622
| condition_decls.cpp:26:19:26:19 | Operand | Operand 'Operand' is not dominated by its definition in function '$@'. | condition_decls.cpp:25:6:25:21 | IR: switch_decl_bind | void switch_decl_bind(int) |
622623
| condition_decls.cpp:26:19:26:20 | Load | Operand 'Load' is not dominated by its definition in function '$@'. | condition_decls.cpp:25:6:25:21 | IR: switch_decl_bind | void switch_decl_bind(int) |
624+
| condition_decls.cpp:26:19:26:20 | Operand | Operand 'Operand' is not dominated by its definition in function '$@'. | condition_decls.cpp:25:6:25:21 | IR: switch_decl_bind | void switch_decl_bind(int) |
623625
| condition_decls.cpp:28:5:28:15 | Load | Operand 'Load' is not dominated by its definition in function '$@'. | condition_decls.cpp:25:6:25:21 | IR: switch_decl_bind | void switch_decl_bind(int) |
624626
| condition_decls.cpp:28:11:28:15 | Load | Operand 'Load' is not dominated by its definition in function '$@'. | condition_decls.cpp:25:6:25:21 | IR: switch_decl_bind | void switch_decl_bind(int) |
625627
| condition_decls.cpp:31:5:31:15 | Load | Operand 'Load' is not dominated by its definition in function '$@'. | condition_decls.cpp:25:6:25:21 | IR: switch_decl_bind | void switch_decl_bind(int) |
@@ -628,14 +630,17 @@ useNotDominatedByDefinition
628630
| condition_decls.cpp:34:9:34:13 | Load | Operand 'Load' is not dominated by its definition in function '$@'. | condition_decls.cpp:25:6:25:21 | IR: switch_decl_bind | void switch_decl_bind(int) |
629631
| condition_decls.cpp:41:18:41:18 | Operand | Operand 'Operand' is not dominated by its definition in function '$@'. | condition_decls.cpp:40:6:40:20 | IR: while_decl_bind | void while_decl_bind(int) |
630632
| condition_decls.cpp:41:18:41:19 | Load | Operand 'Load' is not dominated by its definition in function '$@'. | condition_decls.cpp:40:6:40:20 | IR: while_decl_bind | void while_decl_bind(int) |
633+
| condition_decls.cpp:41:18:41:19 | Operand | Operand 'Operand' is not dominated by its definition in function '$@'. | condition_decls.cpp:40:6:40:20 | IR: while_decl_bind | void while_decl_bind(int) |
631634
| condition_decls.cpp:42:5:42:7 | Load | Operand 'Load' is not dominated by its definition in function '$@'. | condition_decls.cpp:40:6:40:20 | IR: while_decl_bind | void while_decl_bind(int) |
632635
| condition_decls.cpp:44:3:44:5 | Load | Operand 'Load' is not dominated by its definition in function '$@'. | condition_decls.cpp:40:6:40:20 | IR: while_decl_bind | void while_decl_bind(int) |
633636
| condition_decls.cpp:48:48:48:48 | Operand | Operand 'Operand' is not dominated by its definition in function '$@'. | condition_decls.cpp:47:6:47:18 | IR: for_decl_bind | void for_decl_bind(int) |
634637
| condition_decls.cpp:48:48:48:49 | Load | Operand 'Load' is not dominated by its definition in function '$@'. | condition_decls.cpp:47:6:47:18 | IR: for_decl_bind | void for_decl_bind(int) |
638+
| condition_decls.cpp:48:48:48:49 | Operand | Operand 'Operand' is not dominated by its definition in function '$@'. | condition_decls.cpp:47:6:47:18 | IR: for_decl_bind | void for_decl_bind(int) |
635639
| condition_decls.cpp:48:56:48:61 | Load | Operand 'Load' is not dominated by its definition in function '$@'. | condition_decls.cpp:47:6:47:18 | IR: for_decl_bind | void for_decl_bind(int) |
636640
| condition_decls.cpp:49:5:49:7 | Load | Operand 'Load' is not dominated by its definition in function '$@'. | condition_decls.cpp:47:6:47:18 | IR: for_decl_bind | void for_decl_bind(int) |
637641
| condition_decls.cpp:51:3:51:5 | Load | Operand 'Load' is not dominated by its definition in function '$@'. | condition_decls.cpp:47:6:47:18 | IR: for_decl_bind | void for_decl_bind(int) |
638642
| cpp11.cpp:28:21:28:21 | Operand | Operand 'Operand' is not dominated by its definition in function '$@'. | cpp11.cpp:27:7:27:14 | IR: getFirst | int range_based_for_11::getFirst() |
643+
| file://:0:0:0:0 | Operand | Operand 'Operand' is not dominated by its definition in function '$@'. | cpp11.cpp:27:7:27:14 | IR: getFirst | int range_based_for_11::getFirst() |
639644
| misc.c:68:16:68:16 | Load | Operand 'Load' is not dominated by its definition in function '$@'. | misc.c:16:6:16:10 | IR: misc1 | void misc1(int, int) |
640645
| misc.c:70:13:70:15 | Load | Operand 'Load' is not dominated by its definition in function '$@'. | misc.c:16:6:16:10 | IR: misc1 | void misc1(int, int) |
641646
| misc.c:72:11:72:11 | Load | Operand 'Load' is not dominated by its definition in function '$@'. | misc.c:16:6:16:10 | IR: misc1 | void misc1(int, int) |

cpp/ql/test/library-tests/syntax-zoo/unaliased_ssa_sanity.expected

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
missingOperand
22
| misc.c:125:5:125:11 | CopyValue: (statement expression) | Instruction 'CopyValue' is missing an expected operand with tag 'Unary' in function '$@'. | misc.c:97:6:97:10 | IR: misc3 | void misc3() |
3+
| parameterinitializer.cpp:27:3:27:6 | IndirectReadSideEffect: my_c | Instruction 'IndirectReadSideEffect' is missing an expected operand with tag 'SideEffect' in function '$@'. | allocators.cpp:14:5:14:8 | IR: main | int main() |
4+
| parameterinitializer.cpp:27:3:27:6 | IndirectReadSideEffect: my_c | Instruction 'IndirectReadSideEffect' is missing an expected operand with tag 'SideEffect' in function '$@'. | no_dynamic_init.cpp:9:5:9:8 | IR: main | int main() |
5+
| parameterinitializer.cpp:27:3:27:6 | IndirectReadSideEffect: my_c | Instruction 'IndirectReadSideEffect' is missing an expected operand with tag 'SideEffect' in function '$@'. | parameterinitializer.cpp:18:5:18:8 | IR: main | int main() |
6+
| parameterinitializer.cpp:27:3:27:6 | IndirectReadSideEffect: my_c | Instruction 'IndirectReadSideEffect' is missing an expected operand with tag 'SideEffect' in function '$@'. | stream_it.cpp:16:5:16:8 | IR: main | int main() |
37
| try_catch.cpp:13:5:13:16 | ThrowValue: throw ... | Instruction 'ThrowValue' is missing an expected operand with tag 'Load' in function '$@'. | try_catch.cpp:11:6:11:17 | IR: bypass_catch | void bypass_catch() |
48
unexpectedOperand
59
duplicateOperand

0 commit comments

Comments
 (0)