This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH]: PR29066 ptrmemfunc_vbit_in_delta is broken
Mark Mitchell wrote:
Ryan Mansfield wrote:
Is the attached patch OK?
You should submit a ChangeLog entry with every patch. It's a bit of a
formality, but it helps reviewers. Also, do you have an FSF copyright
on file? I see you've contributed a couple of documentation patches,
but this is more substantial, so we need to make sure your paperwork is
one file.
Is the following sufficient?
Forwarded From: Ted Teah via RT <copyright-clerk@fsf.org>
Hi Graeme,
QNX employees are cleared to contribute to binutils, gdb, and gcc.
All the best,
Theodore Teah
Assignment Administrator
Free Software Foundation
51 Franklin Street, Fifth Floor
Boston, MA 02110
Phone +1-617-542-5942
Fax +1-617-542-2652
This is the right idea -- but I don't think we want to return early
here. If you look down further in the function, you can see there is
special handling for templates, for example; we want to get to that
point. So, please arrange things so that we can fall through to that
code. (You can have op0 be something like "pfn == 0 && (delta & 1) ==
0", and then have op1 be "0" or "1".)
Okay, I've made that change. Which g++.dg subdir should the new test
case go in? I just picked 'other' because I wasn't sure.
Thank you for all your help.
Regards,
Ryan Mansfield
2006-11-13 Ryan Mansfield <rmansfield@qnx.com>
PR c++/29066
* typeck.c (build_binary_op): Fix pointer to member function
comparison for ptrmemfunc_vbit_in_delta targets.
2006-11-13 Ryan Mansfield <rmansfield@qnx.com>
PR c++/29066
* g++.dg/other/pr29066.c: New.
Index: gcc/cp/typeck.c
===================================================================
--- gcc/cp/typeck.c (revision 118481)
+++ gcc/cp/typeck.c (working copy)
@@ -3266,8 +3266,28 @@
}
else if (TYPE_PTRMEMFUNC_P (type0) && null_ptr_cst_p (op1))
{
- op0 = build_ptrmemfunc_access_expr (op0, pfn_identifier);
- op1 = cp_convert (TREE_TYPE (op0), integer_zero_node);
+ if (TARGET_PTRMEMFUNC_VBIT_LOCATION
+ == ptrmemfunc_vbit_in_delta)
+ {
+ tree pfn0 = pfn_from_ptrmemfunc (op0);
+ tree delta0 = build_ptrmemfunc_access_expr (op0,
+ delta_identifier);
+ tree e1 = cp_build_binary_op (EQ_EXPR,
+ pfn0,
+ cp_convert (TREE_TYPE (pfn0),
+ integer_zero_node));
+ tree e2 = cp_build_binary_op (BIT_AND_EXPR,
+ delta0,
+ integer_one_node);
+ e2 = cp_build_binary_op (EQ_EXPR, e2, integer_zero_node);
+ op0 = cp_build_binary_op (TRUTH_ANDIF_EXPR, e1, e2);
+ op1 = cp_convert (TREE_TYPE (op0), integer_one_node);
+ }
+ else
+ {
+ op0 = build_ptrmemfunc_access_xpr (op0, pfn_identifier);
+ op1 = cp_convert (TREE_TYPE (op0), integer_zero_node);
+ }
result_type = TREE_TYPE (op0);
}
else if (TYPE_PTRMEMFUNC_P (type1) && null_ptr_cst_p (op0))
@@ -3305,11 +3325,15 @@
delta1 = build_ptrmemfunc_access_expr (op1,
delta_identifier);
e1 = cp_build_binary_op (EQ_EXPR, delta0, delta1);
- e2 = cp_build_binary_op (EQ_EXPR,
- pfn0,
- cp_convert (TREE_TYPE (pfn0),
- integer_zero_node));
- e1 = cp_build_binary_op (TRUTH_ORIF_EXPR, e1, e2);
+ if (TARGET_PTRMEMFUNC_VBIT_LOCATION
+ != ptrmemfunc_vbit_in_delta)
+ {
+ e2 = cp_build_binary_op (EQ_EXPR,
+ pfn0,
+ cp_convert (TREE_TYPE (pfn0),
+ integer_zero_node));
+ e1 = cp_build_binary_op (TRUTH_ORIF_EXPR, e1, e2);
+ }
e2 = build2 (EQ_EXPR, boolean_type_node, pfn0, pfn1);
e = cp_build_binary_op (TRUTH_ANDIF_EXPR, e2, e1);
if (code == EQ_EXPR)
Index: gcc/testsuite/g++.dg/other/pr29066.C
===================================================================
--- gcc/testsuite/g++.dg/other/pr29066.C (revision 0)
+++ gcc/testsuite/g++.dg/other/pr29066.C (revision 0)
@@ -0,0 +1,43 @@
+// PR c++/29066
+// Test pointer to member function comparison
+// { dg-do run }
+// { dg-options "" }
+
+extern "C" void abort (void);
+
+struct X
+{
+ virtual void a(void)=0;
+};
+
+struct Z : public X
+{
+ void a(void) {};
+};
+
+
+void f(X *obj)
+{
+ void (X::*xp)(void) = 0;
+ void (X::*xp2)(void) = 0;
+
+ xp = &X::a;
+
+ if (xp == xp2)
+ {
+ abort();
+ }
+
+ if (xp == 0)
+ {
+ abort();
+ }
+}
+
+int main(int argc, char* argv[])
+{
+ Z myobj;
+
+ f(&myobj);
+ return 0;
+}