Skip to content

Commit 12d3cf6

Browse files
piazzesiNiccolo-GStoon.willemotluis.carneiro
authored
Sync (#154)
* Add processable visitors * Created `DominatorCalculator.maybeDominates` to use instead of `dominates`, which no longer throws an exception * Version and release notes --------- Co-authored-by: toon.willemot <toon.willemot@guardsquare.com> Co-authored-by: luis.carneiro <luis.carneiro@guardsquare.com>
1 parent 62fac35 commit 12d3cf6

File tree

7 files changed

+657
-34
lines changed

7 files changed

+657
-34
lines changed

base/src/main/java/proguard/analysis/CallResolver.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,9 @@ private void addCall(
422422
boolean alwaysInvoked = true;
423423
if (useDominatorAnalysis) {
424424
alwaysInvoked =
425-
dominatorCalculator.dominates(location.offset, DominatorCalculator.EXIT_NODE_OFFSET);
425+
dominatorCalculator
426+
.maybeDominates(location.offset, DominatorCalculator.EXIT_NODE_OFFSET)
427+
.orElse(false);
426428
}
427429
Call call =
428430
instantiateCall(

base/src/main/java/proguard/analysis/DominatorCalculator.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import java.util.LinkedHashSet;
2828
import java.util.List;
2929
import java.util.Map;
30+
import java.util.Optional;
3031
import java.util.Set;
3132
import proguard.classfile.Clazz;
3233
import proguard.classfile.Method;
@@ -121,7 +122,10 @@ public DominatorCalculator(boolean ignoreExceptions) {
121122
* @param dominator The potentially dominating instruction's offset
122123
* @param inferior The potentially dominated instruction's offset
123124
* @return true if the potential dominator is indeed guaranteed to be executed before the inferior
125+
* @deprecated Callers should use {@link #maybeDominates} to handle an optional value instead of
126+
* an exception.
124127
*/
128+
@Deprecated
125129
public boolean dominates(int dominator, int inferior) {
126130
BitSet dominators = dominatorMap.get(inferior);
127131
if (dominators == null) {
@@ -134,6 +138,25 @@ public boolean dominates(int dominator, int inferior) {
134138
return dominators.get(offsetToIndex(dominator));
135139
}
136140

141+
/**
142+
* Check if one instruction dominates another one. If this is the case, the dominating instruction
143+
* is guaranteed to be executed before the inferior instruction. Should you wish to check whether
144+
* an instruction is guaranteed to be executed once the containing method is invoked, you can use
145+
* the virtual inferior {@link #EXIT_NODE_OFFSET} as a collection for all return instructions.
146+
*
147+
* @param dominator The potentially dominating instruction's offset
148+
* @param inferior The potentially dominated instruction's offset
149+
* @return Optional.true if the potential dominator is indeed guaranteed to be executed before the
150+
* inferior, Optional.false if not and Optional.empty when no dominator information is known.
151+
*/
152+
public Optional<Boolean> maybeDominates(int dominator, int inferior) {
153+
BitSet dominators = dominatorMap.get(inferior);
154+
if (dominators == null) {
155+
return Optional.empty();
156+
}
157+
return Optional.of(dominators.get(offsetToIndex(dominator)));
158+
}
159+
137160
/**
138161
* As we introduced {@link #ENTRY_NODE_OFFSET} and {@link #EXIT_NODE_OFFSET} as virtual
139162
* instruction offsets, the rest of the instructions are shifted by those two places. In order to

0 commit comments

Comments
 (0)