This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH][C++] Fix PR38334, TBAA issues with vtbl loads
On Tue, 2 Dec 2008, Mark Mitchell wrote:
> Richard Guenther wrote:
>
> > 2008-12-01 Richard Guenther <rguenther@suse.de>
> >
> > PR c++/38334
> > * typeck.c (get_member_function_from_ptrfunc): Use a ref-all
> > pointer to access the vtable pointer.
>
> I don't understand the newly added comment:
>
> > ! /* Next extract the vtable pointer from the object. As we do not
> > ! represent the vtable pointer in the types we have to make sure
> > ! to not violate TBAA rules here. */
>
> or the change:
>
> > ! vtbl = build1 (NOP_EXPR, build_pointer_type_for_mode (vtbl_ptr_type_node,
> > ! ptr_mode, true),
> > instance_ptr);
>
> Why do we want to use the pointer-type-for-mode, rather than, say "char
> *" or "char **", or some such? (In principle, I think the FEs should
> know nothing of modes; modes are some weird back-end detail, but having
> nothing to do with FE concepts.)
>
> Please adjust the comment to explain why the obvious type (namely, the
> type of the vtable pointer in the object, which is what I think
> vtbl_ptr_type_node is) isn't correct.
vtbl_ptr_type_node is correct, but there is no vtbl_ptr_type member
in the structure we are accessing. Thus type-based alias analysis
concludes that this access cannot alias the object which means we
would remove earlier initializations as unused or (which is why
I need this now) we are emitting type-punning warnings with the
fix for PR36509. The patch makes sure to disable TBAA rules for
this access by doing the access with a TYPE_REF_CAN_ALIAS_ALL
pointer which you can create with build_pointer_type_for_mode (..., true).
I will adjust the comment to mention the ref-all pointer.
Note that using a char * or char ** pointer doesn't help here, we want
to extract a pointer and T1* and T2* do not conflict for TBAA.
Is the patch ok with the extended comment?
Thanks,
Richard.
--
Richard Guenther <rguenther@suse.de>
Novell / SUSE Labs
SUSE LINUX Products GmbH - Nuernberg - AG Nuernberg - HRB 16746 - GF: Markus Rex