@@ -809,6 +809,9 @@ module IR {
809809
810810 override Instruction getRhs ( ) { result = this }
811811
812+ /** Gets the variable (a local or a named result) being zero-initialized. */
813+ ValueEntity getVariable ( ) { result = v }
814+
812815 override Type getResultType ( ) { result = v .getType ( ) }
813816
814817 override ControlFlow:: Root getRoot ( ) { result .isRootOf ( v .getDeclaration ( ) ) }
@@ -1112,14 +1115,12 @@ module IR {
11121115 lhs = fd .getParameter ( idx ) .getDeclaration ( )
11131116 )
11141117 or
1115- exists ( FuncDef fd , int idx |
1116- write .isAdditional ( fd .getBody ( ) , "zero-init:" + idx .toString ( ) ) and
1117- lhs = fd .getResultVar ( idx ) .getDeclaration ( )
1118- )
1119- or
1120- exists ( ValueSpec spec , int idx |
1121- write .isAdditional ( spec , "zero-init:" + idx .toString ( ) ) and
1122- lhs = spec .getNameExpr ( idx )
1118+ // The `zero-init` node writes the variable it initializes: a named
1119+ // function result or a local declared without an initializer.
1120+ exists ( int idx , AstNode an | write .isAdditional ( an , "zero-init:" + idx .toString ( ) ) |
1121+ an = any ( FuncDef fd | lhs = fd .getResultVar ( idx ) .getDeclaration ( ) ) .getBody ( )
1122+ or
1123+ an = any ( ValueSpec spec | lhs = spec .getNameExpr ( idx ) )
11231124 )
11241125 or
11251126 // A tuple-destructuring `extract` node writes its component directly (see
@@ -1392,17 +1393,7 @@ module IR {
13921393 * Gets the instruction corresponding to the implicit initialization of `v`
13931394 * to its zero value.
13941395 */
1395- EvalImplicitInitInstruction implicitInitInstruction ( ValueEntity v ) {
1396- exists ( ValueSpec spec , int i |
1397- spec .getNameExpr ( i ) = v .getDeclaration ( ) and
1398- result .isAdditional ( spec , "zero-init:" + i .toString ( ) )
1399- )
1400- or
1401- exists ( FuncDef fd , int i |
1402- fd .getResultVar ( i ) = v and
1403- result .isAdditional ( fd .getBody ( ) , "zero-init:" + i .toString ( ) )
1404- )
1405- }
1396+ EvalImplicitInitInstruction implicitInitInstruction ( ValueEntity v ) { result .getVariable ( ) = v }
14061397
14071398 /**
14081399 * Gets the instruction corresponding to the extraction of the `idx`th element
0 commit comments