[Fb-contrib-commit] SF.net SVN: fb-contrib: [938] trunk/fb-contrib
Brought to you by:
dbrosius
From: <dbr...@us...> - 2007-10-13 06:07:03
|
Revision: 938 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=938&view=rev Author: dbrosius Date: 2007-10-12 23:06:58 -0700 (Fri, 12 Oct 2007) Log Message: ----------- If the ICONST_1 instruction is the branch target of one or more src statements, or if the ICONST_0 is the branch target of two or more src statements, it is probably generated by the compiler so don't report. Modified Paths: -------------- trunk/fb-contrib/samples/SPP_Sample.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java Modified: trunk/fb-contrib/samples/SPP_Sample.java =================================================================== --- trunk/fb-contrib/samples/SPP_Sample.java 2007-10-13 05:18:24 UTC (rev 937) +++ trunk/fb-contrib/samples/SPP_Sample.java 2007-10-13 06:06:58 UTC (rev 938) @@ -86,6 +86,9 @@ public boolean testFPUselessTrinary(boolean a, boolean b) { - return a || b; + if (a && b) + return a || b; + + return a && b; } } Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java 2007-10-13 05:18:24 UTC (rev 937) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java 2007-10-13 06:06:58 UTC (rev 938) @@ -19,7 +19,9 @@ package com.mebigfatguy.fbcontrib.detect; import java.util.Arrays; +import java.util.HashMap; import java.util.HashSet; +import java.util.Map; import java.util.Set; import org.apache.bcel.Repository; @@ -45,7 +47,8 @@ private int lastPCs[]; private int lastOpcode; private int lastReg; - private Set<Integer> branchTargets; + /** branch targets, to a set of branch instructions */ + private Map<Integer, Set<Integer>> branchTargets; /** * constructs a SPP detector given the reporter to report bugs on @@ -60,7 +63,7 @@ try { stack = new OpcodeStack(); lastPCs = new int[4]; - branchTargets = new HashSet<Integer>(); + branchTargets = new HashMap<Integer, Set<Integer>>(); super.visitClassContext(classContext); } finally { stack = null; @@ -97,21 +100,37 @@ stack.mergeJumps(this); if ((seen >= IFEQ) && (seen <= GOTO)) { - branchTargets.add(Integer.valueOf(getBranchTarget())); + Integer branchTarget = Integer.valueOf(getBranchTarget()); + Set<Integer> branchInsSet = branchTargets.get(branchTarget); + if (branchInsSet == null) + { + branchInsSet = new HashSet<Integer>(); + branchTargets.put(branchTarget, branchInsSet); + } + branchInsSet.add(Integer.valueOf(getPC())); } if (seen == ICONST_0) { byte[] bytes = getCode().getCode(); if ((lastPCs[3] != -1) - && (!branchTargets.contains(Integer.valueOf(lastPCs[2]))) && ((0x00FF & bytes[lastPCs[3]]) == GOTO) && ((0x00FF & bytes[lastPCs[2]]) == ICONST_1) && ((0x00FF & bytes[lastPCs[1]]) == IFEQ)) { - bugReporter.reportBug(new BugInstance(this, "SPP_USELESS_TRINARY", NORMAL_PRIORITY) - .addClass(this) - .addMethod(this) - .addSourceLine(this)); + boolean bug = true; + Set<Integer> branchInsSet = branchTargets.get(Integer.valueOf(getPC())); + if (branchInsSet.size() > 1) + bug = false; + branchInsSet = branchTargets.get(Integer.valueOf(lastPCs[2])); + if (branchInsSet != null) + bug = false; + + if (bug) { + bugReporter.reportBug(new BugInstance(this, "SPP_USELESS_TRINARY", NORMAL_PRIORITY) + .addClass(this) + .addMethod(this) + .addSourceLine(this)); + } } } else if (seen == LDC2_W) { Object con = getConstantRefOperand(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |