struct S { int w, x, y, z; }; struct T { int r; struct S s; }; void bar (struct S, int); void foo (int a, struct T b) { struct S *c = 0; if (a) c = &b.s; bar (*c, a); } The call to bar appears to not be marked [tail-call] because b is marked as a call-clobbered local variable. Which IIRC means that the aliasing code thinks that the address of b escapes. Which is untrue -- no address escapes from this function.
;; Function foo (foo) Visiting use-def links for 0B Visiting use-def links for &bD.1128.sD.1123 foo: Total number of aliased vops: 0 Referenced variables in foo: 4 Variable: cD.1131, UID 0, struct S *, type memory tag: TMT.0D.1138 Variable: aD.1127, UID 1, intD.0, default def: aD.1127_3 Variable: bD.1128, UID 2, struct T, is an alias tag, is addressable, call clobbered, default def: bD.1128_5 Variable: TMT.0D.1138, UID 3, struct S, is addressable, is global, call clobbered, may aliases: { bD.1128 } Alias statistics for foo Total alias queries: 1 Total alias mayalias results: 1 Total alias noalias results: 0 Total simple queries: 1 Total simple resolved: 0 Total TBAA queries: 1 Total TBAA resolved: 0
Testing patch.
Subject: Bug 19633 CVSROOT: /cvs/gcc Module name: gcc Changes by: dnovillo@gcc.gnu.org 2005-01-27 04:45:20 Modified files: gcc : ChangeLog tree-outof-ssa.c tree-ssa-alias.c gcc/testsuite : ChangeLog Added files: gcc/testsuite/gcc.dg: pr19633.c gcc/testsuite/gcc.dg/tree-ssa: pr19633.c Log message: PR tree-optimization/19633 * tree-ssa-alias.c (ptr_is_dereferenced_by): Also handle CALL_EXPRs. (maybe_create_global_var): Do not create .GLOBAL_VAR if there are no call-clobbered variables. * tree-outof-ssa.c (check_replaceable): Return false for calls with side-effects. testsuite/ChangeLog PR tree-optimization/19633 * gcc.dg/pr19633.c: New test. * gcc.dg/tree-ssa/pr19633.c: New test. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.7297&r2=2.7298 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/tree-outof-ssa.c.diff?cvsroot=gcc&r1=2.41&r2=2.42 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/tree-ssa-alias.c.diff?cvsroot=gcc&r1=2.66&r2=2.67 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.4940&r2=1.4941 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/pr19633.c.diff?cvsroot=gcc&r1=NONE&r2=1.1 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/tree-ssa/pr19633.c.diff?cvsroot=gcc&r1=NONE&r2=1.1
Fix: http://gcc.gnu.org/ml/gcc-patches/2005-01/msg01969.html. This does not completely get you the tail call you were looking for, but it does address the address escaping problem. I would probably just close it as we already have PRs for the TREE_ADDRESSABLE arguments in the call.
I still see "b" marked as "call clobbered": struct S { int w, x, y, z; }; struct T { int r; struct S s; }; void bar(struct S, int); void foo(int a, struct T b) { struct S *c = 0; if (a) c = &b.s; bar (*c, a); } --> .alias4 dump ;; Function foo (foo) Visiting use-def links for 0B Visiting use-def links for &bD.1459.sD.1454 foo: Total number of aliased vops: 1 Referenced variables in foo: 4 Variable: cD.1462, UID 0, struct S *, type memory tag: TMT.0D.1469 Variable: aD.1458, UID 1, intD.0, default def: aD.1458_3 Variable: bD.1459, UID 2, struct T, is an alias tag, is addressable, call clobbered, default def: bD.1459_5 Variable: TMT.0D.1469, UID 3, struct S, is addressable, is global, call clobbered, may aliases: { bD.1459 } (...) Aliased symbols bD.1459, UID 2, struct T, is an alias tag, is addressable, call clobbered, default def: bD.1459_5 TMT.0D.1469, UID 3, struct S, is addressable, is global, call clobbered, may aliases: { bD.1459 } Dereferenced pointers cD.1462, UID 0, struct S *, type memory tag: TMT.0D.1469 Type memory tags TMT.0D.1469, UID 3, struct S, is addressable, is global, call clobbered, may aliases: { bD.1459 } (...) foo (aD.1458, bD.1459) { struct S * cD.1462; # BLOCK 0 # PRED: ENTRY [100.0%] (fallthru,exec) if (aD.1458_3 != 0) goto <L0>; else goto <L1>; # SUCC: 1 [67.0%] (true,exec) 2 [33.0%] (false,exec) # BLOCK 1 # PRED: 0 [67.0%] (true,exec) <L0>:; # SUCC: 2 [100.0%] (fallthru,exec) # BLOCK 2 # PRED: 0 [33.0%] (false,exec) 1 [100.0%] (fallthru,exec) # cD.1462_1 = PHI <0B(0), &bD.1459.sD.1454(1)>; <L1>:; # bD.1459_6 = V_MAY_DEF <bD.1459_5>; bar (*cD.1462_1, aD.1458_3); return; # SUCC: EXIT [100.0%] }
Subject: Bug 19633 CVSROOT: /cvs/gcc Module name: gcc Changes by: dnovillo@gcc.gnu.org 2005-02-01 20:30:08 Modified files: gcc : ChangeLog tree-flow.h tree-ssa-alias.c gcc/testsuite : ChangeLog gcc/testsuite/gcc.dg: pr19633.c Added files: gcc/testsuite/gcc.dg: pr19633-1.c Log message: PR tree-optimization/19633 * tree-flow.h (struct ptr_info_def): Add field 'pt_null'. * tree-ssa-alias.c (init_alias_info): Initialize. (merge_pointed_to_info): Set. (add_pointed_to_expr): Set pt_null if EXPR is a NULL pointer. (dump_points_to_info_for): Show value of pt_null. (struct count_ptr_d): Declare. (find_ptr_dereference): Remove. (ptr_is_dereferenced_by): Remove. (count_ptr_derefs): New local function. (count_uses_and_derefs): New local function. (compute_points_to_and_addr_escape): Call it. If the number of dereferences is greater than zero, mark the pointer as dereferenced. If there are fewer dereferences than uses of the pointer, the pointer's value escapes. testsuite/ChangeLog PR tree-optimization/19633 * testsuite/gcc.dg/pr19633-1.c: New test. * testsuite/gcc.dg/pr19633.c: Tweak to make pointer point to NULL or a symbol. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.7365&r2=2.7366 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/tree-flow.h.diff?cvsroot=gcc&r1=2.78&r2=2.79 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/tree-ssa-alias.c.diff?cvsroot=gcc&r1=2.67&r2=2.68 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.4973&r2=1.4974 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/pr19633-1.c.diff?cvsroot=gcc&r1=NONE&r2=1.1 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/pr19633.c.diff?cvsroot=gcc&r1=1.1&r2=1.2
Hmm, the testcase now fails on ppc-darwin.
Should this be closed?
Ping Diego, should this be closed??
Subject: Re: local address incorrectly thought to escape On Mon, Jun 13, 2005 at 01:41:06PM -0000, steven at gcc dot gnu dot org wrote: > Ping Diego, should this be closed?? > If the testcase now works on ppc-darwin (see comment #7), then yes. Diego.
(In reply to comment #10) > If the testcase now works on ppc-darwin (see comment #7), then > yes. Yes it does.
This testcase started failing for me as of last night on trunk. 1c1 < Test Run By root on Thu Dec 14 06:04:39 2006 --- > Test Run By root on Wed Dec 13 06:04:24 2006 .... cut for space saving ..... 30945,30946c30909,30910 < FAIL: gcc.dg/pr19633-1.c (test for excess errors) < WARNING: gcc.dg/pr19633-1.c compilation failed to produce executable --- > PASS: gcc.dg/pr19633-1.c (test for excess errors) > PASS: gcc.dg/pr19633-1.c execution test 39056d39019 < PASS: gcc.dg/tls/opt-13.c (test for excess errors) 42919,42920c42882,42883 < # of expected passes 42352 < # of unexpected failures 12 --- > # of expected passes 42317 > # of unexpected failures 11 42926c42889 < /u01/var/tmp/gcc_trunk_svn/gcc_20061214/gcc/xgcc version 4.3.0 20061214 (experimental) --- > /u01/var/tmp/gcc_trunk_svn/gcc_20061213/gcc/xgcc version 4.3.0 20061213 (experimental) I run on Solaris 10 x86. I can provide more information as needed. Brett Albertson