Bug List: (This bug is not in your last search results)   Show last search results      Search page      Enter new bug
Bug#: 36550
Product:  
Component:  
Status: NEW
Resolution:
Assigned To: Not yet assigned to anyone <unassigned@gcc.gnu.org>
Host:
Reported against  
Priority:  
Severity:  
Target Milestone:  
 
 
Target:
Reporter: Bernhard Reutner-Fischer <aldot@gcc.gnu.org>
Add CC:
CC:
Remove selected CCs
Build:
URL:
Summary:
Keywords:
Known to work:
Known to fail:

Attachment Description Type Created Size Actions
Create a New Attachment (proposed patch, testcase, etc.) View All

Bug 36550 depends on: Show dependency tree
Show dependency graph
Bug 36550 blocks: 20968 24639

Additional Comments:





Mark bug as waiting for feedback
Mark bug as suspended




View Bug Activity   |   Format For Printing   |   Clone This Bug


Description:   Last confirmed: 2008-08-18 17:29 Opened: 2008-06-17 09:53
Yet another one. It behaves the same for 4.1.2 and current trunk.

$ gcc -Os -Wuninitialized -c uninit-J.c
uninit-J.c: In function 'pr':
uninit-J.c:7: warning: 'bug' may be used uninitialized in this function

$ cat uninit-J.c
/* { dg-do compile } */
/* { dg-options "-Os -Wuninitialized" } */
void bail(void) __attribute__((noreturn));
unsigned check(void);
int pr(char**argv)
{
        char *bug;
        if (check()) {
                if (*argv)
                        bug = *++argv;
        } else {
                bug = *argv++;
                if (!*argv)
                        bail();
        }
        /* now bug is set except if (check() && !*argv) */
        if (check()) {
                if (!*argv)
                        return 0;
        }
        /* if we ever get here then bug is set */
        return *bug != 'X';
}

------- Comment #1 From Serge Belyshev 2008-06-17 10:40 -------
check() can return 1 on the first call and 0 on the second and if *argv is NULL
then then "bug" will be used uninitialized.

------- Comment #2 From Bernhard Reutner-Fischer 2008-06-17 10:46 -------
(In reply to comment #1)
> check() can return 1 on the first call and 0 on the second and if *argv is NULL
> then then "bug" will be used uninitialized.

right, but this doesn't matter here. Better testcase:

/* { dg-do compile } */
/* { dg-options "-Os -Wuninitialized" } */
void bail(void) __attribute__((noreturn));
unsigned once(void);
int pr(char**argv)
{
        char *bug;
        unsigned check = once();
        if (check) {
                if (*argv)
                        bug = *++argv;
        } else {
                bug = *argv++;
                if (!*argv)
                        bail();
        }
        /* now bug is set except if (check && !*argv) */
        if (check) {
                if (!*argv)
                        return 0;
        }
        /* if we ever get here then bug is set */
        return *bug != 'X';
}

------- Comment #3 From Andrew Pinski 2008-06-17 13:24 -------
This really needs conditional phis so ...

------- Comment #4 From Andrew Pinski 2008-11-06 21:11 -------
*** Bug 38037 has been marked as a duplicate of this bug. ***

------- Comment #5 From Andrew Pinski 2009-02-04 00:09 -------
*** Bug 39088 has been marked as a duplicate of this bug. ***

------- Comment #6 From Manuel López-Ibáñez 2009-02-07 15:05 -------
*** Bug 27289 has been marked as a duplicate of this bug. ***

------- Comment #7 From Manuel López-Ibáñez 2009-02-12 11:22 -------
*** Bug 39133 has been marked as a duplicate of this bug. ***

------- Comment #8 From Manuel López-Ibáñez 2009-02-12 11:45 -------
I added this as Problem 5 in the wiki:

http://gcc.gnu.org/wiki/Better_Uninitialized_Warnings

------- Comment #9 From Corin 2009-02-12 21:53 -------
I do not really understand problem 5 for the case when the only dependancy for
the code-path check is a local variable. In this case the value cannot be
change by any other code than existing between the two checks, so this case
should be handled reliable for sure. Of course this is not possible with global
oder class variables which might be affected by some other thread.

------- Comment #10 From Manuel López-Ibáñez 2009-02-12 22:05 -------
(In reply to comment #9)
> I do not really understand problem 5 for the case when the only dependancy for
> the code-path check is a local variable. In this case the value cannot be
> change by any other code than existing between the two checks, so this case
> should be handled reliable for sure.

Should? I guess you meant "could". Because it is obviously not handled right
now at the moment of warning.

That page simply lists causes, testcases and possible solutions for existing
problems. As always, contributions are welcome.

Bug List: (This bug is not in your last search results)   Show last search results      Search page      Enter new bug