Bug 23086 - incoming arguments cannot alias local variables
Summary: incoming arguments cannot alias local variables
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 4.1.0
: P3 enhancement
Target Milestone: 4.5.0
Assignee: Diego Novillo
URL:
Keywords: alias, missed-optimization, xfail
: 25558 26609 35359 (view as bug list)
Depends on: 22591
Blocks: 26609
  Show dependency treegraph
 
Reported: 2005-07-26 19:48 UTC by Diego Novillo
Modified: 2009-04-03 12:38 UTC (History)
5 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail: 4.4.0
Last reconfirmed: 2008-03-14 21:10:31


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Diego Novillo 2005-07-26 19:48:19 UTC
The hack in may_alias_p we used to have was papering over the real problem and
causing problems (PR 22591).

The real fix is to notice in the aliaser that a default definition for a
PARM_DECL cannot possibly point to a local variable.

Test XFAIL'd for now.  Fix scheduled for 4.2.
Comment 1 Andrew Pinski 2005-07-26 19:52:16 UTC
Confirmed.
Comment 2 Andrew Pinski 2005-07-27 20:34:09 UTC
Isn't this a simple fix to may_alias_p saying that PARM_DECLs cannot alias local variables?

unless I am missing something obvious.
Comment 3 Diego Novillo 2005-07-27 20:38:54 UTC
Subject: Re:  aliasing information in gcc.dg/tree-ssa/20030807-7.c should be fixed properly

On Wed, Jul 27, 2005 at 08:34:10PM -0000, pinskia at gcc dot gnu dot org wrote:

> Isn't this a simple fix to may_alias_p saying that PARM_DECLs
> cannot alias local variables?
>
It isn't.  Only a default_def of a PARM_DECL is guaranteed not to
point into any local.  may_alias_p is flow-insensitive, so it can
only return answers that apply to *all* the SSA names for a DECL.
Comment 4 Andrew Pinski 2005-07-27 20:39:32 UTC
I must be missing something ovbious since that did not fix it.
Comment 5 Andrew Pinski 2006-01-11 01:07:09 UTC
*** Bug 25558 has been marked as a duplicate of this bug. ***
Comment 6 Andrew Pinski 2006-01-11 01:08:59 UTC
Here is a reduced testcase, which I found independently:
void link_error(void);

int *t;
int g(int *a)
{
  t = a;
  *a = 2;
}

void f(int *a)
{
  int b;
  b = 1;
  g(&b);
  b = 2;
  *a = 1;  <--- a cannot point to b here.
  if (b == 2)
    link_error();
}

int main(void)
{
  int t;
  f(&t);
  return 0;
}
Comment 7 Andrew Pinski 2006-09-12 06:29:42 UTC
*** Bug 26609 has been marked as a duplicate of this bug. ***
Comment 8 Andrew Pinski 2008-02-25 18:03:14 UTC
*** Bug 35359 has been marked as a duplicate of this bug. ***
Comment 9 Richard Biener 2008-03-14 21:10:31 UTC
We could simply prune locals from points-to solutions for default defs.
Comment 10 Richard Biener 2009-04-03 12:19:48 UTC
  *a = 1;  <--- a cannot point to b here.
  if (b == 2)

b != 2 you mean.

This works for me with 4.0.4 even.  Likely optimized on RTL level?

Adjusted testcase:

extern void link_error (void);
extern void abort (void);

int *t;
int __attribute__((noinline)) g(int *a)
{
  t = a;
  *a = 2;
}

void __attribute__((noinline)) f(int *a)
{
  int b;
  b = 1;
  g(&b);
  b = 2;
  *a = 1;
  if (b != 2)
    link_error();
}

int main(void)
{
  int t;
  f(&t);
  if (t != 1)
    abort ();
  return 0;
}


On trunk we now have

f (int * a)
{
  int b;

<bb 2>:
  b = 1;
  g (&b);
  *a = 1;
  return;

}
Comment 11 Richard Biener 2009-04-03 12:38:28 UTC
Subject: Bug 23086

Author: rguenth
Date: Fri Apr  3 12:38:08 2009
New Revision: 145499

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=145499
Log:
2009-04-03  Richard Guenther  <rguenther@suse.de>

	PR tree-optimization/2480
	PR tree-optimization/23086
	* gcc.dg/tree-ssa/pr2480.c: New testcase.
	* gcc.dg/tree-ssa/pr23086.c: Likewise.

Added:
    trunk/gcc/testsuite/gcc.dg/tree-ssa/pr23086.c
    trunk/gcc/testsuite/gcc.dg/tree-ssa/pr2480.c
Modified:
    trunk/gcc/testsuite/ChangeLog