Re: Question on -fwrapv and -fwrapv-pointer

2024-02-15 Thread Kees Cook
On Thu, Feb 15, 2024 at 12:32:17AM -0800, Fangrui Song wrote: > On Fri, Sep 15, 2023 at 11:43 AM Kees Cook via Gcc-patches > wrote: > > > > On Fri, Sep 15, 2023 at 05:47:08PM +, Qing Zhao wrote: > > > > > > > > > > On Sep 15, 2023, at 1:26 PM, Richard Biener > > > > wrote: > > > > > > > > >

Re: Question on -fwrapv and -fwrapv-pointer

2024-02-15 Thread Fangrui Song
On Fri, Sep 15, 2023 at 11:43 AM Kees Cook via Gcc-patches wrote: > > On Fri, Sep 15, 2023 at 05:47:08PM +, Qing Zhao wrote: > > > > > > > On Sep 15, 2023, at 1:26 PM, Richard Biener > > > wrote: > > > > > > > > > > > >> Am 15.09.2023 um 17:37 schrieb Qing Zhao : > > >> > > >>  > > >> > > >

Re: Question on -fwrapv and -fwrapv-pointer

2023-09-15 Thread Kees Cook via Gcc-patches
On Fri, Sep 15, 2023 at 05:47:08PM +, Qing Zhao wrote: > > > > On Sep 15, 2023, at 1:26 PM, Richard Biener > > wrote: > > > > > > > >> Am 15.09.2023 um 17:37 schrieb Qing Zhao : > >> > >>  > >> > On Sep 15, 2023, at 11:29 AM, Richard Biener > wrote: > > >

Re: Question on -fwrapv and -fwrapv-pointer

2023-09-15 Thread Kees Cook via Gcc-patches
On Fri, Sep 15, 2023 at 08:18:28AM -0700, Andrew Pinski wrote: > On Fri, Sep 15, 2023 at 8:12 AM Qing Zhao wrote: > > > > > > > > > On Sep 15, 2023, at 3:43 AM, Xi Ruoyao wrote: > > > > > > On Thu, 2023-09-14 at 21:41 +, Qing Zhao wrote: > > CLANG already provided -fsanitize=unsigned-int

Re: Question on -fwrapv and -fwrapv-pointer

2023-09-15 Thread Qing Zhao via Gcc-patches
> On Sep 15, 2023, at 12:53 PM, Xi Ruoyao wrote: > > On Fri, 2023-09-15 at 15:37 +, Qing Zhao wrote: >> >> >>> On Sep 15, 2023, at 11:29 AM, Richard Biener >>> wrote: >>> >>> >>> Am 15.09.2023 um 17:25 schrieb Qing Zhao :  > On Sep 15, 2023, at 8:41 AM, Arse

Re: Question on -fwrapv and -fwrapv-pointer

2023-09-15 Thread Qing Zhao via Gcc-patches
> On Sep 15, 2023, at 1:26 PM, Richard Biener > wrote: > > > >> Am 15.09.2023 um 17:37 schrieb Qing Zhao : >> >>  >> On Sep 15, 2023, at 11:29 AM, Richard Biener wrote: > Am 15.09.2023 um 17:25 schrieb Qing Zhao :  > On Sep 15, 2023,

Re: Question on -fwrapv and -fwrapv-pointer

2023-09-15 Thread Richard Biener via Gcc-patches
> Am 15.09.2023 um 17:37 schrieb Qing Zhao : > >  > >>> On Sep 15, 2023, at 11:29 AM, Richard Biener >>> wrote: >>> >>> >>> Am 15.09.2023 um 17:25 schrieb Qing Zhao : >>> >>>  >>> On Sep 15, 2023, at 8:41 AM, Arsen Arsenović wrote: Qing Zhao writes:

Re: Question on -fwrapv and -fwrapv-pointer

2023-09-15 Thread Xi Ruoyao via Gcc-patches
On Fri, 2023-09-15 at 15:37 +, Qing Zhao wrote: > > > > On Sep 15, 2023, at 11:29 AM, Richard Biener > > wrote: > > > > > > > > > Am 15.09.2023 um 17:25 schrieb Qing Zhao : > > > > > >  > > > > > > > On Sep 15, 2023, at 8:41 AM, Arsen Arsenović > > > > wrote: > > > > > > > > > > > >

Re: Question on -fwrapv and -fwrapv-pointer

2023-09-15 Thread Qing Zhao via Gcc-patches
> On Sep 15, 2023, at 11:29 AM, Richard Biener > wrote: > > > >> Am 15.09.2023 um 17:25 schrieb Qing Zhao : >> >>  >> >>> On Sep 15, 2023, at 8:41 AM, Arsen Arsenović wrote: >>> >>> >>> Qing Zhao writes: >>> Even though unsigned integer overflow is well defined, it might be

Re: Question on -fwrapv and -fwrapv-pointer

2023-09-15 Thread Richard Biener via Gcc-patches
> Am 15.09.2023 um 17:25 schrieb Qing Zhao : > >  > >> On Sep 15, 2023, at 8:41 AM, Arsen Arsenović wrote: >> >> >> Qing Zhao writes: >> >>> Even though unsigned integer overflow is well defined, it might be >>> unintentional, shall we warn user about this? >> >> This would be better ad

Re: Question on -fwrapv and -fwrapv-pointer

2023-09-15 Thread Qing Zhao via Gcc-patches
> On Sep 15, 2023, at 8:41 AM, Arsen Arsenović wrote: > > > Qing Zhao writes: > >> Even though unsigned integer overflow is well defined, it might be >> unintentional, shall we warn user about this? > > This would be better addressed by providing operators or functions that > do overflow ch

Re: Question on -fwrapv and -fwrapv-pointer

2023-09-15 Thread Andrew Pinski via Gcc-patches
On Fri, Sep 15, 2023 at 8:12 AM Qing Zhao wrote: > > > > > On Sep 15, 2023, at 3:43 AM, Xi Ruoyao wrote: > > > > On Thu, 2023-09-14 at 21:41 +, Qing Zhao wrote: > CLANG already provided -fsanitize=unsigned-integer-overflow. GCC > might need to do the same. > >>> > >>> NO. There is n

Re: Question on -fwrapv and -fwrapv-pointer

2023-09-15 Thread Qing Zhao via Gcc-patches
> On Sep 15, 2023, at 3:43 AM, Xi Ruoyao wrote: > > On Thu, 2023-09-14 at 21:41 +, Qing Zhao wrote: CLANG already provided -fsanitize=unsigned-integer-overflow. GCC might need to do the same. >>> >>> NO. There is no such thing as unsigned integer overflow. That option >>> is badl

Re: Question on -fwrapv and -fwrapv-pointer

2023-09-15 Thread Arsen Arsenović via Gcc-patches
Qing Zhao writes: > Even though unsigned integer overflow is well defined, it might be > unintentional, shall we warn user about this? This would be better addressed by providing operators or functions that do overflow checking in the language, so that they can be explicitly used where overflow

Re: Question on -fwrapv and -fwrapv-pointer

2023-09-15 Thread Xi Ruoyao via Gcc-patches
On Thu, 2023-09-14 at 21:41 +, Qing Zhao wrote: > > > CLANG already provided -fsanitize=unsigned-integer-overflow. GCC > > > might need to do the same. > > > > NO. There is no such thing as unsigned integer overflow. That option > > is badly designed and the GCC community has rejected a few ti

Re: Question on -fwrapv and -fwrapv-pointer

2023-09-14 Thread Kees Cook via Gcc-patches
On Thu, Sep 14, 2023 at 01:57:41PM -0700, Andrew Pinski wrote: > Now -fsanitize=pointer-overflow is already there for GCC which was > added in r8-2238-gc9b39a4955f56fe609ef5478 . LLVM/clang also provides > it in the same timeframe too . > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80998 Ah, than

Re: Question on -fwrapv and -fwrapv-pointer

2023-09-14 Thread Qing Zhao via Gcc-patches
> On Sep 14, 2023, at 4:57 PM, Andrew Pinski wrote: > > On Thu, Sep 14, 2023 at 1:50 PM Qing Zhao via Gcc-patches > wrote: >> >> >> >>> On Sep 14, 2023, at 12:18 PM, Xi Ruoyao wrote: >>> >>> On Thu, 2023-09-14 at 15:57 +, Qing Zhao via Gcc-patches wrote: Currently, GCC behaves as

Re: Question on -fwrapv and -fwrapv-pointer

2023-09-14 Thread Andrew Pinski via Gcc-patches
On Thu, Sep 14, 2023 at 1:50 PM Qing Zhao via Gcc-patches wrote: > > > > > On Sep 14, 2023, at 12:18 PM, Xi Ruoyao wrote: > > > > On Thu, 2023-09-14 at 15:57 +, Qing Zhao via Gcc-patches wrote: > >> Currently, GCC behaves as following: > >> > >> /* True if overflow wraps around for the given

Re: Question on -fwrapv and -fwrapv-pointer

2023-09-14 Thread Qing Zhao via Gcc-patches
> On Sep 14, 2023, at 12:18 PM, Xi Ruoyao wrote: > > On Thu, 2023-09-14 at 15:57 +, Qing Zhao via Gcc-patches wrote: >> Currently, GCC behaves as following: >> >> /* True if overflow wraps around for the given integral or pointer type. >> That >>is, TYPE_MAX + 1 == TYPE_MIN. */ >> #

Re: Question on -fwrapv and -fwrapv-pointer

2023-09-14 Thread Xi Ruoyao via Gcc-patches
On Thu, 2023-09-14 at 15:57 +, Qing Zhao via Gcc-patches wrote: > Currently, GCC behaves as following: > > /* True if overflow wraps around for the given integral or pointer type.  That >    is, TYPE_MAX + 1 == TYPE_MIN.  */ > #define TYPE_OVERFLOW_WRAPS(TYPE) \ >   (POINTER_TYPE_P (TYPE) 

Re: Question on -fwrapv and -fwrapv-pointer

2023-09-14 Thread Qing Zhao via Gcc-patches
> On Sep 14, 2023, at 11:12 AM, Richard Biener > wrote: > > > >> Am 14.09.2023 um 17:01 schrieb Qing Zhao : >> >> Thanks for the info. >> >>> On Sep 14, 2023, at 10:06 AM, Richard Biener >>> wrote: >>> On Thu, Sep 14, 2023 at 3:42 PM Qing Zhao via Gcc-patches wrote: >>

Re: Question on -fwrapv and -fwrapv-pointer

2023-09-14 Thread Richard Biener via Gcc-patches
> Am 14.09.2023 um 17:01 schrieb Qing Zhao : > > Thanks for the info. > >> On Sep 14, 2023, at 10:06 AM, Richard Biener >> wrote: >> >>> On Thu, Sep 14, 2023 at 3:42 PM Qing Zhao via Gcc-patches >>> wrote: >>> >>> Hi, >>> >>> I have several questions on these options: >>> >>> 1.are poi

Re: Question on -fwrapv and -fwrapv-pointer

2023-09-14 Thread Qing Zhao via Gcc-patches
Thanks for the info. > On Sep 14, 2023, at 10:06 AM, Richard Biener > wrote: > > On Thu, Sep 14, 2023 at 3:42 PM Qing Zhao via Gcc-patches > wrote: >> >> Hi, >> >> I have several questions on these options: >> >> 1.are pointers treated as signed integers in general? (I thought that >> poin

Re: Question on -fwrapv and -fwrapv-pointer

2023-09-14 Thread Richard Biener via Gcc-patches
On Thu, Sep 14, 2023 at 3:42 PM Qing Zhao via Gcc-patches wrote: > > Hi, > > I have several questions on these options: > > 1.are pointers treated as signed integers in general? (I thought that > pointers are addresses to the memory, should be treated as unsigned integer…) > 2. If Yes, why? > 3.

Question on -fwrapv and -fwrapv-pointer

2023-09-14 Thread Qing Zhao via Gcc-patches
Hi, I have several questions on these options: 1.are pointers treated as signed integers in general? (I thought that pointers are addresses to the memory, should be treated as unsigned integer…) 2. If Yes, why? 3. why a separate option for pointesr -fwrapv-pointer in addition to -fwrapv if the