This is the mail archive of the
mailing list for the GCC project.
Re: GCC 4.9.2 -O3 gives a seg fault / GCC 4.8.2 -O3 works
- From: Jakub Jelinek <jakub at redhat dot com>
- To: Paul Smith <paul at mad-scientist dot net>
- Cc: gcc at gcc dot gnu dot org
- Date: Tue, 6 Jan 2015 09:43:50 +0100
- Subject: Re: GCC 4.9.2 -O3 gives a seg fault / GCC 4.8.2 -O3 works
- Authentication-results: sourceware.org; auth=none
- References: <1420532328 dot 7095 dot 263 dot camel at homebase>
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
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)
/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);