[PATCH] Fix PR42944

Richard Guenther richard.guenther@gmail.com
Wed Jan 5 11:13:00 GMT 2011


On Tue, Jan 4, 2011 at 6:33 PM, Ulrich Weigand <uweigand@de.ibm.com> wrote:
> Richard Guenther wrote:
>
>> 2010-02-03  Richard Guenther  <rguenther@suse.de>
>>
>>         PR tree-optimization/42944
>>         * tree-ssa-alias.c (ref_maybe_used_by_call_p_1): Handle
>>         calloc.
>>         (call_may_clobber_ref_p_1): Likewise.  Properly handle
>>         malloc and calloc clobbering errno.
>>
>>         * gcc.dg/errno-1.c: New testcase.
>
> This test fails on SPU, presumably because we're using newlib.
> Specifically, errno is a macro that expands to something like:
>   _impure_data._errno
>
> It seems the code in call_may_clobber_ref_p_1 may not expect
> a component reference here?

Yes, we assume that errno is an integer object or accessed
via a pointer.  Basically we try to be able to disambiguate
at least _something_ across malloc/calloc, which is very
important for SPEC 2006 FP performance.  Something like
_impure_data._errno is a very bad choice for errno.

We do unfortunately have no way to conservatively track what
points to errno, so this guard is very important here.

Iff we want to fix this cornercase for 4.6 (for 4.7 somebody
may sit down and really think through how to generally keep
track of errno) then I suppose a target hook might be the
way to go.  For newlib we could say errno is always accessed
via a aggregate decl.  So the target hook would get the
'ref' variable passed and thus can access 'base' from

          if (flag_errno_math
              && TREE_TYPE (base) == integer_type_node)
            {
              struct ptr_info_def *pi;
              if (DECL_P (base)
                  && !TREE_STATIC (base))
                return true;
              else if ((INDIRECT_REF_P (base)
                        || TREE_CODE (base) == MEM_REF)
                       && TREE_CODE (TREE_OPERAND (base, 0)) == SSA_NAME
                       && (pi = SSA_NAME_PTR_INFO (TREE_OPERAND (base, 0))))
                return pi->pt.anything || pi->pt.nonlocal;
            }

and return true if errno might be accessed through it, with the above code
being the default implementation.  The hook could be called
ref_may_alias_errno_p () and we'd wrap that in a helper with the same
name in tree-ssa-alias.c.

I can cook up a patch sketch next week (can you open a bug?) but would
appreciate testing from your side (plus maybe the enable-for-all-newlib
targets stuff).

Thanks,
Richard.


> Bye,
> Ulrich
>
> --
>  Dr. Ulrich Weigand
>  GNU Toolchain for Linux on System z and Cell BE
>  Ulrich.Weigand@de.ibm.com
>



More information about the Gcc-patches mailing list