@@ -67,8 +67,8 @@ class AlwaysNullExpr extends Expr {
6767 exists ( AlwaysNullExpr e1 , AlwaysNullExpr e2 | G:: Internal:: nullValueImpliedBinary ( e1 , e2 , this ) )
6868 or
6969 this =
70- any ( Ssa :: Definition def |
71- forex ( Ssa :: Definition u | u = def .getAnUltimateDefinition ( ) | nullDef ( u ) )
70+ any ( SsaDefinition def |
71+ forex ( SsaDefinition u | u = def .getAnUltimateDefinition ( ) | nullDef ( u ) )
7272 ) .getARead ( )
7373 or
7474 exists ( Callable target |
@@ -80,9 +80,7 @@ class AlwaysNullExpr extends Expr {
8080}
8181
8282/** Holds if SSA definition `def` is always `null`. */
83- private predicate nullDef ( Ssa:: ExplicitDefinition def ) {
84- def .getADefinition ( ) .getSource ( ) instanceof AlwaysNullExpr
85- }
83+ private predicate nullDef ( SsaExplicitWrite def ) { def .getValue ( ) instanceof AlwaysNullExpr }
8684
8785/** An expression that is never `null`. */
8886class NonNullExpr extends Expr {
@@ -94,8 +92,8 @@ class NonNullExpr extends Expr {
9492 this instanceof G:: NullGuardedExpr
9593 or
9694 this =
97- any ( Ssa :: Definition def |
98- forex ( Ssa :: Definition u | u = def .getAnUltimateDefinition ( ) | nonNullDef ( u ) )
95+ any ( SsaDefinition def |
96+ forex ( SsaDefinition u | u = def .getAnUltimateDefinition ( ) | nonNullDef ( u ) )
9997 ) .getARead ( )
10098 or
10199 exists ( Callable target |
@@ -108,10 +106,10 @@ class NonNullExpr extends Expr {
108106}
109107
110108/** Holds if SSA definition `def` is never `null`. */
111- private predicate nonNullDef ( Ssa :: ExplicitDefinition def ) {
112- def .getADefinition ( ) . getSource ( ) instanceof NonNullExpr
109+ private predicate nonNullDef ( SsaExplicitWrite def ) {
110+ def .getValue ( ) instanceof NonNullExpr
113111 or
114- exists ( AssignableDefinition ad | ad = def .getADefinition ( ) |
112+ exists ( AssignableDefinition ad | ad = def .getDefinition ( ) |
115113 ad instanceof AssignableDefinitions:: PatternDefinition
116114 or
117115 ad =
@@ -124,13 +122,11 @@ private predicate nonNullDef(Ssa::ExplicitDefinition def) {
124122}
125123
126124/**
127- * Holds if `node ` is a dereference `d` of SSA definition `def`.
125+ * Holds if `d ` is a dereference of SSA definition `def`.
128126 */
129- private predicate dereferenceAt ( ControlFlowNode node , Ssa:: Definition def , Dereference d ) {
130- d = def .getAReadAtNode ( node )
131- }
127+ private predicate dereferenceAt ( SsaDefinition def , Dereference d ) { d = def .getARead ( ) }
132128
133- private predicate isMaybeNullArgument ( Ssa :: ParameterDefinition def , MaybeNullExpr arg ) {
129+ private predicate isMaybeNullArgument ( SsaParameterInit def , MaybeNullExpr arg ) {
134130 exists ( AssignableDefinitions:: ImplicitParameterDefinition pdef , Parameter p |
135131 p = def .getParameter ( )
136132 |
@@ -182,18 +178,18 @@ private predicate hasMultipleParamsArguments(Call c) {
182178}
183179
184180/** Holds if `def` is an SSA definition that may be `null`. */
185- private predicate defMaybeNull ( Ssa :: Definition def , ControlFlowNode node , string msg , Element reason ) {
181+ private predicate defMaybeNull ( SsaDefinition def , ControlFlowNode node , string msg , Element reason ) {
186182 not nonNullDef ( def ) and
187183 (
188184 // A variable compared to `null` might be `null`
189185 exists ( G:: DereferenceableExpr de | de = def .getARead ( ) |
190186 de .guardSuggestsMaybeNull ( reason ) and
191187 msg = "as suggested by $@ null check" and
192188 node = def .getControlFlowNode ( ) and
193- not de = any ( Ssa :: PhiNode phi ) .getARead ( ) and
189+ not de = any ( SsaPhiDefinition phi ) .getARead ( ) and
194190 // Don't use a check as reason if there is a `null` assignment
195191 // or argument
196- not def .( Ssa :: ExplicitDefinition ) . getADefinition ( ) . getSource ( ) instanceof MaybeNullExpr and
192+ not def .( SsaExplicitWrite ) . getValue ( ) instanceof MaybeNullExpr and
197193 not isMaybeNullArgument ( def , _)
198194 )
199195 or
@@ -207,41 +203,41 @@ private predicate defMaybeNull(Ssa::Definition def, ControlFlowNode node, string
207203 )
208204 or
209205 // If the source of a variable is `null` then the variable may be `null`
210- exists ( AssignableDefinition adef | adef = def .( Ssa :: ExplicitDefinition ) . getADefinition ( ) |
206+ exists ( AssignableDefinition adef | adef = def .( SsaExplicitWrite ) . getDefinition ( ) |
211207 adef .getSource ( ) = maybeNullExpr ( node .asExpr ( ) ) and
212208 reason = adef .getExpr ( ) and
213209 msg = "because of $@ assignment"
214210 )
215211 or
216212 // A variable of nullable type may be null
217- exists ( Dereference d | dereferenceAt ( _ , def , d ) |
213+ exists ( Dereference d | dereferenceAt ( def , d ) |
218214 node = def .getControlFlowNode ( ) and
219215 d .hasNullableType ( ) and
220- not def instanceof Ssa :: PhiNode and
216+ not def instanceof SsaPhiDefinition and
221217 reason = def .getSourceVariable ( ) .getAssignable ( ) and
222218 msg = "because it has a nullable type"
223219 )
224220 )
225221}
226222
227- private Ssa :: Definition getAPseudoInput ( Ssa :: Definition def ) {
228- result = def .( Ssa :: PhiNode ) .getAnInput ( )
223+ private SsaDefinition getAPseudoInput ( SsaDefinition def ) {
224+ result = def .( SsaPhiDefinition ) .getAnInput ( )
229225}
230226
231227// `def.getAnUltimateDefinition()` includes inputs into uncertain
232228// definitions, but we only want inputs into pseudo nodes
233- private Ssa :: Definition getAnUltimateDefinition ( Ssa :: Definition def ) {
229+ private SsaDefinition getAnUltimateDefinition ( SsaDefinition def ) {
234230 result = getAPseudoInput * ( def ) and
235- not result instanceof Ssa :: PhiNode
231+ not result instanceof SsaPhiDefinition
236232}
237233
238234/**
239235 * Holds if SSA definition `def` can reach a read at `cfn`, without passing
240236 * through an intermediate dereference that always throws a null reference
241237 * exception.
242238 */
243- private predicate defReaches ( Ssa :: Definition def , ControlFlowNode cfn ) {
244- exists ( def . getAFirstReadAtNode ( cfn ) )
239+ private predicate defReaches ( SsaDefinition def , ControlFlowNode cfn ) {
240+ Ssa :: ssaGetAFirstUse ( def ) . getControlFlowNode ( ) = cfn
245241 or
246242 exists ( ControlFlowNode mid | defReaches ( def , mid ) |
247243 SsaImpl:: adjacentReadPairSameVar ( _, mid , cfn ) and
@@ -250,11 +246,12 @@ private predicate defReaches(Ssa::Definition def, ControlFlowNode cfn) {
250246}
251247
252248private module NullnessConfig implements ControlFlowReachability:: ConfigSig {
253- predicate source ( ControlFlowNode node , Ssa :: Definition def ) { defMaybeNull ( def , node , _, _) }
249+ predicate source ( ControlFlowNode node , SsaDefinition def ) { defMaybeNull ( def , node , _, _) }
254250
255- predicate sink ( ControlFlowNode node , Ssa :: Definition def ) {
251+ predicate sink ( ControlFlowNode node , SsaDefinition def ) {
256252 exists ( Dereference d |
257- dereferenceAt ( node , def , d ) and
253+ dereferenceAt ( def , d ) and
254+ node = d .getControlFlowNode ( ) and
258255 not d instanceof NonNullExpr
259256 )
260257 }
@@ -267,11 +264,12 @@ private module NullnessConfig implements ControlFlowReachability::ConfigSig {
267264private module NullnessFlow = ControlFlowReachability:: Flow< NullnessConfig > ;
268265
269266predicate maybeNullDeref ( Dereference d , Ssa:: SourceVariable v , string msg , Element reason ) {
270- exists ( Ssa :: Definition origin , Ssa :: Definition ssa , ControlFlowNode src , ControlFlowNode sink |
267+ exists ( SsaDefinition origin , SsaDefinition ssa , ControlFlowNode src , ControlFlowNode sink |
271268 defMaybeNull ( origin , src , msg , reason ) and
272269 NullnessFlow:: flow ( src , origin , sink , ssa ) and
273270 ssa .getSourceVariable ( ) = v and
274- dereferenceAt ( sink , ssa , d ) and
271+ dereferenceAt ( ssa , d ) and
272+ sink = d .getControlFlowNode ( ) and
275273 not d .isAlwaysNull ( v )
276274 )
277275}
@@ -322,9 +320,7 @@ class Dereference extends G::DereferenceableExpr {
322320 not p .getAnnotatedType ( ) .isNullableRefType ( )
323321 or
324322 p .fromSource ( ) and
325- exists (
326- Ssa:: ParameterDefinition def , AssignableDefinitions:: ImplicitParameterDefinition pdef
327- |
323+ exists ( SsaParameterInit def , AssignableDefinitions:: ImplicitParameterDefinition pdef |
328324 p = def .getParameter ( )
329325 |
330326 p .getUnboundDeclaration ( ) = pdef .getParameter ( ) and
@@ -334,9 +330,9 @@ class Dereference extends G::DereferenceableExpr {
334330 )
335331 }
336332
337- private predicate isAlwaysNull0 ( Ssa :: Definition def ) {
338- forall ( Ssa :: Definition input | input = getAnUltimateDefinition ( def ) |
339- input .( Ssa :: ExplicitDefinition ) . getADefinition ( ) . getSource ( ) instanceof AlwaysNullExpr
333+ private predicate isAlwaysNull0 ( SsaDefinition def ) {
334+ forall ( SsaDefinition input | input = getAnUltimateDefinition ( def ) |
335+ input .( SsaExplicitWrite ) . getValue ( ) instanceof AlwaysNullExpr
340336 ) and
341337 not nonNullDef ( def ) and
342338 this = def .getARead ( ) and
@@ -352,7 +348,7 @@ class Dereference extends G::DereferenceableExpr {
352348 // Exclude fields and properties, as they may not have an accurate SSA representation
353349 v .getAssignable ( ) instanceof LocalScopeVariable and
354350 (
355- forex ( Ssa :: Definition def0 | this = def0 .getARead ( ) | this .isAlwaysNull0 ( def0 ) )
351+ forex ( SsaDefinition def0 | this = def0 .getARead ( ) | this .isAlwaysNull0 ( def0 ) )
356352 or
357353 exists ( G:: GuardValue nv |
358354 this .( G:: GuardedExpr ) .mustHaveValue ( nv ) and
0 commit comments