public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: Krishna Narayanan <krishnanarayanan132002@gmail.com>
To: gcc-help <gcc-help@gcc.gnu.org>
Subject: Doubts regarding the issue (Bug:93432).
Date: Sat, 5 Feb 2022 17:56:09 +0530	[thread overview]
Message-ID: <CABhGnjtNOH9FFUDSbrwCUUasPMSJ5JU5KwFBX9XUyAL+SuQj6w@mail.gmail.com> (raw)

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.

                 reply	other threads:[~2022-02-05 12:26 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CABhGnjtNOH9FFUDSbrwCUUasPMSJ5JU5KwFBX9XUyAL+SuQj6w@mail.gmail.com \
    --to=krishnanarayanan132002@gmail.com \
    --cc=gcc-help@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).