[Bug c/103103] New: Incorrect integer optimization omits x < 0 comparison

2021-11-05 Thread k.melekhin at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103103

Bug ID: 103103
   Summary: Incorrect integer optimization omits x < 0 comparison
   Product: gcc
   Version: 11.2.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c
  Assignee: unassigned at gcc dot gnu.org
  Reporter: k.melekhin at gmail dot com
  Target Milestone: ---

Created attachment 51739
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=51739&action=edit
Simple test program + version info

On higher optimization levels O2,O3 the following code omits the "newsz < 0"
comparison, likely due to invalid optimization / assumtion that value will
never change and always be 0, however this is incorrect.

See attachment, shows very simple test to reproduce. Also my gcc version
included
in that file comment.

Gcc's output with -O0 is correct. Tested with other C compilers and they
generate correct output on any optimization level.

[Bug c/103103] Incorrect integer optimization omits x < 0 comparison

2021-11-05 Thread k.melekhin at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103103

--- Comment #3 from Kyryl Melekhin  ---
Thank you!

I figured that this has something to do with being UB behavior with int
overflow, however it's strange to find this kind of bug only on 1 compiler,
with no possible warnings or idications that something is wrong. Perhaps a
warning of UB into overflow from compiler be nice.

Have a good day.

[Bug c/103111] New: bogus stringop overflow warning

2021-11-06 Thread k.melekhin at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103111

Bug ID: 103111
   Summary: bogus stringop overflow warning
   Product: gcc
   Version: 11.2.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c
  Assignee: unassigned at gcc dot gnu.org
  Reporter: k.melekhin at gmail dot com
  Target Milestone: ---

Created attachment 51743
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=51743&action=edit
test sample

Hello, please see the attachment.

Why is this warning being generated, it is clearly seen that there will only be
1 allocation and savepath->s_n is being set to 0. I know if I use unsigned
values warning goes away, but this warning still seems not right, because in
this case we are not even dealing with anything close to being considered
integer overflow.

I think this is a gcc bug, my appologies if this is known bug there seems to be
some similar open for c++ but not sure.