Skip to content

Commit

Permalink
fix: Reset duplicate escaped names when de-duplicating names
Browse files Browse the repository at this point in the history
If two variables are the literal " " then we don't want the escaped \u0020 to become \u0020 and \u00201 for deduplication. The second is not a valid escape. Thus we'll reset it to "vX" where X is the variable index.
  • Loading branch information
Col-E committed Oct 26, 2024
1 parent 33264c3 commit 3608d61
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,11 @@ public void setLabelPrefix(String labelPrefix) {
for (Local local : code.localVariables()) {
// Transform local name to be legal
int index = local.index();
String name = escapeName(local.name(), index, isStatic);
String baseName = local.name();
String name = escapeName(baseName, index, isStatic);
String descriptor = local.type().descriptor();
Type varType = Types.typeFromDescriptor(descriptor);
boolean escaped = !baseName.equals(name);

// De-conflict variable names if two names of incompatible types occupy the same name.
// int foo = 0 ---> foo
Expand All @@ -67,6 +69,11 @@ public void setLabelPrefix(String labelPrefix) {
(varType.getClass() != existingVarType.getClass() || (varType instanceof PrimitiveType varPrim
&& existingVarType instanceof PrimitiveType existingPrim
&& varPrim.kind() != existingPrim.kind()))) {
// If we have an escaped name like "\\u0000" we cannot just append a number to it and call it a day.
// In these cases we will revert the name back to an auto-generated value based on its index.
if (escaped)
name = "v" + local.index();

int i = 2;
String prefix = name;
while (nameToType.get(name) != null)
Expand Down

0 comments on commit 3608d61

Please sign in to comment.