This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug tree-optimization/15438] [3.5 Regression] miscompilation with attribute (__malloc__)
- From: "steven at gcc dot gnu dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 17 May 2004 07:42:31 -0000
- Subject: [Bug tree-optimization/15438] [3.5 Regression] miscompilation with attribute (__malloc__)
- References: <20040514162618.15438.belyshev@lubercy.com>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Additional Comments From steven at gcc dot gnu dot org 2004-05-17 07:42 -------
This is an alias bug. Just before dom2, the tree looks like this:
main ()
{
int * p;
int T.0;
# BLOCK 0
# PRED: ENTRY [100.0%] (fallthru)
# a_5 = VDEF <a_2>;
a = 0;
# VUSE <a_5>;
foo ();
# VUSE <a_5>;
T.0_3 = a;
if (T.0_3 == 0) goto <L0>; else goto <L1>;
# SUCC: 2 [53.5%] (false) 1 [46.5%] (true)
# BLOCK 1
# PRED: 0 [46.5%] (true)
<L0>:;
abort ();
# SUCC:
# BLOCK 2
# PRED: 0 [53.5%] (false)
<L1>:;
return 0;
# SUCC: EXIT [100.0%]
}
Notice that the call to foo() does not clobber a, so we have:
a = 0;
# VUSE <a_5>;
foo ();
# VUSE <a_5>;
T.0_3 = a;
and dom2 thinks "T.0_3 = 0" is a valid constant propagation.
The documentation for attribute malloc says:
`malloc'
The `malloc' attribute is used to tell the compiler that a function
may be treated as if it were the malloc function. The compiler
assumes that calls to malloc result in a pointers that cannot
alias anything. This will often improve optimization.
so while the returned pointer cannot alias anything, it doesn't mean
that the function call may not call clobber global variables. So in
this case, 'a' may be clobbered by the call to foo(), and there should
be a VDEF for a at the function call.
--
What |Removed |Added
----------------------------------------------------------------------------
CC| |dnovillo at redhat dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15438