Skip to content

Commit 09ec313

Browse files
Merge branch 'github:main' into main-1
2 parents 4024e83 + e6884cf commit 09ec313

File tree

45 files changed

+575
-54
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+575
-54
lines changed

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

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -630,10 +630,18 @@ private module Cached {
630630
Operand operand, int indirectionIndex, Operand operandRepr, int indirectionIndexRepr
631631
) {
632632
indirectionIndex = [1 .. countIndirectionsForCppType(getLanguageType(operand))] and
633-
exists(Instruction load |
634-
isDereference(load, operand, false) and
635-
operandRepr = unique( | | getAUse(load)) and
636-
indirectionIndexRepr = indirectionIndex - 1
633+
(
634+
exists(Instruction load |
635+
isDereference(load, operand, false) and
636+
operandRepr = unique( | | getAUse(load)) and
637+
indirectionIndexRepr = indirectionIndex - 1
638+
)
639+
or
640+
exists(CopyValueInstruction copy |
641+
copy.getSourceValueOperand() = operand and
642+
operandRepr = unique( | | getAUse(copy)) and
643+
indirectionIndexRepr = indirectionIndex
644+
)
637645
)
638646
}
639647

@@ -649,11 +657,19 @@ private module Cached {
649657
Instruction instr, int indirectionIndex, Instruction instrRepr, int indirectionIndexRepr
650658
) {
651659
indirectionIndex = [1 .. countIndirectionsForCppType(getResultLanguageType(instr))] and
652-
exists(Instruction load, Operand address |
653-
address = unique( | | getAUse(instr)) and
654-
isDereference(load, address, false) and
655-
instrRepr = load and
656-
indirectionIndexRepr = indirectionIndex - 1
660+
(
661+
exists(Instruction load, Operand address |
662+
address = unique( | | getAUse(instr)) and
663+
isDereference(load, address, false) and
664+
instrRepr = load and
665+
indirectionIndexRepr = indirectionIndex - 1
666+
)
667+
or
668+
exists(CopyValueInstruction copy |
669+
copy.getSourceValueOperand() = unique( | | getAUse(instr)) and
670+
instrRepr = copy and
671+
indirectionIndexRepr = indirectionIndex
672+
)
657673
)
658674
}
659675

cpp/ql/test/library-tests/dataflow/dataflow-tests/localFlow-ir.expected

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,9 @@
5353
| example.c:26:18:26:24 | *& ... | example.c:26:2:26:7 | *coords |
5454
| example.c:26:18:26:24 | getX output argument | example.c:26:2:26:7 | *coords |
5555
| example.c:26:18:26:24 | pointer to getX output argument | example.c:26:2:26:7 | coords |
56-
| example.c:26:19:26:24 | *coords | example.c:26:18:26:24 | *& ... |
5756
| example.c:26:19:26:24 | coords | example.c:26:18:26:24 | & ... |
5857
| example.c:28:22:28:25 | & ... | example.c:28:14:28:25 | & ... |
5958
| example.c:28:22:28:25 | *& ... | example.c:28:14:28:25 | *& ... |
60-
| example.c:28:23:28:25 | *pos | example.c:28:22:28:25 | *& ... |
6159
| example.c:28:23:28:25 | pos | example.c:28:22:28:25 | & ... |
6260
| test.cpp:6:12:6:17 | call to source | test.cpp:6:12:6:17 | call to source |
6361
| test.cpp:6:12:6:17 | call to source | test.cpp:7:8:7:9 | t1 |
@@ -134,7 +132,6 @@
134132
| test.cpp:384:10:384:13 | *& ... | test.cpp:384:10:384:13 | *& ... |
135133
| test.cpp:384:10:384:13 | memcpy output argument | test.cpp:385:8:385:10 | tmp |
136134
| test.cpp:384:10:384:13 | pointer to memcpy output argument | test.cpp:385:8:385:10 | tmp |
137-
| test.cpp:384:11:384:13 | *tmp | test.cpp:384:10:384:13 | *& ... |
138135
| test.cpp:384:11:384:13 | tmp | test.cpp:384:10:384:13 | & ... |
139136
| test.cpp:384:16:384:23 | & ... | test.cpp:384:16:384:23 | & ... |
140137
| test.cpp:384:16:384:23 | *& ... | test.cpp:384:3:384:8 | **call to memcpy |
@@ -143,7 +140,6 @@
143140
| test.cpp:384:16:384:23 | *& ... | test.cpp:384:16:384:23 | *& ... |
144141
| test.cpp:384:16:384:23 | **& ... | test.cpp:384:3:384:8 | **call to memcpy |
145142
| test.cpp:384:16:384:23 | **& ... | test.cpp:384:10:384:13 | memcpy output argument |
146-
| test.cpp:384:17:384:23 | *source1 | test.cpp:384:16:384:23 | *& ... |
147143
| test.cpp:384:17:384:23 | source1 | test.cpp:384:16:384:23 | & ... |
148144
| test.cpp:388:53:388:59 | source1 | test.cpp:391:16:391:23 | *& ... |
149145
| test.cpp:388:66:388:66 | b | test.cpp:393:7:393:7 | b |
@@ -153,15 +149,13 @@
153149
| test.cpp:390:18:390:21 | & ... | test.cpp:391:10:391:13 | & ... |
154150
| test.cpp:390:18:390:21 | *& ... | test.cpp:390:18:390:21 | *& ... |
155151
| test.cpp:390:18:390:21 | *& ... | test.cpp:391:10:391:13 | *& ... |
156-
| test.cpp:390:19:390:21 | *tmp | test.cpp:390:18:390:21 | *& ... |
157152
| test.cpp:390:19:390:21 | tmp | test.cpp:390:18:390:21 | & ... |
158153
| test.cpp:391:10:391:13 | & ... | test.cpp:391:3:391:8 | call to memcpy |
159154
| test.cpp:391:10:391:13 | & ... | test.cpp:391:10:391:13 | & ... |
160155
| test.cpp:391:10:391:13 | & ... | test.cpp:392:8:392:10 | tmp |
161156
| test.cpp:391:10:391:13 | *& ... | test.cpp:391:10:391:13 | *& ... |
162157
| test.cpp:391:10:391:13 | memcpy output argument | test.cpp:392:8:392:10 | tmp |
163158
| test.cpp:391:10:391:13 | pointer to memcpy output argument | test.cpp:392:8:392:10 | tmp |
164-
| test.cpp:391:11:391:13 | *tmp | test.cpp:391:10:391:13 | *& ... |
165159
| test.cpp:391:11:391:13 | tmp | test.cpp:391:10:391:13 | & ... |
166160
| test.cpp:391:16:391:23 | & ... | test.cpp:391:16:391:23 | & ... |
167161
| test.cpp:391:16:391:23 | *& ... | test.cpp:391:3:391:8 | **call to memcpy |
@@ -170,7 +164,6 @@
170164
| test.cpp:391:16:391:23 | *& ... | test.cpp:391:16:391:23 | *& ... |
171165
| test.cpp:391:16:391:23 | **& ... | test.cpp:391:3:391:8 | **call to memcpy |
172166
| test.cpp:391:16:391:23 | **& ... | test.cpp:391:10:391:13 | memcpy output argument |
173-
| test.cpp:391:17:391:23 | *source1 | test.cpp:391:16:391:23 | *& ... |
174167
| test.cpp:391:17:391:23 | source1 | test.cpp:391:16:391:23 | & ... |
175168
| test.cpp:392:8:392:10 | tmp | test.cpp:394:10:394:12 | tmp |
176169
| test.cpp:392:8:392:10 | tmp | test.cpp:394:10:394:12 | tmp |
@@ -209,5 +202,4 @@
209202
| test.cpp:1087:3:1087:3 | a [post update] | test.cpp:1088:8:1088:9 | & ... |
210203
| test.cpp:1087:15:1087:21 | 0 | test.cpp:1087:3:1087:21 | ... = ... |
211204
| test.cpp:1087:15:1087:21 | *0 | test.cpp:1087:3:1087:21 | *... = ... |
212-
| test.cpp:1088:9:1088:9 | *a | test.cpp:1088:8:1088:9 | *& ... |
213205
| test.cpp:1088:9:1088:9 | a | test.cpp:1088:8:1088:9 | & ... |

csharp/ql/lib/semmle/code/csharp/controlflow/internal/Completion.qll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,8 @@ private predicate isMatchingConstant(PatternExpr pe, boolean value) {
293293
value = true
294294
or
295295
exists(Type t, Type strippedType |
296+
not t instanceof UnknownType and
297+
not strippedType instanceof UnknownType and
296298
typePatternMustHaveMatchingCompletion(pe, t, strippedType) and
297299
not typePatternCommonSubType(t, strippedType) and
298300
value = false
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
* Increase query precision for `cs/useless-assignment-to-local` and `cs/constant-condition` when *unknown* types are involved (mostly relevant for `build-mode: none` databases).

csharp/ql/src/codeql-suites/csharp-ccr.qls

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@
77
- cs/reference-equality-on-valuetypes
88
- cs/self-assignment
99
- cs/inefficient-containskey
10+
- cs/call-to-object-tostring
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using System;
2+
3+
partial class C1
4+
{
5+
public C2 Prop { get; set; }
6+
}
7+
8+
class C2 { }
9+
10+
class ConstantMatching
11+
{
12+
void M1()
13+
{
14+
var c1 = new C1();
15+
if (c1.Prop is int) // $ Alert
16+
{
17+
}
18+
19+
// Should not be considered a constant condition as
20+
// we don't know anything about D.
21+
var d = new D();
22+
if (d.Prop is C2)
23+
{
24+
}
25+
}
26+
}
27+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
| ConstantCondition.cs:15:13:15:26 | ... is ... | Condition always evaluates to 'false'. |
2+
| ConstantCondition.cs:15:24:15:26 | access to type Int32 | Pattern never matches. |
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
query: Bad Practices/Control-Flow/ConstantCondition.ql
2+
postprocess: utils/test/InlineExpectationsTestQuery.ql

0 commit comments

Comments
 (0)