Package edu.umd.cs.findbugs.ba.vna

Examples of edu.umd.cs.findbugs.ba.vna.ValueNumberFrame


            // edge.getSource().getId() + " has no value number");
            return tmpFact;
        }

        ValueNumber instanceOfValueNumber = check.getValueNumber();
        ValueNumberFrame vnaFrame = valueNumberDataflow.getStartFact(edge.getTarget());
        if (!vnaFrame.isValid()) {
            return tmpFact;
        }

        Type instanceOfType = check.getType();
        if (!(instanceOfType instanceof ReferenceType || instanceOfType instanceof NullType)) {
            return tmpFact;
        }

        short branchOpcode = edge.getSource().getLastInstruction().getInstruction().getOpcode();

        int edgeType = edge.getType();
        int numSlots = Math.min(fact.getNumSlots(), vnaFrame.getNumSlots());

        if ((edgeType == EdgeTypes.IFCMP_EDGE && (branchOpcode == Constants.IFNE || branchOpcode == Constants.IFGT || branchOpcode == Constants.IFNULL))

                || (edgeType == EdgeTypes.FALL_THROUGH_EDGE && (branchOpcode == Constants.IFEQ || branchOpcode == Constants.IFLE || branchOpcode == Constants.IFNONNULL))) {
            // System.out.println("Successful check on edge " + edge);

            // Successful instanceof check.

            for (int i = 0; i < numSlots; ++i) {
                if (!vnaFrame.getValue(i).equals(instanceOfValueNumber)) {
                    continue;
                }

                Type checkedType = fact.getValue(i);
                if (!(checkedType instanceof ReferenceType)) {
                    continue;
                }

                // Only refine the type if the cast is feasible: i.e., a
                // downcast.
                // Otherwise, just set it to TOP.
                try {
                    boolean guaranteed = Hierarchy.isSubtype((ReferenceType) checkedType, (ReferenceType) instanceOfType);
                    if (guaranteed) {
                        continue;
                    }

                    boolean feasibleCheck = instanceOfType.equals(NullType.instance())
                            || Hierarchy.isSubtype((ReferenceType) instanceOfType, (ReferenceType) checkedType);

                    if (!feasibleCheck && instanceOfType instanceof ObjectType && checkedType instanceof ObjectType) {
                        double v = Analyze.deepInstanceOf(((ObjectType) instanceOfType).getClassName(),
                                ((ObjectType) checkedType).getClassName());
                        if (v > 0.0) {
                            feasibleCheck = true;
                        }
                    }
                    tmpFact = modifyFrame(fact, tmpFact);
                    if (feasibleCheck) {
                        tmpFact.setValue(i, instanceOfType);
                    } else {
                        tmpFact.setTop();
                        return tmpFact;
                    }
                } catch (ClassNotFoundException e) {
                    lookupFailureCallback.reportMissingClass(e);
                    return tmpFact;
                }
            }
        } else if (!instanceOfType.equals(NullType.instance())) {

            for (int i = 0; i < numSlots; ++i) {
                if (!vnaFrame.getValue(i).equals(instanceOfValueNumber)) {
                    continue;
                }

                Type checkedType = fact.getValue(i);
                if (!(checkedType instanceof ReferenceType)) {
View Full Code Here


            if (className.equals("java.lang.Class") && valueNumberDataflow != null) {
                // Record the value number of the value checked by this
                // instruction,
                // and the type the value was compared to.
                try {
                    ValueNumberFrame vnaFrame = valueNumberDataflow.getFactAtLocation(getLocation());
                    if (vnaFrame.isValid()) {
                        ValueNumber stackValue = vnaFrame.getStackValue(1);
                        if (stackValue.hasFlag(ValueNumber.CONSTANT_CLASS_OBJECT)) {
                            String c = valueNumberDataflow.getClassName(stackValue);
                            if (c != null) {
                                if (c.charAt(0) != '[' && !c.endsWith(";")) {
                                    c = "L" + c.replace('.', '/') + ";";
                                }
                                Type type = Type.getType(c);
                                if (type instanceof ReferenceType) {
                                    instanceOfValueNumber = vnaFrame.getTopValue();
                                    instanceOfType = (ReferenceType) type;
                                    sawEffectiveInstanceOf = true;
                                }
                            }
                        }
View Full Code Here

    public void visitINSTANCEOF(INSTANCEOF obj) {
        if (valueNumberDataflow != null) {
            // Record the value number of the value checked by this instruction,
            // and the type the value was compared to.
            try {
                ValueNumberFrame vnaFrame = valueNumberDataflow.getFactAtLocation(getLocation());
                if (vnaFrame.isValid()) {
                    final Type type = obj.getType(getCPG());
                    if (type instanceof ReferenceType) {
                        instanceOfValueNumber = vnaFrame.getTopValue();
                        instanceOfType = (ReferenceType) type;
                        sawEffectiveInstanceOf = true;
                    }
                }
            } catch (DataflowAnalysisException e) {
View Full Code Here

        if (valueNumberDataflow != null) {
            // Record the value number of the value checked by this instruction,
            // and the type the value was compared to.
            try {
                ValueNumberFrame vnaFrame = valueNumberDataflow.getFactAtLocation(getLocation());
                if (vnaFrame.isValid()) {
                    instanceOfValueNumber = vnaFrame.getTopValue();

                    instanceOfType = NullType.instance();
                    instanceOfFollowedByBranch = true;
                }
            } catch (DataflowAnalysisException e) {
View Full Code Here

        if (valueNumberDataflow != null) {
            // Record the value number of the value checked by this instruction,
            // and the type the value was compared to.
            try {
                ValueNumberFrame vnaFrame = valueNumberDataflow.getFactAtLocation(getLocation());
                if (vnaFrame.isValid()) {
                    instanceOfValueNumber = vnaFrame.getTopValue();

                    instanceOfType = NullType.instance();
                    instanceOfFollowedByBranch = true;
                }
            } catch (DataflowAnalysisException e) {
View Full Code Here

    private BitSet findPreviouslyDeadBlocks() throws DataflowAnalysisException, CFGBuilderException {
        BitSet deadBlocks = new BitSet();
        ValueNumberDataflow vnaDataflow = classContext.getValueNumberDataflow(method);
        for (Iterator<BasicBlock> i = vnaDataflow.getCFG().blockIterator(); i.hasNext();) {
            BasicBlock block = i.next();
            ValueNumberFrame vnaFrame = vnaDataflow.getStartFact(block);
            if (vnaFrame.isTop()) {
                deadBlocks.set(block.getLabel());
            }
        }

        return deadBlocks;
View Full Code Here

            for (Iterator<Location> i = classContext.getCFG(method).locationIterator(); i.hasNext();) {
                Location location = i.next();
                Instruction ins = location.getHandle().getInstruction();
                try {
                    ValueNumberFrame vnaFrame = classContext.getValueNumberDataflow(method).getFactAtLocation(location);
                    if (!vnaFrame.isValid()) {
                        continue;
                    }

                    if (ins instanceof InvokeInstruction) {
                        examineCallSite(location, cpg, typeDataflow);
View Full Code Here

                    .getResolvedAnnotation(field, false);
            if (annotation == NullnessAnnotation.NONNULL) {

                BugAnnotation variableAnnotation = null;
                try {
                    ValueNumberFrame vnaFrame = classContext.getValueNumberDataflow(method).getFactAtLocation(location);
                    ValueNumber valueNumber = vnaFrame.getTopValue();
                    variableAnnotation = ValueNumberSourceInfo.findAnnotationFromValueNumber(method, location, valueNumber,
                            vnaFrame, "VALUE_OF");

                } catch (DataflowAnalysisException e) {
                    AnalysisContext.logError("error", e);
View Full Code Here

            System.out.println("Checking null return at " + location);
        }

        IsNullValueDataflow invDataflow = classContext.getIsNullValueDataflow(method);
        IsNullValueFrame frame = invDataflow.getFactAtLocation(location);
        ValueNumberFrame vnaFrame = classContext.getValueNumberDataflow(method).getFactAtLocation(location);
        if (!vnaFrame.isValid()) {
            return;
        }
        ValueNumber valueNumber = vnaFrame.getTopValue();
        if (!frame.isValid()) {
            return;
        }
        IsNullValue tos = frame.getTopValue();
        if (tos.isDefinitelyNull()) {
View Full Code Here

        propertySet.decorateBugInstance(warning);
    }

    private void addParamAnnotations(Location location, BitSet definitelyNullArgSet, BitSet violatedParamSet,
            WarningPropertySet<? super NullArgumentWarningProperty> propertySet, BugInstance warning) {
        ValueNumberFrame vnaFrame = null;
        try {
            vnaFrame = classContext.getValueNumberDataflow(method).getFactAtLocation(location);
        } catch (DataflowAnalysisException e) {
            AnalysisContext.logError("error", e);
        } catch (CFGBuilderException e) {
            AnalysisContext.logError("error", e);
        }

        InvokeInstruction instruction = (InvokeInstruction) location.getHandle().getInstruction();
        SignatureParser sigParser = new SignatureParser(instruction.getSignature(classContext.getConstantPoolGen()));

        for (int i = violatedParamSet.nextSetBit(0); i >= 0; i = violatedParamSet.nextSetBit(i + 1)) {
            boolean definitelyNull = definitelyNullArgSet.get(i);

            if (definitelyNull) {
                propertySet.addProperty(NullArgumentWarningProperty.ARG_DEFINITELY_NULL);
            }
            ValueNumber valueNumber = null;
            if (vnaFrame != null) {
                try {
                    valueNumber = vnaFrame.getArgument(instruction, classContext.getConstantPoolGen(), i, sigParser);
                    BugAnnotation variableAnnotation = ValueNumberSourceInfo.findAnnotationFromValueNumber(method, location,
                            valueNumber, vnaFrame, "VALUE_OF");
                    warning.addOptionalAnnotation(variableAnnotation);
                } catch (DataflowAnalysisException e) {
                    AnalysisContext.logError("error", e);
View Full Code Here

TOP

Related Classes of edu.umd.cs.findbugs.ba.vna.ValueNumberFrame

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.