Program: 19238
Project: 19238
Buggy source:
/** 
 * Computes the GEN and KILL set.
 * @param n Root node.
 * @param gen Local variables that are live because of the instruction at {@code n} will be addedto this set.
 * @param kill Local variables that are killed because of the instruction at {@code n} will beadded to this set.
 * @param conditional {@code true} if any assignments encountered are conditionally executed.These assignments might not kill a variable.
 */
private void computeGenKill(Node n,BitSet gen,BitSet kill,boolean conditional){
switch (n.getToken()) {
case SCRIPT:
case ROOT:
case FUNCTION:
case BLOCK:
    return;
case WHILE:
case DO:
case IF:
case FOR:
  computeGenKill(NodeUtil.getConditionExpression(n),gen,kill,conditional);
return;
case FOR_OF:
case FOR_IN:
{
Node lhs=n.getFirstChild();
if (NodeUtil.isNameDeclaration(lhs)) {
  lhs=lhs.getLastChild();
}
if (lhs.isName()) {
  addToSetIfLocal(lhs,kill);
  addToSetIfLocal(lhs,gen);
}
 else {
  computeGenKill(lhs,gen,kill,conditional);
}
return;
}
case LET:
case CONST:
case VAR:
for (Node c=n.getFirstChild(); c != null; c=c.getNext()) {
if (c.isName()) {
if (c.hasChildren()) {
  computeGenKill(c.getFirstChild(),gen,kill,conditional);
  if (!conditional) {
    addToSetIfLocal(c,kill);
  }
}
}
 else {
Iterable<Node> allVars=NodeUtil.findLhsNodesInNode(n);
for (Node child : allVars) {
  addToSetIfLocal(child,kill);
}
}
}
return;
case AND:
case OR:
computeGenKill(n.getFirstChild(),gen,kill,conditional);
computeGenKill(n.getLastChild(),gen,kill,true);
return;
case HOOK:
computeGenKill(n.getFirstChild(),gen,kill,conditional);
computeGenKill(n.getSecondChild(),gen,kill,true);
computeGenKill(n.getLastChild(),gen,kill,true);
return;
case NAME:
if (isArgumentsName(n)) {
markAllParametersEscaped();
}
 else {
addToSetIfLocal(n,gen);
}
return;
default :
if (NodeUtil.isAssignmentOp(n) && n.getFirstChild().isName()) {
Node lhs=n.getFirstChild();
if (!conditional) {
addToSetIfLocal(lhs,kill);
}
if (!n.isAssign()) {
addToSetIfLocal(lhs,gen);
}
computeGenKill(lhs.getNext(),gen,kill,conditional);
}
 else {
for (Node c=n.getFirstChild(); c != null; c=c.getNext()) {
computeGenKill(c,gen,kill,conditional);
}
}
return;
}
}

Fixed version (ground truth):
/** 
 * Computes the GEN and KILL set.
 * @param n Root node.
 * @param gen Local variables that are live because of the instruction at {@code n} will be addedto this set.
 * @param kill Local variables that are killed because of the instruction at {@code n} will beadded to this set.
 * @param conditional {@code true} if any assignments encountered are conditionally executed.These assignments might not kill a variable.
 */
private void computeGenKill(Node n,BitSet gen,BitSet kill,boolean conditional){
switch (n.getToken()) {
case SCRIPT:
case ROOT:
case FUNCTION:
case BLOCK:
    return;
case WHILE:
case DO:
case IF:
case FOR:
  computeGenKill(NodeUtil.getConditionExpression(n),gen,kill,conditional);
return;
case FOR_OF:
case FOR_IN:
{
Node lhs=n.getFirstChild();
if (NodeUtil.isNameDeclaration(lhs)) {
  lhs=lhs.getLastChild();
}
if (lhs.isName()) {
  addToSetIfLocal(lhs,kill);
  addToSetIfLocal(lhs,gen);
}
 else {
  computeGenKill(lhs,gen,kill,conditional);
}
return;
}
case LET:
case CONST:
case VAR:
for (Node c=n.getFirstChild(); c != null; c=c.getNext()) {
if (c.isName()) {
if (c.hasChildren()) {
  computeGenKill(c.getFirstChild(),gen,kill,conditional);
  if (!conditional) {
    addToSetIfLocal(c,kill);
  }
}
}
 else {
computeGenKill(c,gen,kill,conditional);
}
}
return;
case DESTRUCTURING_LHS:
if (n.hasTwoChildren()) {
computeGenKill(n.getSecondChild(),gen,kill,conditional);
if (!conditional) {
Iterable<Node> allVars=NodeUtil.findLhsNodesInNode(n);
for (Node child : allVars) {
addToSetIfLocal(child,kill);
}
}
}
return;
case AND:
case OR:
computeGenKill(n.getFirstChild(),gen,kill,conditional);
computeGenKill(n.getLastChild(),gen,kill,true);
return;
case HOOK:
computeGenKill(n.getFirstChild(),gen,kill,conditional);
computeGenKill(n.getSecondChild(),gen,kill,true);
computeGenKill(n.getLastChild(),gen,kill,true);
return;
case NAME:
if (isArgumentsName(n)) {
markAllParametersEscaped();
}
 else {
addToSetIfLocal(n,gen);
}
return;
default :
if (NodeUtil.isAssignmentOp(n) && n.getFirstChild().isName()) {
Node lhs=n.getFirstChild();
if (!conditional) {
addToSetIfLocal(lhs,kill);
}
if (!n.isAssign()) {
addToSetIfLocal(lhs,gen);
}
computeGenKill(lhs.getNext(),gen,kill,conditional);
}
 else {
for (Node c=n.getFirstChild(); c != null; c=c.getNext()) {
computeGenKill(c,gen,kill,conditional);
}
}
return;
}
}