1 /* Subroutines shared by all languages that are variants of C.
2 Copyright (C) 1992 Free Software Foundation, Inc.
4 This file is part of GNU CC.
6 GNU CC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU CC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU CC; see the file COPYING. If not, write to
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
27 /* Make bindings for __FUNCTION__ and __PRETTY_FUNCTION__. */
30 declare_function_name ()
33 char *name
, *printable_name
;
35 if (current_function_decl
== NULL
)
38 printable_name
= "top level";
42 char *kind
= "function";
43 if (TREE_CODE (TREE_TYPE (current_function_decl
)) == METHOD_TYPE
)
45 /* Allow functions to be nameless (such as artificial ones). */
46 if (DECL_NAME (current_function_decl
))
47 name
= IDENTIFIER_POINTER (DECL_NAME (current_function_decl
));
50 printable_name
= (*decl_printable_name
) (current_function_decl
, &kind
);
53 push_obstacks_nochange ();
54 decl
= build_decl (VAR_DECL
, get_identifier ("__FUNCTION__"),
55 char_array_type_node
);
56 TREE_STATIC (decl
) = 1;
57 TREE_READONLY (decl
) = 1;
58 DECL_SOURCE_LINE (decl
) = 0;
59 DECL_IN_SYSTEM_HEADER (decl
) = 1;
60 DECL_IGNORED_P (decl
) = 1;
61 init
= build_string (strlen (name
) + 1, name
);
62 TREE_TYPE (init
) = char_array_type_node
;
63 DECL_INITIAL (decl
) = init
;
64 finish_decl (pushdecl (decl
), init
, NULL_TREE
);
66 push_obstacks_nochange ();
67 decl
= build_decl (VAR_DECL
, get_identifier ("__PRETTY_FUNCTION__"),
68 char_array_type_node
);
69 TREE_STATIC (decl
) = 1;
70 TREE_READONLY (decl
) = 1;
71 DECL_SOURCE_LINE (decl
) = 0;
72 DECL_IN_SYSTEM_HEADER (decl
) = 1;
73 DECL_IGNORED_P (decl
) = 1;
74 init
= build_string (strlen (printable_name
) + 1, printable_name
);
75 TREE_TYPE (init
) = char_array_type_node
;
76 DECL_INITIAL (decl
) = init
;
77 finish_decl (pushdecl (decl
), init
, NULL_TREE
);
80 /* Given a chain of STRING_CST nodes,
81 concatenate them into one STRING_CST
82 and give it a suitable array-of-chars data type. */
85 combine_strings (strings
)
88 register tree value
, t
;
89 register int length
= 1;
92 int wchar_bytes
= TYPE_PRECISION (wchar_type_node
) / BITS_PER_UNIT
;
95 if (TREE_CHAIN (strings
))
97 /* More than one in the chain, so concatenate. */
100 /* Don't include the \0 at the end of each substring,
101 except for the last one.
102 Count wide strings and ordinary strings separately. */
103 for (t
= strings
; t
; t
= TREE_CHAIN (t
))
105 if (TREE_TYPE (t
) == wchar_array_type_node
)
107 wide_length
+= (TREE_STRING_LENGTH (t
) - wchar_bytes
);
111 length
+= (TREE_STRING_LENGTH (t
) - 1);
114 /* If anything is wide, the non-wides will be converted,
115 which makes them take more space. */
117 length
= length
* wchar_bytes
+ wide_length
;
119 p
= savealloc (length
);
121 /* Copy the individual strings into the new combined string.
122 If the combined string is wide, convert the chars to ints
123 for any individual strings that are not wide. */
126 for (t
= strings
; t
; t
= TREE_CHAIN (t
))
128 int len
= (TREE_STRING_LENGTH (t
)
129 - ((TREE_TYPE (t
) == wchar_array_type_node
)
131 if ((TREE_TYPE (t
) == wchar_array_type_node
) == wide_flag
)
133 bcopy (TREE_STRING_POINTER (t
), q
, len
);
139 for (i
= 0; i
< len
; i
++)
140 ((int *) q
)[i
] = TREE_STRING_POINTER (t
)[i
];
141 q
+= len
* wchar_bytes
;
147 for (i
= 0; i
< wchar_bytes
; i
++)
153 value
= make_node (STRING_CST
);
154 TREE_STRING_POINTER (value
) = p
;
155 TREE_STRING_LENGTH (value
) = length
;
156 TREE_CONSTANT (value
) = 1;
161 length
= TREE_STRING_LENGTH (value
);
162 if (TREE_TYPE (value
) == wchar_array_type_node
)
166 /* Compute the number of elements, for the array type. */
167 nchars
= wide_flag
? length
/ wchar_bytes
: length
;
169 /* Create the array type for the string constant.
170 -Wwrite-strings says make the string constant an array of const char
171 so that copying it to a non-const pointer will get a warning. */
172 if (warn_write_strings
173 && (! flag_traditional
&& ! flag_writable_strings
))
176 = build_type_variant (wide_flag
? wchar_type_node
: char_type_node
,
179 = build_array_type (elements
,
180 build_index_type (build_int_2 (nchars
- 1, 0)));
184 = build_array_type (wide_flag
? wchar_type_node
: char_type_node
,
185 build_index_type (build_int_2 (nchars
- 1, 0)));
186 TREE_CONSTANT (value
) = 1;
187 TREE_STATIC (value
) = 1;
191 /* Process the attributes listed in ATTRIBUTES
192 and install them in DECL. */
195 decl_attributes (decl
, attributes
)
196 tree decl
, attributes
;
199 for (a
= attributes
; a
; a
= TREE_CHAIN (a
))
200 if (TREE_VALUE (a
) == get_identifier ("packed"))
202 if (TREE_CODE (decl
) == FIELD_DECL
)
203 DECL_PACKED (decl
) = 1;
204 /* We can't set DECL_PACKED for a VAR_DECL, because the bit is
205 used for DECL_REGISTER. It wouldn't mean anything anyway. */
207 else if (TREE_VALUE (a
) != 0
208 && TREE_CODE (TREE_VALUE (a
)) == TREE_LIST
209 && TREE_PURPOSE (TREE_VALUE (a
)) == get_identifier ("mode"))
213 = IDENTIFIER_POINTER (TREE_VALUE (TREE_VALUE (a
)));
215 /* Give this decl a type with the specified mode. */
216 for (i
= 0; i
< NUM_MACHINE_MODES
; i
++)
217 if (!strcmp (specified_name
, GET_MODE_NAME (i
)))
220 = type_for_mode (i
, TREE_UNSIGNED (TREE_TYPE (decl
)));
223 TREE_TYPE (decl
) = type
;
224 DECL_SIZE (decl
) = 0;
225 layout_decl (decl
, 0);
228 error ("no data type for mode `%s'", specified_name
);
231 if (i
== NUM_MACHINE_MODES
)
232 error ("unknown machine mode `%s'", specified_name
);
234 else if (TREE_VALUE (a
) != 0
235 && TREE_CODE (TREE_VALUE (a
)) == TREE_LIST
236 && TREE_PURPOSE (TREE_VALUE (a
)) == get_identifier ("aligned"))
238 int align
= TREE_INT_CST_LOW (TREE_VALUE (TREE_VALUE (a
)))
241 if (exact_log2 (align
) == -1)
242 error_with_decl (decl
,
243 "requested alignment of `%s' is not a power of 2");
244 else if (TREE_CODE (decl
) != VAR_DECL
245 && TREE_CODE (decl
) != FIELD_DECL
)
246 error_with_decl (decl
,
247 "alignment specified for `%s'");
249 DECL_ALIGN (decl
) = align
;
251 else if (TREE_VALUE (a
) != 0
252 && TREE_CODE (TREE_VALUE (a
)) == TREE_LIST
253 && TREE_PURPOSE (TREE_VALUE (a
)) == get_identifier ("format"))
255 tree list
= TREE_VALUE (TREE_VALUE (a
));
256 tree format_type
= TREE_PURPOSE (list
);
257 int format_num
= TREE_INT_CST_LOW (TREE_PURPOSE (TREE_VALUE (list
)));
258 int first_arg_num
= TREE_INT_CST_LOW (TREE_VALUE (TREE_VALUE (list
)));
261 if (TREE_CODE (decl
) != FUNCTION_DECL
)
263 error_with_decl (decl
,
264 "argument format specified for non-function `%s'");
268 if (format_type
== get_identifier ("printf"))
270 else if (format_type
== get_identifier ("scanf"))
274 error_with_decl (decl
, "unrecognized format specifier for `%s'");
278 if (first_arg_num
!= 0 && first_arg_num
<= format_num
)
280 error_with_decl (decl
,
281 "format string arg follows the args to be formatted, for `%s'");
285 record_format_info (DECL_NAME (decl
), is_scan
, format_num
,
290 /* Print a warning if a constant expression had overflow in folding. */
293 constant_expression_warning (value
)
296 if (TREE_CODE (value
) == INTEGER_CST
&& TREE_CONSTANT_OVERFLOW (value
))
297 pedwarn ("overflow in constant expression");
301 c_expand_expr_stmt (expr
)
304 /* Do default conversion if safe and possibly important,
305 in case within ({...}). */
306 if ((TREE_CODE (TREE_TYPE (expr
)) == ARRAY_TYPE
&& lvalue_p (expr
))
307 || TREE_CODE (TREE_TYPE (expr
)) == FUNCTION_TYPE
)
308 expr
= default_conversion (expr
);
310 if (TREE_TYPE (expr
) != error_mark_node
311 && TYPE_SIZE (TREE_TYPE (expr
)) == 0
312 && TREE_CODE (TREE_TYPE (expr
)) != ARRAY_TYPE
)
313 error ("expression statement has incomplete type");
315 expand_expr_stmt (expr
);
318 /* Validate the expression after `case' and apply default promotions. */
321 check_case_value (value
)
324 if (value
== NULL_TREE
)
327 /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue. */
328 STRIP_TYPE_NOPS (value
);
330 if (TREE_CODE (value
) != INTEGER_CST
331 && value
!= error_mark_node
)
333 error ("case label does not reduce to an integer constant");
334 value
= error_mark_node
;
337 /* Promote char or short to int. */
338 value
= default_conversion (value
);
340 constant_expression_warning (value
);
345 /* Return an integer type with BITS bits of precision,
346 that is unsigned if UNSIGNEDP is nonzero, otherwise signed. */
349 type_for_size (bits
, unsignedp
)
353 if (bits
== TYPE_PRECISION (signed_char_type_node
))
354 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
356 if (bits
== TYPE_PRECISION (short_integer_type_node
))
357 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
359 if (bits
== TYPE_PRECISION (integer_type_node
))
360 return unsignedp
? unsigned_type_node
: integer_type_node
;
362 if (bits
== TYPE_PRECISION (long_integer_type_node
))
363 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
365 if (bits
== TYPE_PRECISION (long_long_integer_type_node
))
366 return (unsignedp
? long_long_unsigned_type_node
367 : long_long_integer_type_node
);
369 if (bits
<= TYPE_PRECISION (intQI_type_node
))
370 return unsignedp
? unsigned_intQI_type_node
: intQI_type_node
;
372 if (bits
<= TYPE_PRECISION (intHI_type_node
))
373 return unsignedp
? unsigned_intHI_type_node
: intHI_type_node
;
375 if (bits
<= TYPE_PRECISION (intSI_type_node
))
376 return unsignedp
? unsigned_intSI_type_node
: intSI_type_node
;
378 if (bits
<= TYPE_PRECISION (intDI_type_node
))
379 return unsignedp
? unsigned_intDI_type_node
: intDI_type_node
;
384 /* Return a data type that has machine mode MODE.
385 If the mode is an integer,
386 then UNSIGNEDP selects between signed and unsigned types. */
389 type_for_mode (mode
, unsignedp
)
390 enum machine_mode mode
;
393 if (mode
== TYPE_MODE (signed_char_type_node
))
394 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
396 if (mode
== TYPE_MODE (short_integer_type_node
))
397 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
399 if (mode
== TYPE_MODE (integer_type_node
))
400 return unsignedp
? unsigned_type_node
: integer_type_node
;
402 if (mode
== TYPE_MODE (long_integer_type_node
))
403 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
405 if (mode
== TYPE_MODE (long_long_integer_type_node
))
406 return unsignedp
? long_long_unsigned_type_node
: long_long_integer_type_node
;
408 if (mode
== TYPE_MODE (intQI_type_node
))
409 return unsignedp
? unsigned_intQI_type_node
: intQI_type_node
;
411 if (mode
== TYPE_MODE (intHI_type_node
))
412 return unsignedp
? unsigned_intHI_type_node
: intHI_type_node
;
414 if (mode
== TYPE_MODE (intSI_type_node
))
415 return unsignedp
? unsigned_intSI_type_node
: intSI_type_node
;
417 if (mode
== TYPE_MODE (intDI_type_node
))
418 return unsignedp
? unsigned_intDI_type_node
: intDI_type_node
;
420 if (mode
== TYPE_MODE (float_type_node
))
421 return float_type_node
;
423 if (mode
== TYPE_MODE (double_type_node
))
424 return double_type_node
;
426 if (mode
== TYPE_MODE (long_double_type_node
))
427 return long_double_type_node
;
429 if (mode
== TYPE_MODE (build_pointer_type (char_type_node
)))
430 return build_pointer_type (char_type_node
);
432 if (mode
== TYPE_MODE (build_pointer_type (integer_type_node
)))
433 return build_pointer_type (integer_type_node
);
438 /* Print an error message for invalid operands to arith operation CODE.
439 NOP_EXPR is used as a special case (see truthvalue_conversion). */
442 binary_op_error (code
)
445 register char *opname
;
449 error ("invalid truth-value expression");
459 opname
= "max"; break;
461 opname
= "min"; break;
463 opname
= "=="; break;
465 opname
= "!="; break;
467 opname
= "<="; break;
469 opname
= ">="; break;
475 opname
= "<<"; break;
477 opname
= ">>"; break;
488 case TRUTH_ANDIF_EXPR
:
489 opname
= "&&"; break;
490 case TRUTH_ORIF_EXPR
:
491 opname
= "||"; break;
496 opname
= "rotate"; break;
498 error ("invalid operands to binary %s", opname
);
501 /* Subroutine of build_binary_op, used for comparison operations.
502 See if the operands have both been converted from subword integer types
503 and, if so, perhaps change them both back to their original type.
505 The arguments of this function are all pointers to local variables
506 of build_binary_op: OP0_PTR is &OP0, OP1_PTR is &OP1,
507 RESTYPE_PTR is &RESULT_TYPE and RESCODE_PTR is &RESULTCODE.
509 If this function returns nonzero, it means that the comparison has
510 a constant value. What this function returns is an expression for
514 shorten_compare (op0_ptr
, op1_ptr
, restype_ptr
, rescode_ptr
)
515 tree
*op0_ptr
, *op1_ptr
;
517 enum tree_code
*rescode_ptr
;
522 int unsignedp0
, unsignedp1
;
524 tree primop0
, primop1
;
525 enum tree_code code
= *rescode_ptr
;
527 /* Throw away any conversions to wider types
528 already present in the operands. */
530 primop0
= get_narrower (op0
, &unsignedp0
);
531 primop1
= get_narrower (op1
, &unsignedp1
);
533 /* Handle the case that OP0 does not *contain* a conversion
534 but it *requires* conversion to FINAL_TYPE. */
536 if (op0
== primop0
&& TREE_TYPE (op0
) != *restype_ptr
)
537 unsignedp0
= TREE_UNSIGNED (TREE_TYPE (op0
));
538 if (op1
== primop1
&& TREE_TYPE (op1
) != *restype_ptr
)
539 unsignedp1
= TREE_UNSIGNED (TREE_TYPE (op1
));
541 /* If one of the operands must be floated, we cannot optimize. */
542 real1
= TREE_CODE (TREE_TYPE (primop0
)) == REAL_TYPE
;
543 real2
= TREE_CODE (TREE_TYPE (primop1
)) == REAL_TYPE
;
545 /* If first arg is constant, swap the args (changing operation
546 so value is preserved), for canonicalization. */
548 if (TREE_CONSTANT (primop0
))
550 register tree tem
= primop0
;
551 register int temi
= unsignedp0
;
559 unsignedp0
= unsignedp1
;
583 /* If comparing an integer against a constant more bits wide,
584 maybe we can deduce a value of 1 or 0 independent of the data.
585 Or else truncate the constant now
586 rather than extend the variable at run time.
588 This is only interesting if the constant is the wider arg.
589 Also, it is not safe if the constant is unsigned and the
590 variable arg is signed, since in this case the variable
591 would be sign-extended and then regarded as unsigned.
592 Our technique fails in this case because the lowest/highest
593 possible unsigned results don't follow naturally from the
594 lowest/highest possible values of the variable operand.
595 For just EQ_EXPR and NE_EXPR there is another technique that
596 could be used: see if the constant can be faithfully represented
597 in the other operand's type, by truncating it and reextending it
598 and see if that preserves the constant's value. */
601 && TREE_CODE (primop1
) == INTEGER_CST
602 && TYPE_PRECISION (TREE_TYPE (primop0
)) < TYPE_PRECISION (*restype_ptr
))
604 int min_gt
, max_gt
, min_lt
, max_lt
;
606 /* 1 if comparison is nominally unsigned. */
607 int unsignedp
= TREE_UNSIGNED (*restype_ptr
);
610 type
= signed_or_unsigned_type (unsignedp0
, TREE_TYPE (primop0
));
612 maxval
= TYPE_MAX_VALUE (type
);
613 minval
= TYPE_MIN_VALUE (type
);
615 if (unsignedp
&& !unsignedp0
)
616 *restype_ptr
= signed_type (*restype_ptr
);
618 if (TREE_TYPE (primop1
) != *restype_ptr
)
619 primop1
= convert (*restype_ptr
, primop1
);
620 if (type
!= *restype_ptr
)
622 minval
= convert (*restype_ptr
, minval
);
623 maxval
= convert (*restype_ptr
, maxval
);
626 if (unsignedp
&& unsignedp0
)
628 min_gt
= INT_CST_LT_UNSIGNED (primop1
, minval
);
629 max_gt
= INT_CST_LT_UNSIGNED (primop1
, maxval
);
630 min_lt
= INT_CST_LT_UNSIGNED (minval
, primop1
);
631 max_lt
= INT_CST_LT_UNSIGNED (maxval
, primop1
);
635 min_gt
= INT_CST_LT (primop1
, minval
);
636 max_gt
= INT_CST_LT (primop1
, maxval
);
637 min_lt
= INT_CST_LT (minval
, primop1
);
638 max_lt
= INT_CST_LT (maxval
, primop1
);
642 /* This used to be a switch, but Genix compiler can't handle that. */
645 if (max_lt
|| min_gt
)
646 val
= integer_one_node
;
648 else if (code
== EQ_EXPR
)
650 if (max_lt
|| min_gt
)
651 val
= integer_zero_node
;
653 else if (code
== LT_EXPR
)
656 val
= integer_one_node
;
658 val
= integer_zero_node
;
660 else if (code
== GT_EXPR
)
663 val
= integer_one_node
;
665 val
= integer_zero_node
;
667 else if (code
== LE_EXPR
)
670 val
= integer_one_node
;
672 val
= integer_zero_node
;
674 else if (code
== GE_EXPR
)
677 val
= integer_one_node
;
679 val
= integer_zero_node
;
682 /* If primop0 was sign-extended and unsigned comparison specd,
683 we did a signed comparison above using the signed type bounds.
684 But the comparison we output must be unsigned.
686 Also, for inequalities, VAL is no good; but if the signed
687 comparison had *any* fixed result, it follows that the
688 unsigned comparison just tests the sign in reverse
689 (positive values are LE, negative ones GE).
690 So we can generate an unsigned comparison
691 against an extreme value of the signed type. */
693 if (unsignedp
&& !unsignedp0
)
700 primop1
= TYPE_MIN_VALUE (type
);
706 primop1
= TYPE_MAX_VALUE (type
);
710 type
= unsigned_type (type
);
713 if (!max_gt
&& !unsignedp0
)
715 /* This is the case of (char)x >?< 0x80, which people used to use
716 expecting old C compilers to change the 0x80 into -0x80. */
717 if (val
== integer_zero_node
)
718 warning ("comparison is always 0 due to limited range of data type");
719 if (val
== integer_one_node
)
720 warning ("comparison is always 1 due to limited range of data type");
723 if (!min_lt
&& unsignedp0
)
725 /* This is the case of (unsigned char)x >?< -1 or < 0. */
726 if (val
== integer_zero_node
)
727 warning ("comparison is always 0 due to limited range of data type");
728 if (val
== integer_one_node
)
729 warning ("comparison is always 1 due to limited range of data type");
734 /* Don't forget to evaluate PRIMOP0 if it has side effects. */
735 if (TREE_SIDE_EFFECTS (primop0
))
736 return build (COMPOUND_EXPR
, TREE_TYPE (val
), primop0
, val
);
740 /* Value is not predetermined, but do the comparison
741 in the type of the operand that is not constant.
742 TYPE is already properly set. */
744 else if (real1
&& real2
745 && TYPE_PRECISION (TREE_TYPE (primop0
)) == TYPE_PRECISION (TREE_TYPE (primop1
)))
746 type
= TREE_TYPE (primop0
);
748 /* If args' natural types are both narrower than nominal type
749 and both extend in the same manner, compare them
750 in the type of the wider arg.
751 Otherwise must actually extend both to the nominal
752 common type lest different ways of extending
754 (eg, (short)-1 == (unsigned short)-1 should be 0.) */
756 else if (unsignedp0
== unsignedp1
&& real1
== real2
757 && TYPE_PRECISION (TREE_TYPE (primop0
)) < TYPE_PRECISION (*restype_ptr
)
758 && TYPE_PRECISION (TREE_TYPE (primop1
)) < TYPE_PRECISION (*restype_ptr
))
760 type
= common_type (TREE_TYPE (primop0
), TREE_TYPE (primop1
));
761 type
= signed_or_unsigned_type (unsignedp0
762 || TREE_UNSIGNED (*restype_ptr
),
764 /* Make sure shorter operand is extended the right way
765 to match the longer operand. */
766 primop0
= convert (signed_or_unsigned_type (unsignedp0
, TREE_TYPE (primop0
)),
768 primop1
= convert (signed_or_unsigned_type (unsignedp1
, TREE_TYPE (primop1
)),
773 /* Here we must do the comparison on the nominal type
774 using the args exactly as we received them. */
779 if (!real1
&& !real2
&& integer_zerop (primop1
)
780 && TREE_UNSIGNED (TREE_TYPE (primop0
)))
787 warning ("unsigned value >= 0 is always 1");
788 value
= integer_one_node
;
793 warning ("unsigned value < 0 is always 0");
794 value
= integer_zero_node
;
799 /* Don't forget to evaluate PRIMOP0 if it has side effects. */
800 if (TREE_SIDE_EFFECTS (primop0
))
801 return build (COMPOUND_EXPR
, TREE_TYPE (value
),
808 *op0_ptr
= convert (type
, primop0
);
809 *op1_ptr
= convert (type
, primop1
);
811 *restype_ptr
= integer_type_node
;
816 /* Prepare expr to be an argument of a TRUTH_NOT_EXPR,
817 or validate its data type for an `if' or `while' statement or ?..: exp.
819 This preparation consists of taking the ordinary
820 representation of an expression expr and producing a valid tree
821 boolean expression describing whether expr is nonzero. We could
822 simply always do build_binary_op (NE_EXPR, expr, integer_zero_node, 1),
823 but we optimize comparisons, &&, ||, and !.
825 The resulting type should always be `integer_type_node'. */
828 truthvalue_conversion (expr
)
831 register enum tree_code code
;
833 switch (TREE_CODE (expr
))
835 /* It is simpler and generates better code to have only TRUTH_*_EXPR
836 or comparison expressions as truth values at this level. */
839 /* A one-bit unsigned bit-field is already acceptable. */
840 if (1 == TREE_INT_CST_LOW (DECL_SIZE (TREE_OPERAND (expr
, 1)))
841 && TREE_UNSIGNED (TREE_OPERAND (expr
, 1)))
847 /* It is simpler and generates better code to have only TRUTH_*_EXPR
848 or comparison expressions as truth values at this level. */
850 if (integer_zerop (TREE_OPERAND (expr
, 1)))
851 return build_unary_op (TRUTH_NOT_EXPR
, TREE_OPERAND (expr
, 0), 0);
853 case NE_EXPR
: case LE_EXPR
: case GE_EXPR
: case LT_EXPR
: case GT_EXPR
:
854 case TRUTH_ANDIF_EXPR
:
855 case TRUTH_ORIF_EXPR
:
863 return integer_zerop (expr
) ? integer_zero_node
: integer_one_node
;
866 return real_zerop (expr
) ? integer_zero_node
: integer_one_node
;
869 if (TREE_SIDE_EFFECTS (TREE_OPERAND (expr
, 0)))
870 return build (COMPOUND_EXPR
, integer_type_node
,
871 TREE_OPERAND (expr
, 0), integer_one_node
);
873 return integer_one_node
;
879 /* These don't change whether an object is non-zero or zero. */
880 return truthvalue_conversion (TREE_OPERAND (expr
, 0));
884 /* These don't change whether an object is zero or non-zero, but
885 we can't ignore them if their second arg has side-effects. */
886 if (TREE_SIDE_EFFECTS (TREE_OPERAND (expr
, 1)))
887 return build (COMPOUND_EXPR
, integer_type_node
, TREE_OPERAND (expr
, 1),
888 truthvalue_conversion (TREE_OPERAND (expr
, 0)));
890 return truthvalue_conversion (TREE_OPERAND (expr
, 0));
893 /* Distribute the conversion into the arms of a COND_EXPR. */
894 return fold (build (COND_EXPR
, integer_type_node
, TREE_OPERAND (expr
, 0),
895 truthvalue_conversion (TREE_OPERAND (expr
, 1)),
896 truthvalue_conversion (TREE_OPERAND (expr
, 2))));
899 /* Don't cancel the effect of a CONVERT_EXPR from a REFERENCE_TYPE,
900 since that affects how `default_conversion' will behave. */
901 if (TREE_CODE (TREE_TYPE (expr
)) == REFERENCE_TYPE
902 || TREE_CODE (TREE_TYPE (TREE_OPERAND (expr
, 0))) == REFERENCE_TYPE
)
904 /* fall through... */
906 /* If this is widening the argument, we can ignore it. */
907 if (TYPE_PRECISION (TREE_TYPE (expr
))
908 >= TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (expr
, 0))))
909 return truthvalue_conversion (TREE_OPERAND (expr
, 0));
914 /* These can be changed into a comparison of the two objects. */
915 if (TREE_TYPE (TREE_OPERAND (expr
, 0))
916 == TREE_TYPE (TREE_OPERAND (expr
, 1)))
917 return build_binary_op (NE_EXPR
, TREE_OPERAND (expr
, 0),
918 TREE_OPERAND (expr
, 1), 1);
919 return build_binary_op (NE_EXPR
, TREE_OPERAND (expr
, 0),
920 fold (build1 (NOP_EXPR
,
921 TREE_TYPE (TREE_OPERAND (expr
, 0)),
922 TREE_OPERAND (expr
, 1))), 1);
925 if (warn_parentheses
&& C_EXP_ORIGINAL_CODE (expr
) == MODIFY_EXPR
)
926 warning ("suggest parentheses around assignment used as truth value");
930 return build_binary_op (NE_EXPR
, expr
, integer_zero_node
, 1);
933 /* Read the rest of a #-directive from input stream FINPUT.
934 In normal use, the directive name and the white space after it
935 have already been read, so they won't be included in the result.
936 We allow for the fact that the directive line may contain
937 a newline embedded within a character or string literal which forms
938 a part of the directive.
940 The value is a string in a reusable buffer. It remains valid
941 only until the next time this function is called. */
944 get_directive_line (finput
)
945 register FILE *finput
;
947 static char *directive_buffer
= NULL
;
948 static unsigned buffer_length
= 0;
950 register char *buffer_limit
;
951 register int looking_for
= 0;
952 register int char_escaped
= 0;
954 if (buffer_length
== 0)
956 directive_buffer
= (char *)xmalloc (128);
960 buffer_limit
= &directive_buffer
[buffer_length
];
962 for (p
= directive_buffer
; ; )
966 /* Make buffer bigger if it is full. */
967 if (p
>= buffer_limit
)
969 register unsigned bytes_used
= (p
- directive_buffer
);
973 = (char *)xrealloc (directive_buffer
, buffer_length
);
974 p
= &directive_buffer
[bytes_used
];
975 buffer_limit
= &directive_buffer
[buffer_length
];
980 /* Discard initial whitespace. */
981 if ((c
== ' ' || c
== '\t') && p
== directive_buffer
)
984 /* Detect the end of the directive. */
985 if (c
== '\n' && looking_for
== 0)
994 return directive_buffer
;
996 /* Handle string and character constant syntax. */
999 if (looking_for
== c
&& !char_escaped
)
1000 looking_for
= 0; /* Found terminator... stop looking. */
1003 if (c
== '\'' || c
== '"')
1004 looking_for
= c
; /* Don't stop buffering until we see another
1005 another one of these (or an EOF). */
1007 /* Handle backslash. */
1008 char_escaped
= (c
== '\\' && ! char_escaped
);