1 /* Language-specific hook definitions for C front end.
2 Copyright (C) 1991, 1995, 1997, 1998,
3 1999, 2000, 2001 Free Software Foundation, Inc.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
26 #include "tree-inline.h"
30 #include "diagnostic.h"
39 #include "insn-config.h"
40 #include "integrate.h"
42 static int c_tree_printer PARAMS ((output_buffer *));
43 static int c_missing_noreturn_ok_p PARAMS ((tree));
44 static void c_init PARAMS ((void));
45 static void c_init_options PARAMS ((void));
46 static void c_post_options PARAMS ((void));
47 static int c_disregard_inline_limits PARAMS ((tree));
48 static int c_cannot_inline_tree_fn PARAMS ((tree *));
50 /* Each front end provides its own. */
51 struct lang_hooks lang_hooks = {c_init,
57 /* Post-switch processing. */
61 cpp_post_options (parse_in);
63 /* Use tree inlining if possible. Function instrumentation is only
64 done in the RTL level, so we disable tree inlining. */
65 if (! flag_instrument_function_entry_exit)
69 flag_inline_trees = 1;
72 if (flag_inline_functions)
74 flag_inline_trees = 2;
75 flag_inline_functions = 0;
83 /* Make identifier nodes long enough for the language-specific slots. */
84 set_identifier_size (sizeof (struct lang_identifier));
86 parse_in = cpp_create_reader (ident_hash, CLK_GNUC89);
88 /* Mark as "unspecified". */
89 flag_bounds_check = -1;
95 c_common_lang_init ();
97 /* If still unspecified, make it match -std=c99
98 (allowing for -pedantic-errors). */
99 if (mesg_implicit_function_declaration < 0)
102 mesg_implicit_function_declaration = flag_pedantic_errors ? 2 : 1;
104 mesg_implicit_function_declaration = 0;
107 save_lang_status = &push_c_function_context;
108 restore_lang_status = &pop_c_function_context;
109 mark_lang_status = &mark_c_function_context;
110 lang_expand_expr = &c_expand_expr;
111 lang_safe_from_p = &c_safe_from_p;
112 diagnostic_format_decoder (global_dc) = &c_tree_printer;
113 lang_expand_decl_stmt = &c_expand_decl_stmt;
114 lang_missing_noreturn_ok_p = &c_missing_noreturn_ok_p;
115 lang_disregard_inline_limits = &c_disregard_inline_limits;
116 lang_cannot_inline_tree_fn = &c_cannot_inline_tree_fn;
128 print_lang_statistics ()
132 /* used by print-tree.c */
135 lang_print_xnode (file, node, indent)
136 FILE *file ATTRIBUTE_UNUSED;
137 tree node ATTRIBUTE_UNUSED;
138 int indent ATTRIBUTE_UNUSED;
142 /* Used by c-lex.c, but only for objc. */
145 lookup_interface (arg)
146 tree arg ATTRIBUTE_UNUSED;
153 tree arg ATTRIBUTE_UNUSED;
159 maybe_objc_check_decl (decl)
160 tree decl ATTRIBUTE_UNUSED;
165 maybe_objc_comptypes (lhs, rhs, reflexive)
166 tree lhs ATTRIBUTE_UNUSED;
167 tree rhs ATTRIBUTE_UNUSED;
168 int reflexive ATTRIBUTE_UNUSED;
174 maybe_building_objc_message_expr ()
180 recognize_objc_keyword ()
185 /* Used by c-typeck.c (build_external_ref), but only for objc. */
188 lookup_objc_ivar (id)
189 tree id ATTRIBUTE_UNUSED;
194 #if !defined(ASM_OUTPUT_CONSTRUCTOR) || !defined(ASM_OUTPUT_DESTRUCTOR)
195 extern tree static_ctors;
196 extern tree static_dtors;
198 static tree start_cdtor PARAMS ((int));
199 static void finish_cdtor PARAMS ((tree));
202 start_cdtor (method_type)
205 tree fnname = get_file_function_name (method_type);
206 tree void_list_node_1 = build_tree_list (NULL_TREE, void_type_node);
209 start_function (void_list_node_1,
210 build_nt (CALL_EXPR, fnname,
211 tree_cons (NULL_TREE, NULL_TREE, void_list_node_1),
216 current_function_cannot_inline
217 = "static constructors and destructors cannot be inlined";
219 body = c_begin_compound_stmt ();
223 add_scope_stmt (/*begin_p=*/1, /*partial_p=*/0);
235 scope = add_scope_stmt (/*begin_p=*/0, /*partial_p=*/0);
236 block = poplevel (0, 0, 0);
237 SCOPE_STMT_BLOCK (TREE_PURPOSE (scope)) = block;
238 SCOPE_STMT_BLOCK (TREE_VALUE (scope)) = block;
240 RECHAIN_STMTS (body, COMPOUND_BODY (body));
246 /* Called at end of parsing, but before end-of-file processing. */
251 #ifndef ASM_OUTPUT_CONSTRUCTOR
254 tree body = start_cdtor ('I');
256 for (; static_ctors; static_ctors = TREE_CHAIN (static_ctors))
257 c_expand_expr_stmt (build_function_call (TREE_VALUE (static_ctors),
263 #ifndef ASM_OUTPUT_DESTRUCTOR
266 tree body = start_cdtor ('D');
268 for (; static_dtors; static_dtors = TREE_CHAIN (static_dtors))
269 c_expand_expr_stmt (build_function_call (TREE_VALUE (static_dtors),
277 (*back_end_hook) (getdecls ());
281 FILE *stream = dump_begin (TDI_all, &flags);
285 dump_node (getdecls (), flags & ~TDF_SLIM, stream);
286 dump_end (TDI_all, stream);
291 /* Called during diagnostic message formatting process to print a
292 source-level entity onto BUFFER. The meaning of the format specifiers
295 %F: a function declaration,
298 These format specifiers form a subset of the format specifiers set used
299 by the C++ front-end.
300 Please notice when called, the `%' part was already skipped by the
301 diagnostic machinery. */
303 c_tree_printer (buffer)
304 output_buffer *buffer;
306 tree t = va_arg (output_buffer_format_args (buffer), tree);
308 switch (*output_buffer_text_cursor (buffer))
314 const char *n = DECL_NAME (t)
315 ? (*decl_printable_name) (t, 2)
317 output_add_string (buffer, n);
327 c_missing_noreturn_ok_p (decl)
330 /* A missing noreturn is not ok for freestanding implementations and
331 ok for the `main' function in hosted implementations. */
332 return flag_hosted && MAIN_NAME_P (DECL_ASSEMBLER_NAME (decl));
335 /* We want to inline `extern inline' functions even if this would
336 violate inlining limits. Some glibc and linux constructs depend on
337 such functions always being inlined when optimizing. */
340 c_disregard_inline_limits (fn)
343 return DECL_INLINE (fn) && DECL_EXTERNAL (fn);
346 static tree inline_forbidden_p PARAMS ((tree *, int *, void *));
349 inline_forbidden_p (nodep, walk_subtrees, fn)
351 int *walk_subtrees ATTRIBUTE_UNUSED;
357 switch (TREE_CODE (node))
360 t = get_callee_fndecl (node);
365 /* We cannot inline functions that call setjmp. */
366 if (setjmp_call_p (t))
369 switch (DECL_FUNCTION_CODE (t))
371 /* We cannot inline functions that take a variable number of
373 case BUILT_IN_VARARGS_START:
374 case BUILT_IN_STDARG_START:
376 /* Functions that need information about the address of the
377 caller can't (shouldn't?) be inlined. */
378 case BUILT_IN_RETURN_ADDRESS:
389 /* We cannot inline functions that contain other functions. */
390 if (TREE_CODE (TREE_OPERAND (node, 0)) == FUNCTION_DECL
391 && DECL_INITIAL (TREE_OPERAND (node, 0)))
397 t = TREE_OPERAND (node, 0);
399 /* We will not inline a function which uses computed goto. The
400 addresses of its local labels, which may be tucked into
401 global storage, are of course not constant across
402 instantiations, which causes unexpected behaviour. */
403 if (TREE_CODE (t) != LABEL_DECL)
406 /* We cannot inline a nested function that jumps to a nonlocal
408 if (TREE_CODE (t) == LABEL_DECL
409 && DECL_CONTEXT (t) && DECL_CONTEXT (t) != fn)
422 c_cannot_inline_tree_fn (fnp)
428 if (! function_attribute_inlinable_p (fn))
430 DECL_UNINLINABLE (fn) = 1;
434 /* If a function has pending sizes, we must not defer its
435 compilation, and we can't inline it as a tree. */
436 if (fn == current_function_decl)
438 t = get_pending_sizes ();
439 put_pending_sizes (t);
443 DECL_UNINLINABLE (fn) = 1;
448 if (DECL_CONTEXT (fn))
450 /* If a nested function has pending sizes, we may have already
452 if (DECL_LANG_SPECIFIC (fn)->pending_sizes)
454 DECL_UNINLINABLE (fn) = 1;
460 /* We rely on the fact that this function is called upfront,
461 just before we start expanding a function. If FN is active
462 (i.e., it's the current_function_decl or a parent thereof),
463 we have to walk FN's saved tree. Otherwise, we can safely
464 assume we have done it before and, if we didn't mark it as
465 uninlinable (in which case we wouldn't have been called), it
466 is inlinable. Unfortunately, this strategy doesn't work for
467 nested functions, because they're only expanded as part of
468 their enclosing functions, so the inlinability test comes in
470 t = current_function_decl;
473 t = DECL_CONTEXT (t);
478 if (walk_tree (&DECL_SAVED_TREE (fn), inline_forbidden_p, fn, NULL))
480 DECL_UNINLINABLE (fn) = 1;