WALA icon indicating copy to clipboard operation
WALA copied to clipboard

No dominance frontier error when creating PDG including switch case only containing default branch in CAst

Open mattkindy opened this issue 5 years ago • 1 comments

I'm getting the error

java.lang.IllegalArgumentException: no dominance frontier for node BB[SSA:13..13]12 - source_code_for_testing.dominance_frontier.PostgreSQLErrorConverter.convert(Ljava/sql/SQLException;)I

    at com.ibm.wala.util.graph.dominators.DominanceFrontiers.getDominanceFrontier(DominanceFrontiers.java:48)
    at com.ibm.wala.cfg.cdg.ControlDependenceGraph.buildControlDependence(ControlDependenceGraph.java:72)
    at com.ibm.wala.cfg.cdg.ControlDependenceGraph.<init>(ControlDependenceGraph.java:220)
    at com.ibm.wala.cfg.cdg.ControlDependenceGraph.<init>(ControlDependenceGraph.java:225)
    at com.ibm.wala.ipa.slicer.PDG.createControlDependenceEdges(PDG.java:270)
    at com.ibm.wala.ipa.slicer.PDG.createScalarEdges(PDG.java:200)
    at com.ibm.wala.ipa.slicer.PDG.populate(PDG.java:193)
    at com.ibm.wala.ipa.slicer.PDG.iterator(PDG.java:1216)
package source_code_for_testing.dominance_frontier;

import java.sql.SQLException;

import org.apache.log4j.Logger;

/**
 * Converts SQLExceptions from PostgreSQL into SQLPower error numbers.
 */
public class PostgreSQLErrorConverter extends AbstractErrorConverter {

    private final static Logger logger = Logger.getLogger(PostgreSQLErrorConverter.class);

    public int convert(SQLException e) {
        String state = e.getSQLState();

        logger.debug("SQL STATE = " + state);

        if ("28000".equals(state))
            return INVALID_LOGON;
        if ("42703".equals(state))
            return UNKNOWN_COLUMN;    // postgresql 8.x, proto version 3

        switch (e.getErrorCode()) {

        default:
            return UNKNOWN_ERROR;
        }
    }
}

It looks like the basic block that's causing this error has no immediate dominators (the dominance info's dominator property is null). I've verified I don't encounter the error if I change

switch (e.getErrorCode()) {

    default:
        return UNKNOWN_ERROR;
}

to

return UNKNOWN_ERROR;

or

switch (e.getErrorCode()) {
    case 1:
        return 1;
    default:
        return UNKNOWN_ERROR;
}

This is the simplest code snippet to where I can reproduce this locally

public class DominanceFrontierCase {

    public int convert(Integer i) {
        switch (i.intValue()) {
        default:
            return 1;
        }
    }
}

In AstTranslator, visitSwitch(CAstNode n, WalkContext c, CAstVisitor<WalkContext> visitor) calls to doSimpleSwitch(CAstNode n, WalkContext context, CAstVisitor<WalkContext> visitor) or doIfConvertSwitch(CAstNode n, WalkContext context, CAstVisitor<WalkContext> visitor) depending on the case. I see in doIfConvertSwitch that the defaultGotoBlock has fallthrough set to true; however, in doSimpleSwitch, the equivalent block seems to be set to false. When I change the latter to true, the error disappears

mattkindy avatar Jan 28 '20 20:01 mattkindy

@juliandolby I think this might be fixed now too?

msridhar avatar Mar 05 '21 23:03 msridhar