Skip to content

Commit 5c99785

Browse files
committed
Merge branch 'main' into rust-core-std-models
2 parents 6353dbf + 2c3b489 commit 5c99785

File tree

35 files changed

+1160
-943
lines changed

35 files changed

+1160
-943
lines changed

cpp/ql/lib/semmle/code/cpp/dataflow/ExternalFlow.qll

+5-6
Original file line numberDiff line numberDiff line change
@@ -869,12 +869,11 @@ private predicate elementSpecMatchesSignature(
869869
bindingset[nameWithoutArgs]
870870
pragma[inline_late]
871871
private Class getClassAndNameImpl(Function method, string nameWithoutArgs) {
872-
exists(string memberName | result = method.getClassAndName(memberName) |
873-
nameWithoutArgs = "operator " + method.(ConversionOperator).getDestType()
874-
or
875-
not method instanceof ConversionOperator and
876-
memberName = nameWithoutArgs
877-
)
872+
result = method.getDeclaringType() and
873+
nameWithoutArgs = "operator " + method.(ConversionOperator).getDestType()
874+
or
875+
result = method.getClassAndName(nameWithoutArgs) and
876+
not method instanceof ConversionOperator
878877
}
879878

880879
/**

csharp/ql/src/Useless code/DefaultToStringQuery.qll

+6
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ private predicate alwaysInvokesToString(ParameterRead pr) {
4646
* method from `System.Object` or `System.ValueType`.
4747
*/
4848
predicate alwaysDefaultToString(ValueOrRefType t) {
49+
not t instanceof TupleType and
4950
exists(ToStringMethod m | t.hasMethod(m) |
5051
m.getDeclaringType() instanceof SystemObjectClass or
5152
m.getDeclaringType() instanceof SystemValueTypeClass
@@ -55,6 +56,11 @@ predicate alwaysDefaultToString(ValueOrRefType t) {
5556
overriding.getABaseType+() = t
5657
) and
5758
((t.isAbstract() or t instanceof Interface) implies not t.isEffectivelyPublic())
59+
or
60+
exists(ValueOrRefType elem |
61+
elem = t.(TupleType).getElementType(_) and
62+
alwaysDefaultToString(elem)
63+
)
5864
}
5965

6066
class DefaultToStringType extends ValueOrRefType {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
* C#: Improve precision of the query `cs/call-to-object-tostring` for value tuples.

csharp/ql/test/query-tests/Useless Code/DefaultToString/DefaultToString.cs

+10
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,16 @@ void M()
3535

3636
IPublic g = null;
3737
Console.WriteLine(g); // GOOD
38+
39+
Console.WriteLine(new ValueTuple<int, int>(1, 2)); // GOOD
40+
41+
Console.WriteLine((1, 2)); // GOOD
42+
43+
var t1 = new ValueTuple<int, DefaultToString>(1, new DefaultToString());
44+
Console.WriteLine(t1); // BAD
45+
46+
var t2 = new ValueTuple<A, D>(new A(), new D());
47+
Console.WriteLine(t2); // GOOD
3848
}
3949

4050
class A

csharp/ql/test/query-tests/Useless Code/DefaultToString/DefaultToString.expected

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
| DefaultToString.cs:10:28:10:28 | access to local variable d | Default 'ToString()': $@ inherits 'ToString()' from 'Object', and so is not suitable for printing. | DefaultToString.cs:4:14:4:28 | DefaultToString | DefaultToString |
33
| DefaultToString.cs:16:27:16:30 | access to local variable ints | Default 'ToString()': $@ inherits 'ToString()' from 'Object', and so is not suitable for printing. | file://:0:0:0:0 | Int32[] | Int32[] |
44
| DefaultToString.cs:19:24:19:27 | access to local variable ints | Default 'ToString()': $@ inherits 'ToString()' from 'Object', and so is not suitable for printing. | file://:0:0:0:0 | Int32[] | Int32[] |
5-
| DefaultToString.cs:34:27:34:27 | access to local variable f | Default 'ToString()': $@ inherits 'ToString()' from 'Object', and so is not suitable for printing. | DefaultToString.cs:62:23:62:30 | IPrivate | IPrivate |
5+
| DefaultToString.cs:34:27:34:27 | access to local variable f | Default 'ToString()': $@ inherits 'ToString()' from 'Object', and so is not suitable for printing. | DefaultToString.cs:72:23:72:30 | IPrivate | IPrivate |
6+
| DefaultToString.cs:44:27:44:28 | (...) ... | Default 'ToString()': $@ inherits 'ToString()' from 'Object', and so is not suitable for printing. | file://:0:0:0:0 | (Int32,DefaultToString) | (Int32,DefaultToString) |
67
| DefaultToStringBad.cs:8:35:8:35 | access to local variable p | Default 'ToString()': $@ inherits 'ToString()' from 'Object', and so is not suitable for printing. | DefaultToStringBad.cs:14:11:14:16 | Person | Person |
78
| DefaultToStringBad.cs:11:38:11:41 | access to local variable ints | Default 'ToString()': $@ inherits 'ToString()' from 'Object', and so is not suitable for printing. | file://:0:0:0:0 | Int32[] | Int32[] |
89
| WriteLineArray.cs:7:23:7:26 | access to parameter args | Default 'ToString()': $@ inherits 'ToString()' from 'Object', and so is not suitable for printing. | file://:0:0:0:0 | String[] | String[] |

go/ql/lib/semmle/go/dataflow/internal/DataFlowUtil.qll

+10-2
Original file line numberDiff line numberDiff line change
@@ -379,15 +379,23 @@ module BarrierGuard<guardChecksSig/3 guardChecks> {
379379
)
380380
}
381381

382+
bindingset[inp, c]
383+
pragma[inline_late]
384+
private Node getInputNode(FunctionInput inp, CallNode c) { result = inp.getNode(c) }
385+
386+
bindingset[outp, c]
387+
pragma[inline_late]
388+
private Node getOutputNode(FunctionOutput outp, CallNode c) { result = outp.getNode(c) }
389+
382390
pragma[noinline]
383391
private predicate guardingCall(
384392
Node g, Function f, FunctionInput inp, FunctionOutput outp, DataFlow::Property p, CallNode c,
385393
Node nd, Node resNode
386394
) {
387395
guardingFunction(g, f, inp, outp, p) and
388396
c = f.getACall() and
389-
nd = inp.getNode(c) and
390-
localFlow(pragma[only_bind_out](outp.getNode(c)), resNode)
397+
nd = getInputNode(inp, c) and
398+
localFlow(getOutputNode(outp, c), resNode)
391399
}
392400

393401
private predicate onlyPossibleReturnSatisfyingProperty(

0 commit comments

Comments
 (0)