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"
35 static int c_tree_printer
PARAMS ((output_buffer
*));
36 static tree inline_forbidden_p
PARAMS ((tree
*, int *, void *));
39 c_missing_noreturn_ok_p (decl
)
42 /* A missing noreturn is not ok for freestanding implementations and
43 ok for the `main' function in hosted implementations. */
44 return flag_hosted
&& MAIN_NAME_P (DECL_ASSEMBLER_NAME (decl
));
47 /* We want to inline `extern inline' functions even if this would
48 violate inlining limits. Some glibc and linux constructs depend on
49 such functions always being inlined when optimizing. */
52 c_disregard_inline_limits (fn
)
55 return DECL_DECLARED_INLINE_P (fn
) && DECL_EXTERNAL (fn
);
59 inline_forbidden_p (nodep
, walk_subtrees
, fn
)
61 int *walk_subtrees ATTRIBUTE_UNUSED
;
67 switch (TREE_CODE (node
))
70 t
= get_callee_fndecl (node
);
75 /* We cannot inline functions that call setjmp. */
76 if (setjmp_call_p (t
))
79 switch (DECL_FUNCTION_CODE (t
))
81 /* We cannot inline functions that take a variable number of
83 case BUILT_IN_VARARGS_START
:
84 case BUILT_IN_STDARG_START
:
86 /* Functions that need information about the address of the
87 caller can't (shouldn't?) be inlined. */
88 case BUILT_IN_RETURN_ADDRESS
:
99 /* We cannot inline functions that contain other functions. */
100 if (TREE_CODE (TREE_OPERAND (node
, 0)) == FUNCTION_DECL
101 && DECL_INITIAL (TREE_OPERAND (node
, 0)))
107 t
= TREE_OPERAND (node
, 0);
109 /* We will not inline a function which uses computed goto. The
110 addresses of its local labels, which may be tucked into
111 global storage, are of course not constant across
112 instantiations, which causes unexpected behaviour. */
113 if (TREE_CODE (t
) != LABEL_DECL
)
116 /* We cannot inline a nested function that jumps to a nonlocal
118 if (TREE_CODE (t
) == LABEL_DECL
119 && DECL_CONTEXT (t
) && DECL_CONTEXT (t
) != fn
)
132 c_cannot_inline_tree_fn (fnp
)
138 if (! function_attribute_inlinable_p (fn
))
140 DECL_UNINLINABLE (fn
) = 1;
144 /* If a function has pending sizes, we must not defer its
145 compilation, and we can't inline it as a tree. */
146 if (fn
== current_function_decl
)
148 t
= get_pending_sizes ();
149 put_pending_sizes (t
);
153 DECL_UNINLINABLE (fn
) = 1;
158 if (DECL_CONTEXT (fn
))
160 /* If a nested function has pending sizes, we may have already
162 if (DECL_LANG_SPECIFIC (fn
)->pending_sizes
)
164 DECL_UNINLINABLE (fn
) = 1;
170 /* We rely on the fact that this function is called upfront,
171 just before we start expanding a function. If FN is active
172 (i.e., it's the current_function_decl or a parent thereof),
173 we have to walk FN's saved tree. Otherwise, we can safely
174 assume we have done it before and, if we didn't mark it as
175 uninlinable (in which case we wouldn't have been called), it
176 is inlinable. Unfortunately, this strategy doesn't work for
177 nested functions, because they're only expanded as part of
178 their enclosing functions, so the inlinability test comes in
180 t
= current_function_decl
;
183 t
= DECL_CONTEXT (t
);
188 if (walk_tree (&DECL_SAVED_TREE (fn
), inline_forbidden_p
, fn
, NULL
))
190 DECL_UNINLINABLE (fn
) = 1;
197 /* Initialization common to C and Objective-C front ends. */
199 c_objc_common_init (filename
)
200 const char *filename
;
202 c_init_decl_processing ();
204 filename
= c_common_init (filename
);
208 save_lang_status
= &push_c_function_context
;
209 restore_lang_status
= &pop_c_function_context
;
210 mark_lang_status
= &mark_c_function_context
;
211 lang_expand_expr
= c_expand_expr
;
212 lang_expand_decl_stmt
= c_expand_decl_stmt
;
214 /* These were not defined in the Objective-C front end, but I'm
215 putting them here anyway. The diagnostic format decoder might
216 want an enhanced ObjC implementation. */
217 diagnostic_format_decoder (global_dc
) = &c_tree_printer
;
218 lang_missing_noreturn_ok_p
= &c_missing_noreturn_ok_p
;
220 /* If still unspecified, make it match -std=c99
221 (allowing for -pedantic-errors). */
222 if (mesg_implicit_function_declaration
< 0)
225 mesg_implicit_function_declaration
= flag_pedantic_errors
? 2 : 1;
227 mesg_implicit_function_declaration
= 0;
233 /* Called during diagnostic message formatting process to print a
234 source-level entity onto BUFFER. The meaning of the format specifiers
237 %F: a function declaration,
240 These format specifiers form a subset of the format specifiers set used
241 by the C++ front-end.
242 Please notice when called, the `%' part was already skipped by the
243 diagnostic machinery. */
245 c_tree_printer (buffer
)
246 output_buffer
*buffer
;
248 tree t
= va_arg (output_buffer_format_args (buffer
), tree
);
250 switch (*output_buffer_text_cursor (buffer
))
256 const char *n
= DECL_NAME (t
)
257 ? (*decl_printable_name
) (t
, 2)
259 output_add_string (buffer
, n
);