Bug 32882 - Mismatched types with pointer to member functions and -fstrict-aliasing
Summary: Mismatched types with pointer to member functions and -fstrict-aliasing
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.3.0
: P3 normal
Target Milestone: 4.3.0
Assignee: Not yet assigned to anyone
URL:
Keywords: wrong-code
Depends on:
Blocks: 22368
  Show dependency treegraph
 
Reported: 2007-07-24 16:18 UTC by Richard Biener
Modified: 2007-10-11 11:40 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
testcase (slightly reduced from tr1/3_function_objects/function/8.cc) (12.48 KB, text/plain)
2007-07-24 16:19 UTC, Richard Biener
Details
testcase (more reduced) (2.11 KB, text/plain)
2007-07-24 16:33 UTC, Richard Biener
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Richard Biener 2007-07-24 16:18:09 UTC
8.0.min.ii:15: error: non-trivial conversion at assignment
struct 
{
  X:: * const __pfn;
  long int __delta;
} * const *
struct 
{
  X:: * const __pfn;
  long int __delta;
} * const &
__ptr = __ptr.24

which is gimplified from the INIT_EXPR

__ptr = (struct
  {
    X:: * const __pfn;
    long int __delta;
  } * const *) _M_access ((union _Any_data *) __source)

where __ptrs type is structurally equivalent to the type the _M_access
return value is converted to, but it has no relationship to it.

The backtrace where this INIT_EXPR is created from is

#0  build2_stat (code=INIT_EXPR, tt=0x2b9977879270, arg0=0x2b997792abb0, 
    arg1=0x2b99778c2440)
    at /space/rguenther/src/svn/pointer_plus/gcc/tree.c:3064
#1  0x00000000004faa41 in split_nonconstant_init (dest=0x2b997792abb0, 
    init=0x2b99778c2440)
    at /space/rguenther/src/svn/pointer_plus/gcc/cp/typeck2.c:553
#2  0x00000000004faea8 in store_init_value (decl=0x2b997792abb0, 
    init=0x2b99778c2440)
    at /space/rguenther/src/svn/pointer_plus/gcc/cp/typeck2.c:626
#3  0x0000000000445eaf in check_initializer (decl=0x2b997792abb0, 
    init=0x2b99778c2440, flags=0, cleanup=0x7fff34377270)
    at /space/rguenther/src/svn/pointer_plus/gcc/cp/decl.c:4892
#4  0x0000000000448f10 in cp_finish_decl (decl=0x2b997792abb0, 
    init=0x2b99778c2440, init_const_expr_p=0 '\0', asmspec_tree=0x0, flags=0)
    at /space/rguenther/src/svn/pointer_plus/gcc/cp/decl.c:5291
#5  0x00000000004498e4 in finish_decl (decl=0x2b997792abb0, 
    init=0x2b99778c2440, asmspec_tree=0x0)
    at /space/rguenther/src/svn/pointer_plus/gcc/cp/decl.c:5452
#6  0x00000000004c4289 in tsubst_expr (t=0x2b9977823480, args=0x2b9977717510, 
    complain=tf_warning_or_error, in_decl=0x2b9977815d00, 
    integral_constant_expression_p=0 '\0')
    at /space/rguenther/src/svn/pointer_plus/gcc/cp/pt.c:9850
#7  0x00000000004c3353 in tsubst_expr (t=0x2b997780f930, args=0x2b9977717510, 
) at /space/rguenther/src/svn/pointer_plus/gcc/cp/pt.c:9771
#8  0x00000000004c5877 in tsubst_expr (t=0x2b997780c7d0, args=0x2b9977717510, 
    complain=tf_warning_or_error, in_decl=0x2b9977815d00, 
    integral_constant_expression_p=0 '\0')
    at /space/rguenther/src/svn/pointer_plus/gcc/cp/pt.c:9912
#9  0x00000000004ee15b in instantiate_decl (d=0x2b997791bf00, defer_ok=0, 
    expl_inst_class_mem_p=0 '\0')
    at /space/rguenther/src/svn/pointer_plus/gcc/cp/pt.c:14415
#10 0x00000000004eea19 in instantiate_pending_templates (retries=0)
    at /space/rguenther/src/svn/pointer_plus/gcc/cp/pt.c:14520
#11 0x000000000054d6b0 in cp_write_global_declarations ()
    at /space/rguenther/src/svn/pointer_plus/gcc/cp/decl2.c:3057
#12 0x0000000000a71ed6 in compile_file ()
    at /space/rguenther/src/svn/pointer_plus/gcc/toplev.c:1057
#13 0x0000000000a73aa8 in do_compile ()
    at /space/rguenther/src/svn/pointer_plus/gcc/toplev.c:2151
#14 0x0000000000a73b0c in toplev_main (argc=15, argv=0x7fff3437a0f8)
    at /space/rguenther/src/svn/pointer_plus/gcc/toplev.c:2183
#15 0x00000000006f17f3 in main (argc=15, argv=0x7fff3437a0f8)
    at /space/rguenther/src/svn/pointer_plus/gcc/main.c:35

The strange thing is that w/o -fstrict-aliasing only the trees of
other functions than _M_get_pointer are changed (they get some
change_dynamic_type expressions).
Comment 1 Richard Biener 2007-07-24 16:19:09 UTC
Created attachment 13960 [details]
testcase (slightly reduced from tr1/3_function_objects/function/8.cc)
Comment 2 Richard Biener 2007-07-24 16:28:53 UTC
./cc1plus -fpreprocessed 8.0.min.ii -quiet -dumpbase 8.cc -auxbase 8 -version -fmessage-length=0 -o /dev/null -std=c++0x -fstrict-aliasing
Comment 3 Richard Biener 2007-07-24 16:33:25 UTC
Created attachment 13962 [details]
testcase (more reduced)
Comment 4 Richard Biener 2007-07-25 12:50:59 UTC
break build2_stat if code == INIT_EXPR && !useless_type_conversion_p (arg0->common.type, arg1->common.type)

and you reach the offending tree build.
Comment 5 Richard Biener 2007-07-25 13:48:53 UTC
With -fstrict-aliasing we claim the conversion is neccessary because the pointed
to alias sets of the two pointers are different.  For -fno-strict-aliasing the
frontend later says via the langhook that the two structures are compatible.

Now, both pointer-to-member function structures get assigned alias set zero
anyway from cxx_get_alias_set, but pointers to such structures get their
own alias set.

Index: cp-objcp-common.c
===================================================================
--- cp-objcp-common.c   (revision 126911)
+++ cp-objcp-common.c   (working copy)
@@ -45,7 +45,9 @@ cxx_get_alias_set (tree t)
     return get_alias_set (TYPE_CONTEXT (t));
 
   /* Punt on PMFs until we canonicalize functions properly.  */
-  if (TYPE_PTRMEMFUNC_P (t))
+  if (TYPE_PTRMEMFUNC_P (t)
+      || (POINTER_TYPE_P (t)
+         && TYPE_PTRMEMFUNC_P (TREE_TYPE (t))))
     return 0;
 
   return c_common_get_alias_set (t);

get's this case "working".  Of course it may be time to "canonicalize
functions properly".
Comment 6 Richard Biener 2007-10-11 11:40:57 UTC
This was fixed by

2007-08-20  Richard Guenther  <rguenther@suse.de>

        PR c++/22369
        PR c++/22451
        * call.c (build_new_method_call): Convert initializer to
        the basetype.
        * init.c (build_aggr_init): Do not fiddle with types.
        (build_vec_delete_1): Use correct type for POINTER_PLUS_EXPR.
        * except.c (build_throw): Do not drop qualifiers for the
        pointer type.
        * typeck.c (get_member_function_from_ptrfunc): Do not
        fiddle with types, instead convert.
        (build_ptrmemfunc1): Convert to the target type for
        initialization.
        (gfc_trans_allocate): Convert result to target type.
        * cp-objcp-common.c (cxx_get_alias_set): Pointers to
        pointer-to-member structures shall have alias set zero as well.