[Bug c/109542] bad detection of null dereferance cause ud2a in valid inline function code

2023-04-18 Thread redi at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109542

--- Comment #5 from Jonathan Wakely  ---
You can either perform the arithmetic using intptr_t or uintptr_t, or use
-fdelete-null-pointer-checks (as the documentation for that option explains).

Also I would expect a volatile char* to be used for such accesses.

[Bug c/109542] bad detection of null dereferance cause ud2a in valid inline function code

2023-04-18 Thread xry111 at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109542

--- Comment #4 from Xi Ruoyao  ---
(In reply to Amos Maimon from comment #3)
> 1. the same will occur if you will do :
> p[0xe] = 0xfc;

Yes, it's undefined behavior too as C defines a[b] as *(a+b).

> 2. how do you explin the fact that if the null set in the function
> (SIMPLE_WRITE case) gcc compile it without ud2a

It's an undefined behavior, the compiler can do anything.

[Bug c/109542] bad detection of null dereferance cause ud2a in valid inline function code

2023-04-18 Thread amos.maimon at sap dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109542

--- Comment #3 from Amos Maimon  ---
1. the same will occur if you will do :
p[0xe] = 0xfc;

2. how do you explin the fact that if the null set in the function
(SIMPLE_WRITE case) gcc compile it without ud2a

[Bug c/109542] bad detection of null dereferance cause ud2a in valid inline function code

2023-04-18 Thread rguenth at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109542

Richard Biener  changed:

   What|Removed |Added

 Target||x86_64-*-* i?86-*-*
 Resolution|--- |INVALID
 Status|UNCONFIRMED |RESOLVED

--- Comment #2 from Richard Biener  ---
This works exactly as intended.  In C when you offset a pointer you may not
venture outside of a valid object and at NULL there isn't a valid object
unless -fno-delete-null-pointer-checks.

[Bug c/109542] bad detection of null dereferance cause ud2a in valid inline function code

2023-04-18 Thread xry111 at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109542

Xi Ruoyao  changed:

   What|Removed |Added

 CC||xry111 at gcc dot gnu.org

--- Comment #1 from Xi Ruoyao  ---
Performing arithmetic on NULL pointer is an undefined behavior.

The standard says you can only perform arithmetic on a pointer if it's a
pointer to an array element (an object not in any array will be considered as
the only element in an array with length 1), but NULL is not such a pointer.