Bug 12792

Summary: {u,}int64_t variables are incorrectly reported as used uninitialized
Product: gcc Reporter: Christian Limpach <chris>
Component: tree-optimizationAssignee: Not yet assigned to anyone <unassigned>
Severity: minor CC: gcc-bugs, sami.kantoluoto
Priority: P2 Keywords: diagnostic
Version: 3.3.2   
Target Milestone: 4.0.0   
Host: m68k--netbsdelf Target: m68k--netbsdelf
Build: i386-unknown-netbsdelf Known to work:
Known to fail: Last reconfirmed: 2004-03-04 03:13:43
Bug Depends on:    
Bug Blocks: 24639    
Attachments: proposed fix

Description Christian Limpach 2003-10-27 18:51:46 UTC
long long int and long long unsigned int variables trigger the following 
warning even though the variables are initialized:
longlongint.c: In function `main':
longlongint.c:7: warning: `blkno' might be used uninitialized in this function

reduced test case:
---- cut here ----
# 1 "longlongint.c"
# 1 "<built-in>"
# 1 "<command line>"
# 1 "longlongint.c"

int printf (const char * __restrict, ...);

main(int argc, char **argv)
  long long int blkno;
  long long int t5;

  t5 = 1;

  blkno = t5 * t5;

  printf("%lld\n", blkno);

  return 0;
---- cut here ----
compilation command:
> cc -O1 -Wall longlongint.c -c                                                
longlongint.c: In function `main':
longlongint.c:7: warning: `blkno' might be used uninitialized in this function

There's no warning at -O0, there's a warning at Os, O1 and above.
Comment 1 Charles M. Hannum 2003-10-28 20:52:19 UTC
Created attachment 5014 [details]
proposed fix

The problem is thus:

* The {u,}mulsidi3 generate two parallel sets which modify the upper and lower
halves of the target register.

* life_analysis() does not track subregister modifications -- if you don't
modify the whole register with a single set, it considers the register

The simple, if klugy, solution to this is to stick an explicit clobber in.  It
seems to work.

While doing this, I noticed that constant folding was not happening for
32x32->64 multiplies.  This is because the parallel set generated by
{u,}mulsidi3 cannot be folded at all.  To solve this, I first expand to a
normal multiply, and then use a define_insn_and_split to convert it to the
parallel set after CSE and constant folding.
Comment 2 Andrew Pinski 2003-10-30 05:04:33 UTC
The proper fix is to teach life_analysis about the two halves.
Comment 3 Andrew Pinski 2003-11-20 08:01:38 UTC
*** Bug 13136 has been marked as a duplicate of this bug. ***
Comment 4 Andrew Pinski 2004-02-09 02:27:25 UTC
Suspending as this is fixed on the tree-ssa by looking at the tree level instead of the rtl 
where all problems like this can occur.
Comment 5 Andrew Pinski 2004-05-13 11:34:20 UTC
Fixed for 3.5.0 by the merge of the tree-ssa.