--removedeadswitchcases
See original GitHub issueImagine a switch like this:
switch (1) {
default: {
return false;
}
case 1:
return true;
}
or
switch (boolean) { //illegal in java, legal in bytecode
case 0:
return false;
case 1:
return true;
case 2:
case 3:
case 4:
...
//never executed, remove it from the graph
//an obfuscator could convert ifeq / ifne to switch and then add redundant extra cases
//imagine a goto random label for each extra case
default:
//also not executed if both cases are handled
}
I think there can be done a lot of optimization / obfuscation removal. Also not bad for a second pass.
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (6 by maintainers)
Top Results From Across the Web
Dead code removal from switch cases in JavaScript
Nothing is going to definitively give you a list of dead case statements. If it says it can there is either no possibility...
Read more >Removing duplicate cases in switch - Exakat
Duplicate cases are pure dead code (only one of them is actually used), or a bug (some of the case is misspelled, and...
Read more >MSC07-C. Detect and remove dead code - Confluence
This noncompliant code example demonstrates how dead code can be introduced into a program [Fortify 2006]. The second conditional statement, if ...
Read more >Bitter about how rubber switch cases stress out the joycons.
Do yourself a favor, get a clip on case so there's no stress on your joycons, otherwise you'll end up with joycon wiggling...
Read more >Switch Statements - Refactoring.Guru
You have a complex switch operator or sequence of if statements. Reasons for the Problem. Relatively rare use of switch and case operators...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The former I can see as realistic, though I doubt anyone’s going to bother with an obfuscation so trivial. (Unless it’s @Marcono1234 generating psychotic switch expression examples)
The latter I’m really not keen on. We simply dont know at the bytecode level if something is a bool or not - you could declare it a bool parameter then assign 3 - while I try to infer the type/domain, it’s very possible to get it wrong.
(As an aside, abused booleans can lead to different results in different jvms, I have some tests somewhere I believe)
Ok - I’m going to close this for now. There’s potentially some value in trying to add a last gasp recovery pass to do this, but it’s certainly not the sort of thing you’d want to be doing normally.