This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Fix libstdc++/C++ fallout from RTL alias export


Hi,
> Like
>   D.12950_92 = (struct _Simple_type_wrapper *) 
> &D.12951.D.8815._M_functor._M_pod_data[0];
>   *D.12950_92 = D.12949;
>   __old_functor = D.12951.D.8815._M_functor;
>
> where it stores a struct _Simple_type_wrapper into _M_pod_data and
> then reads from it via a union _Any_data type.
>
> Generated from tr1::function::swap.  Looks innocent but in reality
> isn't:
>
>       void swap(function& __x)
>       {
>         _Any_data __old_functor = _M_functor;
>         _M_functor = __x._M_functor;
>
> because you are effectively doing
>
>   int a, b;
>   *(float *)&a = 0.0;
>   b = a;
>
> and expect the read from a to conflict with the earlier store.
> BUT - the type of the lvalue 'a' is int and you are not allowed
> to access an object with effective dynamic type float via it.
>   
I see. That _Simple_type_wrapper looks like an hack to me, I think we
should replace it altogether.
> In the struct case it gets of course less obvious.  In functional you
> do
>
>  struct Data {
>    char mem[...];
>  } a, b;
>
>  *(T *)&a.mem[0] = ...;
>  b = a;
>
> but with the same argument this fails.  An aggregate copy
> is _not_ like memcpy as far as type based aliasing goes!
>
> So a fixed swap() would be using memcpy.  Or a fixed _Any_data
> would return ref-all pointers.
>   
As I said already, I'm envisaging two completely different approaches
for C++0x and TR1: for the latter, any dirt trick is fine, I would even
say, if you don't get feedback from me decently quickly, just add
attributes at your will and be done with it. For C++0x I think we should
do re-design things in a much better way, I can't believe we can't do
anything else but use memcpy...

Paolo.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]