> How does the other process inspect the memory at the right time?
There must be some side effect of the optimisation, otherwise there wouldn't be a problem. Detect that side effect (e.g. write a buffer of memory to disk, check timing of some code, ptrace-attach to the other process and inspect it, trigger a core dump and pick over the bones, code up an exploit which would work if the explicit_bzero() wasn't present)
> How do you know all the scenarios where some compiler would optimize things out?
You only really need to know one case where the compiler will, if the prevent-optimisation compiler magic isn't sprinkled on it.
> Tests might not hurt, but I am not sure trying to cater for braindead porters is a good idea. They might get the idea they're doing it right once they get the tests to pass one way or another...
At least they'd get an idea that something was up. I guess you might get away with:
#ifndef OPENBSD
#error "You can't just call bcopy() for explicit_bcopy() - see http://good-description-here why not"
#endif