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

Skip to content

Commit bace8c7

Browse files
author
Robert Marsh
committed
C++: side effect instrs for constructor qualifiers
This adds IndirectMustWriteSideEffects for constructor qualifiers. The introduced sanity failures result from constructor calls without qualifier operands in the IR
1 parent 39f550b commit bace8c7

9 files changed

Lines changed: 799 additions & 641 deletions

File tree

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,35 @@ class TranslatedSideEffects extends TranslatedElement, TTranslatedSideEffects {
374374
override Function getFunction() { result = expr.getEnclosingFunction() }
375375
}
376376

377+
class TranslatedStructorCallSideEffects extends TranslatedSideEffects {
378+
TranslatedStructorCallSideEffects() { getParent().(TranslatedStructorCall).hasQualifier() }
379+
380+
override predicate hasInstruction(Opcode opcode, InstructionTag tag, Type t, boolean isGLValue) {
381+
opcode instanceof Opcode::IndirectMustWriteSideEffect and
382+
tag instanceof OnlyInstructionTag and
383+
t = expr.getTarget().getDeclaringType() and
384+
isGLValue = false
385+
}
386+
387+
override Instruction getInstructionSuccessor(InstructionTag tag, EdgeKind kind) {
388+
(
389+
if exists(getChild(0))
390+
then result = getChild(0).getFirstInstruction()
391+
else result = getParent().getChildSuccessor(this)
392+
) and
393+
tag = OnlyInstructionTag() and
394+
kind instanceof GotoEdge
395+
}
396+
397+
override Instruction getFirstInstruction() { result = getInstruction(OnlyInstructionTag()) }
398+
399+
override Instruction getInstructionOperand(InstructionTag tag, OperandTag operandTag) {
400+
tag instanceof OnlyInstructionTag and
401+
operandTag instanceof AddressOperandTag and
402+
result = getParent().(TranslatedStructorCall).getQualifierResult()
403+
}
404+
}
405+
377406
class TranslatedSideEffect extends TranslatedElement, TTranslatedArgumentSideEffect {
378407
Call call;
379408
Expr arg;
@@ -537,3 +566,4 @@ class TranslatedSideEffect extends TranslatedElement, TTranslatedArgumentSideEff
537566
*/
538567
override Function getFunction() { result = arg.getEnclosingFunction() }
539568
}
569+

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ newtype TTranslatedElement =
372372
// The declaration/initialization part of a `ConditionDeclExpr`
373373
TTranslatedConditionDecl(ConditionDeclExpr expr) { not ignoreExpr(expr) } or
374374
// The side effects of a `Call` {
375-
TTranslatedSideEffects(Call expr) { exists(TTranslatedArgumentSideEffect(expr, _, _, _)) } or // A precise side effect of an argument to a `Call` {
375+
TTranslatedSideEffects(Call expr) { exists(TTranslatedArgumentSideEffect(expr, _, _, _)) or expr instanceof ConstructorCall } or // A precise side effect of an argument to a `Call` {
376376
TTranslatedArgumentSideEffect(Call call, Expr expr, int n, boolean isWrite) {
377377
(
378378
expr = call.getArgument(n).getFullyConverted()

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
missingOperand
2+
| ir.cpp:809:7:809:13 | IndirectMustWriteSideEffect: call to Base | Instruction 'IndirectMustWriteSideEffect' is missing an expected operand with tag 'Address' in function '$@'. | ir.cpp:799:6:799:25 | IR: HierarchyConversions | void HierarchyConversions() |
3+
| ir.cpp:810:7:810:26 | IndirectMustWriteSideEffect: call to Base | Instruction 'IndirectMustWriteSideEffect' is missing an expected operand with tag 'Address' in function '$@'. | ir.cpp:799:6:799:25 | IR: HierarchyConversions | void HierarchyConversions() |
4+
| ir.cpp:823:7:823:13 | IndirectMustWriteSideEffect: call to Base | Instruction 'IndirectMustWriteSideEffect' is missing an expected operand with tag 'Address' in function '$@'. | ir.cpp:799:6:799:25 | IR: HierarchyConversions | void HierarchyConversions() |
5+
| ir.cpp:824:7:824:26 | IndirectMustWriteSideEffect: call to Base | Instruction 'IndirectMustWriteSideEffect' is missing an expected operand with tag 'Address' in function '$@'. | ir.cpp:799:6:799:25 | IR: HierarchyConversions | void HierarchyConversions() |
26
unexpectedOperand
37
duplicateOperand
48
missingPhiOperand

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

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

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
missingOperand
2+
| ir.cpp:809:7:809:13 | IndirectMustWriteSideEffect: call to Base | Instruction 'IndirectMustWriteSideEffect' is missing an expected operand with tag 'Address' in function '$@'. | ir.cpp:799:6:799:25 | IR: HierarchyConversions | void HierarchyConversions() |
3+
| ir.cpp:810:7:810:26 | IndirectMustWriteSideEffect: call to Base | Instruction 'IndirectMustWriteSideEffect' is missing an expected operand with tag 'Address' in function '$@'. | ir.cpp:799:6:799:25 | IR: HierarchyConversions | void HierarchyConversions() |
4+
| ir.cpp:823:7:823:13 | IndirectMustWriteSideEffect: call to Base | Instruction 'IndirectMustWriteSideEffect' is missing an expected operand with tag 'Address' in function '$@'. | ir.cpp:799:6:799:25 | IR: HierarchyConversions | void HierarchyConversions() |
5+
| ir.cpp:824:7:824:26 | IndirectMustWriteSideEffect: call to Base | Instruction 'IndirectMustWriteSideEffect' is missing an expected operand with tag 'Address' in function '$@'. | ir.cpp:799:6:799:25 | IR: HierarchyConversions | void HierarchyConversions() |
26
unexpectedOperand
37
duplicateOperand
48
missingPhiOperand

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
missingOperand
2+
| ir.cpp:809:7:809:13 | IndirectMustWriteSideEffect: call to Base | Instruction 'IndirectMustWriteSideEffect' is missing an expected operand with tag 'Address' in function '$@'. | ir.cpp:799:6:799:25 | IR: HierarchyConversions | void HierarchyConversions() |
3+
| ir.cpp:810:7:810:26 | IndirectMustWriteSideEffect: call to Base | Instruction 'IndirectMustWriteSideEffect' is missing an expected operand with tag 'Address' in function '$@'. | ir.cpp:799:6:799:25 | IR: HierarchyConversions | void HierarchyConversions() |
4+
| ir.cpp:823:7:823:13 | IndirectMustWriteSideEffect: call to Base | Instruction 'IndirectMustWriteSideEffect' is missing an expected operand with tag 'Address' in function '$@'. | ir.cpp:799:6:799:25 | IR: HierarchyConversions | void HierarchyConversions() |
5+
| ir.cpp:824:7:824:26 | IndirectMustWriteSideEffect: call to Base | Instruction 'IndirectMustWriteSideEffect' is missing an expected operand with tag 'Address' in function '$@'. | ir.cpp:799:6:799:25 | IR: HierarchyConversions | void HierarchyConversions() |
26
unexpectedOperand
37
duplicateOperand
48
missingPhiOperand

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

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,33 @@
11
missingOperand
2+
| conditional_destructors.cpp:30:9:30:13 | IndirectMustWriteSideEffect: call to C1 | Instruction 'IndirectMustWriteSideEffect' is missing an expected operand with tag 'Address' in function '$@'. | conditional_destructors.cpp:29:6:29:7 | IR: f1 | void f1() |
3+
| conditional_destructors.cpp:30:9:30:13 | IndirectMustWriteSideEffect: call to C1 | Instruction 'IndirectMustWriteSideEffect' is missing an expected operand with tag 'Address' in function '$@'. | forstmt.cpp:1:6:1:7 | IR: f1 | void f1() |
4+
| conditional_destructors.cpp:30:18:30:22 | IndirectMustWriteSideEffect: call to C1 | Instruction 'IndirectMustWriteSideEffect' is missing an expected operand with tag 'Address' in function '$@'. | conditional_destructors.cpp:29:6:29:7 | IR: f1 | void f1() |
5+
| conditional_destructors.cpp:30:18:30:22 | IndirectMustWriteSideEffect: call to C1 | Instruction 'IndirectMustWriteSideEffect' is missing an expected operand with tag 'Address' in function '$@'. | forstmt.cpp:1:6:1:7 | IR: f1 | void f1() |
6+
| conditional_destructors.cpp:33:9:33:13 | IndirectMustWriteSideEffect: call to C1 | Instruction 'IndirectMustWriteSideEffect' is missing an expected operand with tag 'Address' in function '$@'. | conditional_destructors.cpp:29:6:29:7 | IR: f1 | void f1() |
7+
| conditional_destructors.cpp:33:9:33:13 | IndirectMustWriteSideEffect: call to C1 | Instruction 'IndirectMustWriteSideEffect' is missing an expected operand with tag 'Address' in function '$@'. | forstmt.cpp:1:6:1:7 | IR: f1 | void f1() |
8+
| conditional_destructors.cpp:33:18:33:22 | IndirectMustWriteSideEffect: call to C1 | Instruction 'IndirectMustWriteSideEffect' is missing an expected operand with tag 'Address' in function '$@'. | conditional_destructors.cpp:29:6:29:7 | IR: f1 | void f1() |
9+
| conditional_destructors.cpp:33:18:33:22 | IndirectMustWriteSideEffect: call to C1 | Instruction 'IndirectMustWriteSideEffect' is missing an expected operand with tag 'Address' in function '$@'. | forstmt.cpp:1:6:1:7 | IR: f1 | void f1() |
10+
| conditional_destructors.cpp:39:9:39:13 | IndirectMustWriteSideEffect: call to C2 | Instruction 'IndirectMustWriteSideEffect' is missing an expected operand with tag 'Address' in function '$@'. | conditional_destructors.cpp:38:6:38:7 | IR: f2 | void f2() |
11+
| conditional_destructors.cpp:39:9:39:13 | IndirectMustWriteSideEffect: call to C2 | Instruction 'IndirectMustWriteSideEffect' is missing an expected operand with tag 'Address' in function '$@'. | forstmt.cpp:8:6:8:7 | IR: f2 | void f2() |
12+
| conditional_destructors.cpp:39:18:39:22 | IndirectMustWriteSideEffect: call to C2 | Instruction 'IndirectMustWriteSideEffect' is missing an expected operand with tag 'Address' in function '$@'. | conditional_destructors.cpp:38:6:38:7 | IR: f2 | void f2() |
13+
| conditional_destructors.cpp:39:18:39:22 | IndirectMustWriteSideEffect: call to C2 | Instruction 'IndirectMustWriteSideEffect' is missing an expected operand with tag 'Address' in function '$@'. | forstmt.cpp:8:6:8:7 | IR: f2 | void f2() |
14+
| conditional_destructors.cpp:42:9:42:13 | IndirectMustWriteSideEffect: call to C2 | Instruction 'IndirectMustWriteSideEffect' is missing an expected operand with tag 'Address' in function '$@'. | conditional_destructors.cpp:38:6:38:7 | IR: f2 | void f2() |
15+
| conditional_destructors.cpp:42:9:42:13 | IndirectMustWriteSideEffect: call to C2 | Instruction 'IndirectMustWriteSideEffect' is missing an expected operand with tag 'Address' in function '$@'. | forstmt.cpp:8:6:8:7 | IR: f2 | void f2() |
16+
| conditional_destructors.cpp:42:18:42:22 | IndirectMustWriteSideEffect: call to C2 | Instruction 'IndirectMustWriteSideEffect' is missing an expected operand with tag 'Address' in function '$@'. | conditional_destructors.cpp:38:6:38:7 | IR: f2 | void f2() |
17+
| conditional_destructors.cpp:42:18:42:22 | IndirectMustWriteSideEffect: call to C2 | Instruction 'IndirectMustWriteSideEffect' is missing an expected operand with tag 'Address' in function '$@'. | forstmt.cpp:8:6:8:7 | IR: f2 | void f2() |
18+
| cpp11.cpp:77:19:77:21 | IndirectMustWriteSideEffect: call to Val | Instruction 'IndirectMustWriteSideEffect' is missing an expected operand with tag 'Address' in function '$@'. | cpp11.cpp:76:8:76:8 | IR: apply | void lambda::apply<(void lambda::apply2<int(*)(lambda::Val, lambda::Val)>(int(*)(lambda::Val, lambda::Val), lambda::Val, lambda::Val))::(lambda [] type at line 82, col. 17)>(lambda::Val, (void lambda::apply2<int(*)(lambda::Val, lambda::Val)>(int(*)(lambda::Val, lambda::Val), lambda::Val, lambda::Val))::(lambda [] type at line 82, col. 17)) |
19+
| cpp11.cpp:82:11:82:14 | IndirectMustWriteSideEffect: call to Val | Instruction 'IndirectMustWriteSideEffect' is missing an expected operand with tag 'Address' in function '$@'. | cpp11.cpp:81:8:81:8 | IR: apply2 | void lambda::apply2<int(*)(lambda::Val, lambda::Val)>(int(*)(lambda::Val, lambda::Val), lambda::Val, lambda::Val) |
20+
| cpp11.cpp:82:17:82:55 | IndirectMustWriteSideEffect: call to (constructor) | Instruction 'IndirectMustWriteSideEffect' is missing an expected operand with tag 'Address' in function '$@'. | cpp11.cpp:81:8:81:8 | IR: apply2 | void lambda::apply2<int(*)(lambda::Val, lambda::Val)>(int(*)(lambda::Val, lambda::Val), lambda::Val, lambda::Val) |
21+
| cpp11.cpp:82:45:82:48 | IndirectMustWriteSideEffect: call to Val | Instruction 'IndirectMustWriteSideEffect' is missing an expected operand with tag 'Address' in function '$@'. | cpp11.cpp:82:20:82:20 | IR: operator() | void (void lambda::apply2<int(*)(lambda::Val, lambda::Val)>(int(*)(lambda::Val, lambda::Val), lambda::Val, lambda::Val))::(lambda [] type at line 82, col. 17)::operator()(lambda::Val) const |
22+
| cpp11.cpp:82:51:82:51 | IndirectMustWriteSideEffect: call to Val | Instruction 'IndirectMustWriteSideEffect' is missing an expected operand with tag 'Address' in function '$@'. | cpp11.cpp:82:20:82:20 | IR: operator() | void (void lambda::apply2<int(*)(lambda::Val, lambda::Val)>(int(*)(lambda::Val, lambda::Val), lambda::Val, lambda::Val))::(lambda [] type at line 82, col. 17)::operator()(lambda::Val) const |
23+
| cpp11.cpp:88:25:88:30 | IndirectMustWriteSideEffect: call to Val | Instruction 'IndirectMustWriteSideEffect' is missing an expected operand with tag 'Address' in function '$@'. | cpp11.cpp:87:8:87:11 | IR: main | void lambda::main() |
24+
| cpp11.cpp:88:33:88:38 | IndirectMustWriteSideEffect: call to Val | Instruction 'IndirectMustWriteSideEffect' is missing an expected operand with tag 'Address' in function '$@'. | cpp11.cpp:87:8:87:11 | IR: main | void lambda::main() |
25+
| destructors.cpp:51:36:51:38 | IndirectMustWriteSideEffect: call to C | Instruction 'IndirectMustWriteSideEffect' is missing an expected operand with tag 'Address' in function '$@'. | destructors.cpp:49:7:49:7 | IR: f | int cond_destruct::f(int) |
26+
| ir.cpp:809:7:809:13 | IndirectMustWriteSideEffect: call to Base | Instruction 'IndirectMustWriteSideEffect' is missing an expected operand with tag 'Address' in function '$@'. | ir.cpp:799:6:799:25 | IR: HierarchyConversions | void HierarchyConversions() |
27+
| ir.cpp:810:7:810:26 | IndirectMustWriteSideEffect: call to Base | Instruction 'IndirectMustWriteSideEffect' is missing an expected operand with tag 'Address' in function '$@'. | ir.cpp:799:6:799:25 | IR: HierarchyConversions | void HierarchyConversions() |
28+
| ir.cpp:823:7:823:13 | IndirectMustWriteSideEffect: call to Base | Instruction 'IndirectMustWriteSideEffect' is missing an expected operand with tag 'Address' in function '$@'. | ir.cpp:799:6:799:25 | IR: HierarchyConversions | void HierarchyConversions() |
29+
| ir.cpp:824:7:824:26 | IndirectMustWriteSideEffect: call to Base | Instruction 'IndirectMustWriteSideEffect' is missing an expected operand with tag 'Address' in function '$@'. | ir.cpp:799:6:799:25 | IR: HierarchyConversions | void HierarchyConversions() |
230
| 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() |
7-
| 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() |
831
unexpectedOperand
932
duplicateOperand
1033
missingPhiOperand
@@ -13,10 +36,10 @@ missingOperandType
1336
instructionWithoutSuccessor
1437
| VacuousDestructorCall.cpp:2:29:2:29 | InitializeParameter: y |
1538
| assume0.cpp:7:2:7:2 | Chi: call to f |
16-
| condition_decls.cpp:16:19:16:20 | Chi: call to BoxedInt |
17-
| condition_decls.cpp:26:23:26:24 | Chi: call to BoxedInt |
18-
| condition_decls.cpp:41:22:41:23 | Chi: call to BoxedInt |
19-
| condition_decls.cpp:48:52:48:53 | Chi: call to BoxedInt |
39+
| condition_decls.cpp:16:19:16:20 | IndirectMustWriteSideEffect: call to BoxedInt |
40+
| condition_decls.cpp:26:23:26:24 | IndirectMustWriteSideEffect: call to BoxedInt |
41+
| condition_decls.cpp:41:22:41:23 | IndirectMustWriteSideEffect: call to BoxedInt |
42+
| condition_decls.cpp:48:52:48:53 | IndirectMustWriteSideEffect: call to BoxedInt |
2043
| cpp17.cpp:15:11:15:21 | Convert: (void *)... |
2144
| misc.c:171:10:171:13 | Uninitialized: definition of str2 |
2245
| misc.c:219:47:219:48 | InitializeParameter: sp |

0 commit comments

Comments
 (0)