]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/c-common.c
(expand_call): Undo Feb 27 change. Set nregs to -1 for
[thirdparty/gcc.git] / gcc / c-common.c
CommitLineData
b0fc3e72 1/* Subroutines shared by all languages that are variants of C.
557b092e 2 Copyright (C) 1992, 1993, 1994 Free Software Foundation, Inc.
b0fc3e72 3
4This file is part of GNU CC.
5
6GNU CC is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 2, or (at your option)
9any later version.
10
11GNU CC is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GNU CC; see the file COPYING. If not, write to
18the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
19
20#include "config.h"
21#include "tree.h"
22#include "c-lex.h"
23#include "c-tree.h"
24#include "flags.h"
5da0b0ab 25#include "obstack.h"
b0fc3e72 26#include <stdio.h>
fce9faf9 27#include <ctype.h>
b0fc3e72 28
ceee5ef4 29extern struct obstack permanent_obstack;
30
be43ff5a 31static void declare_hidden_char_array PROTO((char *, char *));
32
b1497296 33/* Make bindings for __FUNCTION__ and __PRETTY_FUNCTION__. */
f4e3c278 34
35void
36declare_function_name ()
37{
f4e3c278 38 char *name, *printable_name;
39
40 if (current_function_decl == NULL)
41 {
42 name = "";
43 printable_name = "top level";
44 }
45 else
46 {
47 char *kind = "function";
48 if (TREE_CODE (TREE_TYPE (current_function_decl)) == METHOD_TYPE)
49 kind = "method";
3f3680c7 50 /* Allow functions to be nameless (such as artificial ones). */
51 if (DECL_NAME (current_function_decl))
52 name = IDENTIFIER_POINTER (DECL_NAME (current_function_decl));
53 else
54 name = "";
f4e3c278 55 printable_name = (*decl_printable_name) (current_function_decl, &kind);
56 }
57
be43ff5a 58 declare_hidden_char_array ("__FUNCTION__", name);
59 declare_hidden_char_array ("__PRETTY_FUNCTION__", printable_name);
60}
f4c9036d 61
be43ff5a 62static void
63declare_hidden_char_array (name, value)
64 char *name, *value;
65{
66 tree decl, type, init;
67 int vlen;
f4e3c278 68
be43ff5a 69 /* If the default size of char arrays isn't big enough for the name,
3227fe11 70 or if we want to give warnings for large objects, make a bigger one. */
be43ff5a 71 vlen = strlen (value) + 1;
f4c9036d 72 type = char_array_type_node;
3227fe11 73 if (TREE_INT_CST_LOW (TYPE_MAX_VALUE (TREE_TYPE (type))) < vlen
74 || warn_larger_than)
f4c9036d 75 type = build_array_type (char_type_node,
be43ff5a 76 build_index_type (build_int_2 (vlen, 0)));
f4e3c278 77 push_obstacks_nochange ();
be43ff5a 78 decl = build_decl (VAR_DECL, get_identifier (name), type);
f4e3c278 79 TREE_STATIC (decl) = 1;
80 TREE_READONLY (decl) = 1;
be43ff5a 81 TREE_ASM_WRITTEN (decl) = 1;
8658b58d 82 DECL_SOURCE_LINE (decl) = 0;
776899d6 83 DECL_IN_SYSTEM_HEADER (decl) = 1;
f4e3c278 84 DECL_IGNORED_P (decl) = 1;
be43ff5a 85 init = build_string (vlen, value);
f4c9036d 86 TREE_TYPE (init) = type;
f4e3c278 87 DECL_INITIAL (decl) = init;
88 finish_decl (pushdecl (decl), init, NULL_TREE);
89}
90
b0fc3e72 91/* Given a chain of STRING_CST nodes,
92 concatenate them into one STRING_CST
93 and give it a suitable array-of-chars data type. */
94
95tree
96combine_strings (strings)
97 tree strings;
98{
99 register tree value, t;
100 register int length = 1;
101 int wide_length = 0;
102 int wide_flag = 0;
103 int wchar_bytes = TYPE_PRECISION (wchar_type_node) / BITS_PER_UNIT;
104 int nchars;
105
106 if (TREE_CHAIN (strings))
107 {
108 /* More than one in the chain, so concatenate. */
109 register char *p, *q;
110
111 /* Don't include the \0 at the end of each substring,
112 except for the last one.
113 Count wide strings and ordinary strings separately. */
114 for (t = strings; t; t = TREE_CHAIN (t))
115 {
116 if (TREE_TYPE (t) == wchar_array_type_node)
117 {
118 wide_length += (TREE_STRING_LENGTH (t) - wchar_bytes);
119 wide_flag = 1;
120 }
121 else
122 length += (TREE_STRING_LENGTH (t) - 1);
123 }
124
125 /* If anything is wide, the non-wides will be converted,
126 which makes them take more space. */
127 if (wide_flag)
128 length = length * wchar_bytes + wide_length;
129
130 p = savealloc (length);
131
132 /* Copy the individual strings into the new combined string.
133 If the combined string is wide, convert the chars to ints
134 for any individual strings that are not wide. */
135
136 q = p;
137 for (t = strings; t; t = TREE_CHAIN (t))
138 {
139 int len = (TREE_STRING_LENGTH (t)
140 - ((TREE_TYPE (t) == wchar_array_type_node)
141 ? wchar_bytes : 1));
142 if ((TREE_TYPE (t) == wchar_array_type_node) == wide_flag)
143 {
144 bcopy (TREE_STRING_POINTER (t), q, len);
145 q += len;
146 }
147 else
148 {
149 int i;
150 for (i = 0; i < len; i++)
151 ((int *) q)[i] = TREE_STRING_POINTER (t)[i];
152 q += len * wchar_bytes;
153 }
154 }
155 if (wide_flag)
156 {
157 int i;
158 for (i = 0; i < wchar_bytes; i++)
159 *q++ = 0;
160 }
161 else
162 *q = 0;
163
164 value = make_node (STRING_CST);
165 TREE_STRING_POINTER (value) = p;
166 TREE_STRING_LENGTH (value) = length;
167 TREE_CONSTANT (value) = 1;
168 }
169 else
170 {
171 value = strings;
172 length = TREE_STRING_LENGTH (value);
173 if (TREE_TYPE (value) == wchar_array_type_node)
174 wide_flag = 1;
175 }
176
177 /* Compute the number of elements, for the array type. */
178 nchars = wide_flag ? length / wchar_bytes : length;
179
180 /* Create the array type for the string constant.
181 -Wwrite-strings says make the string constant an array of const char
182 so that copying it to a non-const pointer will get a warning. */
183 if (warn_write_strings
184 && (! flag_traditional && ! flag_writable_strings))
185 {
186 tree elements
187 = build_type_variant (wide_flag ? wchar_type_node : char_type_node,
188 1, 0);
189 TREE_TYPE (value)
190 = build_array_type (elements,
191 build_index_type (build_int_2 (nchars - 1, 0)));
192 }
193 else
194 TREE_TYPE (value)
195 = build_array_type (wide_flag ? wchar_type_node : char_type_node,
196 build_index_type (build_int_2 (nchars - 1, 0)));
197 TREE_CONSTANT (value) = 1;
198 TREE_STATIC (value) = 1;
199 return value;
200}
201\f
202/* Process the attributes listed in ATTRIBUTES
203 and install them in DECL. */
204
205void
206decl_attributes (decl, attributes)
207 tree decl, attributes;
208{
209 tree a;
e532650d 210
b0fc3e72 211 for (a = attributes; a; a = TREE_CHAIN (a))
df4f2c08 212 if (TREE_VALUE (a) == get_identifier ("packed"))
213 {
214 if (TREE_CODE (decl) == FIELD_DECL)
215 DECL_PACKED (decl) = 1;
8fa094cd 216 /* We can't set DECL_PACKED for a VAR_DECL, because the bit is
5e58c22e 217 used for DECL_REGISTER. It wouldn't mean anything anyway. */
e11c4936 218 else
219 warning_with_decl (decl, "`packed' attribute ignore");
220
df4f2c08 221 }
a4a5c6b7 222 else if (TREE_VALUE (a) == get_identifier ("noreturn")
223 || TREE_VALUE (a) == get_identifier ("volatile"))
224 {
e11c4936 225 tree type = TREE_TYPE (decl);
226
a4a5c6b7 227 if (TREE_CODE (decl) == FUNCTION_DECL)
228 TREE_THIS_VOLATILE (decl) = 1;
e11c4936 229 else if (TREE_CODE (type) == POINTER_TYPE
230 && TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE)
231 TREE_TYPE (decl)
232 = build_pointer_type
233 (build_type_variant (TREE_TYPE (type),
234 TREE_READONLY (TREE_TYPE (type)), 1));
235 else
236 warning_with_decl (decl, "`%s' attribute ignored",
237 IDENTIFIER_POINTER (TREE_VALUE (a)));
a4a5c6b7 238 }
239 else if (TREE_VALUE (a) == get_identifier ("const"))
240 {
e11c4936 241 tree type = TREE_TYPE (decl);
242
a4a5c6b7 243 if (TREE_CODE (decl) == FUNCTION_DECL)
244 TREE_READONLY (decl) = 1;
e11c4936 245 else if (TREE_CODE (type) == POINTER_TYPE
246 && TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE)
247 TREE_TYPE (decl)
248 = build_pointer_type
249 (build_type_variant (TREE_TYPE (type), 1,
250 TREE_THIS_VOLATILE (TREE_TYPE (type))));
251 else
252 warning_with_decl (decl, "`const' attribute ignored");
a4a5c6b7 253 }
df4f2c08 254 else if (TREE_VALUE (a) != 0
791fd404 255 && TREE_CODE (TREE_VALUE (a)) == TREE_LIST
256 && TREE_PURPOSE (TREE_VALUE (a)) == get_identifier ("mode"))
df4f2c08 257 {
258 int i;
259 char *specified_name
260 = IDENTIFIER_POINTER (TREE_VALUE (TREE_VALUE (a)));
261
262 /* Give this decl a type with the specified mode. */
263 for (i = 0; i < NUM_MACHINE_MODES; i++)
264 if (!strcmp (specified_name, GET_MODE_NAME (i)))
265 {
266 tree type
88ef61d1 267 = type_for_mode (i, TREE_UNSIGNED (TREE_TYPE (decl)));
df4f2c08 268 if (type != 0)
269 {
270 TREE_TYPE (decl) = type;
271 DECL_SIZE (decl) = 0;
484e4645 272 layout_decl (decl, 0);
df4f2c08 273 }
274 else
275 error ("no data type for mode `%s'", specified_name);
88ef61d1 276 break;
df4f2c08 277 }
278 if (i == NUM_MACHINE_MODES)
e11c4936 279 error_with_decl (decl, "unknown machine mode `%s'", specified_name);
df4f2c08 280 }
e532650d 281 else if (TREE_VALUE (a) != 0
282 && TREE_CODE (TREE_VALUE (a)) == TREE_LIST
283 && TREE_PURPOSE (TREE_VALUE (a)) == get_identifier ("section"))
284 {
285#ifdef ASM_OUTPUT_SECTION_NAME
286 if (TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL)
287 {
288 if (TREE_CODE (decl) == VAR_DECL && current_function_decl != NULL_TREE)
e11c4936 289 error_with_decl (decl,
290 "section attribute cannot be specified for local variables");
e532650d 291 /* The decl may have already been given a section attribute from
292 a previous declaration. Ensure they match. */
293 else if (DECL_SECTION_NAME (decl) != NULL_TREE
294 && strcmp (TREE_STRING_POINTER (DECL_SECTION_NAME (decl)),
295 TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (a)))) != 0)
296 error_with_decl (decl,
297 "section of `%s' conflicts with previous declaration");
298 else
299 DECL_SECTION_NAME (decl) = TREE_VALUE (TREE_VALUE (a));
300 }
301 else
302 error_with_decl (decl,
303 "section attribute not allowed for `%s'");
304#else
305 error_with_decl (decl, "section attributes are not supported for this target");
306#endif
307 }
df4f2c08 308 else if (TREE_VALUE (a) != 0
309 && TREE_CODE (TREE_VALUE (a)) == TREE_LIST
310 && TREE_PURPOSE (TREE_VALUE (a)) == get_identifier ("aligned"))
b0fc3e72 311 {
245de75a 312 tree align_expr = TREE_VALUE (TREE_VALUE (a));
313 int align;
314
315 /* Strip any NOPs of any kind. */
316 while (TREE_CODE (align_expr) == NOP_EXPR
317 || TREE_CODE (align_expr) == CONVERT_EXPR
318 || TREE_CODE (align_expr) == NON_LVALUE_EXPR)
319 align_expr = TREE_OPERAND (align_expr, 0);
320
321 if (TREE_CODE (align_expr) != INTEGER_CST)
322 {
323 error_with_decl (decl,
324 "requested alignment of `%s' is not a constant");
325 continue;
326 }
327
328 align = TREE_INT_CST_LOW (align_expr) * BITS_PER_UNIT;
b0fc3e72 329
330 if (exact_log2 (align) == -1)
88ef61d1 331 error_with_decl (decl,
332 "requested alignment of `%s' is not a power of 2");
b0fc3e72 333 else if (TREE_CODE (decl) != VAR_DECL
334 && TREE_CODE (decl) != FIELD_DECL)
88ef61d1 335 error_with_decl (decl,
6dd9847a 336 "alignment specified for `%s'");
b0fc3e72 337 else
338 DECL_ALIGN (decl) = align;
339 }
340 else if (TREE_VALUE (a) != 0
341 && TREE_CODE (TREE_VALUE (a)) == TREE_LIST
df4f2c08 342 && TREE_PURPOSE (TREE_VALUE (a)) == get_identifier ("format"))
b0fc3e72 343 {
344 tree list = TREE_VALUE (TREE_VALUE (a));
345 tree format_type = TREE_PURPOSE (list);
245de75a 346 tree format_num_expr = TREE_PURPOSE (TREE_VALUE (list));
347 tree first_arg_num_expr = TREE_VALUE (TREE_VALUE (list));
348 int format_num;
349 int first_arg_num;
b0fc3e72 350 int is_scan;
d6cd1111 351 tree argument;
352 int arg_num;
b0fc3e72 353
354 if (TREE_CODE (decl) != FUNCTION_DECL)
355 {
88ef61d1 356 error_with_decl (decl,
357 "argument format specified for non-function `%s'");
245de75a 358 continue;
b0fc3e72 359 }
360
361 if (format_type == get_identifier ("printf"))
362 is_scan = 0;
363 else if (format_type == get_identifier ("scanf"))
364 is_scan = 1;
365 else
366 {
88ef61d1 367 error_with_decl (decl, "unrecognized format specifier for `%s'");
245de75a 368 continue;
b0fc3e72 369 }
370
245de75a 371 /* Strip any conversions from the string index and first arg number
372 and verify they are constants. */
373 while (TREE_CODE (format_num_expr) == NOP_EXPR
374 || TREE_CODE (format_num_expr) == CONVERT_EXPR
375 || TREE_CODE (format_num_expr) == NON_LVALUE_EXPR)
376 format_num_expr = TREE_OPERAND (format_num_expr, 0);
377
378 while (TREE_CODE (first_arg_num_expr) == NOP_EXPR
379 || TREE_CODE (first_arg_num_expr) == CONVERT_EXPR
380 || TREE_CODE (first_arg_num_expr) == NON_LVALUE_EXPR)
381 first_arg_num_expr = TREE_OPERAND (first_arg_num_expr, 0);
382
383 if (TREE_CODE (format_num_expr) != INTEGER_CST
384 || TREE_CODE (first_arg_num_expr) != INTEGER_CST)
385 {
386 error_with_decl (decl,
387 "format string for `%s' has non-constant operand number");
388 continue;
389 }
390
391 format_num = TREE_INT_CST_LOW (format_num_expr);
392 first_arg_num = TREE_INT_CST_LOW (first_arg_num_expr);
b0fc3e72 393 if (first_arg_num != 0 && first_arg_num <= format_num)
394 {
88ef61d1 395 error_with_decl (decl,
245de75a 396 "format string arg follows the args to be formatted, for `%s'");
397 continue;
b0fc3e72 398 }
d6cd1111 399
557b092e 400 /* If a parameter list is specified, verify that the format_num
401 argument is actually a string, in case the format attribute
402 is in error. */
d6cd1111 403 argument = TYPE_ARG_TYPES (TREE_TYPE (decl));
557b092e 404 if (argument)
d6cd1111 405 {
557b092e 406 for (arg_num = 1; ; ++arg_num)
407 {
408 if (argument == 0 || arg_num == format_num)
409 break;
410 argument = TREE_CHAIN (argument);
411 }
412 if (! argument
413 || TREE_CODE (TREE_VALUE (argument)) != POINTER_TYPE
414 || (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_VALUE (argument)))
415 != char_type_node))
5d730828 416 {
417 error_with_decl (decl,
557b092e 418 "format string arg not a string type, for `%s'");
245de75a 419 continue;
5d730828 420 }
557b092e 421 if (first_arg_num != 0)
422 {
423 /* Verify that first_arg_num points to the last arg, the ... */
424 while (argument)
425 arg_num++, argument = TREE_CHAIN (argument);
426 if (arg_num != first_arg_num)
427 {
428 error_with_decl (decl,
429 "args to be formatted is not ..., for `%s'");
430 continue;
431 }
432 }
d6cd1111 433 }
fce9faf9 434
435 record_function_format (DECL_NAME (decl), DECL_ASSEMBLER_NAME (decl),
436 is_scan, format_num, first_arg_num);
b0fc3e72 437 }
438}
439\f
fce9faf9 440/* Check a printf/fprintf/sprintf/scanf/fscanf/sscanf format against
441 a parameter list. */
442
443#define T_I &integer_type_node
444#define T_L &long_integer_type_node
445#define T_S &short_integer_type_node
446#define T_UI &unsigned_type_node
447#define T_UL &long_unsigned_type_node
448#define T_US &short_unsigned_type_node
449#define T_F &float_type_node
450#define T_D &double_type_node
451#define T_LD &long_double_type_node
452#define T_C &char_type_node
453#define T_V &void_type_node
454#define T_W &wchar_type_node
7710f895 455#define T_ST &sizetype
fce9faf9 456
457typedef struct {
458 char *format_chars;
459 int pointer_count;
460 /* Type of argument if no length modifier is used. */
461 tree *nolen;
462 /* Type of argument if length modifier for shortening is used.
463 If NULL, then this modifier is not allowed. */
464 tree *hlen;
465 /* Type of argument if length modifier `l' is used.
466 If NULL, then this modifier is not allowed. */
467 tree *llen;
468 /* Type of argument if length modifier `L' is used.
469 If NULL, then this modifier is not allowed. */
470 tree *bigllen;
471 /* List of other modifier characters allowed with these options. */
472 char *flag_chars;
473} format_char_info;
474
475static format_char_info print_char_table[] = {
476 { "di", 0, T_I, T_I, T_L, NULL, "-wp0 +" },
477 { "oxX", 0, T_UI, T_UI, T_UL, NULL, "-wp0#" },
478 { "u", 0, T_UI, T_UI, T_UL, NULL, "-wp0" },
63b97047 479/* Two GNU extensions. */
480 { "Z", 0, T_ST, NULL, NULL, NULL, "-wp0" },
481 { "m", 0, T_UI, T_UI, T_UL, NULL, "-wp" },
fce9faf9 482 { "feEgG", 0, T_D, NULL, NULL, T_LD, "-wp0 +#" },
483 { "c", 0, T_I, NULL, T_W, NULL, "-w" },
484 { "C", 0, T_W, NULL, NULL, NULL, "-w" },
485 { "s", 1, T_C, NULL, T_W, NULL, "-wp" },
486 { "S", 1, T_W, NULL, NULL, NULL, "-wp" },
487 { "p", 1, T_V, NULL, NULL, NULL, "-w" },
488 { "n", 1, T_I, T_S, T_L, NULL, "" },
489 { NULL }
490};
491
492static format_char_info scan_char_table[] = {
493 { "di", 1, T_I, T_S, T_L, NULL, "*" },
494 { "ouxX", 1, T_UI, T_US, T_UL, NULL, "*" },
495 { "efgEG", 1, T_F, NULL, T_D, T_LD, "*" },
63b97047 496 { "sc", 1, T_C, NULL, T_W, NULL, "*a" },
497 { "[", 1, T_C, NULL, NULL, NULL, "*a" },
fce9faf9 498 { "C", 1, T_W, NULL, NULL, NULL, "*" },
499 { "S", 1, T_W, NULL, NULL, NULL, "*" },
500 { "p", 2, T_V, NULL, NULL, NULL, "*" },
501 { "n", 1, T_I, T_S, T_L, NULL, "" },
502 { NULL }
503};
504
505typedef struct function_format_info {
506 struct function_format_info *next; /* next structure on the list */
507 tree name; /* identifier such as "printf" */
508 tree assembler_name; /* optional mangled identifier (for C++) */
509 int is_scan; /* TRUE if *scanf */
510 int format_num; /* number of format argument */
511 int first_arg_num; /* number of first arg (zero for varargs) */
512} function_format_info;
513
514static function_format_info *function_format_list = NULL;
515
516static void check_format_info PROTO((function_format_info *, tree));
517
518/* Initialize the table of functions to perform format checking on.
519 The ANSI functions are always checked (whether <stdio.h> is
520 included or not), since it is common to call printf without
521 including <stdio.h>. There shouldn't be a problem with this,
522 since ANSI reserves these function names whether you include the
523 header file or not. In any case, the checking is harmless. */
524
525void
526init_function_format_info ()
527{
528 record_function_format (get_identifier ("printf"), NULL_TREE, 0, 1, 2);
529 record_function_format (get_identifier ("fprintf"), NULL_TREE, 0, 2, 3);
530 record_function_format (get_identifier ("sprintf"), NULL_TREE, 0, 2, 3);
531 record_function_format (get_identifier ("scanf"), NULL_TREE, 1, 1, 2);
532 record_function_format (get_identifier ("fscanf"), NULL_TREE, 1, 2, 3);
533 record_function_format (get_identifier ("sscanf"), NULL_TREE, 1, 2, 3);
534 record_function_format (get_identifier ("vprintf"), NULL_TREE, 0, 1, 0);
535 record_function_format (get_identifier ("vfprintf"), NULL_TREE, 0, 2, 0);
536 record_function_format (get_identifier ("vsprintf"), NULL_TREE, 0, 2, 0);
537}
538
539/* Record information for argument format checking. FUNCTION_IDENT is
540 the identifier node for the name of the function to check (its decl
541 need not exist yet). IS_SCAN is true for scanf-type format checking;
542 false indicates printf-style format checking. FORMAT_NUM is the number
543 of the argument which is the format control string (starting from 1).
544 FIRST_ARG_NUM is the number of the first actual argument to check
545 against teh format string, or zero if no checking is not be done
546 (e.g. for varargs such as vfprintf). */
547
548void
549record_function_format (name, assembler_name, is_scan,
550 format_num, first_arg_num)
551 tree name;
552 tree assembler_name;
553 int is_scan;
554 int format_num;
555 int first_arg_num;
556{
557 function_format_info *info;
558
559 /* Re-use existing structure if it's there. */
560
561 for (info = function_format_list; info; info = info->next)
562 {
563 if (info->name == name && info->assembler_name == assembler_name)
564 break;
565 }
566 if (! info)
567 {
568 info = (function_format_info *) xmalloc (sizeof (function_format_info));
569 info->next = function_format_list;
570 function_format_list = info;
571
572 info->name = name;
573 info->assembler_name = assembler_name;
574 }
575
576 info->is_scan = is_scan;
577 info->format_num = format_num;
578 info->first_arg_num = first_arg_num;
579}
580
581static char tfaff[] = "too few arguments for format";
582\f
583/* Check the argument list of a call to printf, scanf, etc.
584 NAME is the function identifier.
585 ASSEMBLER_NAME is the function's assembler identifier.
586 (Either NAME or ASSEMBLER_NAME, but not both, may be NULL_TREE.)
587 PARAMS is the list of argument values. */
588
589void
590check_function_format (name, assembler_name, params)
591 tree name;
592 tree assembler_name;
593 tree params;
594{
595 function_format_info *info;
596
597 /* See if this function is a format function. */
598 for (info = function_format_list; info; info = info->next)
599 {
236236da 600 if (info->assembler_name
fce9faf9 601 ? (info->assembler_name == assembler_name)
602 : (info->name == name))
603 {
604 /* Yup; check it. */
605 check_format_info (info, params);
606 break;
607 }
608 }
609}
610
611/* Check the argument list of a call to printf, scanf, etc.
612 INFO points to the function_format_info structure.
613 PARAMS is the list of argument values. */
614
615static void
616check_format_info (info, params)
617 function_format_info *info;
618 tree params;
619{
620 int i;
621 int arg_num;
622 int suppressed, wide, precise;
623 int length_char;
624 int format_char;
625 int format_length;
626 tree format_tree;
627 tree cur_param;
628 tree cur_type;
629 tree wanted_type;
f19cab4a 630 tree first_fillin_param;
fce9faf9 631 char *format_chars;
632 format_char_info *fci;
633 static char message[132];
634 char flag_chars[8];
f19cab4a 635 int has_operand_number = 0;
fce9faf9 636
637 /* Skip to format argument. If the argument isn't available, there's
638 no work for us to do; prototype checking will catch the problem. */
639 for (arg_num = 1; ; ++arg_num)
640 {
641 if (params == 0)
642 return;
643 if (arg_num == info->format_num)
644 break;
645 params = TREE_CHAIN (params);
646 }
647 format_tree = TREE_VALUE (params);
648 params = TREE_CHAIN (params);
649 if (format_tree == 0)
650 return;
651 /* We can only check the format if it's a string constant. */
652 while (TREE_CODE (format_tree) == NOP_EXPR)
653 format_tree = TREE_OPERAND (format_tree, 0); /* strip coercion */
654 if (format_tree == null_pointer_node)
655 {
656 warning ("null format string");
657 return;
658 }
659 if (TREE_CODE (format_tree) != ADDR_EXPR)
660 return;
661 format_tree = TREE_OPERAND (format_tree, 0);
662 if (TREE_CODE (format_tree) != STRING_CST)
663 return;
664 format_chars = TREE_STRING_POINTER (format_tree);
665 format_length = TREE_STRING_LENGTH (format_tree);
666 if (format_length <= 1)
667 warning ("zero-length format string");
668 if (format_chars[--format_length] != 0)
669 {
670 warning ("unterminated format string");
671 return;
672 }
673 /* Skip to first argument to check. */
674 while (arg_num + 1 < info->first_arg_num)
675 {
676 if (params == 0)
677 return;
678 params = TREE_CHAIN (params);
679 ++arg_num;
680 }
f19cab4a 681
682 first_fillin_param = params;
fce9faf9 683 while (1)
684 {
63b97047 685 int aflag;
fce9faf9 686 if (*format_chars == 0)
687 {
688 if (format_chars - TREE_STRING_POINTER (format_tree) != format_length)
689 warning ("embedded `\\0' in format");
f19cab4a 690 if (info->first_arg_num != 0 && params != 0 && ! has_operand_number)
fce9faf9 691 warning ("too many arguments for format");
692 return;
693 }
694 if (*format_chars++ != '%')
695 continue;
696 if (*format_chars == 0)
697 {
698 warning ("spurious trailing `%%' in format");
699 continue;
700 }
701 if (*format_chars == '%')
702 {
703 ++format_chars;
704 continue;
705 }
706 flag_chars[0] = 0;
707 suppressed = wide = precise = FALSE;
708 if (info->is_scan)
709 {
710 suppressed = *format_chars == '*';
711 if (suppressed)
712 ++format_chars;
713 while (isdigit (*format_chars))
714 ++format_chars;
715 }
716 else
717 {
f19cab4a 718 /* See if we have a number followed by a dollar sign. If we do,
719 it is an operand number, so set PARAMS to that operand. */
720 if (*format_chars >= '0' && *format_chars <= '9')
721 {
722 char *p = format_chars;
723
724 while (*p >= '0' && *p++ <= '9')
725 ;
726
727 if (*p == '$')
728 {
729 int opnum = atoi (format_chars);
730
731 params = first_fillin_param;
732 format_chars = p + 1;
733 has_operand_number = 1;
734
735 for (i = 1; i < opnum && params != 0; i++)
736 params = TREE_CHAIN (params);
737
738 if (opnum == 0 || params == 0)
739 {
740 warning ("operand number out of range in format");
741 return;
742 }
743 }
744 }
745
fce9faf9 746 while (*format_chars != 0 && index (" +#0-", *format_chars) != 0)
747 {
748 if (index (flag_chars, *format_chars) != 0)
749 {
750 sprintf (message, "repeated `%c' flag in format",
751 *format_chars);
752 warning (message);
753 }
754 i = strlen (flag_chars);
755 flag_chars[i++] = *format_chars++;
756 flag_chars[i] = 0;
757 }
758 /* "If the space and + flags both appear,
759 the space flag will be ignored." */
760 if (index (flag_chars, ' ') != 0
761 && index (flag_chars, '+') != 0)
762 warning ("use of both ` ' and `+' flags in format");
763 /* "If the 0 and - flags both appear,
764 the 0 flag will be ignored." */
765 if (index (flag_chars, '0') != 0
766 && index (flag_chars, '-') != 0)
767 warning ("use of both `0' and `-' flags in format");
768 if (*format_chars == '*')
769 {
770 wide = TRUE;
771 /* "...a field width...may be indicated by an asterisk.
772 In this case, an int argument supplies the field width..." */
773 ++format_chars;
774 if (params == 0)
775 {
776 warning (tfaff);
777 return;
778 }
779 if (info->first_arg_num != 0)
780 {
781 cur_param = TREE_VALUE (params);
782 params = TREE_CHAIN (params);
783 ++arg_num;
784 /* size_t is generally not valid here.
785 It will work on most machines, because size_t and int
786 have the same mode. But might as well warn anyway,
787 since it will fail on other machines. */
cbc5b7d9 788 if ((TYPE_MAIN_VARIANT (TREE_TYPE (cur_param))
789 != integer_type_node)
790 &&
791 (TYPE_MAIN_VARIANT (TREE_TYPE (cur_param))
792 != unsigned_type_node))
fce9faf9 793 {
794 sprintf (message,
795 "field width is not type int (arg %d)",
796 arg_num);
797 warning (message);
798 }
799 }
800 }
801 else
802 {
803 while (isdigit (*format_chars))
804 {
805 wide = TRUE;
806 ++format_chars;
807 }
808 }
809 if (*format_chars == '.')
810 {
811 precise = TRUE;
812 ++format_chars;
813 if (*format_chars != '*' && !isdigit (*format_chars))
814 warning ("`.' not followed by `*' or digit in format");
815 /* "...a...precision...may be indicated by an asterisk.
816 In this case, an int argument supplies the...precision." */
817 if (*format_chars == '*')
818 {
819 if (info->first_arg_num != 0)
820 {
821 ++format_chars;
822 if (params == 0)
823 {
824 warning (tfaff);
825 return;
826 }
827 cur_param = TREE_VALUE (params);
828 params = TREE_CHAIN (params);
829 ++arg_num;
830 if (TYPE_MAIN_VARIANT (TREE_TYPE (cur_param))
831 != integer_type_node)
832 {
833 sprintf (message,
834 "field width is not type int (arg %d)",
835 arg_num);
836 warning (message);
837 }
838 }
839 }
840 else
841 {
842 while (isdigit (*format_chars))
843 ++format_chars;
844 }
845 }
846 }
847 if (*format_chars == 'h' || *format_chars == 'l' || *format_chars == 'L')
848 length_char = *format_chars++;
849 else
850 length_char = 0;
63b97047 851 aflag = 0;
852 if (*format_chars == 'a')
853 {
854 aflag = 1;
855 format_chars++;
856 }
fce9faf9 857 if (suppressed && length_char != 0)
858 {
859 sprintf (message,
860 "use of `*' and `%c' together in format",
861 length_char);
862 warning (message);
863 }
864 format_char = *format_chars;
865 if (format_char == 0)
866 {
867 warning ("conversion lacks type at end of format");
868 continue;
869 }
870 format_chars++;
871 fci = info->is_scan ? scan_char_table : print_char_table;
872 while (fci->format_chars != 0
873 && index (fci->format_chars, format_char) == 0)
874 ++fci;
875 if (fci->format_chars == 0)
876 {
877 if (format_char >= 040 && format_char < 0177)
878 sprintf (message,
879 "unknown conversion type character `%c' in format",
880 format_char);
881 else
882 sprintf (message,
883 "unknown conversion type character 0x%x in format",
884 format_char);
885 warning (message);
886 continue;
887 }
888 if (wide && index (fci->flag_chars, 'w') == 0)
889 {
890 sprintf (message, "width used with `%c' format",
891 format_char);
892 warning (message);
893 }
894 if (precise && index (fci->flag_chars, 'p') == 0)
895 {
896 sprintf (message, "precision used with `%c' format",
897 format_char);
898 warning (message);
63b97047 899 }
900 if (aflag && index (fci->flag_chars, 'a') == 0)
901 {
902 sprintf (message, "`a' flag used with `%c' format",
903 format_char);
904 warning (message);
fce9faf9 905 }
906 if (info->is_scan && format_char == '[')
907 {
908 /* Skip over scan set, in case it happens to have '%' in it. */
909 if (*format_chars == '^')
910 ++format_chars;
911 /* Find closing bracket; if one is hit immediately, then
912 it's part of the scan set rather than a terminator. */
913 if (*format_chars == ']')
914 ++format_chars;
915 while (*format_chars && *format_chars != ']')
916 ++format_chars;
917 if (*format_chars != ']')
918 /* The end of the format string was reached. */
919 warning ("no closing `]' for `%%[' format");
920 }
921 if (suppressed)
922 {
923 if (index (fci->flag_chars, '*') == 0)
924 {
925 sprintf (message,
926 "suppression of `%c' conversion in format",
927 format_char);
928 warning (message);
929 }
930 continue;
931 }
932 for (i = 0; flag_chars[i] != 0; ++i)
933 {
934 if (index (fci->flag_chars, flag_chars[i]) == 0)
935 {
936 sprintf (message, "flag `%c' used with type `%c'",
937 flag_chars[i], format_char);
938 warning (message);
939 }
940 }
941 if (precise && index (flag_chars, '0') != 0
942 && (format_char == 'd' || format_char == 'i'
943 || format_char == 'o' || format_char == 'u'
944 || format_char == 'x' || format_char == 'x'))
945 {
946 sprintf (message,
947 "precision and `0' flag not both allowed with `%c' format",
948 format_char);
949 warning (message);
950 }
951 switch (length_char)
952 {
953 default: wanted_type = fci->nolen ? *(fci->nolen) : 0; break;
954 case 'h': wanted_type = fci->hlen ? *(fci->hlen) : 0; break;
955 case 'l': wanted_type = fci->llen ? *(fci->llen) : 0; break;
956 case 'L': wanted_type = fci->bigllen ? *(fci->bigllen) : 0; break;
957 }
958 if (wanted_type == 0)
959 {
960 sprintf (message,
961 "use of `%c' length character with `%c' type character",
962 length_char, format_char);
963 warning (message);
964 }
965
966 /*
967 ** XXX -- should kvetch about stuff such as
968 ** {
969 ** const int i;
970 **
971 ** scanf ("%d", &i);
972 ** }
973 */
974
975 /* Finally. . .check type of argument against desired type! */
976 if (info->first_arg_num == 0)
977 continue;
978 if (params == 0)
979 {
980 warning (tfaff);
981 return;
982 }
983 cur_param = TREE_VALUE (params);
984 params = TREE_CHAIN (params);
985 ++arg_num;
986 cur_type = TREE_TYPE (cur_param);
987
988 /* Check the types of any additional pointer arguments
989 that precede the "real" argument. */
990 for (i = 0; i < fci->pointer_count; ++i)
991 {
992 if (TREE_CODE (cur_type) == POINTER_TYPE)
993 {
994 cur_type = TREE_TYPE (cur_type);
995 continue;
996 }
997 sprintf (message,
998 "format argument is not a %s (arg %d)",
999 ((fci->pointer_count == 1) ? "pointer" : "pointer to a pointer"),
1000 arg_num);
1001 warning (message);
1002 break;
1003 }
1004
1005 /* Check the type of the "real" argument, if there's a type we want. */
1006 if (i == fci->pointer_count && wanted_type != 0
1007 && wanted_type != TYPE_MAIN_VARIANT (cur_type)
1008 /* If we want `void *', allow any pointer type.
1009 (Anything else would already have got a warning.) */
1010 && ! (wanted_type == void_type_node
1011 && fci->pointer_count > 0)
1012 /* Don't warn about differences merely in signedness. */
1013 && !(TREE_CODE (wanted_type) == INTEGER_TYPE
78dafd61 1014 && TREE_CODE (TYPE_MAIN_VARIANT (cur_type)) == INTEGER_TYPE
8200cbb2 1015 && (TREE_UNSIGNED (wanted_type)
4ef20085 1016 ? wanted_type == (cur_type = unsigned_type (cur_type))
1017 : wanted_type == (cur_type = signed_type (cur_type))))
641dd458 1018 /* Likewise, "signed char", "unsigned char" and "char" are
1019 equivalent but the above test won't consider them equivalent. */
1020 && ! (wanted_type == char_type_node
78dafd61 1021 && (TYPE_MAIN_VARIANT (cur_type) == signed_char_type_node
1022 || TYPE_MAIN_VARIANT (cur_type) == unsigned_char_type_node)))
fce9faf9 1023 {
1024 register char *this;
1025 register char *that;
1026
1027 this = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (wanted_type)));
1028 that = 0;
1029 if (TREE_CODE (cur_type) != ERROR_MARK
1030 && TYPE_NAME (cur_type) != 0
1031 && TREE_CODE (cur_type) != INTEGER_TYPE
1032 && !(TREE_CODE (cur_type) == POINTER_TYPE
1033 && TREE_CODE (TREE_TYPE (cur_type)) == INTEGER_TYPE))
1034 {
1035 if (TREE_CODE (TYPE_NAME (cur_type)) == TYPE_DECL
1036 && DECL_NAME (TYPE_NAME (cur_type)) != 0)
1037 that = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (cur_type)));
1038 else
1039 that = IDENTIFIER_POINTER (TYPE_NAME (cur_type));
1040 }
1041
1042 /* A nameless type can't possibly match what the format wants.
1043 So there will be a warning for it.
1044 Make up a string to describe vaguely what it is. */
1045 if (that == 0)
1046 {
1047 if (TREE_CODE (cur_type) == POINTER_TYPE)
1048 that = "pointer";
1049 else
1050 that = "different type";
1051 }
1052
cbc5b7d9 1053 /* Make the warning better in case of mismatch of int vs long. */
1054 if (TREE_CODE (cur_type) == INTEGER_TYPE
1055 && TREE_CODE (wanted_type) == INTEGER_TYPE
1056 && TYPE_PRECISION (cur_type) == TYPE_PRECISION (wanted_type)
1057 && TYPE_NAME (cur_type) != 0
1058 && TREE_CODE (TYPE_NAME (cur_type)) == TYPE_DECL)
1059 that = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (cur_type)));
1060
fce9faf9 1061 if (strcmp (this, that) != 0)
1062 {
1063 sprintf (message, "%s format, %s arg (arg %d)",
1064 this, that, arg_num);
1065 warning (message);
1066 }
1067 }
1068 }
1069}
1070\f
2a1736ed 1071/* Print a warning if a constant expression had overflow in folding.
1072 Invoke this function on every expression that the language
1073 requires to be a constant expression.
1074 Note the ANSI C standard says it is erroneous for a
1075 constant expression to overflow. */
b2806639 1076
1077void
1078constant_expression_warning (value)
1079 tree value;
1080{
837e1122 1081 if ((TREE_CODE (value) == INTEGER_CST || TREE_CODE (value) == REAL_CST
1082 || TREE_CODE (value) == COMPLEX_CST)
1083 && TREE_CONSTANT_OVERFLOW (value) && pedantic)
1084 pedwarn ("overflow in constant expression");
2a1736ed 1085}
1086
1087/* Print a warning if an expression had overflow in folding.
1088 Invoke this function on every expression that
1089 (1) appears in the source code, and
1090 (2) might be a constant expression that overflowed, and
1091 (3) is not already checked by convert_and_check;
1092 however, do not invoke this function on operands of explicit casts. */
1093
1094void
1095overflow_warning (value)
1096 tree value;
1097{
837e1122 1098 if ((TREE_CODE (value) == INTEGER_CST
1099 || (TREE_CODE (value) == COMPLEX_CST
1100 && TREE_CODE (TREE_REALPART (value)) == INTEGER_CST))
1101 && TREE_OVERFLOW (value))
2a1736ed 1102 {
b04da9b5 1103 TREE_OVERFLOW (value) = 0;
d50a966a 1104 warning ("integer overflow in expression");
2a1736ed 1105 }
837e1122 1106 else if ((TREE_CODE (value) == REAL_CST
1107 || (TREE_CODE (value) == COMPLEX_CST
1108 && TREE_CODE (TREE_REALPART (value)) == REAL_CST))
1109 && TREE_OVERFLOW (value))
1110 {
1111 TREE_OVERFLOW (value) = 0;
1112 warning ("floating-pointer overflow in expression");
1113 }
2a1736ed 1114}
1115
1116/* Print a warning if a large constant is truncated to unsigned,
1117 or if -Wconversion is used and a constant < 0 is converted to unsigned.
1118 Invoke this function on every expression that might be implicitly
1119 converted to an unsigned type. */
1120
1121void
1122unsigned_conversion_warning (result, operand)
1123 tree result, operand;
1124{
1125 if (TREE_CODE (operand) == INTEGER_CST
1126 && TREE_CODE (TREE_TYPE (result)) == INTEGER_TYPE
1127 && TREE_UNSIGNED (TREE_TYPE (result))
1128 && !int_fits_type_p (operand, TREE_TYPE (result)))
1129 {
1130 if (!int_fits_type_p (operand, signed_type (TREE_TYPE (result))))
1131 /* This detects cases like converting -129 or 256 to unsigned char. */
454b5afb 1132 warning ("large integer implicitly truncated to unsigned type");
2a1736ed 1133 else if (warn_conversion)
454b5afb 1134 warning ("negative integer implicitly converted to unsigned type");
2a1736ed 1135 }
1136}
1137
1138/* Convert EXPR to TYPE, warning about conversion problems with constants.
1139 Invoke this function on every expression that is converted implicitly,
1140 i.e. because of language rules and not because of an explicit cast. */
1141
1142tree
1143convert_and_check (type, expr)
1144 tree type, expr;
1145{
1146 tree t = convert (type, expr);
1147 if (TREE_CODE (t) == INTEGER_CST)
1148 {
b04da9b5 1149 if (TREE_OVERFLOW (t))
2a1736ed 1150 {
b04da9b5 1151 TREE_OVERFLOW (t) = 0;
1152
1153 /* No warning for converting 0x80000000 to int. */
1154 if (!(TREE_UNSIGNED (type) < TREE_UNSIGNED (TREE_TYPE (expr))
1155 && TREE_CODE (TREE_TYPE (expr)) == INTEGER_TYPE
1156 && TYPE_PRECISION (type) == TYPE_PRECISION (TREE_TYPE (expr))))
96730c20 1157 /* If EXPR fits in the unsigned version of TYPE,
1158 don't warn unless pedantic. */
1159 if (pedantic
1160 || TREE_UNSIGNED (type)
1161 || ! int_fits_type_p (expr, unsigned_type (type)))
1162 warning ("overflow in implicit constant conversion");
2a1736ed 1163 }
1164 else
1165 unsigned_conversion_warning (t, expr);
1166 }
1167 return t;
b2806639 1168}
1169\f
b0fc3e72 1170void
1171c_expand_expr_stmt (expr)
1172 tree expr;
1173{
1174 /* Do default conversion if safe and possibly important,
1175 in case within ({...}). */
1176 if ((TREE_CODE (TREE_TYPE (expr)) == ARRAY_TYPE && lvalue_p (expr))
1177 || TREE_CODE (TREE_TYPE (expr)) == FUNCTION_TYPE)
1178 expr = default_conversion (expr);
1179
1180 if (TREE_TYPE (expr) != error_mark_node
1181 && TYPE_SIZE (TREE_TYPE (expr)) == 0
1182 && TREE_CODE (TREE_TYPE (expr)) != ARRAY_TYPE)
1183 error ("expression statement has incomplete type");
1184
1185 expand_expr_stmt (expr);
1186}
1187\f
1188/* Validate the expression after `case' and apply default promotions. */
1189
1190tree
1191check_case_value (value)
1192 tree value;
1193{
1194 if (value == NULL_TREE)
1195 return value;
1196
1197 /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue. */
fce1d6af 1198 STRIP_TYPE_NOPS (value);
b0fc3e72 1199
1200 if (TREE_CODE (value) != INTEGER_CST
1201 && value != error_mark_node)
1202 {
1203 error ("case label does not reduce to an integer constant");
1204 value = error_mark_node;
1205 }
1206 else
1207 /* Promote char or short to int. */
1208 value = default_conversion (value);
1209
6433f1c2 1210 constant_expression_warning (value);
1211
b0fc3e72 1212 return value;
1213}
1214\f
1215/* Return an integer type with BITS bits of precision,
1216 that is unsigned if UNSIGNEDP is nonzero, otherwise signed. */
1217
1218tree
1219type_for_size (bits, unsignedp)
1220 unsigned bits;
1221 int unsignedp;
1222{
bacde65a 1223 if (bits == TYPE_PRECISION (signed_char_type_node))
b0fc3e72 1224 return unsignedp ? unsigned_char_type_node : signed_char_type_node;
1225
bacde65a 1226 if (bits == TYPE_PRECISION (short_integer_type_node))
b0fc3e72 1227 return unsignedp ? short_unsigned_type_node : short_integer_type_node;
1228
bacde65a 1229 if (bits == TYPE_PRECISION (integer_type_node))
b0fc3e72 1230 return unsignedp ? unsigned_type_node : integer_type_node;
1231
bacde65a 1232 if (bits == TYPE_PRECISION (long_integer_type_node))
b0fc3e72 1233 return unsignedp ? long_unsigned_type_node : long_integer_type_node;
1234
bacde65a 1235 if (bits == TYPE_PRECISION (long_long_integer_type_node))
b0fc3e72 1236 return (unsignedp ? long_long_unsigned_type_node
1237 : long_long_integer_type_node);
1238
bacde65a 1239 if (bits <= TYPE_PRECISION (intQI_type_node))
1240 return unsignedp ? unsigned_intQI_type_node : intQI_type_node;
1241
1242 if (bits <= TYPE_PRECISION (intHI_type_node))
1243 return unsignedp ? unsigned_intHI_type_node : intHI_type_node;
1244
1245 if (bits <= TYPE_PRECISION (intSI_type_node))
1246 return unsignedp ? unsigned_intSI_type_node : intSI_type_node;
1247
1248 if (bits <= TYPE_PRECISION (intDI_type_node))
1249 return unsignedp ? unsigned_intDI_type_node : intDI_type_node;
1250
b0fc3e72 1251 return 0;
1252}
1253
1254/* Return a data type that has machine mode MODE.
1255 If the mode is an integer,
1256 then UNSIGNEDP selects between signed and unsigned types. */
1257
1258tree
1259type_for_mode (mode, unsignedp)
1260 enum machine_mode mode;
1261 int unsignedp;
1262{
1263 if (mode == TYPE_MODE (signed_char_type_node))
1264 return unsignedp ? unsigned_char_type_node : signed_char_type_node;
1265
1266 if (mode == TYPE_MODE (short_integer_type_node))
1267 return unsignedp ? short_unsigned_type_node : short_integer_type_node;
1268
1269 if (mode == TYPE_MODE (integer_type_node))
1270 return unsignedp ? unsigned_type_node : integer_type_node;
1271
1272 if (mode == TYPE_MODE (long_integer_type_node))
1273 return unsignedp ? long_unsigned_type_node : long_integer_type_node;
1274
1275 if (mode == TYPE_MODE (long_long_integer_type_node))
1276 return unsignedp ? long_long_unsigned_type_node : long_long_integer_type_node;
1277
bacde65a 1278 if (mode == TYPE_MODE (intQI_type_node))
1279 return unsignedp ? unsigned_intQI_type_node : intQI_type_node;
1280
1281 if (mode == TYPE_MODE (intHI_type_node))
1282 return unsignedp ? unsigned_intHI_type_node : intHI_type_node;
1283
1284 if (mode == TYPE_MODE (intSI_type_node))
1285 return unsignedp ? unsigned_intSI_type_node : intSI_type_node;
1286
1287 if (mode == TYPE_MODE (intDI_type_node))
1288 return unsignedp ? unsigned_intDI_type_node : intDI_type_node;
1289
b0fc3e72 1290 if (mode == TYPE_MODE (float_type_node))
1291 return float_type_node;
1292
1293 if (mode == TYPE_MODE (double_type_node))
1294 return double_type_node;
1295
1296 if (mode == TYPE_MODE (long_double_type_node))
1297 return long_double_type_node;
1298
1299 if (mode == TYPE_MODE (build_pointer_type (char_type_node)))
1300 return build_pointer_type (char_type_node);
1301
1302 if (mode == TYPE_MODE (build_pointer_type (integer_type_node)))
1303 return build_pointer_type (integer_type_node);
1304
1305 return 0;
1306}
1307\f
1308/* Print an error message for invalid operands to arith operation CODE.
1309 NOP_EXPR is used as a special case (see truthvalue_conversion). */
1310
1311void
1312binary_op_error (code)
1313 enum tree_code code;
1314{
f03946e4 1315 register char *opname = "unknown";
1316
b0fc3e72 1317 switch (code)
1318 {
1319 case NOP_EXPR:
1320 error ("invalid truth-value expression");
1321 return;
1322
1323 case PLUS_EXPR:
1324 opname = "+"; break;
1325 case MINUS_EXPR:
1326 opname = "-"; break;
1327 case MULT_EXPR:
1328 opname = "*"; break;
1329 case MAX_EXPR:
1330 opname = "max"; break;
1331 case MIN_EXPR:
1332 opname = "min"; break;
1333 case EQ_EXPR:
1334 opname = "=="; break;
1335 case NE_EXPR:
1336 opname = "!="; break;
1337 case LE_EXPR:
1338 opname = "<="; break;
1339 case GE_EXPR:
1340 opname = ">="; break;
1341 case LT_EXPR:
1342 opname = "<"; break;
1343 case GT_EXPR:
1344 opname = ">"; break;
1345 case LSHIFT_EXPR:
1346 opname = "<<"; break;
1347 case RSHIFT_EXPR:
1348 opname = ">>"; break;
1349 case TRUNC_MOD_EXPR:
66618a1e 1350 case FLOOR_MOD_EXPR:
b0fc3e72 1351 opname = "%"; break;
1352 case TRUNC_DIV_EXPR:
66618a1e 1353 case FLOOR_DIV_EXPR:
b0fc3e72 1354 opname = "/"; break;
1355 case BIT_AND_EXPR:
1356 opname = "&"; break;
1357 case BIT_IOR_EXPR:
1358 opname = "|"; break;
1359 case TRUTH_ANDIF_EXPR:
1360 opname = "&&"; break;
1361 case TRUTH_ORIF_EXPR:
1362 opname = "||"; break;
1363 case BIT_XOR_EXPR:
1364 opname = "^"; break;
66618a1e 1365 case LROTATE_EXPR:
1366 case RROTATE_EXPR:
1367 opname = "rotate"; break;
b0fc3e72 1368 }
1369 error ("invalid operands to binary %s", opname);
1370}
1371\f
1372/* Subroutine of build_binary_op, used for comparison operations.
1373 See if the operands have both been converted from subword integer types
1374 and, if so, perhaps change them both back to their original type.
5b511807 1375 This function is also responsible for converting the two operands
1376 to the proper common type for comparison.
b0fc3e72 1377
1378 The arguments of this function are all pointers to local variables
1379 of build_binary_op: OP0_PTR is &OP0, OP1_PTR is &OP1,
1380 RESTYPE_PTR is &RESULT_TYPE and RESCODE_PTR is &RESULTCODE.
1381
1382 If this function returns nonzero, it means that the comparison has
1383 a constant value. What this function returns is an expression for
1384 that value. */
1385
1386tree
1387shorten_compare (op0_ptr, op1_ptr, restype_ptr, rescode_ptr)
1388 tree *op0_ptr, *op1_ptr;
1389 tree *restype_ptr;
1390 enum tree_code *rescode_ptr;
1391{
1392 register tree type;
1393 tree op0 = *op0_ptr;
1394 tree op1 = *op1_ptr;
1395 int unsignedp0, unsignedp1;
1396 int real1, real2;
1397 tree primop0, primop1;
1398 enum tree_code code = *rescode_ptr;
1399
1400 /* Throw away any conversions to wider types
1401 already present in the operands. */
1402
1403 primop0 = get_narrower (op0, &unsignedp0);
1404 primop1 = get_narrower (op1, &unsignedp1);
1405
1406 /* Handle the case that OP0 does not *contain* a conversion
1407 but it *requires* conversion to FINAL_TYPE. */
1408
1409 if (op0 == primop0 && TREE_TYPE (op0) != *restype_ptr)
1410 unsignedp0 = TREE_UNSIGNED (TREE_TYPE (op0));
1411 if (op1 == primop1 && TREE_TYPE (op1) != *restype_ptr)
1412 unsignedp1 = TREE_UNSIGNED (TREE_TYPE (op1));
1413
1414 /* If one of the operands must be floated, we cannot optimize. */
1415 real1 = TREE_CODE (TREE_TYPE (primop0)) == REAL_TYPE;
1416 real2 = TREE_CODE (TREE_TYPE (primop1)) == REAL_TYPE;
1417
1418 /* If first arg is constant, swap the args (changing operation
1419 so value is preserved), for canonicalization. */
1420
1421 if (TREE_CONSTANT (primop0))
1422 {
1423 register tree tem = primop0;
1424 register int temi = unsignedp0;
1425 primop0 = primop1;
1426 primop1 = tem;
1427 tem = op0;
1428 op0 = op1;
1429 op1 = tem;
1430 *op0_ptr = op0;
1431 *op1_ptr = op1;
1432 unsignedp0 = unsignedp1;
1433 unsignedp1 = temi;
1434 temi = real1;
1435 real1 = real2;
1436 real2 = temi;
1437
1438 switch (code)
1439 {
1440 case LT_EXPR:
1441 code = GT_EXPR;
1442 break;
1443 case GT_EXPR:
1444 code = LT_EXPR;
1445 break;
1446 case LE_EXPR:
1447 code = GE_EXPR;
1448 break;
1449 case GE_EXPR:
1450 code = LE_EXPR;
1451 break;
1452 }
1453 *rescode_ptr = code;
1454 }
1455
1456 /* If comparing an integer against a constant more bits wide,
1457 maybe we can deduce a value of 1 or 0 independent of the data.
1458 Or else truncate the constant now
1459 rather than extend the variable at run time.
1460
1461 This is only interesting if the constant is the wider arg.
1462 Also, it is not safe if the constant is unsigned and the
1463 variable arg is signed, since in this case the variable
1464 would be sign-extended and then regarded as unsigned.
1465 Our technique fails in this case because the lowest/highest
1466 possible unsigned results don't follow naturally from the
1467 lowest/highest possible values of the variable operand.
1468 For just EQ_EXPR and NE_EXPR there is another technique that
1469 could be used: see if the constant can be faithfully represented
1470 in the other operand's type, by truncating it and reextending it
1471 and see if that preserves the constant's value. */
1472
1473 if (!real1 && !real2
1474 && TREE_CODE (primop1) == INTEGER_CST
1475 && TYPE_PRECISION (TREE_TYPE (primop0)) < TYPE_PRECISION (*restype_ptr))
1476 {
1477 int min_gt, max_gt, min_lt, max_lt;
1478 tree maxval, minval;
1479 /* 1 if comparison is nominally unsigned. */
1480 int unsignedp = TREE_UNSIGNED (*restype_ptr);
1481 tree val;
1482
1483 type = signed_or_unsigned_type (unsignedp0, TREE_TYPE (primop0));
1484
1485 maxval = TYPE_MAX_VALUE (type);
1486 minval = TYPE_MIN_VALUE (type);
1487
1488 if (unsignedp && !unsignedp0)
1489 *restype_ptr = signed_type (*restype_ptr);
1490
1491 if (TREE_TYPE (primop1) != *restype_ptr)
1492 primop1 = convert (*restype_ptr, primop1);
1493 if (type != *restype_ptr)
1494 {
1495 minval = convert (*restype_ptr, minval);
1496 maxval = convert (*restype_ptr, maxval);
1497 }
1498
1499 if (unsignedp && unsignedp0)
1500 {
1501 min_gt = INT_CST_LT_UNSIGNED (primop1, minval);
1502 max_gt = INT_CST_LT_UNSIGNED (primop1, maxval);
1503 min_lt = INT_CST_LT_UNSIGNED (minval, primop1);
1504 max_lt = INT_CST_LT_UNSIGNED (maxval, primop1);
1505 }
1506 else
1507 {
1508 min_gt = INT_CST_LT (primop1, minval);
1509 max_gt = INT_CST_LT (primop1, maxval);
1510 min_lt = INT_CST_LT (minval, primop1);
1511 max_lt = INT_CST_LT (maxval, primop1);
1512 }
1513
1514 val = 0;
1515 /* This used to be a switch, but Genix compiler can't handle that. */
1516 if (code == NE_EXPR)
1517 {
1518 if (max_lt || min_gt)
1519 val = integer_one_node;
1520 }
1521 else if (code == EQ_EXPR)
1522 {
1523 if (max_lt || min_gt)
1524 val = integer_zero_node;
1525 }
1526 else if (code == LT_EXPR)
1527 {
1528 if (max_lt)
1529 val = integer_one_node;
1530 if (!min_lt)
1531 val = integer_zero_node;
1532 }
1533 else if (code == GT_EXPR)
1534 {
1535 if (min_gt)
1536 val = integer_one_node;
1537 if (!max_gt)
1538 val = integer_zero_node;
1539 }
1540 else if (code == LE_EXPR)
1541 {
1542 if (!max_gt)
1543 val = integer_one_node;
1544 if (min_gt)
1545 val = integer_zero_node;
1546 }
1547 else if (code == GE_EXPR)
1548 {
1549 if (!min_lt)
1550 val = integer_one_node;
1551 if (max_lt)
1552 val = integer_zero_node;
1553 }
1554
1555 /* If primop0 was sign-extended and unsigned comparison specd,
1556 we did a signed comparison above using the signed type bounds.
1557 But the comparison we output must be unsigned.
1558
1559 Also, for inequalities, VAL is no good; but if the signed
1560 comparison had *any* fixed result, it follows that the
1561 unsigned comparison just tests the sign in reverse
1562 (positive values are LE, negative ones GE).
1563 So we can generate an unsigned comparison
1564 against an extreme value of the signed type. */
1565
1566 if (unsignedp && !unsignedp0)
1567 {
1568 if (val != 0)
1569 switch (code)
1570 {
1571 case LT_EXPR:
1572 case GE_EXPR:
1573 primop1 = TYPE_MIN_VALUE (type);
1574 val = 0;
1575 break;
1576
1577 case LE_EXPR:
1578 case GT_EXPR:
1579 primop1 = TYPE_MAX_VALUE (type);
1580 val = 0;
1581 break;
1582 }
1583 type = unsigned_type (type);
1584 }
1585
78dafd61 1586 if (!max_gt && !unsignedp0 && TREE_CODE (primop0) != INTEGER_CST)
b0fc3e72 1587 {
1588 /* This is the case of (char)x >?< 0x80, which people used to use
1589 expecting old C compilers to change the 0x80 into -0x80. */
1590 if (val == integer_zero_node)
1591 warning ("comparison is always 0 due to limited range of data type");
1592 if (val == integer_one_node)
1593 warning ("comparison is always 1 due to limited range of data type");
1594 }
1595
78dafd61 1596 if (!min_lt && unsignedp0 && TREE_CODE (primop0) != INTEGER_CST)
b0fc3e72 1597 {
a693ee7d 1598 /* This is the case of (unsigned char)x >?< -1 or < 0. */
b0fc3e72 1599 if (val == integer_zero_node)
1600 warning ("comparison is always 0 due to limited range of data type");
1601 if (val == integer_one_node)
1602 warning ("comparison is always 1 due to limited range of data type");
1603 }
1604
1605 if (val != 0)
1606 {
1607 /* Don't forget to evaluate PRIMOP0 if it has side effects. */
1608 if (TREE_SIDE_EFFECTS (primop0))
1609 return build (COMPOUND_EXPR, TREE_TYPE (val), primop0, val);
1610 return val;
1611 }
1612
1613 /* Value is not predetermined, but do the comparison
1614 in the type of the operand that is not constant.
1615 TYPE is already properly set. */
1616 }
1617 else if (real1 && real2
2203bd5c 1618 && (TYPE_PRECISION (TREE_TYPE (primop0))
1619 == TYPE_PRECISION (TREE_TYPE (primop1))))
b0fc3e72 1620 type = TREE_TYPE (primop0);
1621
1622 /* If args' natural types are both narrower than nominal type
1623 and both extend in the same manner, compare them
1624 in the type of the wider arg.
1625 Otherwise must actually extend both to the nominal
1626 common type lest different ways of extending
1627 alter the result.
1628 (eg, (short)-1 == (unsigned short)-1 should be 0.) */
1629
1630 else if (unsignedp0 == unsignedp1 && real1 == real2
1631 && TYPE_PRECISION (TREE_TYPE (primop0)) < TYPE_PRECISION (*restype_ptr)
1632 && TYPE_PRECISION (TREE_TYPE (primop1)) < TYPE_PRECISION (*restype_ptr))
1633 {
1634 type = common_type (TREE_TYPE (primop0), TREE_TYPE (primop1));
1635 type = signed_or_unsigned_type (unsignedp0
1636 || TREE_UNSIGNED (*restype_ptr),
1637 type);
1638 /* Make sure shorter operand is extended the right way
1639 to match the longer operand. */
1640 primop0 = convert (signed_or_unsigned_type (unsignedp0, TREE_TYPE (primop0)),
1641 primop0);
1642 primop1 = convert (signed_or_unsigned_type (unsignedp1, TREE_TYPE (primop1)),
1643 primop1);
1644 }
1645 else
1646 {
1647 /* Here we must do the comparison on the nominal type
1648 using the args exactly as we received them. */
1649 type = *restype_ptr;
1650 primop0 = op0;
1651 primop1 = op1;
1652
1653 if (!real1 && !real2 && integer_zerop (primop1)
1654 && TREE_UNSIGNED (TREE_TYPE (primop0)))
1655 {
1656 tree value = 0;
1657 switch (code)
1658 {
1659 case GE_EXPR:
1660 if (extra_warnings)
1661 warning ("unsigned value >= 0 is always 1");
1662 value = integer_one_node;
1663 break;
1664
1665 case LT_EXPR:
1666 if (extra_warnings)
1667 warning ("unsigned value < 0 is always 0");
1668 value = integer_zero_node;
1669 }
1670
1671 if (value != 0)
1672 {
1673 /* Don't forget to evaluate PRIMOP0 if it has side effects. */
1674 if (TREE_SIDE_EFFECTS (primop0))
1675 return build (COMPOUND_EXPR, TREE_TYPE (value),
1676 primop0, value);
1677 return value;
1678 }
1679 }
1680 }
1681
1682 *op0_ptr = convert (type, primop0);
1683 *op1_ptr = convert (type, primop1);
1684
1685 *restype_ptr = integer_type_node;
1686
1687 return 0;
1688}
1689\f
1690/* Prepare expr to be an argument of a TRUTH_NOT_EXPR,
1691 or validate its data type for an `if' or `while' statement or ?..: exp.
1692
1693 This preparation consists of taking the ordinary
1694 representation of an expression expr and producing a valid tree
1695 boolean expression describing whether expr is nonzero. We could
1696 simply always do build_binary_op (NE_EXPR, expr, integer_zero_node, 1),
1697 but we optimize comparisons, &&, ||, and !.
1698
1699 The resulting type should always be `integer_type_node'. */
1700
1701tree
1702truthvalue_conversion (expr)
1703 tree expr;
1704{
1705 register enum tree_code code;
1706
baa1f4f5 1707 if (TREE_CODE (expr) == ERROR_MARK)
1708 return expr;
1709
a70adbe5 1710#if 0 /* This appears to be wrong for C++. */
baa1f4f5 1711 /* These really should return error_mark_node after 2.4 is stable.
1712 But not all callers handle ERROR_MARK properly. */
1713 switch (TREE_CODE (TREE_TYPE (expr)))
1714 {
1715 case RECORD_TYPE:
1716 error ("struct type value used where scalar is required");
1717 return integer_zero_node;
1718
1719 case UNION_TYPE:
1720 error ("union type value used where scalar is required");
1721 return integer_zero_node;
1722
1723 case ARRAY_TYPE:
1724 error ("array type value used where scalar is required");
1725 return integer_zero_node;
1726
1727 default:
1728 break;
1729 }
a70adbe5 1730#endif /* 0 */
baa1f4f5 1731
b0fc3e72 1732 switch (TREE_CODE (expr))
1733 {
1734 /* It is simpler and generates better code to have only TRUTH_*_EXPR
1735 or comparison expressions as truth values at this level. */
1736#if 0
1737 case COMPONENT_REF:
1738 /* A one-bit unsigned bit-field is already acceptable. */
1739 if (1 == TREE_INT_CST_LOW (DECL_SIZE (TREE_OPERAND (expr, 1)))
1740 && TREE_UNSIGNED (TREE_OPERAND (expr, 1)))
1741 return expr;
1742 break;
1743#endif
1744
1745 case EQ_EXPR:
1746 /* It is simpler and generates better code to have only TRUTH_*_EXPR
1747 or comparison expressions as truth values at this level. */
1748#if 0
1749 if (integer_zerop (TREE_OPERAND (expr, 1)))
1750 return build_unary_op (TRUTH_NOT_EXPR, TREE_OPERAND (expr, 0), 0);
1751#endif
1752 case NE_EXPR: case LE_EXPR: case GE_EXPR: case LT_EXPR: case GT_EXPR:
1753 case TRUTH_ANDIF_EXPR:
1754 case TRUTH_ORIF_EXPR:
1755 case TRUTH_AND_EXPR:
1756 case TRUTH_OR_EXPR:
31f6e93c 1757 case TRUTH_XOR_EXPR:
3e851b85 1758 return convert (integer_type_node, expr);
1759
b0fc3e72 1760 case ERROR_MARK:
1761 return expr;
1762
1763 case INTEGER_CST:
1764 return integer_zerop (expr) ? integer_zero_node : integer_one_node;
1765
1766 case REAL_CST:
1767 return real_zerop (expr) ? integer_zero_node : integer_one_node;
1768
1769 case ADDR_EXPR:
1770 if (TREE_SIDE_EFFECTS (TREE_OPERAND (expr, 0)))
1771 return build (COMPOUND_EXPR, integer_type_node,
1772 TREE_OPERAND (expr, 0), integer_one_node);
1773 else
1774 return integer_one_node;
1775
2203bd5c 1776 case COMPLEX_EXPR:
2ba726d2 1777 return build_binary_op ((TREE_SIDE_EFFECTS (TREE_OPERAND (expr, 1))
95809de4 1778 ? TRUTH_OR_EXPR : TRUTH_ORIF_EXPR),
2ba726d2 1779 truthvalue_conversion (TREE_OPERAND (expr, 0)),
1780 truthvalue_conversion (TREE_OPERAND (expr, 1)),
2203bd5c 1781 0);
1782
b0fc3e72 1783 case NEGATE_EXPR:
1784 case ABS_EXPR:
1785 case FLOAT_EXPR:
1786 case FFS_EXPR:
1787 /* These don't change whether an object is non-zero or zero. */
1788 return truthvalue_conversion (TREE_OPERAND (expr, 0));
1789
1790 case LROTATE_EXPR:
1791 case RROTATE_EXPR:
1792 /* These don't change whether an object is zero or non-zero, but
1793 we can't ignore them if their second arg has side-effects. */
1794 if (TREE_SIDE_EFFECTS (TREE_OPERAND (expr, 1)))
1795 return build (COMPOUND_EXPR, integer_type_node, TREE_OPERAND (expr, 1),
1796 truthvalue_conversion (TREE_OPERAND (expr, 0)));
1797 else
1798 return truthvalue_conversion (TREE_OPERAND (expr, 0));
1799
1800 case COND_EXPR:
1801 /* Distribute the conversion into the arms of a COND_EXPR. */
1802 return fold (build (COND_EXPR, integer_type_node, TREE_OPERAND (expr, 0),
1803 truthvalue_conversion (TREE_OPERAND (expr, 1)),
1804 truthvalue_conversion (TREE_OPERAND (expr, 2))));
1805
1806 case CONVERT_EXPR:
1807 /* Don't cancel the effect of a CONVERT_EXPR from a REFERENCE_TYPE,
1808 since that affects how `default_conversion' will behave. */
1809 if (TREE_CODE (TREE_TYPE (expr)) == REFERENCE_TYPE
1810 || TREE_CODE (TREE_TYPE (TREE_OPERAND (expr, 0))) == REFERENCE_TYPE)
1811 break;
1812 /* fall through... */
1813 case NOP_EXPR:
1814 /* If this is widening the argument, we can ignore it. */
1815 if (TYPE_PRECISION (TREE_TYPE (expr))
1816 >= TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (expr, 0))))
1817 return truthvalue_conversion (TREE_OPERAND (expr, 0));
1818 break;
1819
b0fc3e72 1820 case MINUS_EXPR:
fe0a0255 1821 /* With IEEE arithmetic, x - x may not equal 0, so we can't optimize
1822 this case. */
1823 if (TARGET_FLOAT_FORMAT == IEEE_FLOAT_FORMAT
1824 && TREE_CODE (TREE_TYPE (expr)) == REAL_TYPE)
1825 break;
1826 /* fall through... */
1827 case BIT_XOR_EXPR:
a70adbe5 1828 /* This and MINUS_EXPR can be changed into a comparison of the
fe0a0255 1829 two objects. */
b0fc3e72 1830 if (TREE_TYPE (TREE_OPERAND (expr, 0))
1831 == TREE_TYPE (TREE_OPERAND (expr, 1)))
1832 return build_binary_op (NE_EXPR, TREE_OPERAND (expr, 0),
1833 TREE_OPERAND (expr, 1), 1);
1834 return build_binary_op (NE_EXPR, TREE_OPERAND (expr, 0),
1835 fold (build1 (NOP_EXPR,
1836 TREE_TYPE (TREE_OPERAND (expr, 0)),
1837 TREE_OPERAND (expr, 1))), 1);
16837b18 1838
1839 case MODIFY_EXPR:
1840 if (warn_parentheses && C_EXP_ORIGINAL_CODE (expr) == MODIFY_EXPR)
1841 warning ("suggest parentheses around assignment used as truth value");
1842 break;
b0fc3e72 1843 }
1844
2ba726d2 1845 if (TREE_CODE (TREE_TYPE (expr)) == COMPLEX_TYPE)
1846 return (build_binary_op
1847 ((TREE_SIDE_EFFECTS (expr)
95809de4 1848 ? TRUTH_OR_EXPR : TRUTH_ORIF_EXPR),
2ba726d2 1849 truthvalue_conversion (build_unary_op (REALPART_EXPR, expr, 0)),
1850 truthvalue_conversion (build_unary_op (IMAGPART_EXPR, expr, 0)),
1851 0));
1852
b0fc3e72 1853 return build_binary_op (NE_EXPR, expr, integer_zero_node, 1);
1854}
1855\f
1856/* Read the rest of a #-directive from input stream FINPUT.
1857 In normal use, the directive name and the white space after it
1858 have already been read, so they won't be included in the result.
1859 We allow for the fact that the directive line may contain
1860 a newline embedded within a character or string literal which forms
1861 a part of the directive.
1862
1863 The value is a string in a reusable buffer. It remains valid
1864 only until the next time this function is called. */
1865
1866char *
1867get_directive_line (finput)
1868 register FILE *finput;
1869{
1870 static char *directive_buffer = NULL;
1871 static unsigned buffer_length = 0;
1872 register char *p;
1873 register char *buffer_limit;
1874 register int looking_for = 0;
1875 register int char_escaped = 0;
1876
1877 if (buffer_length == 0)
1878 {
1879 directive_buffer = (char *)xmalloc (128);
1880 buffer_length = 128;
1881 }
1882
1883 buffer_limit = &directive_buffer[buffer_length];
1884
1885 for (p = directive_buffer; ; )
1886 {
1887 int c;
1888
1889 /* Make buffer bigger if it is full. */
1890 if (p >= buffer_limit)
1891 {
1892 register unsigned bytes_used = (p - directive_buffer);
1893
1894 buffer_length *= 2;
1895 directive_buffer
1896 = (char *)xrealloc (directive_buffer, buffer_length);
1897 p = &directive_buffer[bytes_used];
1898 buffer_limit = &directive_buffer[buffer_length];
1899 }
1900
1901 c = getc (finput);
1902
1903 /* Discard initial whitespace. */
1904 if ((c == ' ' || c == '\t') && p == directive_buffer)
1905 continue;
1906
1907 /* Detect the end of the directive. */
1908 if (c == '\n' && looking_for == 0)
1909 {
1910 ungetc (c, finput);
1911 c = '\0';
1912 }
1913
1914 *p++ = c;
1915
1916 if (c == 0)
1917 return directive_buffer;
1918
1919 /* Handle string and character constant syntax. */
1920 if (looking_for)
1921 {
1922 if (looking_for == c && !char_escaped)
1923 looking_for = 0; /* Found terminator... stop looking. */
1924 }
1925 else
1926 if (c == '\'' || c == '"')
1927 looking_for = c; /* Don't stop buffering until we see another
1928 another one of these (or an EOF). */
1929
1930 /* Handle backslash. */
1931 char_escaped = (c == '\\' && ! char_escaped);
1932 }
1933}
ceee5ef4 1934\f
1935/* Make a variant type in the proper way for C/C++, propagating qualifiers
1936 down to the element type of an array. */
1937
1938tree
1939c_build_type_variant (type, constp, volatilep)
1940 tree type;
1941 int constp, volatilep;
1942{
1943 if (TREE_CODE (type) == ARRAY_TYPE)
1944 {
1945 tree real_main_variant = TYPE_MAIN_VARIANT (type);
ceee5ef4 1946
5c16922f 1947 push_obstacks (TYPE_OBSTACK (type), TYPE_OBSTACK (type));
ceee5ef4 1948 type = build_array_type (c_build_type_variant (TREE_TYPE (type),
1949 constp, volatilep),
1950 TYPE_DOMAIN (type));
1951 TYPE_MAIN_VARIANT (type) = real_main_variant;
5c16922f 1952 pop_obstacks ();
ceee5ef4 1953 }
1954 return build_type_variant (type, constp, volatilep);
1955}