-
Notifications
You must be signed in to change notification settings - Fork 6.7k
Description
Is your feature request related to a problem? Please describe.
Sometimes, you may have a function like this
int bar();
int foo(void* ptr) {
if (ptr == nullptr)
return 0;
return bar();
}
which does a null check on a pointer and returns 0/false if it's null. If the pointer exists in the return value register, the compiler will usually just return the pointer directly. This can result in ugly decompilation where the pointer's type is propagated to all return values (or vice versa resulting in subpieces of the pointer instead).


Describe the solution you'd like
In the case where an equality comparison against a constant occurs, creating a new constant for the success branch to replace the original value and propagating it may result in better decompilation. I'm not super familiar with the decompiler internals so I don't know how this would be implemented specifically or if something similar is already being done.
Describe alternatives you've considered
It's functional as is, but this would be a nice quality-of-life improvement as it'd improve data type analysis in larger functions where this occurs.