public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Doubts regarding the issue (Bug:93432).
@ 2022-02-05 12:26 Krishna Narayanan
  0 siblings, 0 replies; only message in thread
From: Krishna Narayanan @ 2022-02-05 12:26 UTC (permalink / raw)
  To: gcc-help

Respected Sir/Madam,
I have been working on this issue bug 93432 (
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93432) and tried out few more
permutations of the uninitialized variables in the test code.
When I compile and run the test code the output is always some garbage
value due to
the returning of uninitialized variable as mentioned in the comments.
1.I tried removing the continue ,even then it does not give a warning for
both clang and gcc.I have used -Wextra ,-Wall,-Wuninitialized,-Winit-self.
This is the code:

#include <stdio.h>
int test53(int y) {
int z;int x;
for ( x=0; x<10; x=x+1,y=y+1,z=z+1)
{
if (y<10)
{
z=z+1;
}
}return z;
}
int main() {
printf("%d\n", test53(0));
printf("%d\n", test53(5));
printf("%d\n", test53(10));
return 0;
}

2.Now I tried using another uninitialized variable a but did not introduce
in the loop for an increment it throws warning for -Wall,-Wunintiialized
and no warning for -Winit-self,-O2.

#include <stdio.h>
int test53(int y) {
int z;int x;int a;
for ( x=0; x<10; x=x+1,y=y+1,z=z+1)
{
if (y<10)
{
z=z+1+a;
}
}return z;
}
int main() {
printf("%d\n", test53(0));
printf("%d\n", test53(5));
printf("%d\n", test53(10));
return 0;
}

The warning shown is :
*<source>:* In function '*test53*':
*<source>:8:8:* *warning: *'*a*' may be used uninitialized [
*-Wmaybe-uninitialized*]
8 | *z=z+1+a*;
| *~^~~~~~*
*<source>:3:19:* *note: *'*a*' was declared here
3 | int z;int x;int *a*;
| *^*
Compiler returned: 0

3.When I try using it in loop that is giving an increment 'a=a+1' in the
for loop,                     for ( x=0; x<10; x=x+1,y=y+1,z=z+1,a=a+1) the
warning thrown by -Wuninitialized is not shown, that is when a variable as
soon as it is introduced in the for loop the warning suppresses.
There is no warning in the third case.
I am not sure but this means when we indulge a uninitialized variable to
change its own value by using +,-,*,/ there  is no warning but warning
arises when directly use it in a task or function.
Can you please check this?
Hoping for your reply soon.
Thanks and Regards,
Krishna Narayanan.

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-02-05 12:26 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-05 12:26 Doubts regarding the issue (Bug:93432) Krishna Narayanan

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).