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 name
= IDENTIFIER_POINTER (DECL_NAME (current_function_decl
));
46 printable_name
= (*decl_printable_name
) (current_function_decl
, &kind
);
49 push_obstacks_nochange ();
50 decl
= build_decl (VAR_DECL
, get_identifier ("__FUNCTION__"),
51 char_array_type_node
);
52 TREE_STATIC (decl
) = 1;
53 TREE_READONLY (decl
) = 1;
54 DECL_IN_SYSTEM_HEADER (decl
) = 1;
55 DECL_IGNORED_P (decl
) = 1;
56 init
= build_string (strlen (name
) + 1, name
);
57 TREE_TYPE (init
) = char_array_type_node
;
58 DECL_INITIAL (decl
) = init
;
59 finish_decl (pushdecl (decl
), init
, NULL_TREE
);
61 push_obstacks_nochange ();
62 decl
= build_decl (VAR_DECL
, get_identifier ("__PRETTY_FUNCTION__"),
63 char_array_type_node
);
64 TREE_STATIC (decl
) = 1;
65 TREE_READONLY (decl
) = 1;
66 DECL_IN_SYSTEM_HEADER (decl
) = 1;
67 DECL_IGNORED_P (decl
) = 1;
68 init
= build_string (strlen (printable_name
) + 1, printable_name
);
69 TREE_TYPE (init
) = char_array_type_node
;
70 DECL_INITIAL (decl
) = init
;
71 finish_decl (pushdecl (decl
), init
, NULL_TREE
);
74 /* Given a chain of STRING_CST nodes,
75 concatenate them into one STRING_CST
76 and give it a suitable array-of-chars data type. */
79 combine_strings (strings
)
82 register tree value
, t
;
83 register int length
= 1;
86 int wchar_bytes
= TYPE_PRECISION (wchar_type_node
) / BITS_PER_UNIT
;
89 if (TREE_CHAIN (strings
))
91 /* More than one in the chain, so concatenate. */
94 /* Don't include the \0 at the end of each substring,
95 except for the last one.
96 Count wide strings and ordinary strings separately. */
97 for (t
= strings
; t
; t
= TREE_CHAIN (t
))
99 if (TREE_TYPE (t
) == wchar_array_type_node
)
101 wide_length
+= (TREE_STRING_LENGTH (t
) - wchar_bytes
);
105 length
+= (TREE_STRING_LENGTH (t
) - 1);
108 /* If anything is wide, the non-wides will be converted,
109 which makes them take more space. */
111 length
= length
* wchar_bytes
+ wide_length
;
113 p
= savealloc (length
);
115 /* Copy the individual strings into the new combined string.
116 If the combined string is wide, convert the chars to ints
117 for any individual strings that are not wide. */
120 for (t
= strings
; t
; t
= TREE_CHAIN (t
))
122 int len
= (TREE_STRING_LENGTH (t
)
123 - ((TREE_TYPE (t
) == wchar_array_type_node
)
125 if ((TREE_TYPE (t
) == wchar_array_type_node
) == wide_flag
)
127 bcopy (TREE_STRING_POINTER (t
), q
, len
);
133 for (i
= 0; i
< len
; i
++)
134 ((int *) q
)[i
] = TREE_STRING_POINTER (t
)[i
];
135 q
+= len
* wchar_bytes
;
141 for (i
= 0; i
< wchar_bytes
; i
++)
147 value
= make_node (STRING_CST
);
148 TREE_STRING_POINTER (value
) = p
;
149 TREE_STRING_LENGTH (value
) = length
;
150 TREE_CONSTANT (value
) = 1;
155 length
= TREE_STRING_LENGTH (value
);
156 if (TREE_TYPE (value
) == wchar_array_type_node
)
160 /* Compute the number of elements, for the array type. */
161 nchars
= wide_flag
? length
/ wchar_bytes
: length
;
163 /* Create the array type for the string constant.
164 -Wwrite-strings says make the string constant an array of const char
165 so that copying it to a non-const pointer will get a warning. */
166 if (warn_write_strings
167 && (! flag_traditional
&& ! flag_writable_strings
))
170 = build_type_variant (wide_flag
? wchar_type_node
: char_type_node
,
173 = build_array_type (elements
,
174 build_index_type (build_int_2 (nchars
- 1, 0)));
178 = build_array_type (wide_flag
? wchar_type_node
: char_type_node
,
179 build_index_type (build_int_2 (nchars
- 1, 0)));
180 TREE_CONSTANT (value
) = 1;
181 TREE_STATIC (value
) = 1;
185 /* Process the attributes listed in ATTRIBUTES
186 and install them in DECL. */
189 decl_attributes (decl
, attributes
)
190 tree decl
, attributes
;
193 for (a
= attributes
; a
; a
= TREE_CHAIN (a
))
194 if (TREE_VALUE (a
) == get_identifier ("packed"))
196 if (TREE_CODE (decl
) == FIELD_DECL
)
197 DECL_PACKED (decl
) = 1;
198 /* We can't set DECL_PACKED for a VAR_DECL, because the bit is
199 used for DECL_REGISTER. It wouldn't mean anything anyway. */
201 else if (TREE_VALUE (a
) != 0
202 && TREE_CODE (TREE_VALUE (a
)) == TREE_LIST
203 && TREE_PURPOSE (TREE_VALUE (a
)) == get_identifier ("mode"))
207 = IDENTIFIER_POINTER (TREE_VALUE (TREE_VALUE (a
)));
209 /* Give this decl a type with the specified mode. */
210 for (i
= 0; i
< NUM_MACHINE_MODES
; i
++)
211 if (!strcmp (specified_name
, GET_MODE_NAME (i
)))
214 = type_for_mode (i
, TREE_UNSIGNED (TREE_TYPE (decl
)));
217 TREE_TYPE (decl
) = type
;
218 DECL_SIZE (decl
) = 0;
219 layout_decl (decl
, 0);
222 error ("no data type for mode `%s'", specified_name
);
225 if (i
== NUM_MACHINE_MODES
)
226 error ("unknown machine mode `%s'", specified_name
);
228 else if (TREE_VALUE (a
) != 0
229 && TREE_CODE (TREE_VALUE (a
)) == TREE_LIST
230 && TREE_PURPOSE (TREE_VALUE (a
)) == get_identifier ("aligned"))
232 int align
= TREE_INT_CST_LOW (TREE_VALUE (TREE_VALUE (a
)))
235 if (exact_log2 (align
) == -1)
236 error_with_decl (decl
,
237 "requested alignment of `%s' is not a power of 2");
238 else if (TREE_CODE (decl
) != VAR_DECL
239 && TREE_CODE (decl
) != FIELD_DECL
)
240 error_with_decl (decl
,
241 "alignment specified for `%s'");
243 DECL_ALIGN (decl
) = align
;
245 else if (TREE_VALUE (a
) != 0
246 && TREE_CODE (TREE_VALUE (a
)) == TREE_LIST
247 && TREE_PURPOSE (TREE_VALUE (a
)) == get_identifier ("format"))
249 tree list
= TREE_VALUE (TREE_VALUE (a
));
250 tree format_type
= TREE_PURPOSE (list
);
251 int format_num
= TREE_INT_CST_LOW (TREE_PURPOSE (TREE_VALUE (list
)));
252 int first_arg_num
= TREE_INT_CST_LOW (TREE_VALUE (TREE_VALUE (list
)));
255 if (TREE_CODE (decl
) != FUNCTION_DECL
)
257 error_with_decl (decl
,
258 "argument format specified for non-function `%s'");
262 if (format_type
== get_identifier ("printf"))
264 else if (format_type
== get_identifier ("scanf"))
268 error_with_decl (decl
, "unrecognized format specifier for `%s'");
272 if (first_arg_num
!= 0 && first_arg_num
<= format_num
)
274 error_with_decl (decl
,
275 "format string arg follows the args to be formatted, for `%s'");
279 record_format_info (DECL_NAME (decl
), is_scan
, format_num
,
285 c_expand_expr_stmt (expr
)
288 /* Do default conversion if safe and possibly important,
289 in case within ({...}). */
290 if ((TREE_CODE (TREE_TYPE (expr
)) == ARRAY_TYPE
&& lvalue_p (expr
))
291 || TREE_CODE (TREE_TYPE (expr
)) == FUNCTION_TYPE
)
292 expr
= default_conversion (expr
);
294 if (TREE_TYPE (expr
) != error_mark_node
295 && TYPE_SIZE (TREE_TYPE (expr
)) == 0
296 && TREE_CODE (TREE_TYPE (expr
)) != ARRAY_TYPE
)
297 error ("expression statement has incomplete type");
299 expand_expr_stmt (expr
);
302 /* Validate the expression after `case' and apply default promotions. */
305 check_case_value (value
)
308 if (value
== NULL_TREE
)
311 /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue. */
312 STRIP_TYPE_NOPS (value
);
314 if (TREE_CODE (value
) != INTEGER_CST
315 && value
!= error_mark_node
)
317 error ("case label does not reduce to an integer constant");
318 value
= error_mark_node
;
321 /* Promote char or short to int. */
322 value
= default_conversion (value
);
327 /* Return an integer type with BITS bits of precision,
328 that is unsigned if UNSIGNEDP is nonzero, otherwise signed. */
331 type_for_size (bits
, unsignedp
)
335 if (bits
== TYPE_PRECISION (signed_char_type_node
))
336 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
338 if (bits
== TYPE_PRECISION (short_integer_type_node
))
339 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
341 if (bits
== TYPE_PRECISION (integer_type_node
))
342 return unsignedp
? unsigned_type_node
: integer_type_node
;
344 if (bits
== TYPE_PRECISION (long_integer_type_node
))
345 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
347 if (bits
== TYPE_PRECISION (long_long_integer_type_node
))
348 return (unsignedp
? long_long_unsigned_type_node
349 : long_long_integer_type_node
);
351 if (bits
<= TYPE_PRECISION (intQI_type_node
))
352 return unsignedp
? unsigned_intQI_type_node
: intQI_type_node
;
354 if (bits
<= TYPE_PRECISION (intHI_type_node
))
355 return unsignedp
? unsigned_intHI_type_node
: intHI_type_node
;
357 if (bits
<= TYPE_PRECISION (intSI_type_node
))
358 return unsignedp
? unsigned_intSI_type_node
: intSI_type_node
;
360 if (bits
<= TYPE_PRECISION (intDI_type_node
))
361 return unsignedp
? unsigned_intDI_type_node
: intDI_type_node
;
366 /* Return a data type that has machine mode MODE.
367 If the mode is an integer,
368 then UNSIGNEDP selects between signed and unsigned types. */
371 type_for_mode (mode
, unsignedp
)
372 enum machine_mode mode
;
375 if (mode
== TYPE_MODE (signed_char_type_node
))
376 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
378 if (mode
== TYPE_MODE (short_integer_type_node
))
379 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
381 if (mode
== TYPE_MODE (integer_type_node
))
382 return unsignedp
? unsigned_type_node
: integer_type_node
;
384 if (mode
== TYPE_MODE (long_integer_type_node
))
385 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
387 if (mode
== TYPE_MODE (long_long_integer_type_node
))
388 return unsignedp
? long_long_unsigned_type_node
: long_long_integer_type_node
;
390 if (mode
== TYPE_MODE (intQI_type_node
))
391 return unsignedp
? unsigned_intQI_type_node
: intQI_type_node
;
393 if (mode
== TYPE_MODE (intHI_type_node
))
394 return unsignedp
? unsigned_intHI_type_node
: intHI_type_node
;
396 if (mode
== TYPE_MODE (intSI_type_node
))
397 return unsignedp
? unsigned_intSI_type_node
: intSI_type_node
;
399 if (mode
== TYPE_MODE (intDI_type_node
))
400 return unsignedp
? unsigned_intDI_type_node
: intDI_type_node
;
402 if (mode
== TYPE_MODE (float_type_node
))
403 return float_type_node
;
405 if (mode
== TYPE_MODE (double_type_node
))
406 return double_type_node
;
408 if (mode
== TYPE_MODE (long_double_type_node
))
409 return long_double_type_node
;
411 if (mode
== TYPE_MODE (build_pointer_type (char_type_node
)))
412 return build_pointer_type (char_type_node
);
414 if (mode
== TYPE_MODE (build_pointer_type (integer_type_node
)))
415 return build_pointer_type (integer_type_node
);
420 /* Print an error message for invalid operands to arith operation CODE.
421 NOP_EXPR is used as a special case (see truthvalue_conversion). */
424 binary_op_error (code
)
427 register char *opname
;
431 error ("invalid truth-value expression");
441 opname
= "max"; break;
443 opname
= "min"; break;
445 opname
= "=="; break;
447 opname
= "!="; break;
449 opname
= "<="; break;
451 opname
= ">="; break;
457 opname
= "<<"; break;
459 opname
= ">>"; break;
470 case TRUTH_ANDIF_EXPR
:
471 opname
= "&&"; break;
472 case TRUTH_ORIF_EXPR
:
473 opname
= "||"; break;
478 opname
= "rotate"; break;
480 error ("invalid operands to binary %s", opname
);
483 /* Subroutine of build_binary_op, used for comparison operations.
484 See if the operands have both been converted from subword integer types
485 and, if so, perhaps change them both back to their original type.
487 The arguments of this function are all pointers to local variables
488 of build_binary_op: OP0_PTR is &OP0, OP1_PTR is &OP1,
489 RESTYPE_PTR is &RESULT_TYPE and RESCODE_PTR is &RESULTCODE.
491 If this function returns nonzero, it means that the comparison has
492 a constant value. What this function returns is an expression for
496 shorten_compare (op0_ptr
, op1_ptr
, restype_ptr
, rescode_ptr
)
497 tree
*op0_ptr
, *op1_ptr
;
499 enum tree_code
*rescode_ptr
;
504 int unsignedp0
, unsignedp1
;
506 tree primop0
, primop1
;
507 enum tree_code code
= *rescode_ptr
;
509 /* Throw away any conversions to wider types
510 already present in the operands. */
512 primop0
= get_narrower (op0
, &unsignedp0
);
513 primop1
= get_narrower (op1
, &unsignedp1
);
515 /* Handle the case that OP0 does not *contain* a conversion
516 but it *requires* conversion to FINAL_TYPE. */
518 if (op0
== primop0
&& TREE_TYPE (op0
) != *restype_ptr
)
519 unsignedp0
= TREE_UNSIGNED (TREE_TYPE (op0
));
520 if (op1
== primop1
&& TREE_TYPE (op1
) != *restype_ptr
)
521 unsignedp1
= TREE_UNSIGNED (TREE_TYPE (op1
));
523 /* If one of the operands must be floated, we cannot optimize. */
524 real1
= TREE_CODE (TREE_TYPE (primop0
)) == REAL_TYPE
;
525 real2
= TREE_CODE (TREE_TYPE (primop1
)) == REAL_TYPE
;
527 /* If first arg is constant, swap the args (changing operation
528 so value is preserved), for canonicalization. */
530 if (TREE_CONSTANT (primop0
))
532 register tree tem
= primop0
;
533 register int temi
= unsignedp0
;
541 unsignedp0
= unsignedp1
;
565 /* If comparing an integer against a constant more bits wide,
566 maybe we can deduce a value of 1 or 0 independent of the data.
567 Or else truncate the constant now
568 rather than extend the variable at run time.
570 This is only interesting if the constant is the wider arg.
571 Also, it is not safe if the constant is unsigned and the
572 variable arg is signed, since in this case the variable
573 would be sign-extended and then regarded as unsigned.
574 Our technique fails in this case because the lowest/highest
575 possible unsigned results don't follow naturally from the
576 lowest/highest possible values of the variable operand.
577 For just EQ_EXPR and NE_EXPR there is another technique that
578 could be used: see if the constant can be faithfully represented
579 in the other operand's type, by truncating it and reextending it
580 and see if that preserves the constant's value. */
583 && TREE_CODE (primop1
) == INTEGER_CST
584 && TYPE_PRECISION (TREE_TYPE (primop0
)) < TYPE_PRECISION (*restype_ptr
))
586 int min_gt
, max_gt
, min_lt
, max_lt
;
588 /* 1 if comparison is nominally unsigned. */
589 int unsignedp
= TREE_UNSIGNED (*restype_ptr
);
592 type
= signed_or_unsigned_type (unsignedp0
, TREE_TYPE (primop0
));
594 maxval
= TYPE_MAX_VALUE (type
);
595 minval
= TYPE_MIN_VALUE (type
);
597 if (unsignedp
&& !unsignedp0
)
598 *restype_ptr
= signed_type (*restype_ptr
);
600 if (TREE_TYPE (primop1
) != *restype_ptr
)
601 primop1
= convert (*restype_ptr
, primop1
);
602 if (type
!= *restype_ptr
)
604 minval
= convert (*restype_ptr
, minval
);
605 maxval
= convert (*restype_ptr
, maxval
);
608 if (unsignedp
&& unsignedp0
)
610 min_gt
= INT_CST_LT_UNSIGNED (primop1
, minval
);
611 max_gt
= INT_CST_LT_UNSIGNED (primop1
, maxval
);
612 min_lt
= INT_CST_LT_UNSIGNED (minval
, primop1
);
613 max_lt
= INT_CST_LT_UNSIGNED (maxval
, primop1
);
617 min_gt
= INT_CST_LT (primop1
, minval
);
618 max_gt
= INT_CST_LT (primop1
, maxval
);
619 min_lt
= INT_CST_LT (minval
, primop1
);
620 max_lt
= INT_CST_LT (maxval
, primop1
);
624 /* This used to be a switch, but Genix compiler can't handle that. */
627 if (max_lt
|| min_gt
)
628 val
= integer_one_node
;
630 else if (code
== EQ_EXPR
)
632 if (max_lt
|| min_gt
)
633 val
= integer_zero_node
;
635 else if (code
== LT_EXPR
)
638 val
= integer_one_node
;
640 val
= integer_zero_node
;
642 else if (code
== GT_EXPR
)
645 val
= integer_one_node
;
647 val
= integer_zero_node
;
649 else if (code
== LE_EXPR
)
652 val
= integer_one_node
;
654 val
= integer_zero_node
;
656 else if (code
== GE_EXPR
)
659 val
= integer_one_node
;
661 val
= integer_zero_node
;
664 /* If primop0 was sign-extended and unsigned comparison specd,
665 we did a signed comparison above using the signed type bounds.
666 But the comparison we output must be unsigned.
668 Also, for inequalities, VAL is no good; but if the signed
669 comparison had *any* fixed result, it follows that the
670 unsigned comparison just tests the sign in reverse
671 (positive values are LE, negative ones GE).
672 So we can generate an unsigned comparison
673 against an extreme value of the signed type. */
675 if (unsignedp
&& !unsignedp0
)
682 primop1
= TYPE_MIN_VALUE (type
);
688 primop1
= TYPE_MAX_VALUE (type
);
692 type
= unsigned_type (type
);
695 if (!max_gt
&& !unsignedp0
)
697 /* This is the case of (char)x >?< 0x80, which people used to use
698 expecting old C compilers to change the 0x80 into -0x80. */
699 if (val
== integer_zero_node
)
700 warning ("comparison is always 0 due to limited range of data type");
701 if (val
== integer_one_node
)
702 warning ("comparison is always 1 due to limited range of data type");
705 if (!min_lt
&& unsignedp0
)
707 /* This is the case of (unsigned char)x >?< -1 or < 0. */
708 if (val
== integer_zero_node
)
709 warning ("comparison is always 0 due to limited range of data type");
710 if (val
== integer_one_node
)
711 warning ("comparison is always 1 due to limited range of data type");
716 /* Don't forget to evaluate PRIMOP0 if it has side effects. */
717 if (TREE_SIDE_EFFECTS (primop0
))
718 return build (COMPOUND_EXPR
, TREE_TYPE (val
), primop0
, val
);
722 /* Value is not predetermined, but do the comparison
723 in the type of the operand that is not constant.
724 TYPE is already properly set. */
726 else if (real1
&& real2
727 && TYPE_PRECISION (TREE_TYPE (primop0
)) == TYPE_PRECISION (TREE_TYPE (primop1
)))
728 type
= TREE_TYPE (primop0
);
730 /* If args' natural types are both narrower than nominal type
731 and both extend in the same manner, compare them
732 in the type of the wider arg.
733 Otherwise must actually extend both to the nominal
734 common type lest different ways of extending
736 (eg, (short)-1 == (unsigned short)-1 should be 0.) */
738 else if (unsignedp0
== unsignedp1
&& real1
== real2
739 && TYPE_PRECISION (TREE_TYPE (primop0
)) < TYPE_PRECISION (*restype_ptr
)
740 && TYPE_PRECISION (TREE_TYPE (primop1
)) < TYPE_PRECISION (*restype_ptr
))
742 type
= common_type (TREE_TYPE (primop0
), TREE_TYPE (primop1
));
743 type
= signed_or_unsigned_type (unsignedp0
744 || TREE_UNSIGNED (*restype_ptr
),
746 /* Make sure shorter operand is extended the right way
747 to match the longer operand. */
748 primop0
= convert (signed_or_unsigned_type (unsignedp0
, TREE_TYPE (primop0
)),
750 primop1
= convert (signed_or_unsigned_type (unsignedp1
, TREE_TYPE (primop1
)),
755 /* Here we must do the comparison on the nominal type
756 using the args exactly as we received them. */
761 if (!real1
&& !real2
&& integer_zerop (primop1
)
762 && TREE_UNSIGNED (TREE_TYPE (primop0
)))
769 warning ("unsigned value >= 0 is always 1");
770 value
= integer_one_node
;
775 warning ("unsigned value < 0 is always 0");
776 value
= integer_zero_node
;
781 /* Don't forget to evaluate PRIMOP0 if it has side effects. */
782 if (TREE_SIDE_EFFECTS (primop0
))
783 return build (COMPOUND_EXPR
, TREE_TYPE (value
),
790 *op0_ptr
= convert (type
, primop0
);
791 *op1_ptr
= convert (type
, primop1
);
793 *restype_ptr
= integer_type_node
;
798 /* Prepare expr to be an argument of a TRUTH_NOT_EXPR,
799 or validate its data type for an `if' or `while' statement or ?..: exp.
801 This preparation consists of taking the ordinary
802 representation of an expression expr and producing a valid tree
803 boolean expression describing whether expr is nonzero. We could
804 simply always do build_binary_op (NE_EXPR, expr, integer_zero_node, 1),
805 but we optimize comparisons, &&, ||, and !.
807 The resulting type should always be `integer_type_node'. */
810 truthvalue_conversion (expr
)
813 register enum tree_code code
;
815 switch (TREE_CODE (expr
))
817 /* It is simpler and generates better code to have only TRUTH_*_EXPR
818 or comparison expressions as truth values at this level. */
821 /* A one-bit unsigned bit-field is already acceptable. */
822 if (1 == TREE_INT_CST_LOW (DECL_SIZE (TREE_OPERAND (expr
, 1)))
823 && TREE_UNSIGNED (TREE_OPERAND (expr
, 1)))
829 /* It is simpler and generates better code to have only TRUTH_*_EXPR
830 or comparison expressions as truth values at this level. */
832 if (integer_zerop (TREE_OPERAND (expr
, 1)))
833 return build_unary_op (TRUTH_NOT_EXPR
, TREE_OPERAND (expr
, 0), 0);
835 case NE_EXPR
: case LE_EXPR
: case GE_EXPR
: case LT_EXPR
: case GT_EXPR
:
836 case TRUTH_ANDIF_EXPR
:
837 case TRUTH_ORIF_EXPR
:
844 return integer_zerop (expr
) ? integer_zero_node
: integer_one_node
;
847 return real_zerop (expr
) ? integer_zero_node
: integer_one_node
;
850 if (TREE_SIDE_EFFECTS (TREE_OPERAND (expr
, 0)))
851 return build (COMPOUND_EXPR
, integer_type_node
,
852 TREE_OPERAND (expr
, 0), integer_one_node
);
854 return integer_one_node
;
860 /* These don't change whether an object is non-zero or zero. */
861 return truthvalue_conversion (TREE_OPERAND (expr
, 0));
865 /* These don't change whether an object is zero or non-zero, but
866 we can't ignore them if their second arg has side-effects. */
867 if (TREE_SIDE_EFFECTS (TREE_OPERAND (expr
, 1)))
868 return build (COMPOUND_EXPR
, integer_type_node
, TREE_OPERAND (expr
, 1),
869 truthvalue_conversion (TREE_OPERAND (expr
, 0)));
871 return truthvalue_conversion (TREE_OPERAND (expr
, 0));
874 /* Distribute the conversion into the arms of a COND_EXPR. */
875 return fold (build (COND_EXPR
, integer_type_node
, TREE_OPERAND (expr
, 0),
876 truthvalue_conversion (TREE_OPERAND (expr
, 1)),
877 truthvalue_conversion (TREE_OPERAND (expr
, 2))));
880 /* Don't cancel the effect of a CONVERT_EXPR from a REFERENCE_TYPE,
881 since that affects how `default_conversion' will behave. */
882 if (TREE_CODE (TREE_TYPE (expr
)) == REFERENCE_TYPE
883 || TREE_CODE (TREE_TYPE (TREE_OPERAND (expr
, 0))) == REFERENCE_TYPE
)
885 /* fall through... */
887 /* If this is widening the argument, we can ignore it. */
888 if (TYPE_PRECISION (TREE_TYPE (expr
))
889 >= TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (expr
, 0))))
890 return truthvalue_conversion (TREE_OPERAND (expr
, 0));
895 /* These can be changed into a comparison of the two objects. */
896 if (TREE_TYPE (TREE_OPERAND (expr
, 0))
897 == TREE_TYPE (TREE_OPERAND (expr
, 1)))
898 return build_binary_op (NE_EXPR
, TREE_OPERAND (expr
, 0),
899 TREE_OPERAND (expr
, 1), 1);
900 return build_binary_op (NE_EXPR
, TREE_OPERAND (expr
, 0),
901 fold (build1 (NOP_EXPR
,
902 TREE_TYPE (TREE_OPERAND (expr
, 0)),
903 TREE_OPERAND (expr
, 1))), 1);
906 if (warn_parentheses
&& C_EXP_ORIGINAL_CODE (expr
) == MODIFY_EXPR
)
907 warning ("suggest parentheses around assignment used as truth value");
911 return build_binary_op (NE_EXPR
, expr
, integer_zero_node
, 1);
914 /* Read the rest of a #-directive from input stream FINPUT.
915 In normal use, the directive name and the white space after it
916 have already been read, so they won't be included in the result.
917 We allow for the fact that the directive line may contain
918 a newline embedded within a character or string literal which forms
919 a part of the directive.
921 The value is a string in a reusable buffer. It remains valid
922 only until the next time this function is called. */
925 get_directive_line (finput
)
926 register FILE *finput
;
928 static char *directive_buffer
= NULL
;
929 static unsigned buffer_length
= 0;
931 register char *buffer_limit
;
932 register int looking_for
= 0;
933 register int char_escaped
= 0;
935 if (buffer_length
== 0)
937 directive_buffer
= (char *)xmalloc (128);
941 buffer_limit
= &directive_buffer
[buffer_length
];
943 for (p
= directive_buffer
; ; )
947 /* Make buffer bigger if it is full. */
948 if (p
>= buffer_limit
)
950 register unsigned bytes_used
= (p
- directive_buffer
);
954 = (char *)xrealloc (directive_buffer
, buffer_length
);
955 p
= &directive_buffer
[bytes_used
];
956 buffer_limit
= &directive_buffer
[buffer_length
];
961 /* Discard initial whitespace. */
962 if ((c
== ' ' || c
== '\t') && p
== directive_buffer
)
965 /* Detect the end of the directive. */
966 if (c
== '\n' && looking_for
== 0)
975 return directive_buffer
;
977 /* Handle string and character constant syntax. */
980 if (looking_for
== c
&& !char_escaped
)
981 looking_for
= 0; /* Found terminator... stop looking. */
984 if (c
== '\'' || c
== '"')
985 looking_for
= c
; /* Don't stop buffering until we see another
986 another one of these (or an EOF). */
988 /* Handle backslash. */
989 char_escaped
= (c
== '\\' && ! char_escaped
);