]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/cp/cp-lang.c
re PR c/54559 (, ICE in gimplify_expr, at gimplify.c:7592)
[thirdparty/gcc.git] / gcc / cp / cp-lang.c
CommitLineData
19551f29 1/* Language-dependent hooks for C++.
1da2ed5f
JM
2 Copyright 2001, 2002, 2004, 2007, 2008, 2009, 2010
3 Free Software Foundation, Inc.
19551f29
AO
4 Contributed by Alexandre Oliva <aoliva@redhat.com>
5
f5adbb8d 6This file is part of GCC.
19551f29 7
f5adbb8d 8GCC is free software; you can redistribute it and/or modify
19551f29 9it under the terms of the GNU General Public License as published by
e77f031d 10the Free Software Foundation; either version 3, or (at your option)
19551f29
AO
11any later version.
12
f5adbb8d 13GCC is distributed in the hope that it will be useful,
19551f29
AO
14but WITHOUT ANY WARRANTY; without even the implied warranty of
15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16GNU General Public License for more details.
17
18You should have received a copy of the GNU General Public License
e77f031d
NC
19along with GCC; see the file COPYING3. If not see
20<http://www.gnu.org/licenses/>. */
19551f29
AO
21
22#include "config.h"
23#include "system.h"
4977bab6
ZW
24#include "coretypes.h"
25#include "tm.h"
19551f29
AO
26#include "tree.h"
27#include "cp-tree.h"
39dabefd 28#include "c-family/c-common.h"
19551f29 29#include "langhooks.h"
d23c55c2 30#include "langhooks-def.h"
11bb4b27
ZL
31#include "debug.h"
32#include "cp-objcp-common.h"
820cc88f 33#include "hashtab.h"
f0a0390e 34#include "target.h"
f617201f 35#include "parser.h"
19551f29 36
37fa72e9 37enum c_language_kind c_language = clk_cxx;
820cc88f 38static void cp_init_ts (void);
a0ad3539 39static const char * cxx_dwarf_name (tree t, int verbosity);
394d9fe7 40static enum classify_record cp_classify_record (tree type);
f9417da1 41static tree cp_eh_personality (void);
f8fb7295
DS
42static tree get_template_innermost_arguments_folded (const_tree);
43static tree get_template_argument_pack_elems_folded (const_tree);
37fa72e9 44
11bb4b27
ZL
45/* Lang hooks common to C++ and ObjC++ are declared in cp/cp-objcp-common.h;
46 consequently, there should be very few hooks below. */
47
3ac88239
NB
48#undef LANG_HOOKS_NAME
49#define LANG_HOOKS_NAME "GNU C++"
19551f29
AO
50#undef LANG_HOOKS_INIT
51#define LANG_HOOKS_INIT cxx_init
394d9fe7
AO
52#undef LANG_HOOKS_CLASSIFY_RECORD
53#define LANG_HOOKS_CLASSIFY_RECORD cp_classify_record
39ef6592
LC
54#undef LANG_HOOKS_GENERIC_TYPE_P
55#define LANG_HOOKS_GENERIC_TYPE_P class_tmpl_impl_spec_p
f9329c35
DS
56
57#undef LANG_HOOKS_GET_INNERMOST_GENERIC_PARMS
58#define LANG_HOOKS_GET_INNERMOST_GENERIC_PARMS \
59 get_primary_template_innermost_parameters
60#undef LANG_HOOKS_GET_INNERMOST_GENERIC_ARGS
61#define LANG_HOOKS_GET_INNERMOST_GENERIC_ARGS \
f8fb7295 62 get_template_innermost_arguments_folded
d40a19da
DS
63#undef LANG_HOOKS_FUNCTION_PARAMETER_PACK_P
64#define LANG_HOOKS_FUNCTION_PARAMETER_PACK_P \
65 function_parameter_pack_p
f9329c35
DS
66#undef LANG_HOOKS_GET_ARGUMENT_PACK_ELEMS
67#define LANG_HOOKS_GET_ARGUMENT_PACK_ELEMS \
f8fb7295 68 get_template_argument_pack_elems_folded
f9329c35
DS
69#undef LANG_HOOKS_GENERIC_GENERIC_PARAMETER_DECL_P
70#define LANG_HOOKS_GENERIC_GENERIC_PARAMETER_DECL_P \
71 template_template_parameter_p
d40a19da
DS
72#undef LANG_HOOKS_FUNCTION_PARM_EXPANDED_FROM_PACK_P
73#define LANG_HOOKS_FUNCTION_PARM_EXPANDED_FROM_PACK_P \
74 function_parameter_expanded_from_pack_p
75#undef LANG_HOOKS_GET_GENERIC_FUNCTION_DECL
76#define LANG_HOOKS_GET_GENERIC_FUNCTION_DECL get_function_template_decl
a0ad3539
MM
77#undef LANG_HOOKS_DWARF_NAME
78#define LANG_HOOKS_DWARF_NAME cxx_dwarf_name
820cc88f
DB
79#undef LANG_HOOKS_INIT_TS
80#define LANG_HOOKS_INIT_TS cp_init_ts
f9417da1
RG
81#undef LANG_HOOKS_EH_PERSONALITY
82#define LANG_HOOKS_EH_PERSONALITY cp_eh_personality
83#undef LANG_HOOKS_EH_RUNTIME_TYPE
84#define LANG_HOOKS_EH_RUNTIME_TYPE build_eh_type_type
f1e639b1 85
11bb4b27 86/* Each front end provides its own lang hook initializer. */
4537ec0c 87struct lang_hooks lang_hooks = LANG_HOOKS_INITIALIZER;
8ac61af7 88
11bb4b27
ZL
89/* Lang hook routines common to C++ and ObjC++ appear in cp/cp-objcp-common.c;
90 there should be very few routines below. */
8bcefb43 91
11bb4b27 92/* The following function does something real, but only in Objective-C++. */
e1a4dd13 93
11bb4b27 94tree
c3002ae9
ZL
95objcp_tsubst_copy_and_build (tree t ATTRIBUTE_UNUSED,
96 tree args ATTRIBUTE_UNUSED,
97 tsubst_flags_t complain ATTRIBUTE_UNUSED,
11bb4b27
ZL
98 tree in_decl ATTRIBUTE_UNUSED,
99 bool function_p ATTRIBUTE_UNUSED)
f75fbaf7 100{
11bb4b27 101 return NULL_TREE;
f75fbaf7
ZW
102}
103
820cc88f
DB
104static void
105cp_init_ts (void)
106{
81f653d6 107 cp_common_init_ts ();
820cc88f 108
3ed8593d 109 init_shadowed_var_for_decl ();
820cc88f
DB
110}
111
a0ad3539
MM
112static const char *
113cxx_dwarf_name (tree t, int verbosity)
114{
115 gcc_assert (DECL_P (t));
116
bde2d108 117 if (DECL_NAME (t)
5a706c32 118 && (ANON_AGGRNAME_P (DECL_NAME (t)) || LAMBDA_TYPE_P (t)))
bde2d108 119 return NULL;
a0ad3539 120 if (verbosity >= 2)
7496cd5b
SA
121 return decl_as_dwarf_string (t,
122 TFF_DECL_SPECIFIERS | TFF_UNQUALIFIED_NAME
123 | TFF_NO_OMIT_DEFAULT_TEMPLATE_ARGUMENTS);
a0ad3539 124
7496cd5b 125 return lang_decl_dwarf_name (t, verbosity, false);
a0ad3539
MM
126}
127
394d9fe7
AO
128static enum classify_record
129cp_classify_record (tree type)
130{
131 if (CLASSTYPE_DECLARED_CLASS (type))
132 return RECORD_IS_CLASS;
133
134 return RECORD_IS_STRUCT;
135}
136
f9417da1
RG
137static GTY(()) tree cp_eh_personality_decl;
138
139static tree
140cp_eh_personality (void)
141{
142 if (!cp_eh_personality_decl)
143 {
bde8a146
RH
144 const char *lang = (pragma_java_exceptions ? "gcj" : "gxx");
145 cp_eh_personality_decl = build_personality_function (lang);
f9417da1
RG
146 }
147
148 return cp_eh_personality_decl;
149}
150
f8fb7295
DS
151/* This is a subroutine of fold_cplus_constants. It returns TRUE if T
152 is a C++ specific constant that needs to be folded further before
153 being passed to the debug info emitter. */
154
155static bool
156template_arg_needs_folding (const_tree t)
157{
158 /* For now only PTRMEM_CST nodes are to be folded further. */
159 if (TREE_CODE (t) == PTRMEM_CST)
160 return true;
161 return false;
162}
163
164/* Fold the elements of the TREE_VEC C which are C++ specific nodes
165 that would need folding so that they can be processed by the debug
166 info emitter. This is a subroutine of
167 get_template_innermost_arguments_folded and
168 get_template_argument_pack_elems_folded. */
169
170static tree
171fold_cplus_constants (const_tree c)
172{
173 tree folded_elems, elems = CONST_CAST_TREE (c);
174 int vec_len, i;
175
176 if (elems == NULL_TREE || elems == error_mark_node)
177 return elems;
178
179 vec_len = TREE_VEC_LENGTH (elems);
180
181 /* First check if there is at least one element that needs
182 folding. If there is none, we just return ELEMS. Otherwise create
183 and return a new tree vector that contains the folded versions of
184 ELEMS. This is to avoid allocating memory if we don't need
185 to. */
186 for (i = 0; i < vec_len; ++i)
187 {
188 if (template_arg_needs_folding (TREE_VEC_ELT (elems, i)))
189 break;
190 }
191 if (i == vec_len)
192 return elems;
193
194 folded_elems = make_tree_vec (vec_len);
195 for (i = 0; i < vec_len; ++i)
196 {
197 tree elem = TREE_VEC_ELT (elems, i);
198 TREE_VEC_ELT (folded_elems, i) =
199 (elem && !TYPE_P (elem)) ? cplus_expand_constant (elem) : elem;
200
201 }
202 return folded_elems;
203}
204
205/* The C++ implementation of the LANG_HOOKS_GET_INNERMOST_GENERIC_ARGS
206 hook. It returns the innermost template arguments of type T, and
207 makes sure those arguments are folded enough for the debug info
208 emitter. */
209
210static tree
211get_template_innermost_arguments_folded (const_tree t)
212{
213 return fold_cplus_constants (get_template_innermost_arguments (t));
214}
215
216static tree
217get_template_argument_pack_elems_folded (const_tree t)
218{
219 return fold_cplus_constants (get_template_argument_pack_elems (t));
220}
221
6561cdf6 222#include "gt-cp-cp-lang.h"
11bb4b27 223#include "gtype-cp.h"