Bug 20168 - const function causes the creation of GLOBAL_VAR
Summary: const function causes the creation of GLOBAL_VAR
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 4.0.0
: P2 enhancement
Target Milestone: ---
Assignee: Diego Novillo
Keywords: alias
Depends on:
Reported: 2005-02-23 15:20 UTC by Hans-Peter Nilsson
Modified: 2010-07-13 11:00 UTC (History)
1 user (show)

See Also:
Known to work:
Known to fail:
Last reconfirmed: 2005-12-24 20:17:23


Note You need to log in before you can comment on or make changes to this bug.
Description Hans-Peter Nilsson 2005-02-23 15:20:17 UTC
Before the fix for PR 20100 and PR 20115, const and pure calls were both treated
as "const".  After the fix, both are treated as "pure" by that fix, but
a .GLOBAL_VAR is unnecessarily created because of the bambam call in:

extern int constfun (void) __attribute__ ((__const__));
extern void bambam (void);

int x (void)
  int a = constfun ();
  bambam ();
  return a + constfun ();
Comment 1 Andrew Pinski 2005-02-23 15:43:04 UTC
Changing this for Diego.
Comment 2 Hans-Peter Nilsson 2005-02-23 15:45:05 UTC
It deserves mentioning (for the audience) that the right thing happens for
the generated code in the test-case; this problem is mainly an internal
wart (IIUC):
<dnovillo> now, the problem is that if there is a mix of regular and 'const'
functions, we will have created .GLOBAL_VAR 
           unnecessarily.  that's bad.
<dnovillo> testing for !TREE_SIDE_EFFECTS is too broad.  We don't want to
consider 'const' functions.
<hp> yes, but I don't know how to create a test-case for *that*
<dnovillo> hp: this one is good enough.  we created .GLOBAL_VAR.  we shouldn't
have created it.
<dnovillo> the call to bambam shouldn't have a V_MAY_DEF for .GLOBAL_VAR
Comment 3 Diego Novillo 2006-03-10 15:36:19 UTC
Fixed in 4.2.
Comment 4 Andrew Pinski 2006-03-14 01:28:06 UTC
Huh, I still get a .global_var as of yesterday:
  bambam ();
Comment 5 Steven Bosscher 2010-07-13 11:00:19 UTC
Insofar something that doesn't exist anymore can be considered broken, this bug is FIXED:

;; Function x (x)

x ()
  intD.0 aD.1233;
  intD.0 D.1983;

  # BLOCK 2 freq:10000
  # PRED: ENTRY [100.0%]  (fallthru,exec)
  aD.1233_1 = constfunD.1227 ();
  # .MEMD.1986_5 = VDEF <.MEMD.1986_4(D)>
  # USE = nonlocal
  # CLB = nonlocal
  bambamD.1229 ();
  D.1983_3 = aD.1233_1 + aD.1233_1;
  return D.1983_3;
  # SUCC: EXIT [100.0%]