User account creation filtered due to spam.

Bug 36373 - [4.3 Regression] Wrong code with struct return
Summary: [4.3 Regression] Wrong code with struct return
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 4.3.1
: P2 normal
Target Milestone: 4.4.0
Assignee: Not yet assigned to anyone
URL:
Keywords: alias, wrong-code
Depends on:
Blocks:
 
Reported: 2008-05-29 15:06 UTC by Richard Biener
Modified: 2009-06-17 12:37 UTC (History)
5 users (show)

See Also:
Host:
Target:
Build:
Known to work: 4.1.2 4.4.0
Known to fail: 4.3.4
Last reconfirmed: 2008-05-29 15:07:30


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Richard Biener 2008-05-29 15:06:06 UTC
extern void abort (void);
struct Foo {
    int *p;
    int *q;
};
struct Foo __attribute__((noinline))
bar(int *p)
{
  struct Foo f;
  f.p = p;
  return f;
}
void __attribute__((noinline))
foo(struct Foo f)
{
  *f.p = 0;
}
int main()
{
  int a, b;
  a = 0;
  b = 1;
  struct Foo f;
  f = bar (&b);
  f.q = &a;
  foo(f);
  if (b != 0)
    abort ();
  return 0;
}
Comment 1 Richard Biener 2008-05-29 15:07:30 UTC
Mine.
Comment 2 Richard Biener 2008-05-29 15:23:13 UTC
First we miss the constraint

  f = &ANYTHING

from

  f = bar (&b);

but then we also do not handle at all the case of escaping pointers through
by-value passed structures

  foo (f);

and thus we end up not clobbering b for that call.  The first part is easy
to fix.  I have to think about the second one ...
Comment 3 Richard Biener 2008-05-29 15:44:59 UTC
I have a patch.
Comment 4 Richard Biener 2008-05-30 10:58:14 UTC
Umm.  It's worse.

With -O2 -fno-tree-sra:

extern void abort (void);
struct Foo {
    int *p;
} x;
struct Foo __attribute__((noinline))
bar(int *p)
{
  struct Foo f;
  f.p = p;
  return f;
}
void __attribute__((noinline))
foo()
{
  *x.p = 0;
}
int main()
{
  int b;
  b = 1;
  struct Foo g = bar (&b);
  x = g;
  foo();
  if (b != 0)
    abort ();
  return 0;
}


the escape through the global x doesn't work either.  SRA "fixes" this by

  # g_7 = VDEF <g_6(D)>
  g = bar (&b);
  # VUSE <g_7>
  g$p_2 = g.p; 
  # x_9 = VDEF <x_8(D)>
  x.p = g$p_2;

where we (after partial fixes) compute the points-to set of g$p_2 correctly
and thus mark that pointer as escaping to a global in the next stmt.
Comment 5 littlestar 2008-06-26 06:51:47 UTC
ping...
Comment 6 Richard Biener 2008-06-27 18:54:35 UTC
Subject: Bug 36373

Author: rguenth
Date: Fri Jun 27 18:53:43 2008
New Revision: 137197

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=137197
Log:
2008-06-27  Richard Guenther  <rguenther@suse.de>

	PR tree-optimization/36400
	PR tree-optimization/36373
	PR tree-optimization/36344
	* tree-ssa-structalias.c (var_escaped, escaped_tree, escaped_id,
	var_nonlocal, nonlocal_tree, nonlocal_id): New globals
	(update_alias_info): Remove call clobbering code.
	(make_constraint_to): New helper function.
	(make_escape_constraint): Likewise.
	(handle_rhs_call): Use it on all pointer containing arguments.
	Also mark the static chain escaped.
	(handle_lhs_call): Make constraints from NONLOCAL and ESCAPED
	instead of ANYTHING.
	(make_constraint_from): New helper split out from ...
	(make_constraint_from_anything): ... here.
	(find_func_aliases): Add constraints for escape sites.
	(intra_create_variable_infos): Make constraints from NONLOCAL
	for parameters.
	(find_what_p_points_to): Interpret NONLOCAL and ESCAPED the same
	as ANYTHING.
	(clobber_what_p_points_to): Remove.
	(clobber_what_escaped): New function.
	(init_base_vars): Init NONLOCAL and ESCAPED.
	(do_sd_constraint): Do not propagate the solution from ESCAPED
	but use ESCAPED as a placeholder.
	(solve_graph): Likewise.
	* tree-flow.h (clobber_what_p_points_to): Remove.
	(clobber_what_escaped): Declare.
	* tree-ssa-alias.c (set_initial_properties): Call it.
	Remove code clobbering escaped pointers.

	* gcc.dg/torture/pr36373-1.c: New testcase.
	* gcc.dg/torture/pr36373-2.c: Likewise.
	* gcc.dg/torture/pr36373-3.c: Likewise.
	* gcc.dg/torture/pr36373-4.c: Likewise.
	* gcc.dg/torture/pr36373-5.c: Likewise.
	* gcc.dg/torture/pr36373-6.c: Likewise.
	* gcc.dg/torture/pr36373-7.c: Likewise.
	* gcc.dg/torture/pr36373-8.c: Likewise.
	* gcc.dg/torture/pr36373-9.c: Likewise.
	* gcc.dg/torture/pr36373-10.c: Likewise.
	* gcc.dg/torture/pr36400.c: Likewise.
	* gcc.c-torture/execute/pta-field-1.c: Likewise.
	* gcc.c-torture/execute/pta-field-2.c: Likewise.
	* gcc.dg/tree-ssa/loadpre8.c: Remove XFAIL.
	* gcc.dg/tree-ssa/pr24287.c: XFAIL.

Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gcc.dg/tree-ssa/loadpre8.c
    trunk/gcc/testsuite/gcc.dg/tree-ssa/pr24287.c
    trunk/gcc/tree-flow.h
    trunk/gcc/tree-ssa-alias.c
    trunk/gcc/tree-ssa-structalias.c

Comment 7 Richard Biener 2008-06-27 21:55:33 UTC
Subject: Bug 36373

Author: rguenth
Date: Fri Jun 27 21:54:42 2008
New Revision: 137204

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=137204
Log:
2008-06-27  Richard Guenther  <rguenther@suse.de>

	PR tree-optimization/36400
	PR tree-optimization/36373
	PR tree-optimization/36344
	* tree-ssa-structalias.c (var_escaped, escaped_tree, escaped_id,
	var_nonlocal, nonlocal_tree, nonlocal_id): New globals
	(update_alias_info): Remove call clobbering code.
	(make_constraint_to): New helper function.
	(make_escape_constraint): Likewise.
	(handle_rhs_call): Use it on all pointer containing arguments.
	Also mark the static chain escaped.
	(handle_lhs_call): Make constraints from NONLOCAL and ESCAPED
	instead of ANYTHING.
	(make_constraint_from): New helper split out from ...
	(make_constraint_from_anything): ... here.
	(find_func_aliases): Add constraints for escape sites.
	(intra_create_variable_infos): Make constraints from NONLOCAL
	for parameters.
	(find_what_p_points_to): Interpret NONLOCAL and ESCAPED the same
	as ANYTHING.
	(clobber_what_p_points_to): Remove.
	(clobber_what_escaped): New function.
	(init_base_vars): Init NONLOCAL and ESCAPED.
	(do_sd_constraint): Do not propagate the solution from ESCAPED
	but use ESCAPED as a placeholder.
	(solve_graph): Likewise.
	* tree-flow.h (clobber_what_p_points_to): Remove.
	(clobber_what_escaped): Declare.
	* tree-ssa-alias.c (set_initial_properties): Call it.
	Remove code clobbering escaped pointers.

	* gcc.dg/torture/pr36373-1.c: New testcase.
	* gcc.dg/torture/pr36373-2.c: Likewise.
	* gcc.dg/torture/pr36373-3.c: Likewise.
	* gcc.dg/torture/pr36373-4.c: Likewise.
	* gcc.dg/torture/pr36373-5.c: Likewise.
	* gcc.dg/torture/pr36373-6.c: Likewise.
	* gcc.dg/torture/pr36373-7.c: Likewise.
	* gcc.dg/torture/pr36373-8.c: Likewise.
	* gcc.dg/torture/pr36373-9.c: Likewise.
	* gcc.dg/torture/pr36373-10.c: Likewise.
	* gcc.dg/torture/pr36400.c: Likewise.
	* gcc.c-torture/execute/pta-field-1.c: Likewise.
	* gcc.c-torture/execute/pta-field-2.c: Likewise.
	* gcc.dg/tree-ssa/loadpre8.c: Remove XFAIL.
	* gcc.dg/tree-ssa/pr24287.c: XFAIL.

Added:
    trunk/gcc/testsuite/gcc.c-torture/execute/pta-field-1.c
    trunk/gcc/testsuite/gcc.c-torture/execute/pta-field-2.c
    trunk/gcc/testsuite/gcc.dg/torture/pr36373-1.c
    trunk/gcc/testsuite/gcc.dg/torture/pr36373-10.c
    trunk/gcc/testsuite/gcc.dg/torture/pr36373-2.c
    trunk/gcc/testsuite/gcc.dg/torture/pr36373-3.c
    trunk/gcc/testsuite/gcc.dg/torture/pr36373-4.c
    trunk/gcc/testsuite/gcc.dg/torture/pr36373-5.c
    trunk/gcc/testsuite/gcc.dg/torture/pr36373-6.c
    trunk/gcc/testsuite/gcc.dg/torture/pr36373-7.c
    trunk/gcc/testsuite/gcc.dg/torture/pr36373-8.c
    trunk/gcc/testsuite/gcc.dg/torture/pr36373-9.c
    trunk/gcc/testsuite/gcc.dg/torture/pr36400.c

Comment 8 Richard Biener 2008-06-28 11:19:30 UTC
Fixed for 4.4.0.
Comment 9 Jakub Jelinek 2008-07-31 09:25:36 UTC
Downgrading to P2, as the required changes are probably too big and risky for the branches.
Comment 10 Ramana Radhakrishnan 2009-01-15 10:37:51 UTC
Change CC addresses
Comment 11 Richard Biener 2009-01-16 23:08:56 UTC
I have no plans to fix this on the branches.
Comment 12 Joseph S. Myers 2009-03-31 20:51:59 UTC
Closing 4.2 branch.
Comment 13 Richard Biener 2009-06-17 12:37:15 UTC
WONTFIX for 4.3.  Alias fixes are considered too risky at this stage.