2 Copyright (C) 2000-2020 Free Software Foundation, Inc.
3 Contributed by Andy Vaught
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 3, or (at your option) any later
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
21 /* Since target arithmetic must be done on the host, there has to
22 be some way of evaluating arithmetic expressions as the host
23 would evaluate them. We use the GNU MP library and the MPFR
24 library to do arithmetic, and this file provides the interface. */
28 #include "coretypes.h"
32 #include "target-memory.h"
33 #include "constructor.h"
37 /* MPFR does not have a direct replacement for mpz_set_f() from GMP.
38 It's easily implemented with a few calls though. */
41 gfc_mpfr_to_mpz (mpz_t z
, mpfr_t x
, locus
*where
)
45 if (mpfr_inf_p (x
) || mpfr_nan_p (x
))
47 gfc_error ("Conversion of an Infinity or Not-a-Number at %L "
53 e
= mpfr_get_z_exp (z
, x
);
56 mpz_mul_2exp (z
, z
, e
);
58 mpz_tdiv_q_2exp (z
, z
, -e
);
62 /* Set the model number precision by the requested KIND. */
65 gfc_set_model_kind (int kind
)
67 int index
= gfc_validate_kind (BT_REAL
, kind
, false);
70 base2prec
= gfc_real_kinds
[index
].digits
;
71 if (gfc_real_kinds
[index
].radix
!= 2)
72 base2prec
*= gfc_real_kinds
[index
].radix
/ 2;
73 mpfr_set_default_prec (base2prec
);
77 /* Set the model number precision from mpfr_t x. */
80 gfc_set_model (mpfr_t x
)
82 mpfr_set_default_prec (mpfr_get_prec (x
));
86 /* Given an arithmetic error code, return a pointer to a string that
87 explains the error. */
90 gfc_arith_error (arith code
)
97 p
= G_("Arithmetic OK at %L");
100 p
= G_("Arithmetic overflow at %L");
102 case ARITH_UNDERFLOW
:
103 p
= G_("Arithmetic underflow at %L");
106 p
= G_("Arithmetic NaN at %L");
109 p
= G_("Division by zero at %L");
111 case ARITH_INCOMMENSURATE
:
112 p
= G_("Array operands are incommensurate at %L");
114 case ARITH_ASYMMETRIC
:
115 p
= G_("Integer outside symmetric range implied by Standard Fortran"
118 case ARITH_WRONGCONCAT
:
119 p
= G_("Illegal type in character concatenation at %L");
123 gfc_internal_error ("gfc_arith_error(): Bad error code");
130 /* Get things ready to do math. */
133 gfc_arith_init_1 (void)
135 gfc_integer_info
*int_info
;
136 gfc_real_info
*real_info
;
140 mpfr_set_default_prec (128);
143 /* Convert the minimum and maximum values for each kind into their
144 GNU MP representation. */
145 for (int_info
= gfc_integer_kinds
; int_info
->kind
!= 0; int_info
++)
148 mpz_init (int_info
->huge
);
149 mpz_set_ui (int_info
->huge
, int_info
->radix
);
150 mpz_pow_ui (int_info
->huge
, int_info
->huge
, int_info
->digits
);
151 mpz_sub_ui (int_info
->huge
, int_info
->huge
, 1);
153 /* These are the numbers that are actually representable by the
154 target. For bases other than two, this needs to be changed. */
155 if (int_info
->radix
!= 2)
156 gfc_internal_error ("Fix min_int calculation");
158 /* See PRs 13490 and 17912, related to integer ranges.
159 The pedantic_min_int exists for range checking when a program
160 is compiled with -pedantic, and reflects the belief that
161 Standard Fortran requires integers to be symmetrical, i.e.
162 every negative integer must have a representable positive
163 absolute value, and vice versa. */
165 mpz_init (int_info
->pedantic_min_int
);
166 mpz_neg (int_info
->pedantic_min_int
, int_info
->huge
);
168 mpz_init (int_info
->min_int
);
169 mpz_sub_ui (int_info
->min_int
, int_info
->pedantic_min_int
, 1);
172 mpfr_set_z (a
, int_info
->huge
, GFC_RND_MODE
);
173 mpfr_log10 (a
, a
, GFC_RND_MODE
);
175 int_info
->range
= (int) mpfr_get_si (a
, GFC_RND_MODE
);
180 for (real_info
= gfc_real_kinds
; real_info
->kind
!= 0; real_info
++)
182 gfc_set_model_kind (real_info
->kind
);
187 /* huge(x) = (1 - b**(-p)) * b**(emax-1) * b */
189 mpfr_init (real_info
->huge
);
190 mpfr_set_ui (real_info
->huge
, 1, GFC_RND_MODE
);
191 mpfr_set_ui (a
, real_info
->radix
, GFC_RND_MODE
);
192 mpfr_pow_si (a
, a
, -real_info
->digits
, GFC_RND_MODE
);
193 mpfr_sub (real_info
->huge
, real_info
->huge
, a
, GFC_RND_MODE
);
196 mpfr_set_ui (a
, real_info
->radix
, GFC_RND_MODE
);
197 mpfr_pow_ui (a
, a
, real_info
->max_exponent
- 1, GFC_RND_MODE
);
199 /* (1 - b**(-p)) * b**(emax-1) */
200 mpfr_mul (real_info
->huge
, real_info
->huge
, a
, GFC_RND_MODE
);
202 /* (1 - b**(-p)) * b**(emax-1) * b */
203 mpfr_mul_ui (real_info
->huge
, real_info
->huge
, real_info
->radix
,
206 /* tiny(x) = b**(emin-1) */
207 mpfr_init (real_info
->tiny
);
208 mpfr_set_ui (real_info
->tiny
, real_info
->radix
, GFC_RND_MODE
);
209 mpfr_pow_si (real_info
->tiny
, real_info
->tiny
,
210 real_info
->min_exponent
- 1, GFC_RND_MODE
);
212 /* subnormal (x) = b**(emin - digit) */
213 mpfr_init (real_info
->subnormal
);
214 mpfr_set_ui (real_info
->subnormal
, real_info
->radix
, GFC_RND_MODE
);
215 mpfr_pow_si (real_info
->subnormal
, real_info
->subnormal
,
216 real_info
->min_exponent
- real_info
->digits
, GFC_RND_MODE
);
218 /* epsilon(x) = b**(1-p) */
219 mpfr_init (real_info
->epsilon
);
220 mpfr_set_ui (real_info
->epsilon
, real_info
->radix
, GFC_RND_MODE
);
221 mpfr_pow_si (real_info
->epsilon
, real_info
->epsilon
,
222 1 - real_info
->digits
, GFC_RND_MODE
);
224 /* range(x) = int(min(log10(huge(x)), -log10(tiny)) */
225 mpfr_log10 (a
, real_info
->huge
, GFC_RND_MODE
);
226 mpfr_log10 (b
, real_info
->tiny
, GFC_RND_MODE
);
227 mpfr_neg (b
, b
, GFC_RND_MODE
);
230 mpfr_min (a
, a
, b
, GFC_RND_MODE
);
232 real_info
->range
= (int) mpfr_get_si (a
, GFC_RND_MODE
);
234 /* precision(x) = int((p - 1) * log10(b)) + k */
235 mpfr_set_ui (a
, real_info
->radix
, GFC_RND_MODE
);
236 mpfr_log10 (a
, a
, GFC_RND_MODE
);
237 mpfr_mul_ui (a
, a
, real_info
->digits
- 1, GFC_RND_MODE
);
239 real_info
->precision
= (int) mpfr_get_si (a
, GFC_RND_MODE
);
241 /* If the radix is an integral power of 10, add one to the precision. */
242 for (i
= 10; i
<= real_info
->radix
; i
*= 10)
243 if (i
== real_info
->radix
)
244 real_info
->precision
++;
246 mpfr_clears (a
, b
, NULL
);
251 /* Clean up, get rid of numeric constants. */
254 gfc_arith_done_1 (void)
256 gfc_integer_info
*ip
;
259 for (ip
= gfc_integer_kinds
; ip
->kind
; ip
++)
261 mpz_clear (ip
->min_int
);
262 mpz_clear (ip
->pedantic_min_int
);
263 mpz_clear (ip
->huge
);
266 for (rp
= gfc_real_kinds
; rp
->kind
; rp
++)
267 mpfr_clears (rp
->epsilon
, rp
->huge
, rp
->tiny
, rp
->subnormal
, NULL
);
273 /* Given a wide character value and a character kind, determine whether
274 the character is representable for that kind. */
276 gfc_check_character_range (gfc_char_t c
, int kind
)
278 /* As wide characters are stored as 32-bit values, they're all
279 representable in UCS=4. */
284 return c
<= 255 ? true : false;
290 /* Given an integer and a kind, make sure that the integer lies within
291 the range of the kind. Returns ARITH_OK, ARITH_ASYMMETRIC or
295 gfc_check_integer_range (mpz_t p
, int kind
)
300 i
= gfc_validate_kind (BT_INTEGER
, kind
, false);
305 if (mpz_cmp (p
, gfc_integer_kinds
[i
].pedantic_min_int
) < 0)
306 result
= ARITH_ASYMMETRIC
;
310 if (flag_range_check
== 0)
313 if (mpz_cmp (p
, gfc_integer_kinds
[i
].min_int
) < 0
314 || mpz_cmp (p
, gfc_integer_kinds
[i
].huge
) > 0)
315 result
= ARITH_OVERFLOW
;
321 /* Given a real and a kind, make sure that the real lies within the
322 range of the kind. Returns ARITH_OK, ARITH_OVERFLOW or
326 gfc_check_real_range (mpfr_t p
, int kind
)
332 i
= gfc_validate_kind (BT_REAL
, kind
, false);
336 mpfr_abs (q
, p
, GFC_RND_MODE
);
342 if (flag_range_check
!= 0)
343 retval
= ARITH_OVERFLOW
;
345 else if (mpfr_nan_p (p
))
347 if (flag_range_check
!= 0)
350 else if (mpfr_sgn (q
) == 0)
355 else if (mpfr_cmp (q
, gfc_real_kinds
[i
].huge
) > 0)
357 if (flag_range_check
== 0)
358 mpfr_set_inf (p
, mpfr_sgn (p
));
360 retval
= ARITH_OVERFLOW
;
362 else if (mpfr_cmp (q
, gfc_real_kinds
[i
].subnormal
) < 0)
364 if (flag_range_check
== 0)
366 if (mpfr_sgn (p
) < 0)
368 mpfr_set_ui (p
, 0, GFC_RND_MODE
);
369 mpfr_set_si (q
, -1, GFC_RND_MODE
);
370 mpfr_copysign (p
, p
, q
, GFC_RND_MODE
);
373 mpfr_set_ui (p
, 0, GFC_RND_MODE
);
376 retval
= ARITH_UNDERFLOW
;
378 else if (mpfr_cmp (q
, gfc_real_kinds
[i
].tiny
) < 0)
380 mpfr_exp_t emin
, emax
;
383 /* Save current values of emin and emax. */
384 emin
= mpfr_get_emin ();
385 emax
= mpfr_get_emax ();
387 /* Set emin and emax for the current model number. */
388 en
= gfc_real_kinds
[i
].min_exponent
- gfc_real_kinds
[i
].digits
+ 1;
389 mpfr_set_emin ((mpfr_exp_t
) en
);
390 mpfr_set_emax ((mpfr_exp_t
) gfc_real_kinds
[i
].max_exponent
);
391 mpfr_check_range (q
, 0, GFC_RND_MODE
);
392 mpfr_subnormalize (q
, 0, GFC_RND_MODE
);
394 /* Reset emin and emax. */
395 mpfr_set_emin (emin
);
396 mpfr_set_emax (emax
);
398 /* Copy sign if needed. */
399 if (mpfr_sgn (p
) < 0)
400 mpfr_neg (p
, q
, MPFR_RNDN
);
402 mpfr_set (p
, q
, MPFR_RNDN
);
411 /* Low-level arithmetic functions. All of these subroutines assume
412 that all operands are of the same type and return an operand of the
413 same type. The other thing about these subroutines is that they
414 can fail in various ways -- overflow, underflow, division by zero,
415 zero raised to the zero, etc. */
418 gfc_arith_not (gfc_expr
*op1
, gfc_expr
**resultp
)
422 result
= gfc_get_constant_expr (BT_LOGICAL
, op1
->ts
.kind
, &op1
->where
);
423 result
->value
.logical
= !op1
->value
.logical
;
431 gfc_arith_and (gfc_expr
*op1
, gfc_expr
*op2
, gfc_expr
**resultp
)
435 result
= gfc_get_constant_expr (BT_LOGICAL
, gfc_kind_max (op1
, op2
),
437 result
->value
.logical
= op1
->value
.logical
&& op2
->value
.logical
;
445 gfc_arith_or (gfc_expr
*op1
, gfc_expr
*op2
, gfc_expr
**resultp
)
449 result
= gfc_get_constant_expr (BT_LOGICAL
, gfc_kind_max (op1
, op2
),
451 result
->value
.logical
= op1
->value
.logical
|| op2
->value
.logical
;
459 gfc_arith_eqv (gfc_expr
*op1
, gfc_expr
*op2
, gfc_expr
**resultp
)
463 result
= gfc_get_constant_expr (BT_LOGICAL
, gfc_kind_max (op1
, op2
),
465 result
->value
.logical
= op1
->value
.logical
== op2
->value
.logical
;
473 gfc_arith_neqv (gfc_expr
*op1
, gfc_expr
*op2
, gfc_expr
**resultp
)
477 result
= gfc_get_constant_expr (BT_LOGICAL
, gfc_kind_max (op1
, op2
),
479 result
->value
.logical
= op1
->value
.logical
!= op2
->value
.logical
;
486 /* Make sure a constant numeric expression is within the range for
487 its type and kind. Note that there's also a gfc_check_range(),
488 but that one deals with the intrinsic RANGE function. */
491 gfc_range_check (gfc_expr
*e
)
499 rc
= gfc_check_integer_range (e
->value
.integer
, e
->ts
.kind
);
503 rc
= gfc_check_real_range (e
->value
.real
, e
->ts
.kind
);
504 if (rc
== ARITH_UNDERFLOW
)
505 mpfr_set_ui (e
->value
.real
, 0, GFC_RND_MODE
);
506 if (rc
== ARITH_OVERFLOW
)
507 mpfr_set_inf (e
->value
.real
, mpfr_sgn (e
->value
.real
));
509 mpfr_set_nan (e
->value
.real
);
513 rc
= gfc_check_real_range (mpc_realref (e
->value
.complex), e
->ts
.kind
);
514 if (rc
== ARITH_UNDERFLOW
)
515 mpfr_set_ui (mpc_realref (e
->value
.complex), 0, GFC_RND_MODE
);
516 if (rc
== ARITH_OVERFLOW
)
517 mpfr_set_inf (mpc_realref (e
->value
.complex),
518 mpfr_sgn (mpc_realref (e
->value
.complex)));
520 mpfr_set_nan (mpc_realref (e
->value
.complex));
522 rc2
= gfc_check_real_range (mpc_imagref (e
->value
.complex), e
->ts
.kind
);
523 if (rc
== ARITH_UNDERFLOW
)
524 mpfr_set_ui (mpc_imagref (e
->value
.complex), 0, GFC_RND_MODE
);
525 if (rc
== ARITH_OVERFLOW
)
526 mpfr_set_inf (mpc_imagref (e
->value
.complex),
527 mpfr_sgn (mpc_imagref (e
->value
.complex)));
529 mpfr_set_nan (mpc_imagref (e
->value
.complex));
536 gfc_internal_error ("gfc_range_check(): Bad type");
543 /* Several of the following routines use the same set of statements to
544 check the validity of the result. Encapsulate the checking here. */
547 check_result (arith rc
, gfc_expr
*x
, gfc_expr
*r
, gfc_expr
**rp
)
551 if (val
== ARITH_UNDERFLOW
)
554 gfc_warning (OPT_Wunderflow
, gfc_arith_error (val
), &x
->where
);
558 if (val
== ARITH_ASYMMETRIC
)
560 gfc_warning (0, gfc_arith_error (val
), &x
->where
);
564 if (val
== ARITH_OK
|| val
== ARITH_OVERFLOW
)
573 /* It may seem silly to have a subroutine that actually computes the
574 unary plus of a constant, but it prevents us from making exceptions
575 in the code elsewhere. Used for unary plus and parenthesized
579 gfc_arith_identity (gfc_expr
*op1
, gfc_expr
**resultp
)
581 *resultp
= gfc_copy_expr (op1
);
587 gfc_arith_uminus (gfc_expr
*op1
, gfc_expr
**resultp
)
592 result
= gfc_get_constant_expr (op1
->ts
.type
, op1
->ts
.kind
, &op1
->where
);
594 switch (op1
->ts
.type
)
597 mpz_neg (result
->value
.integer
, op1
->value
.integer
);
601 mpfr_neg (result
->value
.real
, op1
->value
.real
, GFC_RND_MODE
);
605 mpc_neg (result
->value
.complex, op1
->value
.complex, GFC_MPC_RND_MODE
);
609 gfc_internal_error ("gfc_arith_uminus(): Bad basic type");
612 rc
= gfc_range_check (result
);
614 return check_result (rc
, op1
, result
, resultp
);
619 gfc_arith_plus (gfc_expr
*op1
, gfc_expr
*op2
, gfc_expr
**resultp
)
624 result
= gfc_get_constant_expr (op1
->ts
.type
, op1
->ts
.kind
, &op1
->where
);
626 switch (op1
->ts
.type
)
629 mpz_add (result
->value
.integer
, op1
->value
.integer
, op2
->value
.integer
);
633 mpfr_add (result
->value
.real
, op1
->value
.real
, op2
->value
.real
,
638 mpc_add (result
->value
.complex, op1
->value
.complex, op2
->value
.complex,
643 gfc_internal_error ("gfc_arith_plus(): Bad basic type");
646 rc
= gfc_range_check (result
);
648 return check_result (rc
, op1
, result
, resultp
);
653 gfc_arith_minus (gfc_expr
*op1
, gfc_expr
*op2
, gfc_expr
**resultp
)
658 result
= gfc_get_constant_expr (op1
->ts
.type
, op1
->ts
.kind
, &op1
->where
);
660 switch (op1
->ts
.type
)
663 mpz_sub (result
->value
.integer
, op1
->value
.integer
, op2
->value
.integer
);
667 mpfr_sub (result
->value
.real
, op1
->value
.real
, op2
->value
.real
,
672 mpc_sub (result
->value
.complex, op1
->value
.complex,
673 op2
->value
.complex, GFC_MPC_RND_MODE
);
677 gfc_internal_error ("gfc_arith_minus(): Bad basic type");
680 rc
= gfc_range_check (result
);
682 return check_result (rc
, op1
, result
, resultp
);
687 gfc_arith_times (gfc_expr
*op1
, gfc_expr
*op2
, gfc_expr
**resultp
)
692 result
= gfc_get_constant_expr (op1
->ts
.type
, op1
->ts
.kind
, &op1
->where
);
694 switch (op1
->ts
.type
)
697 mpz_mul (result
->value
.integer
, op1
->value
.integer
, op2
->value
.integer
);
701 mpfr_mul (result
->value
.real
, op1
->value
.real
, op2
->value
.real
,
706 gfc_set_model (mpc_realref (op1
->value
.complex));
707 mpc_mul (result
->value
.complex, op1
->value
.complex, op2
->value
.complex,
712 gfc_internal_error ("gfc_arith_times(): Bad basic type");
715 rc
= gfc_range_check (result
);
717 return check_result (rc
, op1
, result
, resultp
);
722 gfc_arith_divide (gfc_expr
*op1
, gfc_expr
*op2
, gfc_expr
**resultp
)
729 result
= gfc_get_constant_expr (op1
->ts
.type
, op1
->ts
.kind
, &op1
->where
);
731 switch (op1
->ts
.type
)
734 if (mpz_sgn (op2
->value
.integer
) == 0)
740 if (warn_integer_division
)
744 mpz_tdiv_qr (result
->value
.integer
, r
, op1
->value
.integer
,
747 if (mpz_cmp_si (r
, 0) != 0)
750 p
= mpz_get_str (NULL
, 10, result
->value
.integer
);
751 gfc_warning_now (OPT_Winteger_division
, "Integer division "
752 "truncated to constant %qs at %L", p
,
759 mpz_tdiv_q (result
->value
.integer
, op1
->value
.integer
,
765 if (mpfr_sgn (op2
->value
.real
) == 0 && flag_range_check
== 1)
771 mpfr_div (result
->value
.real
, op1
->value
.real
, op2
->value
.real
,
776 if (mpc_cmp_si_si (op2
->value
.complex, 0, 0) == 0
777 && flag_range_check
== 1)
783 gfc_set_model (mpc_realref (op1
->value
.complex));
784 if (mpc_cmp_si_si (op2
->value
.complex, 0, 0) == 0)
786 /* In Fortran, return (NaN + NaN I) for any zero divisor. See
788 mpfr_set_nan (mpc_realref (result
->value
.complex));
789 mpfr_set_nan (mpc_imagref (result
->value
.complex));
792 mpc_div (result
->value
.complex, op1
->value
.complex, op2
->value
.complex,
797 gfc_internal_error ("gfc_arith_divide(): Bad basic type");
801 rc
= gfc_range_check (result
);
803 return check_result (rc
, op1
, result
, resultp
);
806 /* Raise a number to a power. */
809 arith_power (gfc_expr
*op1
, gfc_expr
*op2
, gfc_expr
**resultp
)
816 result
= gfc_get_constant_expr (op1
->ts
.type
, op1
->ts
.kind
, &op1
->where
);
818 switch (op2
->ts
.type
)
821 power_sign
= mpz_sgn (op2
->value
.integer
);
825 /* Handle something to the zeroth power. Since we're dealing
826 with integral exponents, there is no ambiguity in the
827 limiting procedure used to determine the value of 0**0. */
828 switch (op1
->ts
.type
)
831 mpz_set_ui (result
->value
.integer
, 1);
835 mpfr_set_ui (result
->value
.real
, 1, GFC_RND_MODE
);
839 mpc_set_ui (result
->value
.complex, 1, GFC_MPC_RND_MODE
);
843 gfc_internal_error ("arith_power(): Bad base");
848 switch (op1
->ts
.type
)
852 /* First, we simplify the cases of op1 == 1, 0 or -1. */
853 if (mpz_cmp_si (op1
->value
.integer
, 1) == 0)
856 mpz_set_si (result
->value
.integer
, 1);
858 else if (mpz_cmp_si (op1
->value
.integer
, 0) == 0)
860 /* 0**op2 == 0, if op2 > 0
861 0**op2 overflow, if op2 < 0 ; in that case, we
862 set the result to 0 and return ARITH_DIV0. */
863 mpz_set_si (result
->value
.integer
, 0);
864 if (mpz_cmp_si (op2
->value
.integer
, 0) < 0)
867 else if (mpz_cmp_si (op1
->value
.integer
, -1) == 0)
869 /* (-1)**op2 == (-1)**(mod(op2,2)) */
870 unsigned int odd
= mpz_fdiv_ui (op2
->value
.integer
, 2);
872 mpz_set_si (result
->value
.integer
, -1);
874 mpz_set_si (result
->value
.integer
, 1);
876 /* Then, we take care of op2 < 0. */
877 else if (mpz_cmp_si (op2
->value
.integer
, 0) < 0)
879 /* if op2 < 0, op1**op2 == 0 because abs(op1) > 1. */
880 mpz_set_si (result
->value
.integer
, 0);
881 if (warn_integer_division
)
882 gfc_warning_now (OPT_Winteger_division
, "Negative "
883 "exponent of integer has zero "
884 "result at %L", &result
->where
);
888 /* We have abs(op1) > 1 and op2 > 1.
889 If op2 > bit_size(op1), we'll have an out-of-range
893 k
= gfc_validate_kind (BT_INTEGER
, op1
->ts
.kind
, false);
894 power
= gfc_integer_kinds
[k
].bit_size
;
895 if (mpz_cmp_si (op2
->value
.integer
, power
) < 0)
897 gfc_extract_int (op2
, &power
);
898 mpz_pow_ui (result
->value
.integer
, op1
->value
.integer
,
900 rc
= gfc_range_check (result
);
901 if (rc
== ARITH_OVERFLOW
)
902 gfc_error_now ("Result of exponentiation at %L "
903 "exceeds the range of %s", &op1
->where
,
904 gfc_typename (&(op1
->ts
)));
908 /* Provide a nonsense value to propagate up. */
909 mpz_set (result
->value
.integer
,
910 gfc_integer_kinds
[k
].huge
);
911 mpz_add_ui (result
->value
.integer
,
912 result
->value
.integer
, 1);
920 mpfr_pow_z (result
->value
.real
, op1
->value
.real
,
921 op2
->value
.integer
, GFC_RND_MODE
);
925 mpc_pow_z (result
->value
.complex, op1
->value
.complex,
926 op2
->value
.integer
, GFC_MPC_RND_MODE
);
937 if (gfc_init_expr_flag
)
939 if (!gfc_notify_std (GFC_STD_F2003
, "Noninteger "
940 "exponent in an initialization "
941 "expression at %L", &op2
->where
))
943 gfc_free_expr (result
);
944 return ARITH_PROHIBIT
;
948 if (mpfr_cmp_si (op1
->value
.real
, 0) < 0)
950 gfc_error ("Raising a negative REAL at %L to "
951 "a REAL power is prohibited", &op1
->where
);
952 gfc_free_expr (result
);
953 return ARITH_PROHIBIT
;
956 mpfr_pow (result
->value
.real
, op1
->value
.real
, op2
->value
.real
,
962 if (gfc_init_expr_flag
)
964 if (!gfc_notify_std (GFC_STD_F2003
, "Noninteger "
965 "exponent in an initialization "
966 "expression at %L", &op2
->where
))
968 gfc_free_expr (result
);
969 return ARITH_PROHIBIT
;
973 mpc_pow (result
->value
.complex, op1
->value
.complex,
974 op2
->value
.complex, GFC_MPC_RND_MODE
);
978 gfc_internal_error ("arith_power(): unknown type");
982 rc
= gfc_range_check (result
);
984 return check_result (rc
, op1
, result
, resultp
);
988 /* Concatenate two string constants. */
991 gfc_arith_concat (gfc_expr
*op1
, gfc_expr
*op2
, gfc_expr
**resultp
)
996 /* By cleverly playing around with constructors, it is possible
997 to get mismaching types here. */
998 if (op1
->ts
.type
!= BT_CHARACTER
|| op2
->ts
.type
!= BT_CHARACTER
999 || op1
->ts
.kind
!= op2
->ts
.kind
)
1000 return ARITH_WRONGCONCAT
;
1002 result
= gfc_get_constant_expr (BT_CHARACTER
, op1
->ts
.kind
,
1005 len
= op1
->value
.character
.length
+ op2
->value
.character
.length
;
1007 result
->value
.character
.string
= gfc_get_wide_string (len
+ 1);
1008 result
->value
.character
.length
= len
;
1010 memcpy (result
->value
.character
.string
, op1
->value
.character
.string
,
1011 op1
->value
.character
.length
* sizeof (gfc_char_t
));
1013 memcpy (&result
->value
.character
.string
[op1
->value
.character
.length
],
1014 op2
->value
.character
.string
,
1015 op2
->value
.character
.length
* sizeof (gfc_char_t
));
1017 result
->value
.character
.string
[len
] = '\0';
1024 /* Comparison between real values; returns 0 if (op1 .op. op2) is true.
1025 This function mimics mpfr_cmp but takes NaN into account. */
1028 compare_real (gfc_expr
*op1
, gfc_expr
*op2
, gfc_intrinsic_op op
)
1034 rc
= mpfr_equal_p (op1
->value
.real
, op2
->value
.real
) ? 0 : 1;
1037 rc
= mpfr_greater_p (op1
->value
.real
, op2
->value
.real
) ? 1 : -1;
1040 rc
= mpfr_greaterequal_p (op1
->value
.real
, op2
->value
.real
) ? 1 : -1;
1043 rc
= mpfr_less_p (op1
->value
.real
, op2
->value
.real
) ? -1 : 1;
1046 rc
= mpfr_lessequal_p (op1
->value
.real
, op2
->value
.real
) ? -1 : 1;
1049 gfc_internal_error ("compare_real(): Bad operator");
1055 /* Comparison operators. Assumes that the two expression nodes
1056 contain two constants of the same type. The op argument is
1057 needed to handle NaN correctly. */
1060 gfc_compare_expr (gfc_expr
*op1
, gfc_expr
*op2
, gfc_intrinsic_op op
)
1064 switch (op1
->ts
.type
)
1067 rc
= mpz_cmp (op1
->value
.integer
, op2
->value
.integer
);
1071 rc
= compare_real (op1
, op2
, op
);
1075 rc
= gfc_compare_string (op1
, op2
);
1079 rc
= ((!op1
->value
.logical
&& op2
->value
.logical
)
1080 || (op1
->value
.logical
&& !op2
->value
.logical
));
1084 gfc_internal_error ("gfc_compare_expr(): Bad basic type");
1091 /* Compare a pair of complex numbers. Naturally, this is only for
1092 equality and inequality. */
1095 compare_complex (gfc_expr
*op1
, gfc_expr
*op2
)
1097 return mpc_cmp (op1
->value
.complex, op2
->value
.complex) == 0;
1101 /* Given two constant strings and the inverse collating sequence, compare the
1102 strings. We return -1 for a < b, 0 for a == b and 1 for a > b.
1103 We use the processor's default collating sequence. */
1106 gfc_compare_string (gfc_expr
*a
, gfc_expr
*b
)
1108 size_t len
, alen
, blen
, i
;
1111 alen
= a
->value
.character
.length
;
1112 blen
= b
->value
.character
.length
;
1114 len
= MAX(alen
, blen
);
1116 for (i
= 0; i
< len
; i
++)
1118 ac
= ((i
< alen
) ? a
->value
.character
.string
[i
] : ' ');
1119 bc
= ((i
< blen
) ? b
->value
.character
.string
[i
] : ' ');
1127 /* Strings are equal */
1133 gfc_compare_with_Cstring (gfc_expr
*a
, const char *b
, bool case_sensitive
)
1135 size_t len
, alen
, blen
, i
;
1138 alen
= a
->value
.character
.length
;
1141 len
= MAX(alen
, blen
);
1143 for (i
= 0; i
< len
; i
++)
1145 ac
= ((i
< alen
) ? a
->value
.character
.string
[i
] : ' ');
1146 bc
= ((i
< blen
) ? b
[i
] : ' ');
1148 if (!case_sensitive
)
1160 /* Strings are equal */
1165 /* Specific comparison subroutines. */
1168 gfc_arith_eq (gfc_expr
*op1
, gfc_expr
*op2
, gfc_expr
**resultp
)
1172 result
= gfc_get_constant_expr (BT_LOGICAL
, gfc_default_logical_kind
,
1174 result
->value
.logical
= (op1
->ts
.type
== BT_COMPLEX
)
1175 ? compare_complex (op1
, op2
)
1176 : (gfc_compare_expr (op1
, op2
, INTRINSIC_EQ
) == 0);
1184 gfc_arith_ne (gfc_expr
*op1
, gfc_expr
*op2
, gfc_expr
**resultp
)
1188 result
= gfc_get_constant_expr (BT_LOGICAL
, gfc_default_logical_kind
,
1190 result
->value
.logical
= (op1
->ts
.type
== BT_COMPLEX
)
1191 ? !compare_complex (op1
, op2
)
1192 : (gfc_compare_expr (op1
, op2
, INTRINSIC_EQ
) != 0);
1200 gfc_arith_gt (gfc_expr
*op1
, gfc_expr
*op2
, gfc_expr
**resultp
)
1204 result
= gfc_get_constant_expr (BT_LOGICAL
, gfc_default_logical_kind
,
1206 result
->value
.logical
= (gfc_compare_expr (op1
, op2
, INTRINSIC_GT
) > 0);
1214 gfc_arith_ge (gfc_expr
*op1
, gfc_expr
*op2
, gfc_expr
**resultp
)
1218 result
= gfc_get_constant_expr (BT_LOGICAL
, gfc_default_logical_kind
,
1220 result
->value
.logical
= (gfc_compare_expr (op1
, op2
, INTRINSIC_GE
) >= 0);
1228 gfc_arith_lt (gfc_expr
*op1
, gfc_expr
*op2
, gfc_expr
**resultp
)
1232 result
= gfc_get_constant_expr (BT_LOGICAL
, gfc_default_logical_kind
,
1234 result
->value
.logical
= (gfc_compare_expr (op1
, op2
, INTRINSIC_LT
) < 0);
1242 gfc_arith_le (gfc_expr
*op1
, gfc_expr
*op2
, gfc_expr
**resultp
)
1246 result
= gfc_get_constant_expr (BT_LOGICAL
, gfc_default_logical_kind
,
1248 result
->value
.logical
= (gfc_compare_expr (op1
, op2
, INTRINSIC_LE
) <= 0);
1256 reduce_unary (arith (*eval
) (gfc_expr
*, gfc_expr
**), gfc_expr
*op
,
1259 gfc_constructor_base head
;
1264 if (op
->expr_type
== EXPR_CONSTANT
)
1265 return eval (op
, result
);
1268 head
= gfc_constructor_copy (op
->value
.constructor
);
1269 for (c
= gfc_constructor_first (head
); c
; c
= gfc_constructor_next (c
))
1271 rc
= reduce_unary (eval
, c
->expr
, &r
);
1276 gfc_replace_expr (c
->expr
, r
);
1280 gfc_constructor_free (head
);
1283 gfc_constructor
*c
= gfc_constructor_first (head
);
1284 r
= gfc_get_array_expr (c
->expr
->ts
.type
, c
->expr
->ts
.kind
,
1286 r
->shape
= gfc_copy_shape (op
->shape
, op
->rank
);
1288 r
->value
.constructor
= head
;
1297 reduce_binary_ac (arith (*eval
) (gfc_expr
*, gfc_expr
*, gfc_expr
**),
1298 gfc_expr
*op1
, gfc_expr
*op2
, gfc_expr
**result
)
1300 gfc_constructor_base head
;
1303 arith rc
= ARITH_OK
;
1305 head
= gfc_constructor_copy (op1
->value
.constructor
);
1306 for (c
= gfc_constructor_first (head
); c
; c
= gfc_constructor_next (c
))
1308 if (c
->expr
->expr_type
== EXPR_CONSTANT
)
1309 rc
= eval (c
->expr
, op2
, &r
);
1311 rc
= reduce_binary_ac (eval
, c
->expr
, op2
, &r
);
1316 gfc_replace_expr (c
->expr
, r
);
1320 gfc_constructor_free (head
);
1323 gfc_constructor
*c
= gfc_constructor_first (head
);
1324 r
= gfc_get_array_expr (c
->expr
->ts
.type
, c
->expr
->ts
.kind
,
1326 r
->shape
= gfc_copy_shape (op1
->shape
, op1
->rank
);
1327 r
->rank
= op1
->rank
;
1328 r
->value
.constructor
= head
;
1337 reduce_binary_ca (arith (*eval
) (gfc_expr
*, gfc_expr
*, gfc_expr
**),
1338 gfc_expr
*op1
, gfc_expr
*op2
, gfc_expr
**result
)
1340 gfc_constructor_base head
;
1343 arith rc
= ARITH_OK
;
1345 head
= gfc_constructor_copy (op2
->value
.constructor
);
1346 for (c
= gfc_constructor_first (head
); c
; c
= gfc_constructor_next (c
))
1348 if (c
->expr
->expr_type
== EXPR_CONSTANT
)
1349 rc
= eval (op1
, c
->expr
, &r
);
1351 rc
= reduce_binary_ca (eval
, op1
, c
->expr
, &r
);
1356 gfc_replace_expr (c
->expr
, r
);
1360 gfc_constructor_free (head
);
1363 gfc_constructor
*c
= gfc_constructor_first (head
);
1364 r
= gfc_get_array_expr (c
->expr
->ts
.type
, c
->expr
->ts
.kind
,
1366 r
->shape
= gfc_copy_shape (op2
->shape
, op2
->rank
);
1367 r
->rank
= op2
->rank
;
1368 r
->value
.constructor
= head
;
1376 /* We need a forward declaration of reduce_binary. */
1377 static arith
reduce_binary (arith (*eval
) (gfc_expr
*, gfc_expr
*, gfc_expr
**),
1378 gfc_expr
*op1
, gfc_expr
*op2
, gfc_expr
**result
);
1382 reduce_binary_aa (arith (*eval
) (gfc_expr
*, gfc_expr
*, gfc_expr
**),
1383 gfc_expr
*op1
, gfc_expr
*op2
, gfc_expr
**result
)
1385 gfc_constructor_base head
;
1386 gfc_constructor
*c
, *d
;
1388 arith rc
= ARITH_OK
;
1390 if (!gfc_check_conformance (op1
, op2
, _("elemental binary operation")))
1391 return ARITH_INCOMMENSURATE
;
1393 head
= gfc_constructor_copy (op1
->value
.constructor
);
1394 for (c
= gfc_constructor_first (head
),
1395 d
= gfc_constructor_first (op2
->value
.constructor
);
1397 c
= gfc_constructor_next (c
), d
= gfc_constructor_next (d
))
1399 rc
= reduce_binary (eval
, c
->expr
, d
->expr
, &r
);
1403 gfc_replace_expr (c
->expr
, r
);
1407 rc
= ARITH_INCOMMENSURATE
;
1410 gfc_constructor_free (head
);
1413 gfc_constructor
*c
= gfc_constructor_first (head
);
1414 r
= gfc_get_array_expr (c
->expr
->ts
.type
, c
->expr
->ts
.kind
,
1416 r
->shape
= gfc_copy_shape (op1
->shape
, op1
->rank
);
1417 r
->rank
= op1
->rank
;
1418 r
->value
.constructor
= head
;
1427 reduce_binary (arith (*eval
) (gfc_expr
*, gfc_expr
*, gfc_expr
**),
1428 gfc_expr
*op1
, gfc_expr
*op2
, gfc_expr
**result
)
1430 if (op1
->expr_type
== EXPR_CONSTANT
&& op2
->expr_type
== EXPR_CONSTANT
)
1431 return eval (op1
, op2
, result
);
1433 if (op1
->expr_type
== EXPR_CONSTANT
&& op2
->expr_type
== EXPR_ARRAY
)
1434 return reduce_binary_ca (eval
, op1
, op2
, result
);
1436 if (op1
->expr_type
== EXPR_ARRAY
&& op2
->expr_type
== EXPR_CONSTANT
)
1437 return reduce_binary_ac (eval
, op1
, op2
, result
);
1439 return reduce_binary_aa (eval
, op1
, op2
, result
);
1445 arith (*f2
)(gfc_expr
*, gfc_expr
**);
1446 arith (*f3
)(gfc_expr
*, gfc_expr
*, gfc_expr
**);
1450 /* High level arithmetic subroutines. These subroutines go into
1451 eval_intrinsic(), which can do one of several things to its
1452 operands. If the operands are incompatible with the intrinsic
1453 operation, we return a node pointing to the operands and hope that
1454 an operator interface is found during resolution.
1456 If the operands are compatible and are constants, then we try doing
1457 the arithmetic. We also handle the cases where either or both
1458 operands are array constructors. */
1461 eval_intrinsic (gfc_intrinsic_op op
,
1462 eval_f eval
, gfc_expr
*op1
, gfc_expr
*op2
)
1464 gfc_expr temp
, *result
;
1468 gfc_clear_ts (&temp
.ts
);
1474 if (op1
->ts
.type
!= BT_LOGICAL
)
1477 temp
.ts
.type
= BT_LOGICAL
;
1478 temp
.ts
.kind
= gfc_default_logical_kind
;
1482 /* Logical binary operators */
1485 case INTRINSIC_NEQV
:
1487 if (op1
->ts
.type
!= BT_LOGICAL
|| op2
->ts
.type
!= BT_LOGICAL
)
1490 temp
.ts
.type
= BT_LOGICAL
;
1491 temp
.ts
.kind
= gfc_default_logical_kind
;
1496 case INTRINSIC_UPLUS
:
1497 case INTRINSIC_UMINUS
:
1498 if (!gfc_numeric_ts (&op1
->ts
))
1505 case INTRINSIC_PARENTHESES
:
1510 /* Additional restrictions for ordering relations. */
1512 case INTRINSIC_GE_OS
:
1514 case INTRINSIC_LT_OS
:
1516 case INTRINSIC_LE_OS
:
1518 case INTRINSIC_GT_OS
:
1519 if (op1
->ts
.type
== BT_COMPLEX
|| op2
->ts
.type
== BT_COMPLEX
)
1521 temp
.ts
.type
= BT_LOGICAL
;
1522 temp
.ts
.kind
= gfc_default_logical_kind
;
1528 case INTRINSIC_EQ_OS
:
1530 case INTRINSIC_NE_OS
:
1531 if (op1
->ts
.type
== BT_CHARACTER
&& op2
->ts
.type
== BT_CHARACTER
)
1534 temp
.ts
.type
= BT_LOGICAL
;
1535 temp
.ts
.kind
= gfc_default_logical_kind
;
1537 /* If kind mismatch, exit and we'll error out later. */
1538 if (op1
->ts
.kind
!= op2
->ts
.kind
)
1545 /* Numeric binary */
1546 case INTRINSIC_PLUS
:
1547 case INTRINSIC_MINUS
:
1548 case INTRINSIC_TIMES
:
1549 case INTRINSIC_DIVIDE
:
1550 case INTRINSIC_POWER
:
1551 if (!gfc_numeric_ts (&op1
->ts
) || !gfc_numeric_ts (&op2
->ts
))
1554 /* Insert any necessary type conversions to make the operands
1557 temp
.expr_type
= EXPR_OP
;
1558 gfc_clear_ts (&temp
.ts
);
1559 temp
.value
.op
.op
= op
;
1561 temp
.value
.op
.op1
= op1
;
1562 temp
.value
.op
.op2
= op2
;
1564 gfc_type_convert_binary (&temp
, warn_conversion
|| warn_conversion_extra
);
1566 if (op
== INTRINSIC_EQ
|| op
== INTRINSIC_NE
1567 || op
== INTRINSIC_GE
|| op
== INTRINSIC_GT
1568 || op
== INTRINSIC_LE
|| op
== INTRINSIC_LT
1569 || op
== INTRINSIC_EQ_OS
|| op
== INTRINSIC_NE_OS
1570 || op
== INTRINSIC_GE_OS
|| op
== INTRINSIC_GT_OS
1571 || op
== INTRINSIC_LE_OS
|| op
== INTRINSIC_LT_OS
)
1573 temp
.ts
.type
= BT_LOGICAL
;
1574 temp
.ts
.kind
= gfc_default_logical_kind
;
1580 /* Character binary */
1581 case INTRINSIC_CONCAT
:
1582 if (op1
->ts
.type
!= BT_CHARACTER
|| op2
->ts
.type
!= BT_CHARACTER
1583 || op1
->ts
.kind
!= op2
->ts
.kind
)
1586 temp
.ts
.type
= BT_CHARACTER
;
1587 temp
.ts
.kind
= op1
->ts
.kind
;
1591 case INTRINSIC_USER
:
1595 gfc_internal_error ("eval_intrinsic(): Bad operator");
1598 if (op1
->expr_type
!= EXPR_CONSTANT
1599 && (op1
->expr_type
!= EXPR_ARRAY
1600 || !gfc_is_constant_expr (op1
) || !gfc_expanded_ac (op1
)))
1604 && op2
->expr_type
!= EXPR_CONSTANT
1605 && (op2
->expr_type
!= EXPR_ARRAY
1606 || !gfc_is_constant_expr (op2
) || !gfc_expanded_ac (op2
)))
1610 rc
= reduce_unary (eval
.f2
, op1
, &result
);
1612 rc
= reduce_binary (eval
.f3
, op1
, op2
, &result
);
1615 /* Something went wrong. */
1616 if (op
== INTRINSIC_POWER
&& rc
== ARITH_PROHIBIT
)
1621 gfc_error (gfc_arith_error (rc
), &op1
->where
);
1622 if (rc
== ARITH_OVERFLOW
)
1625 if (rc
== ARITH_DIV0
&& op2
->ts
.type
== BT_INTEGER
)
1626 gfc_seen_div0
= true;
1633 gfc_free_expr (op1
);
1634 gfc_free_expr (op2
);
1638 /* Create a run-time expression. */
1639 result
= gfc_get_operator_expr (&op1
->where
, op
, op1
, op2
);
1640 result
->ts
= temp
.ts
;
1646 /* Modify type of expression for zero size array. */
1649 eval_type_intrinsic0 (gfc_intrinsic_op iop
, gfc_expr
*op
)
1652 gfc_internal_error ("eval_type_intrinsic0(): op NULL");
1657 case INTRINSIC_GE_OS
:
1659 case INTRINSIC_LT_OS
:
1661 case INTRINSIC_LE_OS
:
1663 case INTRINSIC_GT_OS
:
1665 case INTRINSIC_EQ_OS
:
1667 case INTRINSIC_NE_OS
:
1668 op
->ts
.type
= BT_LOGICAL
;
1669 op
->ts
.kind
= gfc_default_logical_kind
;
1680 /* Return nonzero if the expression is a zero size array. */
1683 gfc_zero_size_array (gfc_expr
*e
)
1685 if (e
->expr_type
!= EXPR_ARRAY
)
1688 return e
->value
.constructor
== NULL
;
1692 /* Reduce a binary expression where at least one of the operands
1693 involves a zero-length array. Returns NULL if neither of the
1694 operands is a zero-length array. */
1697 reduce_binary0 (gfc_expr
*op1
, gfc_expr
*op2
)
1699 if (gfc_zero_size_array (op1
))
1701 gfc_free_expr (op2
);
1705 if (gfc_zero_size_array (op2
))
1707 gfc_free_expr (op1
);
1716 eval_intrinsic_f2 (gfc_intrinsic_op op
,
1717 arith (*eval
) (gfc_expr
*, gfc_expr
**),
1718 gfc_expr
*op1
, gfc_expr
*op2
)
1725 if (gfc_zero_size_array (op1
))
1726 return eval_type_intrinsic0 (op
, op1
);
1730 result
= reduce_binary0 (op1
, op2
);
1732 return eval_type_intrinsic0 (op
, result
);
1736 return eval_intrinsic (op
, f
, op1
, op2
);
1741 eval_intrinsic_f3 (gfc_intrinsic_op op
,
1742 arith (*eval
) (gfc_expr
*, gfc_expr
*, gfc_expr
**),
1743 gfc_expr
*op1
, gfc_expr
*op2
)
1751 result
= reduce_binary0 (op1
, op2
);
1753 return eval_type_intrinsic0(op
, result
);
1756 return eval_intrinsic (op
, f
, op1
, op2
);
1761 gfc_parentheses (gfc_expr
*op
)
1763 if (gfc_is_constant_expr (op
))
1766 return eval_intrinsic_f2 (INTRINSIC_PARENTHESES
, gfc_arith_identity
,
1771 gfc_uplus (gfc_expr
*op
)
1773 return eval_intrinsic_f2 (INTRINSIC_UPLUS
, gfc_arith_identity
, op
, NULL
);
1778 gfc_uminus (gfc_expr
*op
)
1780 return eval_intrinsic_f2 (INTRINSIC_UMINUS
, gfc_arith_uminus
, op
, NULL
);
1785 gfc_add (gfc_expr
*op1
, gfc_expr
*op2
)
1787 return eval_intrinsic_f3 (INTRINSIC_PLUS
, gfc_arith_plus
, op1
, op2
);
1792 gfc_subtract (gfc_expr
*op1
, gfc_expr
*op2
)
1794 return eval_intrinsic_f3 (INTRINSIC_MINUS
, gfc_arith_minus
, op1
, op2
);
1799 gfc_multiply (gfc_expr
*op1
, gfc_expr
*op2
)
1801 return eval_intrinsic_f3 (INTRINSIC_TIMES
, gfc_arith_times
, op1
, op2
);
1806 gfc_divide (gfc_expr
*op1
, gfc_expr
*op2
)
1808 return eval_intrinsic_f3 (INTRINSIC_DIVIDE
, gfc_arith_divide
, op1
, op2
);
1813 gfc_power (gfc_expr
*op1
, gfc_expr
*op2
)
1815 return eval_intrinsic_f3 (INTRINSIC_POWER
, arith_power
, op1
, op2
);
1820 gfc_concat (gfc_expr
*op1
, gfc_expr
*op2
)
1822 return eval_intrinsic_f3 (INTRINSIC_CONCAT
, gfc_arith_concat
, op1
, op2
);
1827 gfc_and (gfc_expr
*op1
, gfc_expr
*op2
)
1829 return eval_intrinsic_f3 (INTRINSIC_AND
, gfc_arith_and
, op1
, op2
);
1834 gfc_or (gfc_expr
*op1
, gfc_expr
*op2
)
1836 return eval_intrinsic_f3 (INTRINSIC_OR
, gfc_arith_or
, op1
, op2
);
1841 gfc_not (gfc_expr
*op1
)
1843 return eval_intrinsic_f2 (INTRINSIC_NOT
, gfc_arith_not
, op1
, NULL
);
1848 gfc_eqv (gfc_expr
*op1
, gfc_expr
*op2
)
1850 return eval_intrinsic_f3 (INTRINSIC_EQV
, gfc_arith_eqv
, op1
, op2
);
1855 gfc_neqv (gfc_expr
*op1
, gfc_expr
*op2
)
1857 return eval_intrinsic_f3 (INTRINSIC_NEQV
, gfc_arith_neqv
, op1
, op2
);
1862 gfc_eq (gfc_expr
*op1
, gfc_expr
*op2
, gfc_intrinsic_op op
)
1864 return eval_intrinsic_f3 (op
, gfc_arith_eq
, op1
, op2
);
1869 gfc_ne (gfc_expr
*op1
, gfc_expr
*op2
, gfc_intrinsic_op op
)
1871 return eval_intrinsic_f3 (op
, gfc_arith_ne
, op1
, op2
);
1876 gfc_gt (gfc_expr
*op1
, gfc_expr
*op2
, gfc_intrinsic_op op
)
1878 return eval_intrinsic_f3 (op
, gfc_arith_gt
, op1
, op2
);
1883 gfc_ge (gfc_expr
*op1
, gfc_expr
*op2
, gfc_intrinsic_op op
)
1885 return eval_intrinsic_f3 (op
, gfc_arith_ge
, op1
, op2
);
1890 gfc_lt (gfc_expr
*op1
, gfc_expr
*op2
, gfc_intrinsic_op op
)
1892 return eval_intrinsic_f3 (op
, gfc_arith_lt
, op1
, op2
);
1897 gfc_le (gfc_expr
*op1
, gfc_expr
*op2
, gfc_intrinsic_op op
)
1899 return eval_intrinsic_f3 (op
, gfc_arith_le
, op1
, op2
);
1903 /******* Simplification of intrinsic functions with constant arguments *****/
1906 /* Deal with an arithmetic error. */
1909 arith_error (arith rc
, gfc_typespec
*from
, gfc_typespec
*to
, locus
*where
)
1914 gfc_error ("Arithmetic OK converting %s to %s at %L",
1915 gfc_typename (from
), gfc_typename (to
), where
);
1917 case ARITH_OVERFLOW
:
1918 gfc_error ("Arithmetic overflow converting %s to %s at %L. This check "
1919 "can be disabled with the option %<-fno-range-check%>",
1920 gfc_typename (from
), gfc_typename (to
), where
);
1922 case ARITH_UNDERFLOW
:
1923 gfc_error ("Arithmetic underflow converting %s to %s at %L. This check "
1924 "can be disabled with the option %<-fno-range-check%>",
1925 gfc_typename (from
), gfc_typename (to
), where
);
1928 gfc_error ("Arithmetic NaN converting %s to %s at %L. This check "
1929 "can be disabled with the option %<-fno-range-check%>",
1930 gfc_typename (from
), gfc_typename (to
), where
);
1933 gfc_error ("Division by zero converting %s to %s at %L",
1934 gfc_typename (from
), gfc_typename (to
), where
);
1936 case ARITH_INCOMMENSURATE
:
1937 gfc_error ("Array operands are incommensurate converting %s to %s at %L",
1938 gfc_typename (from
), gfc_typename (to
), where
);
1940 case ARITH_ASYMMETRIC
:
1941 gfc_error ("Integer outside symmetric range implied by Standard Fortran"
1942 " converting %s to %s at %L",
1943 gfc_typename (from
), gfc_typename (to
), where
);
1946 gfc_internal_error ("gfc_arith_error(): Bad error code");
1949 /* TODO: Do something about the error, i.e., throw exception, return
1953 /* Returns true if significant bits were lost when converting real
1954 constant r from from_kind to to_kind. */
1957 wprecision_real_real (mpfr_t r
, int from_kind
, int to_kind
)
1962 gfc_set_model_kind (to_kind
);
1964 gfc_set_model_kind (from_kind
);
1967 mpfr_set (rv
, r
, GFC_RND_MODE
);
1968 mpfr_sub (diff
, rv
, r
, GFC_RND_MODE
);
1970 ret
= ! mpfr_zero_p (diff
);
1976 /* Return true if conversion from an integer to a real loses precision. */
1979 wprecision_int_real (mpz_t n
, mpfr_t r
)
1984 mpfr_get_z (i
, r
, GFC_RND_MODE
);
1986 ret
= mpz_cmp_si (i
, 0) != 0;
1991 /* Convert integers to integers. */
1994 gfc_int2int (gfc_expr
*src
, int kind
)
1999 result
= gfc_get_constant_expr (BT_INTEGER
, kind
, &src
->where
);
2001 mpz_set (result
->value
.integer
, src
->value
.integer
);
2003 if ((rc
= gfc_check_integer_range (result
->value
.integer
, kind
)) != ARITH_OK
)
2005 if (rc
== ARITH_ASYMMETRIC
)
2007 gfc_warning (0, gfc_arith_error (rc
), &src
->where
);
2011 arith_error (rc
, &src
->ts
, &result
->ts
, &src
->where
);
2012 gfc_free_expr (result
);
2017 /* If we do not trap numeric overflow, we need to convert the number to
2018 signed, throwing away high-order bits if necessary. */
2019 if (flag_range_check
== 0)
2023 k
= gfc_validate_kind (BT_INTEGER
, kind
, false);
2024 gfc_convert_mpz_to_signed (result
->value
.integer
,
2025 gfc_integer_kinds
[k
].bit_size
);
2027 if (warn_conversion
&& !src
->do_not_warn
&& kind
< src
->ts
.kind
)
2028 gfc_warning_now (OPT_Wconversion
, "Conversion from %qs to %qs at %L",
2029 gfc_typename (&src
->ts
), gfc_typename (&result
->ts
),
2036 /* Convert integers to reals. */
2039 gfc_int2real (gfc_expr
*src
, int kind
)
2044 result
= gfc_get_constant_expr (BT_REAL
, kind
, &src
->where
);
2046 mpfr_set_z (result
->value
.real
, src
->value
.integer
, GFC_RND_MODE
);
2048 if ((rc
= gfc_check_real_range (result
->value
.real
, kind
)) != ARITH_OK
)
2050 arith_error (rc
, &src
->ts
, &result
->ts
, &src
->where
);
2051 gfc_free_expr (result
);
2056 && wprecision_int_real (src
->value
.integer
, result
->value
.real
))
2057 gfc_warning (OPT_Wconversion
, "Change of value in conversion "
2058 "from %qs to %qs at %L",
2059 gfc_typename (&src
->ts
),
2060 gfc_typename (&result
->ts
),
2067 /* Convert default integer to default complex. */
2070 gfc_int2complex (gfc_expr
*src
, int kind
)
2075 result
= gfc_get_constant_expr (BT_COMPLEX
, kind
, &src
->where
);
2077 mpc_set_z (result
->value
.complex, src
->value
.integer
, GFC_MPC_RND_MODE
);
2079 if ((rc
= gfc_check_real_range (mpc_realref (result
->value
.complex), kind
))
2082 arith_error (rc
, &src
->ts
, &result
->ts
, &src
->where
);
2083 gfc_free_expr (result
);
2088 && wprecision_int_real (src
->value
.integer
,
2089 mpc_realref (result
->value
.complex)))
2090 gfc_warning_now (OPT_Wconversion
, "Change of value in conversion "
2091 "from %qs to %qs at %L",
2092 gfc_typename (&src
->ts
),
2093 gfc_typename (&result
->ts
),
2100 /* Convert default real to default integer. */
2103 gfc_real2int (gfc_expr
*src
, int kind
)
2107 bool did_warn
= false;
2109 result
= gfc_get_constant_expr (BT_INTEGER
, kind
, &src
->where
);
2111 gfc_mpfr_to_mpz (result
->value
.integer
, src
->value
.real
, &src
->where
);
2113 if ((rc
= gfc_check_integer_range (result
->value
.integer
, kind
)) != ARITH_OK
)
2115 arith_error (rc
, &src
->ts
, &result
->ts
, &src
->where
);
2116 gfc_free_expr (result
);
2120 /* If there was a fractional part, warn about this. */
2122 if (warn_conversion
)
2126 mpfr_frac (f
, src
->value
.real
, GFC_RND_MODE
);
2127 if (mpfr_cmp_si (f
, 0) != 0)
2129 gfc_warning_now (OPT_Wconversion
, "Change of value in conversion "
2130 "from %qs to %qs at %L", gfc_typename (&src
->ts
),
2131 gfc_typename (&result
->ts
), &src
->where
);
2135 if (!did_warn
&& warn_conversion_extra
)
2137 gfc_warning_now (OPT_Wconversion_extra
, "Conversion from %qs to %qs "
2138 "at %L", gfc_typename (&src
->ts
),
2139 gfc_typename (&result
->ts
), &src
->where
);
2146 /* Convert real to real. */
2149 gfc_real2real (gfc_expr
*src
, int kind
)
2153 bool did_warn
= false;
2155 result
= gfc_get_constant_expr (BT_REAL
, kind
, &src
->where
);
2157 mpfr_set (result
->value
.real
, src
->value
.real
, GFC_RND_MODE
);
2159 rc
= gfc_check_real_range (result
->value
.real
, kind
);
2161 if (rc
== ARITH_UNDERFLOW
)
2164 gfc_warning (OPT_Woverflow
, gfc_arith_error (rc
), &src
->where
);
2165 mpfr_set_ui (result
->value
.real
, 0, GFC_RND_MODE
);
2167 else if (rc
!= ARITH_OK
)
2169 arith_error (rc
, &src
->ts
, &result
->ts
, &src
->where
);
2170 gfc_free_expr (result
);
2174 /* As a special bonus, don't warn about REAL values which are not changed by
2175 the conversion if -Wconversion is specified and -Wconversion-extra is
2178 if ((warn_conversion
|| warn_conversion_extra
) && src
->ts
.kind
> kind
)
2180 int w
= warn_conversion
? OPT_Wconversion
: OPT_Wconversion_extra
;
2182 /* Calculate the difference between the constant and the rounded
2183 value and check it against zero. */
2185 if (wprecision_real_real (src
->value
.real
, src
->ts
.kind
, kind
))
2187 gfc_warning_now (w
, "Change of value in conversion from "
2189 gfc_typename (&src
->ts
), gfc_typename (&result
->ts
),
2191 /* Make sure the conversion warning is not emitted again. */
2196 if (!did_warn
&& warn_conversion_extra
)
2197 gfc_warning_now (OPT_Wconversion_extra
, "Conversion from %qs to %qs "
2198 "at %L", gfc_typename(&src
->ts
),
2199 gfc_typename(&result
->ts
), &src
->where
);
2205 /* Convert real to complex. */
2208 gfc_real2complex (gfc_expr
*src
, int kind
)
2212 bool did_warn
= false;
2214 result
= gfc_get_constant_expr (BT_COMPLEX
, kind
, &src
->where
);
2216 mpc_set_fr (result
->value
.complex, src
->value
.real
, GFC_MPC_RND_MODE
);
2218 rc
= gfc_check_real_range (mpc_realref (result
->value
.complex), kind
);
2220 if (rc
== ARITH_UNDERFLOW
)
2223 gfc_warning (OPT_Woverflow
, gfc_arith_error (rc
), &src
->where
);
2224 mpfr_set_ui (mpc_realref (result
->value
.complex), 0, GFC_RND_MODE
);
2226 else if (rc
!= ARITH_OK
)
2228 arith_error (rc
, &src
->ts
, &result
->ts
, &src
->where
);
2229 gfc_free_expr (result
);
2233 if ((warn_conversion
|| warn_conversion_extra
) && src
->ts
.kind
> kind
)
2235 int w
= warn_conversion
? OPT_Wconversion
: OPT_Wconversion_extra
;
2237 if (wprecision_real_real (src
->value
.real
, src
->ts
.kind
, kind
))
2239 gfc_warning_now (w
, "Change of value in conversion from "
2241 gfc_typename (&src
->ts
), gfc_typename (&result
->ts
),
2243 /* Make sure the conversion warning is not emitted again. */
2248 if (!did_warn
&& warn_conversion_extra
)
2249 gfc_warning_now (OPT_Wconversion_extra
, "Conversion from %qs to %qs "
2250 "at %L", gfc_typename(&src
->ts
),
2251 gfc_typename(&result
->ts
), &src
->where
);
2257 /* Convert complex to integer. */
2260 gfc_complex2int (gfc_expr
*src
, int kind
)
2264 bool did_warn
= false;
2266 result
= gfc_get_constant_expr (BT_INTEGER
, kind
, &src
->where
);
2268 gfc_mpfr_to_mpz (result
->value
.integer
, mpc_realref (src
->value
.complex),
2271 if ((rc
= gfc_check_integer_range (result
->value
.integer
, kind
)) != ARITH_OK
)
2273 arith_error (rc
, &src
->ts
, &result
->ts
, &src
->where
);
2274 gfc_free_expr (result
);
2278 if (warn_conversion
|| warn_conversion_extra
)
2280 int w
= warn_conversion
? OPT_Wconversion
: OPT_Wconversion_extra
;
2282 /* See if we discarded an imaginary part. */
2283 if (mpfr_cmp_si (mpc_imagref (src
->value
.complex), 0) != 0)
2285 gfc_warning_now (w
, "Non-zero imaginary part discarded "
2286 "in conversion from %qs to %qs at %L",
2287 gfc_typename(&src
->ts
), gfc_typename (&result
->ts
),
2296 mpfr_frac (f
, src
->value
.real
, GFC_RND_MODE
);
2297 if (mpfr_cmp_si (f
, 0) != 0)
2299 gfc_warning_now (w
, "Change of value in conversion from "
2300 "%qs to %qs at %L", gfc_typename (&src
->ts
),
2301 gfc_typename (&result
->ts
), &src
->where
);
2307 if (!did_warn
&& warn_conversion_extra
)
2309 gfc_warning_now (OPT_Wconversion_extra
, "Conversion from %qs to %qs "
2310 "at %L", gfc_typename (&src
->ts
),
2311 gfc_typename (&result
->ts
), &src
->where
);
2319 /* Convert complex to real. */
2322 gfc_complex2real (gfc_expr
*src
, int kind
)
2326 bool did_warn
= false;
2328 result
= gfc_get_constant_expr (BT_REAL
, kind
, &src
->where
);
2330 mpc_real (result
->value
.real
, src
->value
.complex, GFC_RND_MODE
);
2332 rc
= gfc_check_real_range (result
->value
.real
, kind
);
2334 if (rc
== ARITH_UNDERFLOW
)
2337 gfc_warning (OPT_Woverflow
, gfc_arith_error (rc
), &src
->where
);
2338 mpfr_set_ui (result
->value
.real
, 0, GFC_RND_MODE
);
2342 arith_error (rc
, &src
->ts
, &result
->ts
, &src
->where
);
2343 gfc_free_expr (result
);
2347 if (warn_conversion
|| warn_conversion_extra
)
2349 int w
= warn_conversion
? OPT_Wconversion
: OPT_Wconversion_extra
;
2351 /* See if we discarded an imaginary part. */
2352 if (mpfr_cmp_si (mpc_imagref (src
->value
.complex), 0) != 0)
2354 gfc_warning (w
, "Non-zero imaginary part discarded "
2355 "in conversion from %qs to %qs at %L",
2356 gfc_typename(&src
->ts
), gfc_typename (&result
->ts
),
2361 /* Calculate the difference between the real constant and the rounded
2362 value and check it against zero. */
2364 if (kind
> src
->ts
.kind
2365 && wprecision_real_real (mpc_realref (src
->value
.complex),
2366 src
->ts
.kind
, kind
))
2368 gfc_warning_now (w
, "Change of value in conversion from "
2370 gfc_typename (&src
->ts
), gfc_typename (&result
->ts
),
2372 /* Make sure the conversion warning is not emitted again. */
2377 if (!did_warn
&& warn_conversion_extra
)
2378 gfc_warning_now (OPT_Wconversion
, "Conversion from %qs to %qs at %L",
2379 gfc_typename(&src
->ts
), gfc_typename (&result
->ts
),
2386 /* Convert complex to complex. */
2389 gfc_complex2complex (gfc_expr
*src
, int kind
)
2393 bool did_warn
= false;
2395 result
= gfc_get_constant_expr (BT_COMPLEX
, kind
, &src
->where
);
2397 mpc_set (result
->value
.complex, src
->value
.complex, GFC_MPC_RND_MODE
);
2399 rc
= gfc_check_real_range (mpc_realref (result
->value
.complex), kind
);
2401 if (rc
== ARITH_UNDERFLOW
)
2404 gfc_warning (OPT_Woverflow
, gfc_arith_error (rc
), &src
->where
);
2405 mpfr_set_ui (mpc_realref (result
->value
.complex), 0, GFC_RND_MODE
);
2407 else if (rc
!= ARITH_OK
)
2409 arith_error (rc
, &src
->ts
, &result
->ts
, &src
->where
);
2410 gfc_free_expr (result
);
2414 rc
= gfc_check_real_range (mpc_imagref (result
->value
.complex), kind
);
2416 if (rc
== ARITH_UNDERFLOW
)
2419 gfc_warning (OPT_Woverflow
, gfc_arith_error (rc
), &src
->where
);
2420 mpfr_set_ui (mpc_imagref (result
->value
.complex), 0, GFC_RND_MODE
);
2422 else if (rc
!= ARITH_OK
)
2424 arith_error (rc
, &src
->ts
, &result
->ts
, &src
->where
);
2425 gfc_free_expr (result
);
2429 if ((warn_conversion
|| warn_conversion_extra
) && src
->ts
.kind
> kind
2430 && (wprecision_real_real (mpc_realref (src
->value
.complex),
2432 || wprecision_real_real (mpc_imagref (src
->value
.complex),
2433 src
->ts
.kind
, kind
)))
2435 int w
= warn_conversion
? OPT_Wconversion
: OPT_Wconversion_extra
;
2437 gfc_warning_now (w
, "Change of value in conversion from "
2439 gfc_typename (&src
->ts
), gfc_typename (&result
->ts
),
2444 if (!did_warn
&& warn_conversion_extra
&& src
->ts
.kind
!= kind
)
2445 gfc_warning_now (OPT_Wconversion_extra
, "Conversion from %qs to %qs "
2446 "at %L", gfc_typename(&src
->ts
),
2447 gfc_typename (&result
->ts
), &src
->where
);
2453 /* Logical kind conversion. */
2456 gfc_log2log (gfc_expr
*src
, int kind
)
2460 result
= gfc_get_constant_expr (BT_LOGICAL
, kind
, &src
->where
);
2461 result
->value
.logical
= src
->value
.logical
;
2467 /* Convert logical to integer. */
2470 gfc_log2int (gfc_expr
*src
, int kind
)
2474 result
= gfc_get_constant_expr (BT_INTEGER
, kind
, &src
->where
);
2475 mpz_set_si (result
->value
.integer
, src
->value
.logical
);
2481 /* Convert integer to logical. */
2484 gfc_int2log (gfc_expr
*src
, int kind
)
2488 result
= gfc_get_constant_expr (BT_LOGICAL
, kind
, &src
->where
);
2489 result
->value
.logical
= (mpz_cmp_si (src
->value
.integer
, 0) != 0);
2494 /* Convert character to character. We only use wide strings internally,
2495 so we only set the kind. */
2498 gfc_character2character (gfc_expr
*src
, int kind
)
2501 result
= gfc_copy_expr (src
);
2502 result
->ts
.kind
= kind
;
2507 /* Helper function to set the representation in a Hollerith conversion.
2508 This assumes that the ts.type and ts.kind of the result have already
2512 hollerith2representation (gfc_expr
*result
, gfc_expr
*src
)
2514 size_t src_len
, result_len
;
2516 src_len
= src
->representation
.length
- src
->ts
.u
.pad
;
2517 gfc_target_expr_size (result
, &result_len
);
2519 if (src_len
> result_len
)
2521 gfc_warning (OPT_Wcharacter_truncation
, "The Hollerith constant at %L "
2522 "is truncated in conversion to %qs", &src
->where
,
2523 gfc_typename(&result
->ts
));
2526 result
->representation
.string
= XCNEWVEC (char, result_len
+ 1);
2527 memcpy (result
->representation
.string
, src
->representation
.string
,
2528 MIN (result_len
, src_len
));
2530 if (src_len
< result_len
)
2531 memset (&result
->representation
.string
[src_len
], ' ', result_len
- src_len
);
2533 result
->representation
.string
[result_len
] = '\0'; /* For debugger */
2534 result
->representation
.length
= result_len
;
2538 /* Helper function to set the representation in a character conversion.
2539 This assumes that the ts.type and ts.kind of the result have already
2543 character2representation (gfc_expr
*result
, gfc_expr
*src
)
2545 size_t src_len
, result_len
, i
;
2546 src_len
= src
->value
.character
.length
;
2547 gfc_target_expr_size (result
, &result_len
);
2549 if (src_len
> result_len
)
2550 gfc_warning (OPT_Wcharacter_truncation
, "The character constant at %L is "
2551 "truncated in conversion to %s", &src
->where
,
2552 gfc_typename(&result
->ts
));
2554 result
->representation
.string
= XCNEWVEC (char, result_len
+ 1);
2556 for (i
= 0; i
< MIN (result_len
, src_len
); i
++)
2557 result
->representation
.string
[i
] = (char) src
->value
.character
.string
[i
];
2559 if (src_len
< result_len
)
2560 memset (&result
->representation
.string
[src_len
], ' ',
2561 result_len
- src_len
);
2563 result
->representation
.string
[result_len
] = '\0'; /* For debugger. */
2564 result
->representation
.length
= result_len
;
2567 /* Convert Hollerith to integer. The constant will be padded or truncated. */
2570 gfc_hollerith2int (gfc_expr
*src
, int kind
)
2573 result
= gfc_get_constant_expr (BT_INTEGER
, kind
, &src
->where
);
2575 hollerith2representation (result
, src
);
2576 gfc_interpret_integer (kind
, (unsigned char *) result
->representation
.string
,
2577 result
->representation
.length
, result
->value
.integer
);
2582 /* Convert character to integer. The constant will be padded or truncated. */
2585 gfc_character2int (gfc_expr
*src
, int kind
)
2588 result
= gfc_get_constant_expr (BT_INTEGER
, kind
, &src
->where
);
2590 character2representation (result
, src
);
2591 gfc_interpret_integer (kind
, (unsigned char *) result
->representation
.string
,
2592 result
->representation
.length
, result
->value
.integer
);
2596 /* Convert Hollerith to real. The constant will be padded or truncated. */
2599 gfc_hollerith2real (gfc_expr
*src
, int kind
)
2602 result
= gfc_get_constant_expr (BT_REAL
, kind
, &src
->where
);
2604 hollerith2representation (result
, src
);
2605 gfc_interpret_float (kind
, (unsigned char *) result
->representation
.string
,
2606 result
->representation
.length
, result
->value
.real
);
2611 /* Convert character to real. The constant will be padded or truncated. */
2614 gfc_character2real (gfc_expr
*src
, int kind
)
2617 result
= gfc_get_constant_expr (BT_REAL
, kind
, &src
->where
);
2619 character2representation (result
, src
);
2620 gfc_interpret_float (kind
, (unsigned char *) result
->representation
.string
,
2621 result
->representation
.length
, result
->value
.real
);
2627 /* Convert Hollerith to complex. The constant will be padded or truncated. */
2630 gfc_hollerith2complex (gfc_expr
*src
, int kind
)
2633 result
= gfc_get_constant_expr (BT_COMPLEX
, kind
, &src
->where
);
2635 hollerith2representation (result
, src
);
2636 gfc_interpret_complex (kind
, (unsigned char *) result
->representation
.string
,
2637 result
->representation
.length
, result
->value
.complex);
2642 /* Convert character to complex. The constant will be padded or truncated. */
2645 gfc_character2complex (gfc_expr
*src
, int kind
)
2648 result
= gfc_get_constant_expr (BT_COMPLEX
, kind
, &src
->where
);
2650 character2representation (result
, src
);
2651 gfc_interpret_complex (kind
, (unsigned char *) result
->representation
.string
,
2652 result
->representation
.length
, result
->value
.complex);
2658 /* Convert Hollerith to character. */
2661 gfc_hollerith2character (gfc_expr
*src
, int kind
)
2665 result
= gfc_copy_expr (src
);
2666 result
->ts
.type
= BT_CHARACTER
;
2667 result
->ts
.kind
= kind
;
2668 result
->ts
.u
.pad
= 0;
2670 result
->value
.character
.length
= result
->representation
.length
;
2671 result
->value
.character
.string
2672 = gfc_char_to_widechar (result
->representation
.string
);
2678 /* Convert Hollerith to logical. The constant will be padded or truncated. */
2681 gfc_hollerith2logical (gfc_expr
*src
, int kind
)
2684 result
= gfc_get_constant_expr (BT_LOGICAL
, kind
, &src
->where
);
2686 hollerith2representation (result
, src
);
2687 gfc_interpret_logical (kind
, (unsigned char *) result
->representation
.string
,
2688 result
->representation
.length
, &result
->value
.logical
);
2693 /* Convert character to logical. The constant will be padded or truncated. */
2696 gfc_character2logical (gfc_expr
*src
, int kind
)
2699 result
= gfc_get_constant_expr (BT_LOGICAL
, kind
, &src
->where
);
2701 character2representation (result
, src
);
2702 gfc_interpret_logical (kind
, (unsigned char *) result
->representation
.string
,
2703 result
->representation
.length
, &result
->value
.logical
);