Bug 50800 - Internal compiler error in finish_member_declarations, possibly related to may_alias attribute
Summary: Internal compiler error in finish_member_declarations, possibly related to ma...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 6.0
: P3 normal
Target Milestone: ---
Assignee: Jason Merrill
URL:
Keywords:
: 57472 (view as bug list)
Depends on: 18174 37553
Blocks:
  Show dependency treegraph
 
Reported: 2011-10-19 18:14 UTC by Mathias Gaunard
Modified: 2016-10-12 17:07 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail: 4.8.3, 4.9.1, 5.0
Last reconfirmed: 2011-10-19 00:00:00


Attachments
Reduced testcase (28.45 KB, text/x-c++src)
2011-10-20 20:07 UTC, Mathias Gaunard
Details
smaller test case (4.95 KB, text/x-c++src)
2011-12-03 07:01 UTC, John Regehr
Details
smaller again (1.78 KB, text/x-c)
2011-12-05 22:07 UTC, John Regehr
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Mathias Gaunard 2011-10-19 18:14:18 UTC
The attached preprocessed testcase results in an internal compiler error:

/home/gaunard/dev/boost/trunk/boost/type_traits/detail/cv_traits_impl.hpp:36:1: internal compiler error: in finish_member_declaration, at cp/semantics.c:2559

This seems to be tied to the use of the may_alias attribute.
Comment 1 Mathias Gaunard 2011-10-19 18:20:06 UTC
Testcase is here (couldn't attach it due to bugzilla size restrictions):
http://mathias.gaunard.com/data/ice_finish_member_declaration.cpp
Comment 2 Paolo Carlini 2011-10-19 23:56:54 UTC
That you couldn't attach it should tell you something... Please do your best to reduce its size: http://gcc.gnu.org/wiki/A_guide_to_testcase_reduction
Comment 3 Mathias Gaunard 2011-10-20 20:07:24 UTC
Created attachment 25562 [details]
Reduced testcase

Original testcase reduced using automated delta tools
Comment 4 John Regehr 2011-12-03 07:01:50 UTC
Created attachment 25977 [details]
smaller test case
Comment 5 John Regehr 2011-12-05 22:07:16 UTC
Created attachment 25997 [details]
smaller again
Comment 6 Mathias Gaunard 2012-08-14 10:53:07 UTC
I've had this happen with 4.7.1 without any may_alias involved.

Why is this bug still marked 'waiting'? Are more testcases necessary?
Comment 7 Paolo Carlini 2012-08-14 10:58:40 UTC
Became "Waiting" with Comment #2 and then nobody updated the status, it's as simple as that.
Comment 8 Marc Glisse 2012-08-14 11:03:31 UTC
Although if you have a testcase without may_alias, you should attach it.
Comment 9 Matthias Kretz (Vir) 2014-09-26 12:47:54 UTC
I assume I hit the same issue. I got the testcase down to a few lines:

#include <type_traits>
template <typename L> typename std::remove_reference<L>::type foo(L &&lhs, int rhs);
template <typename T> T d(T i)
{
  enum { Size = sizeof(int) };
  return foo(i, Size);
}
template <typename T> struct A {
  typedef int TA __attribute__((__may_alias__));
};
int main()
{
  typedef A<int> V;
  typedef typename std::remove_reference<typename V::TA &>::type T;
  return d(1);
}

It only needs the -std=c++11 flag. Tested to fail: 4.8.0/1/2/3 and 4.9.0/1/2 (4.9.2 is 20140924).

Backtrace from 4.9.2 snapshot:
/opt/gcc-4.9-snapshot/include/c++/4.9.2/type_traits:1488:5: internal compiler error: in finish_member_declaration, at cp/semantics.c:2827
     { typedef _Tp   type; };
     ^
0x6395c0 finish_member_declaration(tree_node*)
        ../.././gcc/cp/semantics.c:2827
0x5b975d instantiate_class_template_1
        ../.././gcc/cp/pt.c:9244
0x5b975d instantiate_class_template(tree_node*)
        ../.././gcc/cp/pt.c:9445
0x61039d complete_type(tree_node*)
        ../.././gcc/cp/typeck.c:134
0x5a8531 tsubst(tree_node*, tree_node*, int, tree_node*)
        ../.././gcc/cp/pt.c:12163
0x5acac7 tsubst_function_type
        ../.././gcc/cp/pt.c:11344
0x5a7e7f tsubst(tree_node*, tree_node*, int, tree_node*)
        ../.././gcc/cp/pt.c:12081
0x5ae8fe tsubst_decl
        ../.././gcc/cp/pt.c:10596
0x5a822f tsubst(tree_node*, tree_node*, int, tree_node*)
        ../.././gcc/cp/pt.c:11543
0x5b09fb instantiate_template_1
        ../.././gcc/cp/pt.c:15580
0x5b09fb instantiate_template(tree_node*, tree_node*, int)
        ../.././gcc/cp/pt.c:15630
0x5b6c2e fn_type_unification(tree_node*, tree_node*, tree_node*, tree_node* const*, unsigned int, tree_node*, unification_kind_t, int, bool, bool)
        ../.././gcc/cp/pt.c:15979
0x574031 add_template_candidate_real
        ../.././gcc/cp/call.c:2998
0x571984 add_template_candidate
        ../.././gcc/cp/call.c:3095
0x571984 add_candidates
        ../.././gcc/cp/call.c:5169
0x5755d9 perform_overload_resolution
        ../.././gcc/cp/call.c:3904
0x5770ea build_new_function_call(tree_node*, vec<tree_node*, va_gc, vl_embed>**, bool, int)
        ../.././gcc/cp/call.c:3981
0x639891 finish_call_expr(tree_node*, vec<tree_node*, va_gc, vl_embed>**, bool, bool, int)
        ../.././gcc/cp/semantics.c:2358
0x5a1b34 tsubst_copy_and_build(tree_node*, tree_node*, int, tree_node*, bool, bool)
        ../.././gcc/cp/pt.c:14861
0x5a519c tsubst_expr
        ../.././gcc/cp/pt.c:14048
Comment 10 Markus Trippelsdorf 2014-09-26 13:04:51 UTC
markus@x4 tmp % cat finish.ii
template <typename>
struct B;
template <typename _Tp>
struct B<_Tp &> {
  typedef _Tp type;
};
template <typename L>
typename B<L>::type foo(L &&);
int a;
struct A {
  typedef int TA __attribute__((__may_alias__));
};
void d() { foo(a); }
int main() { B<A::TA &> b; }

markus@x4 tmp % g++ -std=c++11 finish.ii
finish.ii: In instantiation of ‘struct B<int&>’:
finish.ii:15:25:   required from here
finish.ii:4:17: internal compiler error: in finish_member_declaration, at cp/semantics.c:2844
Comment 11 Jakub Jelinek 2014-12-19 13:28:34 UTC
GCC 4.8.4 has been released.
Comment 12 Jason Merrill 2015-04-16 17:55:02 UTC
This is related to the fix for bug 18174, which made int& a different type from A::TA&.  But this difference is not reflected in the mangling, so B<int&> and B<A::TA&> have the same mangling, which we can't allow.

The compiler tries to handle this by stripping attributes from template arguments, so that B<A::TA&> is treated as B<int&>.  This was failing in this case because the middle end was giving the two types different TYPE_CANONICAL.  I guess we need to work harder at stripping the attributes.
Comment 13 Jason Merrill 2015-04-23 15:55:52 UTC
Author: jason
Date: Thu Apr 23 15:55:21 2015
New Revision: 222377

URL: https://gcc.gnu.org/viewcvs?rev=222377&root=gcc&view=rev
Log:
	PR c++/50800
	* tree.c (strip_typedefs): Add remove_attributes parm.
	(strip_typedefs_expr): Likewise.
	(apply_identity_attributes): New subroutine of strip_typedefs.
	* pt.c (canonicalize_type_argument): Let strip_typedefs handle attrs.
	(convert_nontype_argument, unify): Likewise.
	* cp-tree.h: Adjust.

Added:
    trunk/gcc/testsuite/g++.dg/ext/attrib50.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/cp-tree.h
    trunk/gcc/cp/pt.c
    trunk/gcc/cp/tree.c
    trunk/gcc/testsuite/g++.dg/abi/mangle40.C
    trunk/gcc/testsuite/g++.dg/ext/alias-canon2.C
    trunk/gcc/testsuite/g++.dg/ext/alias-mangle.C
Comment 14 Jason Merrill 2015-04-24 19:12:16 UTC
Author: jason
Date: Fri Apr 24 19:11:45 2015
New Revision: 222419

URL: https://gcc.gnu.org/viewcvs?rev=222419&root=gcc&view=rev
Log:
	PR c++/50800
gcc/
	* tree.c (build_reference_type_for_mode): Don't pass can_alias_all
	down when building TYPE_CANONICAL.
	(build_pointer_type_for_mode): Likewise.
gcc/cp/
	* typeck.c (structural_comptypes): Don't check TYPE_REF_CAN_ALIAS_ALL.

Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/typeck.c
    trunk/gcc/tree.c
Comment 15 Jason Merrill 2015-04-24 20:54:00 UTC
Author: jason
Date: Fri Apr 24 20:53:28 2015
New Revision: 222426

URL: https://gcc.gnu.org/viewcvs?rev=222426&root=gcc&view=rev
Log:
	PR c++/50800
	* g++.dg/ext/alias-canon2.C: Remove clashing fn definitions.

Modified:
    trunk/gcc/testsuite/g++.dg/ext/alias-canon2.C
Comment 16 Jason Merrill 2015-04-28 14:44:25 UTC
Author: jason
Date: Tue Apr 28 14:43:54 2015
New Revision: 222530

URL: https://gcc.gnu.org/viewcvs?rev=222530&root=gcc&view=rev
Log:
	PR c++/50800
	* tree.c (strip_typedefs): Add remove_attributes parm.
	(strip_typedefs_expr): Likewise.
	(apply_identity_attributes): New subroutine of strip_typedefs.
	* pt.c (canonicalize_type_argument): Let strip_typedefs handle attrs.
	(convert_nontype_argument, unify): Likewise.
	* cp-tree.h: Adjust.

Added:
    trunk/gcc/testsuite/g++.dg/ext/attrib50.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/cp-tree.h
    trunk/gcc/cp/pt.c
    trunk/gcc/cp/tree.c
    trunk/gcc/testsuite/g++.dg/abi/mangle40.C
    trunk/gcc/testsuite/g++.dg/ext/alias-mangle.C
Comment 17 Jason Merrill 2015-04-29 20:51:36 UTC
Author: jason
Date: Wed Apr 29 20:51:05 2015
New Revision: 222591

URL: https://gcc.gnu.org/viewcvs?rev=222591&root=gcc&view=rev
Log:
	PR c++/50800
	* tree.c (apply_identity_attributes): Fix handling of classes.

Added:
    trunk/gcc/testsuite/g++.dg/cpp0x/alignas3.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/tree.c
Comment 18 Paolo Carlini 2015-06-04 09:43:57 UTC
*** Bug 57472 has been marked as a duplicate of this bug. ***
Comment 19 edanor1@wp.pl 2015-07-06 08:10:22 UTC
Hi everyone,

I just got a similar output on GCC 5.1.0. I think it might be related, however this appears to be for different syntax.

Flags are: "-mavx -std=c++11 -Wfatal-errors -O0"

Please let me know if you still need a test case.

.../BOOST/boost_1_57_0/boost/type_traits/remove_reference.hpp:42:1: note: in expansion of macro ‘BOOST_TT_AUX_TYPE_TRAIT_PARTIAL_SPEC1_1’
 BOOST_TT_AUX_TYPE_TRAIT_PARTIAL_SPEC1_1(typename T,remove_reference,T&,T)
 ^
0x6ef1fc finish_member_declaration(tree_node*)
        ../../gcc/cp/semantics.c:2872
0x66af2d instantiate_class_template_1
        ../../gcc/cp/pt.c:9487
0x66af2d instantiate_class_template(tree_node*)
        ../../gcc/cp/pt.c:9688
0x6c5bed complete_type(tree_node*)
        ../../gcc/cp/typeck.c:146
0x653e5f tsubst(tree_node*, tree_node*, int, tree_node*)
        ../../gcc/cp/pt.c:12441
0x65e759 tsubst_template_args
        ../../gcc/cp/pt.c:10257
0x65ec84 tsubst_aggr_type
        ../../gcc/cp/pt.c:10454
0x653891 tsubst(tree_node*, tree_node*, int, tree_node*)
        ../../gcc/cp/pt.c:11909
0x66b909 instantiate_class_template_1
        ../../gcc/cp/pt.c:9275
0x66b909 instantiate_class_template(tree_node*)
        ../../gcc/cp/pt.c:9688
0x6c5bed complete_type(tree_node*)
        ../../gcc/cp/typeck.c:146
0x653e5f tsubst(tree_node*, tree_node*, int, tree_node*)
        ../../gcc/cp/pt.c:12441
0x6519e1 tsubst_copy_and_build(tree_node*, tree_node*, int, tree_node*, bool, bool)
        ../../gcc/cp/pt.c:14654
0x6514e5 tsubst_copy_and_build(tree_node*, tree_node*, int, tree_node*, bool, bool)
        ../../gcc/cp/pt.c:15066
0x653320 tsubst(tree_node*, tree_node*, int, tree_node*)
        ../../gcc/cp/pt.c:12530
0x660c02 tsubst_decl
        ../../gcc/cp/pt.c:11339
0x653c54 tsubst(tree_node*, tree_node*, int, tree_node*)
        ../../gcc/cp/pt.c:11830
0x66aed2 instantiate_class_template_1
        ../../gcc/cp/pt.c:9424
0x66aed2 instantiate_class_template(tree_node*)
        ../../gcc/cp/pt.c:9688
0x6c5bed complete_type(tree_node*)
        ../../gcc/cp/typeck.c:146
Comment 20 Jason Merrill 2016-10-12 17:07:20 UTC
Fixed in GCC 6.