1 /* Some code common to C and ObjC front ends.
2 Copyright (C) 2001 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 2, or (at your option) any later
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING. If not, write to the Free
18 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
25 #include "insn-config.h"
26 #include "integrate.h"
32 #include "diagnostic.h"
33 #include "tree-inline.h"
36 #include "langhooks.h"
39 static bool c_tree_printer
PARAMS ((output_buffer
*, text_info
*));
40 static tree inline_forbidden_p
PARAMS ((tree
*, int *, void *));
41 static void expand_deferred_fns
PARAMS ((void));
42 static tree start_cdtor
PARAMS ((int));
43 static void finish_cdtor
PARAMS ((tree
));
45 static GTY(()) varray_type deferred_fns
;
48 c_missing_noreturn_ok_p (decl
)
51 /* A missing noreturn is not ok for freestanding implementations and
52 ok for the `main' function in hosted implementations. */
53 return flag_hosted
&& MAIN_NAME_P (DECL_ASSEMBLER_NAME (decl
));
56 /* We want to inline `extern inline' functions even if this would
57 violate inlining limits. Some glibc and linux constructs depend on
58 such functions always being inlined when optimizing. */
61 c_disregard_inline_limits (fn
)
64 if (lookup_attribute ("always_inline", DECL_ATTRIBUTES (fn
)) != NULL
)
67 return DECL_DECLARED_INLINE_P (fn
) && DECL_EXTERNAL (fn
);
71 inline_forbidden_p (nodep
, walk_subtrees
, fn
)
73 int *walk_subtrees ATTRIBUTE_UNUSED
;
79 switch (TREE_CODE (node
))
82 t
= get_callee_fndecl (node
);
87 /* We cannot inline functions that call setjmp. */
88 if (setjmp_call_p (t
))
91 switch (DECL_FUNCTION_CODE (t
))
93 /* We cannot inline functions that take a variable number of
95 case BUILT_IN_VA_START
:
96 case BUILT_IN_STDARG_START
:
98 /* Functions that need information about the address of the
99 caller can't (shouldn't?) be inlined. */
100 case BUILT_IN_RETURN_ADDRESS
:
111 /* We cannot inline functions that contain other functions. */
112 if (TREE_CODE (TREE_OPERAND (node
, 0)) == FUNCTION_DECL
113 && DECL_INITIAL (TREE_OPERAND (node
, 0)))
119 t
= TREE_OPERAND (node
, 0);
121 /* We will not inline a function which uses computed goto. The
122 addresses of its local labels, which may be tucked into
123 global storage, are of course not constant across
124 instantiations, which causes unexpected behavior. */
125 if (TREE_CODE (t
) != LABEL_DECL
)
128 /* We cannot inline a nested function that jumps to a nonlocal
130 if (TREE_CODE (t
) == LABEL_DECL
131 && DECL_CONTEXT (t
) && DECL_CONTEXT (t
) != fn
)
144 c_cannot_inline_tree_fn (fnp
)
150 if (flag_really_no_inline
151 && lookup_attribute ("always_inline", DECL_ATTRIBUTES (fn
)) == NULL
)
154 /* Don't auto-inline anything that might not be bound within
155 this unit of translation. */
156 if (!DECL_DECLARED_INLINE_P (fn
) && !(*targetm
.binds_local_p
) (fn
))
159 if (! function_attribute_inlinable_p (fn
))
162 /* If a function has pending sizes, we must not defer its
163 compilation, and we can't inline it as a tree. */
164 if (fn
== current_function_decl
)
166 t
= get_pending_sizes ();
167 put_pending_sizes (t
);
173 if (DECL_CONTEXT (fn
))
175 /* If a nested function has pending sizes, we may have already
177 if (DECL_LANG_SPECIFIC (fn
)->pending_sizes
)
182 /* We rely on the fact that this function is called upfront,
183 just before we start expanding a function. If FN is active
184 (i.e., it's the current_function_decl or a parent thereof),
185 we have to walk FN's saved tree. Otherwise, we can safely
186 assume we have done it before and, if we didn't mark it as
187 uninlinable (in which case we wouldn't have been called), it
188 is inlinable. Unfortunately, this strategy doesn't work for
189 nested functions, because they're only expanded as part of
190 their enclosing functions, so the inlinability test comes in
192 t
= current_function_decl
;
195 t
= DECL_CONTEXT (t
);
200 if (walk_tree (&DECL_SAVED_TREE (fn
), inline_forbidden_p
, fn
, NULL
))
206 DECL_UNINLINABLE (fn
) = 1;
210 /* Called from check_global_declarations. */
213 c_warn_unused_global_decl (decl
)
216 if (TREE_CODE (decl
) == FUNCTION_DECL
&& DECL_DECLARED_INLINE_P (decl
))
218 if (DECL_IN_SYSTEM_HEADER (decl
))
224 /* Initialization common to C and Objective-C front ends. */
226 c_objc_common_init (filename
)
227 const char *filename
;
229 c_init_decl_processing ();
231 filename
= c_common_init (filename
);
232 if (filename
== NULL
)
235 lang_expand_decl_stmt
= c_expand_decl_stmt
;
237 /* These were not defined in the Objective-C front end, but I'm
238 putting them here anyway. The diagnostic format decoder might
239 want an enhanced ObjC implementation. */
240 diagnostic_format_decoder (global_dc
) = &c_tree_printer
;
241 lang_missing_noreturn_ok_p
= &c_missing_noreturn_ok_p
;
243 /* If still unspecified, make it match -std=c99
244 (allowing for -pedantic-errors). */
245 if (mesg_implicit_function_declaration
< 0)
248 mesg_implicit_function_declaration
= flag_pedantic_errors
? 2 : 1;
250 mesg_implicit_function_declaration
= 0;
253 VARRAY_TREE_INIT (deferred_fns
, 32, "deferred_fns");
258 /* Register a function tree, so that its optimization and conversion
259 to RTL is only done at the end of the compilation. */
265 VARRAY_PUSH_TREE (deferred_fns
, fn
);
270 /* Expand deferred functions for C and ObjC. */
273 expand_deferred_fns ()
277 for (i
= 0; i
< VARRAY_ACTIVE_SIZE (deferred_fns
); i
++)
279 tree decl
= VARRAY_TREE (deferred_fns
, i
);
281 if (! TREE_ASM_WRITTEN (decl
))
283 /* For static inline functions, delay the decision whether to
284 emit them or not until wrapup_global_declarations. */
285 if (! TREE_PUBLIC (decl
))
286 DECL_DEFER_OUTPUT (decl
) = 1;
287 c_expand_deferred_function (decl
);
295 start_cdtor (method_type
)
298 tree fnname
= get_file_function_name (method_type
);
299 tree void_list_node_1
= build_tree_list (NULL_TREE
, void_type_node
);
302 start_function (void_list_node_1
,
303 build_nt (CALL_EXPR
, fnname
,
304 tree_cons (NULL_TREE
, NULL_TREE
, void_list_node_1
),
309 current_function_cannot_inline
310 = "static constructors and destructors cannot be inlined";
312 body
= c_begin_compound_stmt ();
316 add_scope_stmt (/*begin_p=*/1, /*partial_p=*/0);
328 scope
= add_scope_stmt (/*begin_p=*/0, /*partial_p=*/0);
329 block
= poplevel (0, 0, 0);
330 SCOPE_STMT_BLOCK (TREE_PURPOSE (scope
)) = block
;
331 SCOPE_STMT_BLOCK (TREE_VALUE (scope
)) = block
;
333 RECHAIN_STMTS (body
, COMPOUND_BODY (body
));
335 finish_function (0, 0);
338 /* Called at end of parsing, but before end-of-file processing. */
341 c_objc_common_finish_file ()
343 expand_deferred_fns ();
347 tree body
= start_cdtor ('I');
349 for (; static_ctors
; static_ctors
= TREE_CHAIN (static_ctors
))
350 c_expand_expr_stmt (build_function_call (TREE_VALUE (static_ctors
),
358 tree body
= start_cdtor ('D');
360 for (; static_dtors
; static_dtors
= TREE_CHAIN (static_dtors
))
361 c_expand_expr_stmt (build_function_call (TREE_VALUE (static_dtors
),
369 FILE *stream
= dump_begin (TDI_all
, &flags
);
373 dump_node (getdecls (), flags
& ~TDF_SLIM
, stream
);
374 dump_end (TDI_all
, stream
);
379 /* Called during diagnostic message formatting process to print a
380 source-level entity onto BUFFER. The meaning of the format specifiers
383 %F: a function declaration,
386 These format specifiers form a subset of the format specifiers set used
387 by the C++ front-end.
388 Please notice when called, the `%' part was already skipped by the
389 diagnostic machinery. */
391 c_tree_printer (buffer
, text
)
392 output_buffer
*buffer
;
395 tree t
= va_arg (*text
->args_ptr
, tree
);
397 switch (*text
->format_spec
)
403 const char *n
= DECL_NAME (t
)
404 ? (*lang_hooks
.decl_printable_name
) (t
, 2)
406 output_add_string (buffer
, n
);
415 #include "gt-c-objc-common.h"