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 #include "langhooks.h"
43 #include "langhooks-def.h"
45 static int c_tree_printer
PARAMS ((output_buffer
*));
46 static int c_missing_noreturn_ok_p
PARAMS ((tree
));
47 static const char *c_init
PARAMS ((const char *));
48 static void c_init_options
PARAMS ((void));
49 static void c_post_options
PARAMS ((void));
50 static int c_disregard_inline_limits
PARAMS ((tree
));
51 static int c_cannot_inline_tree_fn
PARAMS ((tree
*));
53 #undef LANG_HOOKS_NAME
54 #define LANG_HOOKS_NAME "GNU C"
55 #undef LANG_HOOKS_INIT
56 #define LANG_HOOKS_INIT c_init
57 #undef LANG_HOOKS_INIT_OPTIONS
58 #define LANG_HOOKS_INIT_OPTIONS c_init_options
59 #undef LANG_HOOKS_DECODE_OPTION
60 #define LANG_HOOKS_DECODE_OPTION c_decode_option
61 #undef LANG_HOOKS_POST_OPTIONS
62 #define LANG_HOOKS_POST_OPTIONS c_post_options
63 #undef LANG_HOOKS_GET_ALIAS_SET
64 #define LANG_HOOKS_GET_ALIAS_SET c_common_get_alias_set
65 #undef LANG_HOOKS_PRINT_IDENTIFIER
66 #define LANG_HOOKS_PRINT_IDENTIFIER c_print_identifier
67 #undef LANG_HOOKS_SET_YYDEBUG
68 #define LANG_HOOKS_SET_YYDEBUG c_set_yydebug
70 #undef LANG_HOOKS_TREE_INLINING_CANNOT_INLINE_TREE_FN
71 #define LANG_HOOKS_TREE_INLINING_CANNOT_INLINE_TREE_FN \
72 c_cannot_inline_tree_fn
73 #undef LANG_HOOKS_TREE_INLINING_DISREGARD_INLINE_LIMITS
74 #define LANG_HOOKS_TREE_INLINING_DISREGARD_INLINE_LIMITS \
75 c_disregard_inline_limits
76 #undef LANG_HOOKS_TREE_INLINING_ANON_AGGR_TYPE_P
77 #define LANG_HOOKS_TREE_INLINING_ANON_AGGR_TYPE_P \
80 /* Each front end provides its own. */
81 const struct lang_hooks lang_hooks
= LANG_HOOKS_INITIALIZER
;
83 static varray_type deferred_fns
;
85 /* Post-switch processing. */
89 cpp_post_options (parse_in
);
91 /* Use tree inlining if possible. Function instrumentation is only
92 done in the RTL level, so we disable tree inlining. */
93 if (! flag_instrument_function_entry_exit
)
97 flag_inline_trees
= 1;
100 if (flag_inline_functions
)
102 flag_inline_trees
= 2;
103 flag_inline_functions
= 0;
111 parse_in
= cpp_create_reader (CLK_GNUC89
);
113 /* Mark as "unspecified". */
114 flag_bounds_check
= -1;
119 const char *filename
;
121 c_init_decl_processing ();
123 filename
= c_common_lang_init (filename
);
127 /* If still unspecified, make it match -std=c99
128 (allowing for -pedantic-errors). */
129 if (mesg_implicit_function_declaration
< 0)
132 mesg_implicit_function_declaration
= flag_pedantic_errors
? 2 : 1;
134 mesg_implicit_function_declaration
= 0;
137 save_lang_status
= &push_c_function_context
;
138 restore_lang_status
= &pop_c_function_context
;
139 mark_lang_status
= &mark_c_function_context
;
140 lang_expand_expr
= &c_expand_expr
;
141 lang_safe_from_p
= &c_safe_from_p
;
142 diagnostic_format_decoder (global_dc
) = &c_tree_printer
;
143 lang_expand_decl_stmt
= &c_expand_decl_stmt
;
144 lang_missing_noreturn_ok_p
= &c_missing_noreturn_ok_p
;
146 VARRAY_TREE_INIT (deferred_fns
, 32, "deferred_fns");
147 ggc_add_tree_varray_root (&deferred_fns
, 1);
152 /* Used by c-lex.c, but only for objc. */
155 lookup_interface (arg
)
156 tree arg ATTRIBUTE_UNUSED
;
163 tree arg ATTRIBUTE_UNUSED
;
169 maybe_objc_check_decl (decl
)
170 tree decl ATTRIBUTE_UNUSED
;
175 maybe_objc_comptypes (lhs
, rhs
, reflexive
)
176 tree lhs ATTRIBUTE_UNUSED
;
177 tree rhs ATTRIBUTE_UNUSED
;
178 int reflexive ATTRIBUTE_UNUSED
;
184 maybe_building_objc_message_expr ()
190 recognize_objc_keyword ()
195 /* Used by c-typeck.c (build_external_ref), but only for objc. */
198 lookup_objc_ivar (id
)
199 tree id ATTRIBUTE_UNUSED
;
204 #if !defined(ASM_OUTPUT_CONSTRUCTOR) || !defined(ASM_OUTPUT_DESTRUCTOR)
205 extern tree static_ctors
;
206 extern tree static_dtors
;
208 static tree start_cdtor
PARAMS ((int));
209 static void finish_cdtor
PARAMS ((tree
));
212 start_cdtor (method_type
)
215 tree fnname
= get_file_function_name (method_type
);
216 tree void_list_node_1
= build_tree_list (NULL_TREE
, void_type_node
);
219 start_function (void_list_node_1
,
220 build_nt (CALL_EXPR
, fnname
,
221 tree_cons (NULL_TREE
, NULL_TREE
, void_list_node_1
),
226 current_function_cannot_inline
227 = "static constructors and destructors cannot be inlined";
229 body
= c_begin_compound_stmt ();
233 add_scope_stmt (/*begin_p=*/1, /*partial_p=*/0);
245 scope
= add_scope_stmt (/*begin_p=*/0, /*partial_p=*/0);
246 block
= poplevel (0, 0, 0);
247 SCOPE_STMT_BLOCK (TREE_PURPOSE (scope
)) = block
;
248 SCOPE_STMT_BLOCK (TREE_VALUE (scope
)) = block
;
250 RECHAIN_STMTS (body
, COMPOUND_BODY (body
));
256 /* Register a function tree, so that its optimization and conversion
257 to RTL is only done at the end of the compilation. */
263 VARRAY_PUSH_TREE (deferred_fns
, fn
);
268 /* Called at end of parsing, but before end-of-file processing. */
276 for (i
= 0; i
< VARRAY_ACTIVE_SIZE (deferred_fns
); i
++)
278 tree decl
= VARRAY_TREE (deferred_fns
, i
);
280 if (! TREE_ASM_WRITTEN (decl
) && TREE_PUBLIC (decl
))
282 c_expand_deferred_function (decl
);
283 VARRAY_TREE (deferred_fns
, i
) = NULL
;
290 for (i
= 0; i
< VARRAY_ACTIVE_SIZE (deferred_fns
); i
++)
292 tree decl
= VARRAY_TREE (deferred_fns
, i
);
295 && ! TREE_ASM_WRITTEN (decl
)
296 && (flag_keep_inline_functions
297 || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl
))))
299 c_expand_deferred_function (decl
);
300 VARRAY_TREE (deferred_fns
, i
) = NULL
;
304 } while (reconsider
);
306 VARRAY_FREE (deferred_fns
);
308 #ifndef ASM_OUTPUT_CONSTRUCTOR
311 tree body
= start_cdtor ('I');
313 for (; static_ctors
; static_ctors
= TREE_CHAIN (static_ctors
))
314 c_expand_expr_stmt (build_function_call (TREE_VALUE (static_ctors
),
320 #ifndef ASM_OUTPUT_DESTRUCTOR
323 tree body
= start_cdtor ('D');
325 for (; static_dtors
; static_dtors
= TREE_CHAIN (static_dtors
))
326 c_expand_expr_stmt (build_function_call (TREE_VALUE (static_dtors
),
334 (*back_end_hook
) (getdecls ());
338 FILE *stream
= dump_begin (TDI_all
, &flags
);
342 dump_node (getdecls (), flags
& ~TDF_SLIM
, stream
);
343 dump_end (TDI_all
, stream
);
348 /* Called during diagnostic message formatting process to print a
349 source-level entity onto BUFFER. The meaning of the format specifiers
352 %F: a function declaration,
355 These format specifiers form a subset of the format specifiers set used
356 by the C++ front-end.
357 Please notice when called, the `%' part was already skipped by the
358 diagnostic machinery. */
360 c_tree_printer (buffer
)
361 output_buffer
*buffer
;
363 tree t
= va_arg (output_buffer_format_args (buffer
), tree
);
365 switch (*output_buffer_text_cursor (buffer
))
371 const char *n
= DECL_NAME (t
)
372 ? (*decl_printable_name
) (t
, 2)
374 output_add_string (buffer
, n
);
384 c_missing_noreturn_ok_p (decl
)
387 /* A missing noreturn is not ok for freestanding implementations and
388 ok for the `main' function in hosted implementations. */
389 return flag_hosted
&& MAIN_NAME_P (DECL_ASSEMBLER_NAME (decl
));
392 /* We want to inline `extern inline' functions even if this would
393 violate inlining limits. Some glibc and linux constructs depend on
394 such functions always being inlined when optimizing. */
397 c_disregard_inline_limits (fn
)
400 return DECL_DECLARED_INLINE_P (fn
) && DECL_EXTERNAL (fn
);
403 static tree inline_forbidden_p
PARAMS ((tree
*, int *, void *));
406 inline_forbidden_p (nodep
, walk_subtrees
, fn
)
408 int *walk_subtrees ATTRIBUTE_UNUSED
;
414 switch (TREE_CODE (node
))
417 t
= get_callee_fndecl (node
);
422 /* We cannot inline functions that call setjmp. */
423 if (setjmp_call_p (t
))
426 switch (DECL_FUNCTION_CODE (t
))
428 /* We cannot inline functions that take a variable number of
430 case BUILT_IN_VARARGS_START
:
431 case BUILT_IN_STDARG_START
:
433 /* Functions that need information about the address of the
434 caller can't (shouldn't?) be inlined. */
435 case BUILT_IN_RETURN_ADDRESS
:
446 /* We cannot inline functions that contain other functions. */
447 if (TREE_CODE (TREE_OPERAND (node
, 0)) == FUNCTION_DECL
448 && DECL_INITIAL (TREE_OPERAND (node
, 0)))
454 t
= TREE_OPERAND (node
, 0);
456 /* We will not inline a function which uses computed goto. The
457 addresses of its local labels, which may be tucked into
458 global storage, are of course not constant across
459 instantiations, which causes unexpected behaviour. */
460 if (TREE_CODE (t
) != LABEL_DECL
)
463 /* We cannot inline a nested function that jumps to a nonlocal
465 if (TREE_CODE (t
) == LABEL_DECL
466 && DECL_CONTEXT (t
) && DECL_CONTEXT (t
) != fn
)
479 c_cannot_inline_tree_fn (fnp
)
485 if (! function_attribute_inlinable_p (fn
))
487 DECL_UNINLINABLE (fn
) = 1;
491 /* If a function has pending sizes, we must not defer its
492 compilation, and we can't inline it as a tree. */
493 if (fn
== current_function_decl
)
495 t
= get_pending_sizes ();
496 put_pending_sizes (t
);
500 DECL_UNINLINABLE (fn
) = 1;
505 if (DECL_CONTEXT (fn
))
507 /* If a nested function has pending sizes, we may have already
509 if (DECL_LANG_SPECIFIC (fn
)->pending_sizes
)
511 DECL_UNINLINABLE (fn
) = 1;
517 /* We rely on the fact that this function is called upfront,
518 just before we start expanding a function. If FN is active
519 (i.e., it's the current_function_decl or a parent thereof),
520 we have to walk FN's saved tree. Otherwise, we can safely
521 assume we have done it before and, if we didn't mark it as
522 uninlinable (in which case we wouldn't have been called), it
523 is inlinable. Unfortunately, this strategy doesn't work for
524 nested functions, because they're only expanded as part of
525 their enclosing functions, so the inlinability test comes in
527 t
= current_function_decl
;
530 t
= DECL_CONTEXT (t
);
535 if (walk_tree (&DECL_SAVED_TREE (fn
), inline_forbidden_p
, fn
, NULL
))
537 DECL_UNINLINABLE (fn
) = 1;