On 2016.12.16 at 18:27 +0100, Jakub Jelinek wrote: > On Fri, Dec 16, 2016 at 10:10:00AM -0700, Martin Sebor wrote: > > > No. The first call to sm_read_sector just doesn't exit. So it is warning > > > about dead code. > > > > If the code is dead then GCC should eliminate it. With it eliminated > > There is (especially with jump threading, but not limited to that, other > optimizations may result in that too), code that even very smart optimizing > compiler isn't able to prove that is dead. > > > the warning would be gone. The warning isn't smart and it doesn't > > try to be. It only works with what GCC gives it. In this case the > > dump shows that GCC thinks the code is reachable. If it isn't that > > would seem to highlight a missed optimization opportunity, not a need > > to make the warning smarter than the optimizer. > > No, it highlights that the warning is done in a wrong place where it suffers > from too many false positives.
Another issue with Martin's patch is that it adds many false positives when one uses -fsanitize=undefined, e.g.: % cat test.ii struct A { char *msg; A(const char *); }; A::A(const char *p1) { msg = new char[__builtin_strlen(p1) + 1]; __builtin_strcpy(msg, p1); } % g++ -Wall -O2 -c test.ii % g++ -Wall -fsanitize=undefined -O2 -c test.ii test.ii: In constructor ‘A::A(const char*)’: test.ii:6:34: warning: argument 1 null where non-null expected [-Wnonnull] msg = new char[__builtin_strlen(p1) + 1]; ~~~~~~~~~~~~~~~~^~~~ test.ii:6:34: note: in a call to built-in function ‘long unsigned int __builtin_strlen(const char*)’ -- Markus