Backport a few clang fixes

This is a smaller subset of clang related fixes. Should merge better than the larger chunk.
Well, the rationale was that if the code below works on another compiler (say ICC, as I think it does), we should not get the slow version just because it's not gcc. I prefer that we review and fix the code if it breaks rather than having a suboptimal behaviour by default.