Doubts regarding the issue (Bug:93432).

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux