public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/110530] New: Local variable unexpectedly assigned to zero during passing as an argument
@ 2023-07-03 8:01 haiqingzhao at microsoft dot com
2023-07-03 8:14 ` [Bug c/110530] " pinskia at gcc dot gnu.org
2023-07-03 11:57 ` haiqingzhao at microsoft dot com
0 siblings, 2 replies; 3+ messages in thread
From: haiqingzhao at microsoft dot com @ 2023-07-03 8:01 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110530
Bug ID: 110530
Summary: Local variable unexpectedly assigned to zero during
passing as an argument
Product: gcc
Version: 11.3.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: haiqingzhao at microsoft dot com
Target Milestone: ---
Created attachment 55462
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=55462&action=edit
This source file reproduces the issue occurring under -Os optimization
1) GCC version: 11.3.0
2) System type: ubuntu 22.04.1
3) Option given: -Os
4) The complete command line that triggers the bug:
i. gcc -Os test.c -o test.o
ii. ./test.o
5) No compiler output error messages or warning messages
6) No pre-processed files
7) Description:
The behaviour of the source file (test.c) works normally under gcc version
9.4.0 no matter if "-Os optimization" is enabled or not. It works still
normally under gcc version 11.3.0 with no optimization enabled, but prints
error message when "-Os optimization" is enabled.
During debugging, it is found that the value of the local variable "size"
is unexpectedly assigned to zero inside the function "process_data" before
calling the function "get_data" at line 18.
It looks like the initialization for the local variable "size" at line 27
is executed after calling the function "get_data" at line 29.
8) Experiment has been done:
i. The source code works normally if the type for the local variable "size"
is changed from unsigned int to unsigned long
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug c/110530] Local variable unexpectedly assigned to zero during passing as an argument
2023-07-03 8:01 [Bug c/110530] New: Local variable unexpectedly assigned to zero during passing as an argument haiqingzhao at microsoft dot com
@ 2023-07-03 8:14 ` pinskia at gcc dot gnu.org
2023-07-03 11:57 ` haiqingzhao at microsoft dot com
1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-07-03 8:14 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110530
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |INVALID
Status|UNCONFIRMED |RESOLVED
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
This code is undefined for 2 reasons.
First is unsigned int and unsigned long are 2 different sizes on LP64 targets
(x86_64-linux-gnu is one of those, while windows is not).
Second is if they are the same size, then there is an aliasing violation in
that you cannot do a store as an `unsigned long` and then do a load from that
same location as an `unsigned int` as C says those 2 types don't alias.
-fsanitize=address will catch the first reason.
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug c/110530] Local variable unexpectedly assigned to zero during passing as an argument
2023-07-03 8:01 [Bug c/110530] New: Local variable unexpectedly assigned to zero during passing as an argument haiqingzhao at microsoft dot com
2023-07-03 8:14 ` [Bug c/110530] " pinskia at gcc dot gnu.org
@ 2023-07-03 11:57 ` haiqingzhao at microsoft dot com
1 sibling, 0 replies; 3+ messages in thread
From: haiqingzhao at microsoft dot com @ 2023-07-03 11:57 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110530
--- Comment #2 from Haiqing Zhao <haiqingzhao at microsoft dot com> ---
(In reply to Andrew Pinski from comment #1)
> This code is undefined for 2 reasons.
>
> First is unsigned int and unsigned long are 2 different sizes on LP64
> targets (x86_64-linux-gnu is one of those, while windows is not).
> Second is if they are the same size, then there is an aliasing violation in
> that you cannot do a store as an `unsigned long` and then do a load from
> that same location as an `unsigned int` as C says those 2 types don't alias.
>
>
> -fsanitize=address will catch the first reason.
Dear Andrew,
Thanks a lot for your prompt explanation. I tested on a 32-bit platform and the
issue shall be due to the neglect of strict aliasing. With the experiment which
addes -fno-strict-alising when compiling, the code can also execute normally.
Again thanks for your information.
Sincere Regards,
Haiqing
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-07-03 11:57 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-03 8:01 [Bug c/110530] New: Local variable unexpectedly assigned to zero during passing as an argument haiqingzhao at microsoft dot com
2023-07-03 8:14 ` [Bug c/110530] " pinskia at gcc dot gnu.org
2023-07-03 11:57 ` haiqingzhao at microsoft dot com
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).