On Tue, Aug 11, 2015 at 1:34 PM, Dan Albert <danalb...@google.com> wrote:
> Yeah, those sound like exactly what we want. Helping people find UB is > good, but optimizing assuming we've fixed all of the UB isn't something we > can do. > Dan -- that's the situation you're in today. GCC has done that kind of optimization for *years*. Consider the following code (simplified to the point that it's a toy, but...) void * doFoo ( void *p, size_t sz ) { std::memcpy(buf, p, sz); if (p == nullptr) p = malloc (10); return p; } int main() { void * q = doFoo(nullptr, 0); std::cout << q << std::endl; } You see the UB there - right? memcpy(buf, null, 0); Built that with gcc (I used 4.9) - and see what it prints. At -O3 (on my machine - Mac OS X) it prints "0". It has removed the check for nullptr, and the malloc. Interestingly enough, clang completely elides the call to doFoo, and just calls malloc(10). -- Marshall
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits