Deleted Added
full compact
c-objc-common.c (107590) c-objc-common.c (117395)
1/* Some code common to C and ObjC front ends.
2 Copyright (C) 2001 Free Software Foundation, Inc.
3
4This file is part of GCC.
5
6GCC is free software; you can redistribute it and/or modify it under
7the terms of the GNU General Public License as published by the Free
8Software Foundation; either version 2, or (at your option) any later

--- 19 unchanged lines hidden (view full) ---

28#include "c-tree.h"
29#include "function.h"
30#include "flags.h"
31#include "toplev.h"
32#include "diagnostic.h"
33#include "tree-inline.h"
34#include "varray.h"
35#include "ggc.h"
1/* Some code common to C and ObjC front ends.
2 Copyright (C) 2001 Free Software Foundation, Inc.
3
4This file is part of GCC.
5
6GCC is free software; you can redistribute it and/or modify it under
7the terms of the GNU General Public License as published by the Free
8Software Foundation; either version 2, or (at your option) any later

--- 19 unchanged lines hidden (view full) ---

28#include "c-tree.h"
29#include "function.h"
30#include "flags.h"
31#include "toplev.h"
32#include "diagnostic.h"
33#include "tree-inline.h"
34#include "varray.h"
35#include "ggc.h"
36#include "langhooks.h"
37#include "target.h"
36
38
37static int c_tree_printer PARAMS ((output_buffer *));
39static bool c_tree_printer PARAMS ((output_buffer *, text_info *));
38static tree inline_forbidden_p PARAMS ((tree *, int *, void *));
39static void expand_deferred_fns PARAMS ((void));
40static tree start_cdtor PARAMS ((int));
41static void finish_cdtor PARAMS ((tree));
42
40static tree inline_forbidden_p PARAMS ((tree *, int *, void *));
41static void expand_deferred_fns PARAMS ((void));
42static tree start_cdtor PARAMS ((int));
43static void finish_cdtor PARAMS ((tree));
44
43static varray_type deferred_fns;
45static GTY(()) varray_type deferred_fns;
44
45int
46c_missing_noreturn_ok_p (decl)
47 tree decl;
48{
49 /* A missing noreturn is not ok for freestanding implementations and
50 ok for the `main' function in hosted implementations. */
51 return flag_hosted && MAIN_NAME_P (DECL_ASSEMBLER_NAME (decl));

--- 33 unchanged lines hidden (view full) ---

85 /* We cannot inline functions that call setjmp. */
86 if (setjmp_call_p (t))
87 return node;
88
89 switch (DECL_FUNCTION_CODE (t))
90 {
91 /* We cannot inline functions that take a variable number of
92 arguments. */
46
47int
48c_missing_noreturn_ok_p (decl)
49 tree decl;
50{
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));

--- 33 unchanged lines hidden (view full) ---

87 /* We cannot inline functions that call setjmp. */
88 if (setjmp_call_p (t))
89 return node;
90
91 switch (DECL_FUNCTION_CODE (t))
92 {
93 /* We cannot inline functions that take a variable number of
94 arguments. */
93 case BUILT_IN_VARARGS_START:
95 case BUILT_IN_VA_START:
94 case BUILT_IN_STDARG_START:
95#if 0
96 /* Functions that need information about the address of the
97 caller can't (shouldn't?) be inlined. */
98 case BUILT_IN_RETURN_ADDRESS:
99#endif
100 return node;
101

--- 12 unchanged lines hidden (view full) ---

114
115 case GOTO_STMT:
116 case GOTO_EXPR:
117 t = TREE_OPERAND (node, 0);
118
119 /* We will not inline a function which uses computed goto. The
120 addresses of its local labels, which may be tucked into
121 global storage, are of course not constant across
96 case BUILT_IN_STDARG_START:
97#if 0
98 /* Functions that need information about the address of the
99 caller can't (shouldn't?) be inlined. */
100 case BUILT_IN_RETURN_ADDRESS:
101#endif
102 return node;
103

--- 12 unchanged lines hidden (view full) ---

116
117 case GOTO_STMT:
118 case GOTO_EXPR:
119 t = TREE_OPERAND (node, 0);
120
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
122 instantiations, which causes unexpected behaviour. */
124 instantiations, which causes unexpected behavior. */
123 if (TREE_CODE (t) != LABEL_DECL)
124 return node;
125
126 /* We cannot inline a nested function that jumps to a nonlocal
127 label. */
128 if (TREE_CODE (t) == LABEL_DECL
129 && DECL_CONTEXT (t) && DECL_CONTEXT (t) != fn)
130 return node;

--- 31 unchanged lines hidden (view full) ---

162 tree t;
163
164 if (flag_really_no_inline
165 && lookup_attribute ("always_inline", DECL_ATTRIBUTES (fn)) == NULL)
166 return 1;
167
168 /* Don't auto-inline anything that might not be bound within
169 this unit of translation. */
125 if (TREE_CODE (t) != LABEL_DECL)
126 return node;
127
128 /* We cannot inline a nested function that jumps to a nonlocal
129 label. */
130 if (TREE_CODE (t) == LABEL_DECL
131 && DECL_CONTEXT (t) && DECL_CONTEXT (t) != fn)
132 return node;

--- 31 unchanged lines hidden (view full) ---

164 tree t;
165
166 if (flag_really_no_inline
167 && lookup_attribute ("always_inline", DECL_ATTRIBUTES (fn)) == NULL)
168 return 1;
169
170 /* Don't auto-inline anything that might not be bound within
171 this unit of translation. */
170 if (!DECL_DECLARED_INLINE_P (fn) && flag_pic && TREE_PUBLIC (fn))
171 {
172 DECL_UNINLINABLE (fn) = 1;
173 return 1;
174 }
172 if (!DECL_DECLARED_INLINE_P (fn) && !(*targetm.binds_local_p) (fn))
173 goto cannot_inline;
175
176 if (! function_attribute_inlinable_p (fn))
174
175 if (! function_attribute_inlinable_p (fn))
177 {
178 DECL_UNINLINABLE (fn) = 1;
179 return 1;
180 }
176 goto cannot_inline;
181
182 /* If a function has pending sizes, we must not defer its
183 compilation, and we can't inline it as a tree. */
184 if (fn == current_function_decl)
185 {
186 t = get_pending_sizes ();
187 put_pending_sizes (t);
188
189 if (t)
177
178 /* If a function has pending sizes, we must not defer its
179 compilation, and we can't inline it as a tree. */
180 if (fn == current_function_decl)
181 {
182 t = get_pending_sizes ();
183 put_pending_sizes (t);
184
185 if (t)
190 {
191 DECL_UNINLINABLE (fn) = 1;
192 return 1;
193 }
186 goto cannot_inline;
194 }
195
196 if (DECL_CONTEXT (fn))
197 {
198 /* If a nested function has pending sizes, we may have already
199 saved them. */
200 if (DECL_LANG_SPECIFIC (fn)->pending_sizes)
187 }
188
189 if (DECL_CONTEXT (fn))
190 {
191 /* If a nested function has pending sizes, we may have already
192 saved them. */
193 if (DECL_LANG_SPECIFIC (fn)->pending_sizes)
201 {
202 DECL_UNINLINABLE (fn) = 1;
203 return 1;
204 }
194 goto cannot_inline;
205 }
206 else
207 {
208 /* We rely on the fact that this function is called upfront,
209 just before we start expanding a function. If FN is active
210 (i.e., it's the current_function_decl or a parent thereof),
211 we have to walk FN's saved tree. Otherwise, we can safely
212 assume we have done it before and, if we didn't mark it as

--- 5 unchanged lines hidden (view full) ---

218 t = current_function_decl;
219
220 while (t && t != fn)
221 t = DECL_CONTEXT (t);
222 if (! t)
223 return 0;
224 }
225
195 }
196 else
197 {
198 /* We rely on the fact that this function is called upfront,
199 just before we start expanding a function. If FN is active
200 (i.e., it's the current_function_decl or a parent thereof),
201 we have to walk FN's saved tree. Otherwise, we can safely
202 assume we have done it before and, if we didn't mark it as

--- 5 unchanged lines hidden (view full) ---

208 t = current_function_decl;
209
210 while (t && t != fn)
211 t = DECL_CONTEXT (t);
212 if (! t)
213 return 0;
214 }
215
226 if (walk_tree (&DECL_SAVED_TREE (fn), inline_forbidden_p, fn, NULL))
227 {
228 DECL_UNINLINABLE (fn) = 1;
229 return 1;
230 }
216 if (walk_tree_without_duplicates
217 (&DECL_SAVED_TREE (fn), inline_forbidden_p, fn))
218 goto cannot_inline;
231
232 return 0;
219
220 return 0;
221
222 cannot_inline:
223 DECL_UNINLINABLE (fn) = 1;
224 return 1;
233}
234
225}
226
227/* Called from check_global_declarations. */
228
229bool
230c_warn_unused_global_decl (decl)
231 tree decl;
232{
233 if (TREE_CODE (decl) == FUNCTION_DECL && DECL_DECLARED_INLINE_P (decl))
234 return false;
235 if (DECL_IN_SYSTEM_HEADER (decl))
236 return false;
237
238 return true;
239}
240
235/* Initialization common to C and Objective-C front ends. */
236const char *
237c_objc_common_init (filename)
238 const char *filename;
239{
240 c_init_decl_processing ();
241
242 filename = c_common_init (filename);
241/* Initialization common to C and Objective-C front ends. */
242const char *
243c_objc_common_init (filename)
244 const char *filename;
245{
246 c_init_decl_processing ();
247
248 filename = c_common_init (filename);
249 if (filename == NULL)
250 return NULL;
243
251
244 add_c_tree_codes ();
245
246 save_lang_status = &push_c_function_context;
247 restore_lang_status = &pop_c_function_context;
248 mark_lang_status = &mark_c_function_context;
249 lang_expand_expr = c_expand_expr;
250 lang_expand_decl_stmt = c_expand_decl_stmt;
251
252 /* These were not defined in the Objective-C front end, but I'm
253 putting them here anyway. The diagnostic format decoder might
254 want an enhanced ObjC implementation. */
255 diagnostic_format_decoder (global_dc) = &c_tree_printer;
256 lang_missing_noreturn_ok_p = &c_missing_noreturn_ok_p;
257
258 /* If still unspecified, make it match -std=c99
259 (allowing for -pedantic-errors). */
260 if (mesg_implicit_function_declaration < 0)
261 {
262 if (flag_isoc99)
263 mesg_implicit_function_declaration = flag_pedantic_errors ? 2 : 1;
264 else
265 mesg_implicit_function_declaration = 0;
266 }
267
268 VARRAY_TREE_INIT (deferred_fns, 32, "deferred_fns");
252 lang_expand_decl_stmt = c_expand_decl_stmt;
253
254 /* These were not defined in the Objective-C front end, but I'm
255 putting them here anyway. The diagnostic format decoder might
256 want an enhanced ObjC implementation. */
257 diagnostic_format_decoder (global_dc) = &c_tree_printer;
258 lang_missing_noreturn_ok_p = &c_missing_noreturn_ok_p;
259
260 /* If still unspecified, make it match -std=c99
261 (allowing for -pedantic-errors). */
262 if (mesg_implicit_function_declaration < 0)
263 {
264 if (flag_isoc99)
265 mesg_implicit_function_declaration = flag_pedantic_errors ? 2 : 1;
266 else
267 mesg_implicit_function_declaration = 0;
268 }
269
270 VARRAY_TREE_INIT (deferred_fns, 32, "deferred_fns");
269 ggc_add_tree_varray_root (&deferred_fns, 1);
270
271 return filename;
272}
273
274/* Register a function tree, so that its optimization and conversion
275 to RTL is only done at the end of the compilation. */
276
277int

--- 21 unchanged lines hidden (view full) ---

299 /* For static inline functions, delay the decision whether to
300 emit them or not until wrapup_global_declarations. */
301 if (! TREE_PUBLIC (decl))
302 DECL_DEFER_OUTPUT (decl) = 1;
303 c_expand_deferred_function (decl);
304 }
305 }
306
271
272 return filename;
273}
274
275/* Register a function tree, so that its optimization and conversion
276 to RTL is only done at the end of the compilation. */
277
278int

--- 21 unchanged lines hidden (view full) ---

300 /* For static inline functions, delay the decision whether to
301 emit them or not until wrapup_global_declarations. */
302 if (! TREE_PUBLIC (decl))
303 DECL_DEFER_OUTPUT (decl) = 1;
304 c_expand_deferred_function (decl);
305 }
306 }
307
307 VARRAY_FREE (deferred_fns);
308 deferred_fns = 0;
308}
309
310static tree
311start_cdtor (method_type)
312 int method_type;
313{
314 tree fnname = get_file_function_name (method_type);
315 tree void_list_node_1 = build_tree_list (NULL_TREE, void_type_node);

--- 82 unchanged lines hidden (view full) ---

398 %D: a general decl,
399 %F: a function declaration,
400 %T: a type.
401
402 These format specifiers form a subset of the format specifiers set used
403 by the C++ front-end.
404 Please notice when called, the `%' part was already skipped by the
405 diagnostic machinery. */
309}
310
311static tree
312start_cdtor (method_type)
313 int method_type;
314{
315 tree fnname = get_file_function_name (method_type);
316 tree void_list_node_1 = build_tree_list (NULL_TREE, void_type_node);

--- 82 unchanged lines hidden (view full) ---

399 %D: a general decl,
400 %F: a function declaration,
401 %T: a type.
402
403 These format specifiers form a subset of the format specifiers set used
404 by the C++ front-end.
405 Please notice when called, the `%' part was already skipped by the
406 diagnostic machinery. */
406static int
407c_tree_printer (buffer)
407static bool
408c_tree_printer (buffer, text)
408 output_buffer *buffer;
409 output_buffer *buffer;
410 text_info *text;
409{
411{
410 tree t = va_arg (output_buffer_format_args (buffer), tree);
412 tree t = va_arg (*text->args_ptr, tree);
411
413
412 switch (*output_buffer_text_cursor (buffer))
414 switch (*text->format_spec)
413 {
414 case 'D':
415 case 'F':
416 case 'T':
417 {
418 const char *n = DECL_NAME (t)
415 {
416 case 'D':
417 case 'F':
418 case 'T':
419 {
420 const char *n = DECL_NAME (t)
419 ? (*decl_printable_name) (t, 2)
421 ? (*lang_hooks.decl_printable_name) (t, 2)
420 : "({anonymous})";
421 output_add_string (buffer, n);
422 }
422 : "({anonymous})";
423 output_add_string (buffer, n);
424 }
423 return 1;
425 return true;
424
425 default:
426
427 default:
426 return 0;
428 return false;
427 }
428}
429 }
430}
431
432#include "gt-c-objc-common.h"