* combine.c (simplify_and_const_int): Simplify (AND (PLUS X Y) C)
[official-gcc.git] / gcc / c-objc-common.c
blobbe3b847facd8f9b5164b7b1bc3472a1a80fc77dc
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
9 version.
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
14 for more details.
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
19 02111-1307, USA. */
21 #include "config.h"
22 #include "system.h"
23 #include "tree.h"
24 #include "rtl.h"
25 #include "insn-config.h"
26 #include "integrate.h"
27 #include "expr.h"
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"
35 static int c_tree_printer PARAMS ((output_buffer *));
36 static tree inline_forbidden_p PARAMS ((tree *, int *, void *));
38 int
39 c_missing_noreturn_ok_p (decl)
40 tree 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. */
51 int
52 c_disregard_inline_limits (fn)
53 tree fn;
55 return DECL_DECLARED_INLINE_P (fn) && DECL_EXTERNAL (fn);
58 static tree
59 inline_forbidden_p (nodep, walk_subtrees, fn)
60 tree *nodep;
61 int *walk_subtrees ATTRIBUTE_UNUSED;
62 void *fn;
64 tree node = *nodep;
65 tree t;
67 switch (TREE_CODE (node))
69 case CALL_EXPR:
70 t = get_callee_fndecl (node);
72 if (! t)
73 break;
75 /* We cannot inline functions that call setjmp. */
76 if (setjmp_call_p (t))
77 return node;
79 switch (DECL_FUNCTION_CODE (t))
81 /* We cannot inline functions that take a variable number of
82 arguments. */
83 case BUILT_IN_VARARGS_START:
84 case BUILT_IN_STDARG_START:
85 #if 0
86 /* Functions that need information about the address of the
87 caller can't (shouldn't?) be inlined. */
88 case BUILT_IN_RETURN_ADDRESS:
89 #endif
90 return node;
92 default:
93 break;
96 break;
98 case DECL_STMT:
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)))
102 return node;
103 break;
105 case GOTO_STMT:
106 case GOTO_EXPR:
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)
114 return node;
116 /* We cannot inline a nested function that jumps to a nonlocal
117 label. */
118 if (TREE_CODE (t) == LABEL_DECL
119 && DECL_CONTEXT (t) && DECL_CONTEXT (t) != fn)
120 return node;
122 break;
124 default:
125 break;
128 return NULL_TREE;
132 c_cannot_inline_tree_fn (fnp)
133 tree *fnp;
135 tree fn = *fnp;
136 tree t;
138 if (! function_attribute_inlinable_p (fn))
140 DECL_UNINLINABLE (fn) = 1;
141 return 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);
151 if (t)
153 DECL_UNINLINABLE (fn) = 1;
154 return 1;
158 if (DECL_CONTEXT (fn))
160 /* If a nested function has pending sizes, we may have already
161 saved them. */
162 if (DECL_LANG_SPECIFIC (fn)->pending_sizes)
164 DECL_UNINLINABLE (fn) = 1;
165 return 1;
168 else
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
179 late. */
180 t = current_function_decl;
182 while (t && t != fn)
183 t = DECL_CONTEXT (t);
184 if (! t)
185 return 0;
188 if (walk_tree (&DECL_SAVED_TREE (fn), inline_forbidden_p, fn, NULL))
190 DECL_UNINLINABLE (fn) = 1;
191 return 1;
194 return 0;
197 /* Initialization common to C and Objective-C front ends. */
198 const char *
199 c_objc_common_init (filename)
200 const char *filename;
202 c_init_decl_processing ();
204 filename = c_common_init (filename);
206 add_c_tree_codes ();
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)
224 if (flag_isoc99)
225 mesg_implicit_function_declaration = flag_pedantic_errors ? 2 : 1;
226 else
227 mesg_implicit_function_declaration = 0;
230 return filename;
233 /* Called during diagnostic message formatting process to print a
234 source-level entity onto BUFFER. The meaning of the format specifiers
235 is as follows:
236 %D: a general decl,
237 %F: a function declaration,
238 %T: a type.
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. */
244 static int
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))
252 case 'D':
253 case 'F':
254 case 'T':
256 const char *n = DECL_NAME (t)
257 ? (*decl_printable_name) (t, 2)
258 : "({anonymous})";
259 output_add_string (buffer, n);
261 return 1;
263 default:
264 return 0;