Enable IntLongMath checker of error prone
- This checker avoid that an expression of type int may
overflow before being assigned to a long.
- Do not longer use long where it is not needed since an
integer can be used from a dex specification point of view.
Bug:
Change-Id: I392a1f79f0c89659bcb02063be4233ea1b104eb3
diff --git a/build.gradle b/build.gradle
index 6dadb5c..35da63e 100644
--- a/build.gradle
+++ b/build.gradle
@@ -19,7 +19,8 @@
'-Xep:OperatorPrecedence:WARN',
'-Xep:RemoveUnusedImports:WARN',
'-Xep:MissingOverride:WARN',
- '-Xep:OvershadowingSubclassFields:WARN']
+ '-Xep:OvershadowingSubclassFields:WARN',
+ '-Xep:IntLongMath:WARN']
apply from: 'copyAdditionalJctfCommonFiles.gradle'
diff --git a/src/main/java/com/android/tools/r8/ir/code/Switch.java b/src/main/java/com/android/tools/r8/ir/code/Switch.java
index e962d90..9493fa7 100644
--- a/src/main/java/com/android/tools/r8/ir/code/Switch.java
+++ b/src/main/java/com/android/tools/r8/ir/code/Switch.java
@@ -68,12 +68,14 @@
}
// Size of the switch payload if emitted as packed (in code units).
- static public long packedPayloadSize(int keys[]) {
+ // This size can not exceed Constants.U16BIT_MAX * 2 + 4 and can be contained in an integer.
+ private static int packedPayloadSize(int keys[]) {
return (numberOfTargetsForPacked(keys) * 2) + 4;
}
// Size of the switch payload if emitted as sparse (in code units).
- public static long sparsePayloadSize(int keys[]) {
+ // This size can not exceed Constants.U16BIT_MAX * 4 + 2 and can be contained in an integer.
+ private static int sparsePayloadSize(int keys[]) {
return (keys.length * 4) + 2;
}
@@ -84,7 +86,7 @@
* @param keys the switch keys
* @return Size of the switch payload instruction in code units
*/
- public static long payloadSize(List<Integer> keys) {
+ public static int payloadSize(List<Integer> keys) {
return payloadSize(Ints.toArray(keys));
}
@@ -93,8 +95,8 @@
*
* @see #payloadSize(List)
*/
- public static long payloadSize(int keys[]) {
- long sparse = sparsePayloadSize(keys);
+ public static int payloadSize(int keys[]) {
+ int sparse = sparsePayloadSize(keys);
if (canBePacked(keys)) {
return Math.min(sparse, packedPayloadSize(keys));
} else {
@@ -112,12 +114,12 @@
}
// Size of the switch payload if emitted as packed (in code units).
- private long packedPayloadSize() {
+ private int packedPayloadSize() {
return packedPayloadSize(keys);
}
// Size of the switch payload if emitted as sparse (in code units).
- private long sparsePayloadSize() {
+ private int sparsePayloadSize() {
return sparsePayloadSize(keys);
}
diff --git a/src/main/java/com/android/tools/r8/ir/optimize/CodeRewriter.java b/src/main/java/com/android/tools/r8/ir/optimize/CodeRewriter.java
index 256194d..e948ace 100644
--- a/src/main/java/com/android/tools/r8/ir/optimize/CodeRewriter.java
+++ b/src/main/java/com/android/tools/r8/ir/optimize/CodeRewriter.java
@@ -494,7 +494,7 @@
}
// Get the existing dex size for the payload and switch.
- long currentSize = Switch.payloadSize(keys) + Switch.estimatedDexSize();
+ int currentSize = Switch.payloadSize(keys) + Switch.estimatedDexSize();
// Never replace with more than 10 if/switch instructions.
if (outliers.size() + sequences.size() <= 10) {