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][C++] Fix PR38334, TBAA issues with vtbl loads


On Tue, 2 Dec 2008, Mark Mitchell wrote:

> Richard Guenther wrote:
> 
> > Sure.  The problem is we only know after inlining and some non-trivial
> > optimization (and at this point nothing distinguishes the access from
> > other pointer arithmetic and accesses).  I can disable the spurious
> > warning easily if you tell me that if the vtbl load is not "dead" then
> > the referenced object does contain such a pointer (and we know that
> > by means of recording a proper alias relationship).
> 
> Any C++ program that tries to apply a virtual pointer-to-function-member
> to a object whose dynamic type is not dynamic has undefined behavior.
> Is that what you're asking?

Yes, I guess so ;)  In this case it is appropriate to simply silence the
warning by doing

Index: typeck.c
===================================================================
--- typeck.c	(revision 142371)
+++ typeck.c	(working copy)
@@ -2790,6 +2790,10 @@ get_member_function_from_ptrfunc (tree *
       vtbl = build1 (NOP_EXPR, build_pointer_type (vtbl_ptr_type_node),
 		     instance_ptr);
       vtbl = cp_build_indirect_ref (vtbl, NULL, tf_warning_or_error);
+      /* If the object is not dynamic the access invokes undefined
+	 behavior.  As it is not executed in this case silence the
+	 spurious warnings it may provoke.  */
+      TREE_NO_WARNING (vtbl) = 1;
 
       /* Finally, extract the function pointer from the vtable.  */
       e2 = fold_build2 (POINTER_PLUS_EXPR, TREE_TYPE (vtbl), vtbl,


I verified that no other testcases in the testsuite have the TBAA
issue by making PTA more precise for pointer arithmetic.

If the above is ok I'll proceed with that to fix the PR36509 fallout.

Thanks,
Richard.


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