Re: Handling C2Y zero-length operations on null pointers

2024-12-12 Thread Chris Bazley via Gcc
___ From: Alejandro Colomar Sent: Sunday, December 01, 2024 17:24 To: qing.z...@oracle.com Cc: f...@deneb.enyo.de; gcc@gcc.gnu.org; ja...@redhat.com; josmy...@redhat.com; libc-al...@sourceware.org; uec...@tugraz.at; Chris Bazley Subject: Re: Handling C2Y zero-length operations

Re: Handling C2Y zero-length operations on null pointers

2024-12-01 Thread Alejandro Colomar via Gcc
> > And get clarified the qsort/bsearch cases whether it is about just > > nmemb == 0 or nmemb * size == 0. > > C does not support zero-sized objects, so that's something for us to > figure out on our own. We can treat size == 0 as invalid because the > functions can't work, as they use pointers

Re: Handling C2Y zero-length operations on null pointers

2024-12-01 Thread Alejandro Colomar via Gcc
Hi, I had a discussion about this with another WG14 member when this was voted in. We both voted against, because this is nefarious for static analysis. However, I think this can be though to resemble how 'const' works in the standard: const char cbuf[10]; memcpy((char *)cbuf,

Re: Handling C2Y zero-length operations on null pointers

2024-11-13 Thread Qing Zhao via Gcc
> On Nov 12, 2024, at 01:51, Martin Uecker wrote: > > Am Montag, dem 07.10.2024 um 15:14 + schrieb Qing Zhao: >> >>> On Oct 7, 2024, at 10:13, Jakub Jelinek via Gcc wrote: >>> >>> On Fri, Oct 04, 2024 at 12:42:24AM +0200, Florian Weimer wrote: * Joseph Myers: > The real qu

Re: Handling C2Y zero-length operations on null pointers

2024-11-11 Thread Martin Uecker via Gcc
Am Dienstag, dem 12.11.2024 um 07:51 +0100 schrieb Martin Uecker: > Am Montag, dem 07.10.2024 um 15:14 + schrieb Qing Zhao: > > > > > On Oct 7, 2024, at 10:13, Jakub Jelinek via Gcc wrote: > > > > > > On Fri, Oct 04, 2024 at 12:42:24AM +0200, Florian Weimer wrote: > > > > * Joseph Myers: > >

Re: Handling C2Y zero-length operations on null pointers

2024-11-11 Thread Martin Uecker via Gcc
Am Montag, dem 07.10.2024 um 15:14 + schrieb Qing Zhao: > > > On Oct 7, 2024, at 10:13, Jakub Jelinek via Gcc wrote: > > > > On Fri, Oct 04, 2024 at 12:42:24AM +0200, Florian Weimer wrote: > > > * Joseph Myers: > > > > > > > The real question is how to achieve optimal warnings in the absenc

Re: Handling C2Y zero-length operations on null pointers

2024-10-07 Thread Qing Zhao via Gcc
> On Oct 7, 2024, at 11:22, Jakub Jelinek wrote: > > On Mon, Oct 07, 2024 at 03:14:22PM +, Qing Zhao wrote: >>> Consider the qsort case. My understanding was that the paper is making >>> typedef int (*cmpfn) (const void *, const void *); >>> qsort (NULL, 0, 1, (cmpfn) NULL); >>> valid (but

Re: Handling C2Y zero-length operations on null pointers

2024-10-07 Thread Jakub Jelinek via Gcc
On Mon, Oct 07, 2024 at 03:14:22PM +, Qing Zhao wrote: > > Consider the qsort case. My understanding was that the paper is making > > typedef int (*cmpfn) (const void *, const void *); > > qsort (NULL, 0, 1, (cmpfn) NULL); > > valid (but is > > qsort (NULL, 1, 0, (cmpfn) NULL); > > still inval

Re: Handling C2Y zero-length operations on null pointers

2024-10-07 Thread Qing Zhao via Gcc
> On Oct 7, 2024, at 10:13, Jakub Jelinek via Gcc wrote: > > On Fri, Oct 04, 2024 at 12:42:24AM +0200, Florian Weimer wrote: >> * Joseph Myers: >> >>> The real question is how to achieve optimal warnings in the absence of the >>> attribute. Should we have a variant of the nonnull attribute t

Re: Handling C2Y zero-length operations on null pointers

2024-10-07 Thread Florian Weimer
* Jakub Jelinek: > How do you express that with access attribute, which can only have 1 > size argument? Don't we sometimes use inline functions to handle such special cases? > For the rest, perhaps we need some nonnull_if_nonzero argument > which requires that the parameter identified by the fi

Re: Handling C2Y zero-length operations on null pointers

2024-10-07 Thread Jakub Jelinek via Gcc
On Fri, Oct 04, 2024 at 12:42:24AM +0200, Florian Weimer wrote: > * Joseph Myers: > > > The real question is how to achieve optimal warnings in the absence of the > > attribute. Should we have a variant of the nonnull attribute that warns > > for NULL arguments but without optimizing based on t

Re: Handling C2Y zero-length operations on null pointers

2024-10-03 Thread Paul Eggert
On 2024-10-03 15:42, Florian Weimer wrote: I think attribute access already covers part of it: The GCC documentation for attribute access[1] is unclear as to whether the pointer is allowed to be null when the size is zero. Perhaps we could ask the GCC maintainers to document that it's allowed

Re: Handling C2Y zero-length operations on null pointers

2024-10-03 Thread Florian Weimer
* Joseph Myers: > The real question is how to achieve optimal warnings in the absence of the > attribute. Should we have a variant of the nonnull attribute that warns > for NULL arguments but without optimizing based on them? I think attribute access already covers part of it: #include void

Handling C2Y zero-length operations on null pointers

2024-10-03 Thread Joseph Myers via Gcc
WG14 accepted https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3322.pdf at this week's meeting in Minneapolis, allowing various zero-length language and library operations on null pointers in C2Y (in support of the idiom where an empty array may be represented by a null pointer with zero lengt