Reputation: 319
I am reading some assembly, and I'm fairly sure that I have some logically impossible/dead code in it. Here it is:
shr %eax
test %eax, %eax
jns 0x[something]
[if body]
[something]
Is it ever, in any case, possible for the if-body to get executed? I feel like the answer is no, but then again, wouldn't the compiler optimize this out?
Apologize for the vagueness in the code, didn't want to add more code than was necessary to give the question context. Let me know if more information would be useful.
Upvotes: 0
Views: 1603
Reputation: 6135
Unless there is a branch directly to the if-body from somewhere else, it cannot possibly be reached through that jns
. The shr
(logical shift right) instruction will always result in a high bit (sign bit) of zero, so that test
and jns
will always have the same behavior no matter what value eax
started out with.
That said, it would be worthwhile to search elsewhere in the code and see if anything jumps to the test
, or to the jnz
, or to the [if body]
, since those instructions might still not be dead code if they're reachable another way.
Upvotes: 3