This repository was archived by the owner on Jan 5, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +28
-0
lines changed
test/query-tests/RedundantCode/CompareIdenticalValues Expand file tree Collapse file tree 3 files changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -24,6 +24,11 @@ class SsaSourceVariable extends LocalVariable {
24
24
// variables that have their address taken
25
25
exists ( AddressExpr addr | addr .getOperand ( ) .stripParens ( ) = getAUse ( ) )
26
26
or
27
+ exists ( DataFlow:: MethodReadNode mrn |
28
+ mrn .getReceiver ( ) = getARead ( ) and
29
+ mrn .getMethod ( ) .getReceiverType ( ) instanceof PointerType
30
+ )
31
+ or
27
32
// variables where there is an unresolved reference with the same name in the same
28
33
// scope or a nested scope, suggesting that name resolution information may be incomplete
29
34
exists ( FunctionScope scope , FuncDef inner |
Original file line number Diff line number Diff line change 1
1
| CompareIdenticalValues.go:9:3:9:8 | ...<=... | This expression compares $@ to itself. | CompareIdenticalValues.go:9:3:9:3 | y | an expression |
2
2
| tst.go:6:9:6:14 | ...==... | This expression compares $@ to itself. | tst.go:6:9:6:9 | x | an expression |
3
+ | tst.go:60:9:60:14 | ...==... | This expression compares $@ to itself. | tst.go:60:9:60:9 | y | an expression |
3
4
| vp.go:16:9:16:38 | ...!=... | This expression compares $@ to itself. | vp.go:16:9:16:21 | call to GetLength | an expression |
Original file line number Diff line number Diff line change @@ -37,3 +37,25 @@ func baz() bool {
37
37
bump (& x )
38
38
return x == 0
39
39
}
40
+
41
+ type counter int
42
+
43
+ func (x * counter ) bump () {
44
+ * x ++
45
+ }
46
+
47
+ func (x counter ) bimp () {
48
+ x ++
49
+ }
50
+
51
+ func baz2 () bool {
52
+ var x counter
53
+ x .bump ()
54
+ return x == 0 // OK
55
+ }
56
+
57
+ func baz3 () bool {
58
+ var y counter
59
+ y .bimp ()
60
+ return y == 0 // NOT OK
61
+ }
You can’t perform that action at this time.
0 commit comments