This is the mail archive of the
mailing list for the GCC project.
Re: Obscure crashes due to gcc 4.9 -O2 => -fisolate-erroneous-paths-dereference
- From: Martin Sebor <msebor at redhat dot com>
- To: Jeff Law <law at redhat dot com>, Jakub Jelinek <jakub at redhat dot com>, Florian Weimer <fweimer at redhat dot com>
- Cc: Sandra Loosemore <sandra at codesourcery dot com>, Jeff Prothero <jprother at altera dot com>, gcc at gcc dot gnu dot org
- Date: Tue, 03 Mar 2015 12:57:08 -0700
- Subject: Re: Obscure crashes due to gcc 4.9 -O2 => -fisolate-erroneous-paths-dereference
- Authentication-results: sourceware.org; auth=none
- References: <pdf61azt48b dot fsf at sj-interactive3 dot altera dot com> <20150218192943 dot GR1746 at tucnak dot redhat dot com> <54E64DFF dot 8030100 at codesourcery dot com> <54E71534 dot 8070805 at redhat dot com> <20150220121014 dot GY1746 at tucnak dot redhat dot com> <54E76865 dot 4010305 at redhat dot com>
On 02/20/2015 10:01 AM, Jeff Law wrote:
On 02/20/15 05:10, Jakub Jelinek wrote:
On Fri, Feb 20, 2015 at 12:06:28PM +0100, Florian Weimer wrote:
On 02/19/2015 09:56 PM, Sandra Loosemore wrote:
Hmmmm, Passing the additional option in user code would be one thing,
but what about library code? E.g., using memcpy (either explicitly or
implicitly for a structure copy)?
The memcpy problem isn't restricted to embedded architectures.
const unsigned char *source;
memcpy(vec.data(), source, size);
std::vector<T>::data() can return a null pointer if the vector is empty,
which means that this code is invalid for empty inputs.
I think the C standard is wrong here. We should extend it, as a QoI
matter, and support null pointers for variable-length inputs and outputs
if the size is 0. But I suspect this is still a minority view.
I disagree. If you want a function that will have that different
don't call it memcpy.
Right. If someone wants to take it up with the Austin group, that's
fine. But until/unless the Austin group blesses, I don't think we should
extend as a QoI matter.
As a data point(*) it might be interesting to note that GCC itself
relies on memcpy providing stronger guarantees than the C standard
requires it to by emitting calls to the function for large structure
self-assignments (which are strictly conforming, as discussed in bug
[*] IMO, one in favor of tightening up the memcpy specification
to require implementations to provide the expected semantics.