This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: GCC 4.9.2 -O3 gives a seg fault / GCC 4.8.2 -O3 works


On Tue, 2015-01-06 at 09:43 +0100, Jakub Jelinek wrote:
> On Tue, Jan 06, 2015 at 03:18:48AM -0500, Paul Smith wrote:
> > Hi all.  It's possible my code is doing something illegal, but it's also
> > possible I've found a problem with -O3 optimization in GCC 4.9.2.  I've
> > built this same code with GCC 4.8.2 -O3 on GNU/Linux and it works fine.
> > It also works with GCC 4.9.2 with lower -O (-O2 for example).
> 
> Your testcase is invalid.
> GCC trunk -fsanitize=undefined (in particular -fsanitize=nonnull-attribute)
> diagnoses it:
> /tmp/mystring.cpp:103:26: runtime error: null pointer passed as argument 2, which is declared to never be null
> LD_PRELOAD=libmemstomp.so detects it too.
> 
> Calling memcpy (p, NULL, 0); is invalid according to C and C++
> standards, you need to guard it, e.g. with if (data) memcpy (p, data, len1);
> or if (len1) memcpy (p, data, len1);

Ah interesting.  You're right, this is definitely not correct.  But
since len1 is 0 in this case, no implementation of memcpy() actually
tried to dereference the data pointer and so there was no failure (we
build and test with clang on OSX and MSVC on Windows, and run with
valgrind and ASAN (clang)).

I'll have to look at other possible failure situations.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]