FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
codeql/csharp/ql/src/Dead Code/DeadCode.qll at codeql-cli/v2.19.2 · github/codeql · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
github
/
codeql
Public
Notifications
You must be signed in to change notification settings
Fork
2.1k
Star
10k
Code
Issues
997
Pull requests
467
Discussions
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Discussions
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
codeql
/
csharp
/
ql
/
src
/
Dead Code
/
DeadCode.qll
Copy path
More file actions
More file actions
Latest commit
History
History
History
101 lines (91 loc) · 2.85 KB
Breadcrumbs
codeql
/
csharp
/
ql
/
src
/
Dead Code
/
DeadCode.qll
Copy path
File metadata and controls
101 lines (91 loc) · 2.85 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import
csharp
import
semmle.code.csharp.commons.Util
import
semmle.code.csharp.frameworks.test.NUnit
MethodCall
getAnAccessByReflection
(
Method
m
)
{
exists
(
TypeofExpr
typeof
|
typeof
.
getTypeAccess
(
)
.
getType
(
)
=
m
.
getDeclaringType
(
)
and
result
.
getTarget
(
)
.
hasName
(
"GetMethod"
)
and
result
.
getQualifier
(
)
=
typeof
and
result
.
getArgument
(
0
)
.
getValue
(
)
=
m
.
getName
(
)
)
}
Expr
getAnAccessByDynamicCall
(
Method
m
)
{
exists
(
DynamicMethodCall
call
,
Type
receiverType
|
call
.
getLateBoundTargetName
(
)
=
m
.
getName
(
)
and
call
.
getQualifier
(
)
.
getType
(
)
=
receiverType
and
(
receiverType
instanceof
DynamicType
or
m
.
getDeclaringType
(
)
.
getABaseType
*
(
)
=
receiverType
)
and
result
=
call
)
or
exists
(
MethodCall
mc
,
Method
target
|
target
=
mc
.
getTarget
(
)
and
target
.
hasName
(
"InvokeMember"
)
and
target
.
getDeclaringType
(
)
.
hasFullyQualifiedName
(
"System"
,
"Type"
)
and
mc
.
getArgument
(
0
)
.
(
StringLiteral
)
.
getValue
(
)
=
m
.
getName
(
)
and
mc
.
getArgument
(
3
)
.
getType
(
)
.
(
RefType
)
.
hasMethod
(
m
)
and
result
=
mc
)
}
Expr
getAMethodAccess
(
Method
m
)
{
result
=
getAnAccessByDynamicCall
(
m
)
or
result
=
getAnAccessByReflection
(
m
)
or
result
.
(
MethodCall
)
.
getTarget
(
)
.
getUnboundDeclaration
(
)
=
m
or
result
.
(
MethodAccess
)
.
getTarget
(
)
.
getUnboundDeclaration
(
)
=
m
}
predicate
potentiallyAccessedByForEach
(
Method
m
)
{
m
.
hasName
(
"GetEnumerator"
)
and
m
.
getDeclaringType
(
)
.
getABaseType
+
(
)
.
hasFullyQualifiedName
(
"System.Collections"
,
"IEnumerable"
)
or
foreach_stmt_desugar
(
_
,
m
,
1
)
}
predicate
isRecursivelyLiveExpression
(
Expr
e
)
{
exists
(
Callable
c
|
c
=
e
.
getEnclosingCallable
(
)
|
isRecursivelyLiveMethod
(
c
)
or
not
c
instanceof
Method
)
}
predicate
isRecursivelyLiveMethod
(
Method
m
)
{
not
m
.
isPrivate
(
)
or
isRecursivelyLiveExpression
(
getAMethodAccess
(
m
)
)
or
m
instanceof
MainMethod
or
// Explicit implementations should be considered public
m
.
implementsExplicitInterface
(
)
or
potentiallyAccessedByForEach
(
m
)
or
isRecursivelyLiveMethod
(
m
.
(
ConstructedMethod
)
.
getUnboundDeclaration
(
)
)
or
nunitValueSource
(
m
)
or
exists
(
TestClass
tc
|
tc
.
getAMethod
(
)
=
m
and
exists
(
m
.
getAnAttribute
(
)
)
)
}
predicate
nunitValueSource
(
Method
m
)
{
exists
(
ValueSourceAttribute
attribute
|
attribute
.
getSourceMethod
(
)
=
m
)
}
predicate
nunitTestCaseSource
(
Declaration
f
)
{
exists
(
TestCaseSourceAttribute
attribute
|
attribute
.
getUnboundDeclaration
(
)
=
f
)
}
predicate
isDeadMethod
(
Method
m
)
{
not
isRecursivelyLiveMethod
(
m
)
and
m
.
isSourceDeclaration
(
)
}
predicate
isDeadField
(
Field
f
)
{
f
.
isPrivate
(
)
and
not
f
.
getDeclaringType
(
)
instanceof
AnonymousClass
and
f
.
getUnboundDeclaration
(
)
=
f
and
not
nunitTestCaseSource
(
f
)
and
forall
(
FieldAccess
fc
|
fc
.
getTarget
(
)
.
getUnboundDeclaration
(
)
=
f
|
isDeadMethod
(
fc
.
getEnclosingCallable
(
)
)
or
not
fc
instanceof
FieldRead
and
not
fc
.
isRefArgument
(
)
)
}
Back
|
FazBrowse Home
|
New Git URL