Skip to content

Commit afdaabf

Browse files
committed
C++: Support default arguments in constructors and accept test changes.
1 parent 6f4f9ad commit afdaabf

3 files changed

Lines changed: 28 additions & 9 deletions

File tree

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -603,15 +603,15 @@ private Type stripReferences(Type unspecifiedType) {
603603
private predicate forwardingCallTargetsConstructor(
604604
CallInstruction call, Cpp::Constructor constructor
605605
) {
606-
exists(int start |
606+
exists(int start, int numberOfForwardedArguments |
607607
External::forwards(call.getStaticCallTarget(), constructor, start) and
608-
call.getNumberOfPositionalArguments() = start + constructor.getNumberOfParameters() and
609-
forall(int i, Type typeCall, Type typeConstructor |
610-
i = [0 .. constructor.getNumberOfParameters() - 1] and
611-
typeCall = stripReferences(call.getPositionalArgument(start + i).getResultType()) and
612-
typeConstructor = stripReferences(constructor.getParameter(i).getUnspecifiedType())
613-
|
614-
typeCall = typeConstructor
608+
call.getNumberOfPositionalArguments() = start + numberOfForwardedArguments and
609+
forall(int i | i = [0 .. constructor.getNumberOfParameters() - 1] |
610+
i < numberOfForwardedArguments and
611+
stripReferences(call.getPositionalArgument(start + i).getResultType()) =
612+
stripReferences(constructor.getParameter(i).getUnspecifiedType())
613+
or
614+
i >= numberOfForwardedArguments and constructor.getParameter(i).hasInitializer()
615615
)
616616
)
617617
}

cpp/ql/test/library-tests/dataflow/external-models/flow.expected

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,15 @@ edges
392392
| test.cpp:397:20:397:22 | call to get [x] | test.cpp:398:11:398:11 | *e [x] | provenance | |
393393
| test.cpp:398:11:398:11 | *e [x] | test.cpp:398:13:398:13 | x | provenance | |
394394
| test.cpp:398:13:398:13 | x | test.cpp:398:13:398:13 | x | provenance | Sink:MaD:3 |
395+
| test.cpp:408:11:408:19 | call to ymlSource | test.cpp:408:11:408:19 | call to ymlSource | provenance | Src:MaD:48 |
396+
| test.cpp:408:11:408:19 | call to ymlSource | test.cpp:409:16:409:16 | *x | provenance | |
397+
| test.cpp:409:3:409:3 | emplace output argument [element, x] | test.cpp:411:34:411:34 | *c [element, x] | provenance | |
398+
| test.cpp:409:16:409:16 | *x | test.cpp:409:3:409:3 | emplace output argument [element, x] | provenance | MaD:87 |
399+
| test.cpp:411:34:411:34 | *c [element, x] | test.cpp:411:39:411:41 | call to get [x] | provenance | MaD:88 |
400+
| test.cpp:411:39:411:41 | call to get [x] | test.cpp:411:39:411:41 | call to get [x] | provenance | |
401+
| test.cpp:411:39:411:41 | call to get [x] | test.cpp:412:11:412:11 | *e [x] | provenance | |
402+
| test.cpp:412:11:412:11 | *e [x] | test.cpp:412:13:412:13 | x | provenance | |
403+
| test.cpp:412:13:412:13 | x | test.cpp:412:13:412:13 | x | provenance | Sink:MaD:3 |
395404
| windows.cpp:22:15:22:29 | *call to GetCommandLineA | windows.cpp:24:8:24:11 | * ... | provenance | |
396405
| windows.cpp:22:15:22:29 | *call to GetCommandLineA | windows.cpp:27:36:27:38 | *cmd | provenance | |
397406
| windows.cpp:22:15:22:29 | call to GetCommandLineA | windows.cpp:22:15:22:29 | *call to GetCommandLineA | provenance | Src:MaD:5 |
@@ -890,6 +899,16 @@ nodes
890899
| test.cpp:398:11:398:11 | *e [x] | semmle.label | *e [x] |
891900
| test.cpp:398:13:398:13 | x | semmle.label | x |
892901
| test.cpp:398:13:398:13 | x | semmle.label | x |
902+
| test.cpp:408:11:408:19 | call to ymlSource | semmle.label | call to ymlSource |
903+
| test.cpp:408:11:408:19 | call to ymlSource | semmle.label | call to ymlSource |
904+
| test.cpp:409:3:409:3 | emplace output argument [element, x] | semmle.label | emplace output argument [element, x] |
905+
| test.cpp:409:16:409:16 | *x | semmle.label | *x |
906+
| test.cpp:411:34:411:34 | *c [element, x] | semmle.label | *c [element, x] |
907+
| test.cpp:411:39:411:41 | call to get [x] | semmle.label | call to get [x] |
908+
| test.cpp:411:39:411:41 | call to get [x] | semmle.label | call to get [x] |
909+
| test.cpp:412:11:412:11 | *e [x] | semmle.label | *e [x] |
910+
| test.cpp:412:13:412:13 | x | semmle.label | x |
911+
| test.cpp:412:13:412:13 | x | semmle.label | x |
893912
| windows.cpp:22:15:22:29 | *call to GetCommandLineA | semmle.label | *call to GetCommandLineA |
894913
| windows.cpp:22:15:22:29 | call to GetCommandLineA | semmle.label | call to GetCommandLineA |
895914
| windows.cpp:24:8:24:11 | * ... | semmle.label | * ... |

cpp/ql/test/library-tests/dataflow/external-models/test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,5 +409,5 @@ void forward_test_model_with_default_argument() {
409409
c.emplace(0, x);
410410

411411
ElementWithDefaultArgument e = c.get();
412-
ymlSink(e.x); // $ MISSING: ir
412+
ymlSink(e.x); // $ ir
413413
}

0 commit comments

Comments
 (0)