[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] New: 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

Bug ID: 109542
   Summary: bad detection of null dereferance cause ud2a in valid
inline function code
   Product: gcc
   Version: 11.3.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c
  Assignee: unassigned at gcc dot gnu.org
  Reporter: amos.maimon at sap dot com
  Target Milestone: ---

Created attachment 54881
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=54881=edit
snip code that reproduce the issue that decribe above

There is a bug in the detection of null dereferance - and user code change to
UD2A.
This happened when the function picked to be inline.

How to reproduce:
1. download the attached code snip.
2. compile with the following params:
 gcc -Wall -Werror -Wno-packed-not-aligned -Wno-address-of-packed-member
-Wno-multichar -Wno-unused -fno-strict-aliasing -fno-optimize-sibling-calls
-mno-sse -fno-omit-frame-pointer -g -finline-limit=6000 -mcmodel=large
-ffreestanding -mno-red-zone -O2 test.c
3. with objdump you can see that the line :
 *(p + 0xe) = 0xfc;
compile to :
1044:   c6 04 25 fe ff 0f 00movb   $0x0,0xe
104b:   00
104c:   0f 0b   ud2

While if instead p you will use local parameter (define SIMPLE_WRITE and
recompile)
 it will keep user code as expected:
1044:   c6 04 25 fe ff 0f 00movb   $0xfc,0xe
104b:   fc

Note that the problam will not occur if -fno-delete-null-pointer-checks will be
added to the compilation parameters.