Bug 29479 - wrong may be used uninitialized in this function warnings
Summary: wrong may be used uninitialized in this function warnings
Status: RESOLVED DUPLICATE of bug 27289
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 4.2.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-10-15 16:44 UTC by Martin Koegler
Modified: 2008-02-01 17:08 UTC (History)
10 users (show)

See Also:
Host: i686-pc-linux-gnu
Target: i686-pc-linux-gnu
Build: i686-pc-linux-gnu
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Martin Koegler 2006-10-15 16:44:32 UTC
Another warning regression while compiling GDB:

This time, it generates warning about the use of uninitialised variables. I reduced the test case. The message says that tmp_obstack might be uninitialized. This is wrong, as the flag, which controls, if tmp_obstack is not change during the execution of the function. Therefore if tmp_obstack is read, it had assigned a value before.

A bugfix should be tested on the current CVS version of GDB (this bug affects p-valprint.c and cp-valprint.c), as a small change in the test case can produce a different result.


z2.i:
struct obstack
{
  long chunk_size;
  char *object_base;
  char *next_free;
  char *chunk_limit;
  int temp;
  int alignment_mask;
  void *extra_arg;
  unsigned use_extra_arg:1;
  unsigned maybe_empty_object:1;
  unsigned alloc_failed:1;
};

struct obstack dont_print_statmem_obstack;
struct obstack dont_print_vb_obstack;

typedef char gdb_byte;
struct type;

static void
cp_print_value (struct type *type, struct type **dont_print_vb)
{
  struct obstack tmp_obstack;
  int i, n_baseclasses = rand ();

  if (dont_print_vb == 0)
    {
      tmp_obstack = dont_print_vb_obstack;
    }

  for (i = 0; i < n_baseclasses; i++)
    {
      if (rand ())
        {
          gdb_byte *buf = __builtin_alloca (rand ());
        }
    }

  if (dont_print_vb == 0)
    {
      dont_print_vb_obstack = tmp_obstack;
    }
}


void
cp_print_value_fields (struct type *type,
                       struct type **dont_print_vb, int dont_print_statmem)
{
  int i, len, n_baseclasses;
  struct obstack tmp_obstack;

  len = rand ();
  n_baseclasses = 2;

  cp_print_value (type, dont_print_vb);

  if (dont_print_statmem == 0)
    {
      tmp_obstack = dont_print_statmem_obstack;
    }

  for (i = n_baseclasses; i < len; i++)
    {
      continue;
    }

  if (dont_print_statmem == 0)
    {
      dont_print_statmem_obstack = tmp_obstack;
    }
}
$./cc1 -O1 -Wuninitialized  z2.i
 cp_print_value cp_print_value_fields
Analyzing compilation unitPerforming interprocedural optimizations
Assembling functions:
 cp_print_value
z2.i: In function 'cp_print_value':
z2.i:24: warning: 'tmp_obstack.alloc_failed' may be used uninitialized in this function
z2.i:24: warning: 'tmp_obstack.maybe_empty_object' may be used uninitialized in this function
z2.i:24: warning: 'tmp_obstack.use_extra_arg' may be used uninitialized in this function
z2.i:24: warning: 'tmp_obstack.extra_arg' may be used uninitialized in this function
z2.i:24: warning: 'tmp_obstack.alignment_mask' may be used uninitialized in this function
z2.i:24: warning: 'tmp_obstack.temp' may be used uninitialized in this function
z2.i:24: warning: 'tmp_obstack.chunk_limit' may be used uninitialized in this function
z2.i:24: warning: 'tmp_obstack.next_free' may be used uninitialized in this function
z2.i:24: warning: 'tmp_obstack.object_base' may be used uninitialized in this function
z2.i:24: warning: 'tmp_obstack.chunk_size' may be used uninitialized in this function
 cp_print_value_fields
z2.i: In function 'cp_print_value_fields':
z2.i:52: warning: 'tmp_obstack.alloc_failed' may be used uninitialized in this function
z2.i:52: warning: 'tmp_obstack.maybe_empty_object' may be used uninitialized in this function
z2.i:52: warning: 'tmp_obstack.use_extra_arg' may be used uninitialized in this function
z2.i:52: warning: 'tmp_obstack.extra_arg' may be used uninitialized in this function
z2.i:52: warning: 'tmp_obstack.alignment_mask' may be used uninitialized in this function
z2.i:52: warning: 'tmp_obstack.temp' may be used uninitialized in this function
z2.i:52: warning: 'tmp_obstack.chunk_limit' may be used uninitialized in this function
z2.i:52: warning: 'tmp_obstack.next_free' may be used uninitialized in this function
z2.i:52: warning: 'tmp_obstack.object_base' may be used uninitialized in this function
z2.i:52: warning: 'tmp_obstack.chunk_size' may be used uninitialized in this function

Execution times (seconds)
 callgraph construction:   0.00 ( 0%) usr   0.00 ( 0%) sys   0.01 (20%) wall       2 kB ( 0%) ggc
 life info update      :   0.01 (25%) usr   0.00 ( 0%) sys   0.00 ( 0%) wall       0 kB ( 0%) ggc
 tree CFG cleanup      :   0.01 (25%) usr   0.00 ( 0%) sys   0.00 ( 0%) wall       0 kB ( 0%) ggc
 tree SSA verifier     :   0.01 (25%) usr   0.00 ( 0%) sys   0.01 (20%) wall       0 kB ( 0%) ggc
 expand                :   0.00 ( 0%) usr   0.00 ( 0%) sys   0.01 (20%) wall      31 kB ( 3%) ggc
 global alloc          :   0.00 ( 0%) usr   0.00 ( 0%) sys   0.01 (20%) wall       5 kB ( 1%) ggc
 TOTAL                 :   0.04             0.00             0.05               1035 kB
Extra diagnostic checks enabled; compiler may run slowly.
Configure with --disable-checking to disable checks.

$/usr/lib/gcc/x86_64-linux-gnu/4.1.2/cc1 -O1 -Wuninitialized -m32 z2.i
 cp_print_value cp_print_value_fields
Analyzing compilation unitPerforming intraprocedural optimizations
Assembling functions:
 cp_print_value cp_print_value_fields
Execution times (seconds)
 preprocessing         :   0.00 ( 0%) usr   0.00 ( 0%) sys   0.01 (33%) wall       2 kB ( 0%) ggc
 tree SSA incremental  :   0.01 (50%) usr   0.00 ( 0%) sys   0.00 ( 0%) wall       3 kB ( 0%) ggc
 expand                :   0.01 (50%) usr   0.00 ( 0%) sys   0.00 ( 0%) wall      56 kB ( 3%) ggc
 symout                :   0.00 ( 0%) usr   0.00 ( 0%) sys   0.01 (33%) wall       0 kB ( 0%) ggc
 TOTAL                 :   0.02             0.00             0.03               1835 kB

$./cc1 --version
GNU C version 4.2.0 20061015 (experimental) m68hc05 (i686-pc-linux-gnu)
        compiled by GNU C version 4.2.0 20061015 (experimental) m68hc05.
GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096

$/usr/lib/gcc/x86_64-linux-gnu/4.1.2/cc1 --version
GNU C version 4.1.2 20060901 (prerelease) (Debian 4.1.1-13) (x86_64-linux-gnu)
        compiled by GNU C version 4.1.2 20060901 (prerelease) (Debian 4.1.1-13).
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Comment 1 Andrew Pinski 2006-10-15 17:30:25 UTC
This is just a dup of bug 5035, just more optimizations to 4.2 causes the warning to show up.

*** This bug has been marked as a duplicate of 5035 ***
Comment 2 Manuel López-Ibáñez 2008-02-01 17:02:35 UTC
Reopen temporarily ...
Comment 3 Manuel López-Ibáñez 2008-02-01 17:05:33 UTC
*** Bug 27289 has been marked as a duplicate of this bug. ***
Comment 4 Manuel López-Ibáñez 2008-02-01 17:08:39 UTC
... to mark as a duplicate of PR 27289. They are almost the same testcase. The other one is shorter.

*** This bug has been marked as a duplicate of 27289 ***