This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: C++ interop issue due to non-null pointers
- From: Jakub Jelinek <jakub at redhat dot com>
- To: Florian Weimer <fweimer at redhat dot com>
- Cc: Trevor Saunders <tsaunders at mozilla dot com>, Jonathan Wakely <jwakely dot gcc at gmail dot com>, GCC <gcc at gcc dot gnu dot org>
- Date: Tue, 17 Jun 2014 17:00:39 +0200
- Subject: Re: C++ interop issue due to non-null pointers
- Authentication-results: sourceware.org; auth=none
- References: <53997584 dot 8080706 at redhat dot com> <CAH6eHdRua1KTs1QXf2Pu39orxCx6agdzwdzVvcPkcNVEEkRErA at mail dot gmail dot com> <53A03782 dot 9020208 at redhat dot com> <20140617142403 dot GA25179 at tsaunders-iceball dot corp dot tor1 dot mozilla dot com> <53A051E8 dot 5000105 at redhat dot com> <20140617143939 dot GC31640 at tucnak dot redhat dot com> <53A0562D dot 1010604 at redhat dot com>
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
On Tue, Jun 17, 2014 at 04:52:29PM +0200, Florian Weimer wrote:
> On 06/17/2014 04:39 PM, Jakub Jelinek wrote:
> >On Tue, Jun 17, 2014 at 04:34:16PM +0200, Florian Weimer wrote:
> >>>I'm not that familiar with the exact requirements of std::vector, could
> >>>we use the same trick as
> >>>http://mxr.mozilla.org/mozilla-central/source/xpcom/glue/nsTArray.h#275
> >>>that is instead of pointing at null point at a global header used for
> >>>all empty vectors?
> >>
> >>For std::vector, we could use reinterpret_cast<T*>(alignof(T)) or
> >>reinterpret_cast<T*>(sizeof(T)) if those are sufficiently well-defined as
> >>far as GCC is concerned. The smaller constant is easier to load, and no
> >>relocation is required.
> >
> >If there is no object at those addresses, that is still undefined behavior.
>
> GCC is the implementation, so it could be made defined there.
>
> >GCC will likely not optimize it away at this point, but having code with
> >undefined behavior is just asking for future trouble. Just use "" instead?
>
> It's always const and may lack sufficient alignment. The former isn't a
> problem in C++ (I think), but the alignment is an issue.
Alignment for what? You don't specify any alignment to the C qsort,
only size, but even say size 8 can have just alignment of 1, consider
say struct S { char c[8]; };. So, the only problem with alignment would
be in the callback function where it could try to dereference the passed in
const void * pointers, but if the array length is 0, the callback function
is never called, so I don't see why alignment would be an issue.
Jakub