OSDN Git Service

2010-11-09 Janus Weil <janus@gcc.gnu.org>
[pf3gnuchains/gcc-fork.git] / gcc / fortran / iresolve.c
1 /* Intrinsic function resolution.
2    Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
3    2009, 2010
4    Free Software Foundation, Inc.
5    Contributed by Andy Vaught & Katherine Holcomb
6
7 This file is part of GCC.
8
9 GCC is free software; you can redistribute it and/or modify it under
10 the terms of the GNU General Public License as published by the Free
11 Software Foundation; either version 3, or (at your option) any later
12 version.
13
14 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
17 for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with GCC; see the file COPYING3.  If not see
21 <http://www.gnu.org/licenses/>.  */
22
23
24 /* Assign name and types to intrinsic procedures.  For functions, the
25    first argument to a resolution function is an expression pointer to
26    the original function node and the rest are pointers to the
27    arguments of the function call.  For subroutines, a pointer to the
28    code node is passed.  The result type and library subroutine name
29    are generally set according to the function arguments.  */
30
31 #include "config.h"
32 #include "system.h"
33 #include "coretypes.h"
34 #include "tree.h"
35 #include "gfortran.h"
36 #include "intrinsic.h"
37 #include "constructor.h"
38
39 /* Given printf-like arguments, return a stable version of the result string. 
40
41    We already have a working, optimized string hashing table in the form of
42    the identifier table.  Reusing this table is likely not to be wasted, 
43    since if the function name makes it to the gimple output of the frontend,
44    we'll have to create the identifier anyway.  */
45
46 const char *
47 gfc_get_string (const char *format, ...)
48 {
49   char temp_name[128];
50   va_list ap;
51   tree ident;
52
53   va_start (ap, format);
54   vsnprintf (temp_name, sizeof (temp_name), format, ap);
55   va_end (ap);
56   temp_name[sizeof (temp_name) - 1] = 0;
57
58   ident = get_identifier (temp_name);
59   return IDENTIFIER_POINTER (ident);
60 }
61
62 /* MERGE and SPREAD need to have source charlen's present for passing
63    to the result expression.  */
64 static void
65 check_charlen_present (gfc_expr *source)
66 {
67   if (source->ts.u.cl == NULL)
68     source->ts.u.cl = gfc_new_charlen (gfc_current_ns, NULL);
69
70   if (source->expr_type == EXPR_CONSTANT)
71     {
72       source->ts.u.cl->length
73                 = gfc_get_int_expr (gfc_default_integer_kind, NULL,
74                                     source->value.character.length);
75       source->rank = 0;
76     }
77   else if (source->expr_type == EXPR_ARRAY)
78     {
79       gfc_constructor *c = gfc_constructor_first (source->value.constructor);
80       source->ts.u.cl->length
81                 = gfc_get_int_expr (gfc_default_integer_kind, NULL,
82                                     c->expr->value.character.length);
83     }
84 }
85
86 /* Helper function for resolving the "mask" argument.  */
87
88 static void
89 resolve_mask_arg (gfc_expr *mask)
90 {
91
92   gfc_typespec ts;
93   gfc_clear_ts (&ts);
94
95   if (mask->rank == 0)
96     {
97       /* For the scalar case, coerce the mask to kind=4 unconditionally
98          (because this is the only kind we have a library function
99          for).  */
100
101       if (mask->ts.kind != 4)
102         {
103           ts.type = BT_LOGICAL;
104           ts.kind = 4;
105           gfc_convert_type (mask, &ts, 2);
106         }
107     }
108   else
109     {
110       /* In the library, we access the mask with a GFC_LOGICAL_1
111          argument.  No need to waste memory if we are about to create
112          a temporary array.  */
113       if (mask->expr_type == EXPR_OP && mask->ts.kind != 1)
114         {
115           ts.type = BT_LOGICAL;
116           ts.kind = 1;
117           gfc_convert_type_warn (mask, &ts, 2, 0);
118         }
119     }
120 }
121
122
123 static void
124 resolve_bound (gfc_expr *f, gfc_expr *array, gfc_expr *dim, gfc_expr *kind,
125                const char *name, bool coarray)
126 {
127   f->ts.type = BT_INTEGER;
128   if (kind)
129     f->ts.kind = mpz_get_si (kind->value.integer);
130   else
131     f->ts.kind = gfc_default_integer_kind;
132
133   if (dim == NULL)
134     {
135       f->rank = 1;
136       f->shape = gfc_get_shape (1);
137       mpz_init_set_ui (f->shape[0], coarray ? gfc_get_corank (array)
138                                             : array->rank);
139     }
140
141   f->value.function.name = xstrdup (name);
142 }
143
144
145 static void
146 resolve_transformational (const char *name, gfc_expr *f, gfc_expr *array,
147                           gfc_expr *dim, gfc_expr *mask)
148 {
149   const char *prefix;
150
151   f->ts = array->ts;
152
153   if (mask)
154     {
155       if (mask->rank == 0)
156         prefix = "s";
157       else
158         prefix = "m";
159
160       resolve_mask_arg (mask);
161     }
162   else
163     prefix = "";
164
165   if (dim != NULL)
166     {
167       f->rank = array->rank - 1;
168       f->shape = gfc_copy_shape_excluding (array->shape, array->rank, dim);
169       gfc_resolve_dim_arg (dim);
170     }
171
172   f->value.function.name
173     = gfc_get_string (PREFIX ("%s%s_%c%d"), prefix, name,
174                     gfc_type_letter (array->ts.type), array->ts.kind);
175 }
176
177
178 /********************** Resolution functions **********************/
179
180
181 void
182 gfc_resolve_abs (gfc_expr *f, gfc_expr *a)
183 {
184   f->ts = a->ts;
185   if (f->ts.type == BT_COMPLEX)
186     f->ts.type = BT_REAL;
187
188   f->value.function.name
189     = gfc_get_string ("__abs_%c%d", gfc_type_letter (a->ts.type), a->ts.kind);
190 }
191
192
193 void
194 gfc_resolve_access (gfc_expr *f, gfc_expr *name ATTRIBUTE_UNUSED,
195                     gfc_expr *mode ATTRIBUTE_UNUSED)
196 {
197   f->ts.type = BT_INTEGER;
198   f->ts.kind = gfc_c_int_kind;
199   f->value.function.name = PREFIX ("access_func");
200 }
201
202
203 void
204 gfc_resolve_adjustl (gfc_expr *f, gfc_expr *string)
205 {
206   f->ts.type = BT_CHARACTER;
207   f->ts.kind = string->ts.kind;
208   f->value.function.name = gfc_get_string ("__adjustl_s%d", f->ts.kind);
209 }
210
211
212 void
213 gfc_resolve_adjustr (gfc_expr *f, gfc_expr *string)
214 {
215   f->ts.type = BT_CHARACTER;
216   f->ts.kind = string->ts.kind;
217   f->value.function.name = gfc_get_string ("__adjustr_s%d", f->ts.kind);
218 }
219
220
221 static void
222 gfc_resolve_char_achar (gfc_expr *f, gfc_expr *x, gfc_expr *kind,
223                         const char *name)
224 {
225   f->ts.type = BT_CHARACTER;
226   f->ts.kind = (kind == NULL)
227              ? gfc_default_character_kind : mpz_get_si (kind->value.integer);
228   f->ts.u.cl = gfc_new_charlen (gfc_current_ns, NULL);
229   f->ts.u.cl->length = gfc_get_int_expr (gfc_default_integer_kind, NULL, 1);
230
231   f->value.function.name = gfc_get_string (name, f->ts.kind,
232                                            gfc_type_letter (x->ts.type),
233                                            x->ts.kind);
234 }
235
236
237 void
238 gfc_resolve_achar (gfc_expr *f, gfc_expr *x, gfc_expr *kind)
239 {
240   gfc_resolve_char_achar (f, x, kind, "__achar_%d_%c%d");
241 }
242
243
244 void
245 gfc_resolve_acos (gfc_expr *f, gfc_expr *x)
246 {
247   f->ts = x->ts;
248   f->value.function.name
249     = gfc_get_string ("__acos_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
250 }
251
252
253 void
254 gfc_resolve_acosh (gfc_expr *f, gfc_expr *x)
255 {
256   f->ts = x->ts;
257   f->value.function.name
258     = gfc_get_string ("__acosh_%c%d", gfc_type_letter (x->ts.type),
259                       x->ts.kind);
260 }
261
262
263 void
264 gfc_resolve_aimag (gfc_expr *f, gfc_expr *x)
265 {
266   f->ts.type = BT_REAL;
267   f->ts.kind = x->ts.kind;
268   f->value.function.name
269     = gfc_get_string ("__aimag_%c%d", gfc_type_letter (x->ts.type),
270                       x->ts.kind);
271 }
272
273
274 void
275 gfc_resolve_and (gfc_expr *f, gfc_expr *i, gfc_expr *j)
276 {
277   f->ts.type = i->ts.type;
278   f->ts.kind = gfc_kind_max (i, j);
279
280   if (i->ts.kind != j->ts.kind)
281     {
282       if (i->ts.kind == gfc_kind_max (i, j))
283         gfc_convert_type (j, &i->ts, 2);
284       else
285         gfc_convert_type (i, &j->ts, 2);
286     }
287
288   f->value.function.name
289     = gfc_get_string ("__and_%c%d", gfc_type_letter (i->ts.type), f->ts.kind);
290 }
291
292
293 void
294 gfc_resolve_aint (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
295 {
296   gfc_typespec ts;
297   gfc_clear_ts (&ts);
298   
299   f->ts.type = a->ts.type;
300   f->ts.kind = (kind == NULL) ? a->ts.kind : mpz_get_si (kind->value.integer);
301
302   if (a->ts.kind != f->ts.kind)
303     {
304       ts.type = f->ts.type;
305       ts.kind = f->ts.kind;
306       gfc_convert_type (a, &ts, 2);
307     }
308   /* The resolved name is only used for specific intrinsics where
309      the return kind is the same as the arg kind.  */
310   f->value.function.name
311     = gfc_get_string ("__aint_%c%d", gfc_type_letter (a->ts.type), a->ts.kind);
312 }
313
314
315 void
316 gfc_resolve_dint (gfc_expr *f, gfc_expr *a)
317 {
318   gfc_resolve_aint (f, a, NULL);
319 }
320
321
322 void
323 gfc_resolve_all (gfc_expr *f, gfc_expr *mask, gfc_expr *dim)
324 {
325   f->ts = mask->ts;
326
327   if (dim != NULL)
328     {
329       gfc_resolve_dim_arg (dim);
330       f->rank = mask->rank - 1;
331       f->shape = gfc_copy_shape_excluding (mask->shape, mask->rank, dim);
332     }
333
334   f->value.function.name
335     = gfc_get_string (PREFIX ("all_%c%d"), gfc_type_letter (mask->ts.type),
336                       mask->ts.kind);
337 }
338
339
340 void
341 gfc_resolve_anint (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
342 {
343   gfc_typespec ts;
344   gfc_clear_ts (&ts);
345   
346   f->ts.type = a->ts.type;
347   f->ts.kind = (kind == NULL) ? a->ts.kind : mpz_get_si (kind->value.integer);
348
349   if (a->ts.kind != f->ts.kind)
350     {
351       ts.type = f->ts.type;
352       ts.kind = f->ts.kind;
353       gfc_convert_type (a, &ts, 2);
354     }
355
356   /* The resolved name is only used for specific intrinsics where
357      the return kind is the same as the arg kind.  */
358   f->value.function.name
359     = gfc_get_string ("__anint_%c%d", gfc_type_letter (a->ts.type),
360                       a->ts.kind);
361 }
362
363
364 void
365 gfc_resolve_dnint (gfc_expr *f, gfc_expr *a)
366 {
367   gfc_resolve_anint (f, a, NULL);
368 }
369
370
371 void
372 gfc_resolve_any (gfc_expr *f, gfc_expr *mask, gfc_expr *dim)
373 {
374   f->ts = mask->ts;
375
376   if (dim != NULL)
377     {
378       gfc_resolve_dim_arg (dim);
379       f->rank = mask->rank - 1;
380       f->shape = gfc_copy_shape_excluding (mask->shape, mask->rank, dim);
381     }
382
383   f->value.function.name
384     = gfc_get_string (PREFIX ("any_%c%d"), gfc_type_letter (mask->ts.type),
385                       mask->ts.kind);
386 }
387
388
389 void
390 gfc_resolve_asin (gfc_expr *f, gfc_expr *x)
391 {
392   f->ts = x->ts;
393   f->value.function.name
394     = gfc_get_string ("__asin_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
395 }
396
397 void
398 gfc_resolve_asinh (gfc_expr *f, gfc_expr *x)
399 {
400   f->ts = x->ts;
401   f->value.function.name
402     = gfc_get_string ("__asinh_%c%d", gfc_type_letter (x->ts.type),
403                       x->ts.kind);
404 }
405
406 void
407 gfc_resolve_atan (gfc_expr *f, gfc_expr *x)
408 {
409   f->ts = x->ts;
410   f->value.function.name
411     = gfc_get_string ("__atan_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
412 }
413
414 void
415 gfc_resolve_atanh (gfc_expr *f, gfc_expr *x)
416 {
417   f->ts = x->ts;
418   f->value.function.name
419     = gfc_get_string ("__atanh_%c%d", gfc_type_letter (x->ts.type),
420                       x->ts.kind);
421 }
422
423 void
424 gfc_resolve_atan2 (gfc_expr *f, gfc_expr *x, gfc_expr *y ATTRIBUTE_UNUSED)
425 {
426   f->ts = x->ts;
427   f->value.function.name
428     = gfc_get_string ("__atan2_%c%d", gfc_type_letter (x->ts.type),
429                       x->ts.kind);
430 }
431
432
433 /* Resolve the BESYN and BESJN intrinsics.  */
434
435 void
436 gfc_resolve_besn (gfc_expr *f, gfc_expr *n, gfc_expr *x)
437 {
438   gfc_typespec ts;
439   gfc_clear_ts (&ts);
440   
441   f->ts = x->ts;
442   if (n->ts.kind != gfc_c_int_kind)
443     {
444       ts.type = BT_INTEGER;
445       ts.kind = gfc_c_int_kind;
446       gfc_convert_type (n, &ts, 2);
447     }
448   f->value.function.name = gfc_get_string ("<intrinsic>");
449 }
450
451
452 void
453 gfc_resolve_bessel_n2 (gfc_expr *f, gfc_expr *n1, gfc_expr *n2, gfc_expr *x)
454 {
455   gfc_typespec ts;
456   gfc_clear_ts (&ts);
457   
458   f->ts = x->ts;
459   f->rank = 1;
460   if (n1->expr_type == EXPR_CONSTANT && n2->expr_type == EXPR_CONSTANT)
461     {
462       f->shape = gfc_get_shape (1);
463       mpz_init (f->shape[0]);
464       mpz_sub (f->shape[0], n2->value.integer, n1->value.integer);
465       mpz_add_ui (f->shape[0], f->shape[0], 1);
466     }
467
468   if (n1->ts.kind != gfc_c_int_kind)
469     {
470       ts.type = BT_INTEGER;
471       ts.kind = gfc_c_int_kind;
472       gfc_convert_type (n1, &ts, 2);
473     }
474
475   if (n2->ts.kind != gfc_c_int_kind)
476     {
477       ts.type = BT_INTEGER;
478       ts.kind = gfc_c_int_kind;
479       gfc_convert_type (n2, &ts, 2);
480     }
481
482   if (f->value.function.isym->id == GFC_ISYM_JN2)
483     f->value.function.name = gfc_get_string (PREFIX ("bessel_jn_r%d"),
484                                              f->ts.kind);
485   else
486     f->value.function.name = gfc_get_string (PREFIX ("bessel_yn_r%d"),
487                                              f->ts.kind);
488 }
489
490
491 void
492 gfc_resolve_btest (gfc_expr *f, gfc_expr *i, gfc_expr *pos)
493 {
494   f->ts.type = BT_LOGICAL;
495   f->ts.kind = gfc_default_logical_kind;
496   f->value.function.name
497     = gfc_get_string ("__btest_%d_%d", i->ts.kind, pos->ts.kind);
498 }
499
500
501 void
502 gfc_resolve_ceiling (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
503 {
504   f->ts.type = BT_INTEGER;
505   f->ts.kind = (kind == NULL)
506              ? gfc_default_integer_kind : mpz_get_si (kind->value.integer);
507   f->value.function.name
508     = gfc_get_string ("__ceiling_%d_%c%d", f->ts.kind,
509                       gfc_type_letter (a->ts.type), a->ts.kind);
510 }
511
512
513 void
514 gfc_resolve_char (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
515 {
516   gfc_resolve_char_achar (f, a, kind, "__char_%d_%c%d");
517 }
518
519
520 void
521 gfc_resolve_chdir (gfc_expr *f, gfc_expr *d ATTRIBUTE_UNUSED)
522 {
523   f->ts.type = BT_INTEGER;
524   f->ts.kind = gfc_default_integer_kind;
525   f->value.function.name = gfc_get_string (PREFIX ("chdir_i%d"), f->ts.kind);
526 }
527
528
529 void
530 gfc_resolve_chdir_sub (gfc_code *c)
531 {
532   const char *name;
533   int kind;
534
535   if (c->ext.actual->next->expr != NULL)
536     kind = c->ext.actual->next->expr->ts.kind;
537   else
538     kind = gfc_default_integer_kind;
539
540   name = gfc_get_string (PREFIX ("chdir_i%d_sub"), kind);
541   c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
542 }
543
544
545 void
546 gfc_resolve_chmod (gfc_expr *f, gfc_expr *name ATTRIBUTE_UNUSED,
547                    gfc_expr *mode ATTRIBUTE_UNUSED)
548 {
549   f->ts.type = BT_INTEGER;
550   f->ts.kind = gfc_c_int_kind;
551   f->value.function.name = PREFIX ("chmod_func");
552 }
553
554
555 void
556 gfc_resolve_chmod_sub (gfc_code *c)
557 {
558   const char *name;
559   int kind;
560
561   if (c->ext.actual->next->next->expr != NULL)
562     kind = c->ext.actual->next->next->expr->ts.kind;
563   else
564     kind = gfc_default_integer_kind;
565
566   name = gfc_get_string (PREFIX ("chmod_i%d_sub"), kind);
567   c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
568 }
569
570
571 void
572 gfc_resolve_cmplx (gfc_expr *f, gfc_expr *x, gfc_expr *y, gfc_expr *kind)
573 {
574   f->ts.type = BT_COMPLEX;
575   f->ts.kind = (kind == NULL)
576              ? gfc_default_real_kind : mpz_get_si (kind->value.integer);
577
578   if (y == NULL)
579     f->value.function.name
580       = gfc_get_string ("__cmplx0_%d_%c%d", f->ts.kind,
581                         gfc_type_letter (x->ts.type), x->ts.kind);
582   else
583     f->value.function.name
584       = gfc_get_string ("__cmplx1_%d_%c%d_%c%d", f->ts.kind,
585                         gfc_type_letter (x->ts.type), x->ts.kind,
586                         gfc_type_letter (y->ts.type), y->ts.kind);
587 }
588
589
590 void
591 gfc_resolve_dcmplx (gfc_expr *f, gfc_expr *x, gfc_expr *y)
592 {
593   gfc_resolve_cmplx (f, x, y, gfc_get_int_expr (gfc_default_integer_kind, NULL,
594                                                 gfc_default_double_kind));
595 }
596
597
598 void
599 gfc_resolve_complex (gfc_expr *f, gfc_expr *x, gfc_expr *y)
600 {
601   int kind;
602
603   if (x->ts.type == BT_INTEGER)
604     {
605       if (y->ts.type == BT_INTEGER)
606         kind = gfc_default_real_kind;
607       else
608         kind = y->ts.kind;
609     }
610   else
611     {
612       if (y->ts.type == BT_REAL)
613         kind = (x->ts.kind > y->ts.kind) ? x->ts.kind : y->ts.kind;
614       else
615         kind = x->ts.kind;
616     }
617
618   f->ts.type = BT_COMPLEX;
619   f->ts.kind = kind;
620   f->value.function.name
621     = gfc_get_string ("__cmplx1_%d_%c%d_%c%d", f->ts.kind,
622                       gfc_type_letter (x->ts.type), x->ts.kind,
623                       gfc_type_letter (y->ts.type), y->ts.kind);
624 }
625
626
627 void
628 gfc_resolve_conjg (gfc_expr *f, gfc_expr *x)
629 {
630   f->ts = x->ts;
631   f->value.function.name = gfc_get_string ("__conjg_%d", x->ts.kind);
632 }
633
634
635 void
636 gfc_resolve_cos (gfc_expr *f, gfc_expr *x)
637 {
638   f->ts = x->ts;
639   f->value.function.name
640     = gfc_get_string ("__cos_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
641 }
642
643
644 void
645 gfc_resolve_cosh (gfc_expr *f, gfc_expr *x)
646 {
647   f->ts = x->ts;
648   f->value.function.name
649     = gfc_get_string ("__cosh_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
650 }
651
652
653 void
654 gfc_resolve_count (gfc_expr *f, gfc_expr *mask, gfc_expr *dim, gfc_expr *kind)
655 {
656   f->ts.type = BT_INTEGER;
657   if (kind)
658     f->ts.kind = mpz_get_si (kind->value.integer);
659   else
660     f->ts.kind = gfc_default_integer_kind;
661
662   if (dim != NULL)
663     {
664       f->rank = mask->rank - 1;
665       gfc_resolve_dim_arg (dim);
666       f->shape = gfc_copy_shape_excluding (mask->shape, mask->rank, dim);
667     }
668
669   resolve_mask_arg (mask);
670
671   f->value.function.name
672     = gfc_get_string (PREFIX ("count_%d_%c"), f->ts.kind,
673                       gfc_type_letter (mask->ts.type));
674 }
675
676
677 void
678 gfc_resolve_cshift (gfc_expr *f, gfc_expr *array, gfc_expr *shift,
679                     gfc_expr *dim)
680 {
681   int n, m;
682
683   if (array->ts.type == BT_CHARACTER && array->ref)
684     gfc_resolve_substring_charlen (array);
685
686   f->ts = array->ts;
687   f->rank = array->rank;
688   f->shape = gfc_copy_shape (array->shape, array->rank);
689
690   if (shift->rank > 0)
691     n = 1;
692   else
693     n = 0;
694
695   /* If dim kind is greater than default integer we need to use the larger.  */
696   m = gfc_default_integer_kind;
697   if (dim != NULL)
698     m = m < dim->ts.kind ? dim->ts.kind : m;
699   
700   /* Convert shift to at least m, so we don't need
701       kind=1 and kind=2 versions of the library functions.  */
702   if (shift->ts.kind < m)
703     {
704       gfc_typespec ts;
705       gfc_clear_ts (&ts);
706       ts.type = BT_INTEGER;
707       ts.kind = m;
708       gfc_convert_type_warn (shift, &ts, 2, 0);
709     }
710  
711   if (dim != NULL)
712     {
713       if (dim->expr_type != EXPR_CONSTANT && dim->symtree != NULL
714           && dim->symtree->n.sym->attr.optional)
715         {
716           /* Mark this for later setting the type in gfc_conv_missing_dummy.  */
717           dim->representation.length = shift->ts.kind;
718         }
719       else
720         {
721           gfc_resolve_dim_arg (dim);
722           /* Convert dim to shift's kind to reduce variations.  */
723           if (dim->ts.kind != shift->ts.kind)
724             gfc_convert_type_warn (dim, &shift->ts, 2, 0);
725         }
726     }
727
728   if (array->ts.type == BT_CHARACTER)
729     {
730       if (array->ts.kind == gfc_default_character_kind)
731         f->value.function.name
732           = gfc_get_string (PREFIX ("cshift%d_%d_char"), n, shift->ts.kind);
733       else
734         f->value.function.name
735           = gfc_get_string (PREFIX ("cshift%d_%d_char%d"), n, shift->ts.kind,
736                             array->ts.kind);
737     }
738   else
739     f->value.function.name
740         = gfc_get_string (PREFIX ("cshift%d_%d"), n, shift->ts.kind);
741 }
742
743
744 void
745 gfc_resolve_ctime (gfc_expr *f, gfc_expr *time)
746 {
747   gfc_typespec ts;
748   gfc_clear_ts (&ts);
749   
750   f->ts.type = BT_CHARACTER;
751   f->ts.kind = gfc_default_character_kind;
752
753   /* ctime TIME argument is a INTEGER(KIND=8), says the doc */
754   if (time->ts.kind != 8)
755     {
756       ts.type = BT_INTEGER;
757       ts.kind = 8;
758       ts.u.derived = NULL;
759       ts.u.cl = NULL;
760       gfc_convert_type (time, &ts, 2);
761     }
762
763   f->value.function.name = gfc_get_string (PREFIX ("ctime"));
764 }
765
766
767 void
768 gfc_resolve_dble (gfc_expr *f, gfc_expr *a)
769 {
770   f->ts.type = BT_REAL;
771   f->ts.kind = gfc_default_double_kind;
772   f->value.function.name
773     = gfc_get_string ("__dble_%c%d", gfc_type_letter (a->ts.type), a->ts.kind);
774 }
775
776
777 void
778 gfc_resolve_dim (gfc_expr *f, gfc_expr *a, gfc_expr *p)
779 {
780   f->ts.type = a->ts.type;
781   if (p != NULL)
782     f->ts.kind = gfc_kind_max (a,p);
783   else
784     f->ts.kind = a->ts.kind;
785
786   if (p != NULL && a->ts.kind != p->ts.kind)
787     {
788       if (a->ts.kind == gfc_kind_max (a,p))
789         gfc_convert_type (p, &a->ts, 2);
790       else
791         gfc_convert_type (a, &p->ts, 2);
792     }
793
794   f->value.function.name
795     = gfc_get_string ("__dim_%c%d", gfc_type_letter (f->ts.type), f->ts.kind);
796 }
797
798
799 void
800 gfc_resolve_dot_product (gfc_expr *f, gfc_expr *a, gfc_expr *b)
801 {
802   gfc_expr temp;
803
804   temp.expr_type = EXPR_OP;
805   gfc_clear_ts (&temp.ts);
806   temp.value.op.op = INTRINSIC_NONE;
807   temp.value.op.op1 = a;
808   temp.value.op.op2 = b;
809   gfc_type_convert_binary (&temp, 1);
810   f->ts = temp.ts;
811   f->value.function.name
812     = gfc_get_string (PREFIX ("dot_product_%c%d"),
813                       gfc_type_letter (f->ts.type), f->ts.kind);
814 }
815
816
817 void
818 gfc_resolve_dprod (gfc_expr *f, gfc_expr *a ATTRIBUTE_UNUSED,
819                    gfc_expr *b ATTRIBUTE_UNUSED)
820 {
821   f->ts.kind = gfc_default_double_kind;
822   f->ts.type = BT_REAL;
823   f->value.function.name = gfc_get_string ("__dprod_r%d", f->ts.kind);
824 }
825
826
827 void
828 gfc_resolve_dshift (gfc_expr *f, gfc_expr *i, gfc_expr *j ATTRIBUTE_UNUSED,
829                     gfc_expr *shift ATTRIBUTE_UNUSED)
830 {
831   f->ts = i->ts;
832   if (f->value.function.isym->id == GFC_ISYM_DSHIFTL)
833     f->value.function.name = gfc_get_string ("dshiftl_i%d", f->ts.kind);
834   else if (f->value.function.isym->id == GFC_ISYM_DSHIFTR)
835     f->value.function.name = gfc_get_string ("dshiftr_i%d", f->ts.kind);
836   else
837     gcc_unreachable ();
838 }
839
840
841 void
842 gfc_resolve_eoshift (gfc_expr *f, gfc_expr *array, gfc_expr *shift,
843                      gfc_expr *boundary, gfc_expr *dim)
844 {
845   int n, m;
846
847   if (array->ts.type == BT_CHARACTER && array->ref)
848     gfc_resolve_substring_charlen (array);
849
850   f->ts = array->ts;
851   f->rank = array->rank;
852   f->shape = gfc_copy_shape (array->shape, array->rank);
853
854   n = 0;
855   if (shift->rank > 0)
856     n = n | 1;
857   if (boundary && boundary->rank > 0)
858     n = n | 2;
859
860   /* If dim kind is greater than default integer we need to use the larger.  */
861   m = gfc_default_integer_kind;
862   if (dim != NULL)
863     m = m < dim->ts.kind ? dim->ts.kind : m;
864   
865   /* Convert shift to at least m, so we don't need
866       kind=1 and kind=2 versions of the library functions.  */
867   if (shift->ts.kind < m)
868     {
869       gfc_typespec ts;
870       gfc_clear_ts (&ts);
871       ts.type = BT_INTEGER;
872       ts.kind = m;
873       gfc_convert_type_warn (shift, &ts, 2, 0);
874     }
875  
876   if (dim != NULL)
877     {
878       if (dim->expr_type != EXPR_CONSTANT && dim->symtree != NULL
879           && dim->symtree->n.sym->attr.optional)
880         {
881           /* Mark this for later setting the type in gfc_conv_missing_dummy.  */
882           dim->representation.length = shift->ts.kind;
883         }
884       else
885         {
886           gfc_resolve_dim_arg (dim);
887           /* Convert dim to shift's kind to reduce variations.  */
888           if (dim->ts.kind != shift->ts.kind)
889             gfc_convert_type_warn (dim, &shift->ts, 2, 0);
890         }
891     }
892
893   if (array->ts.type == BT_CHARACTER)
894     {
895       if (array->ts.kind == gfc_default_character_kind)
896         f->value.function.name
897           = gfc_get_string (PREFIX ("eoshift%d_%d_char"), n, shift->ts.kind);
898       else
899         f->value.function.name
900           = gfc_get_string (PREFIX ("eoshift%d_%d_char%d"), n, shift->ts.kind,
901                             array->ts.kind);
902     }
903   else
904     f->value.function.name
905         = gfc_get_string (PREFIX ("eoshift%d_%d"), n, shift->ts.kind);
906 }
907
908
909 void
910 gfc_resolve_exp (gfc_expr *f, gfc_expr *x)
911 {
912   f->ts = x->ts;
913   f->value.function.name
914     = gfc_get_string ("__exp_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
915 }
916
917
918 void
919 gfc_resolve_exponent (gfc_expr *f, gfc_expr *x)
920 {
921   f->ts.type = BT_INTEGER;
922   f->ts.kind = gfc_default_integer_kind;
923   f->value.function.name = gfc_get_string ("__exponent_%d", x->ts.kind);
924 }
925
926
927 /* Resolve the EXTENDS_TYPE_OF intrinsic function.  */
928
929 void
930 gfc_resolve_extends_type_of (gfc_expr *f, gfc_expr *a, gfc_expr *mo)
931 {
932   gfc_symbol *vtab;
933   gfc_symtree *st;
934
935   /* Prevent double resolution.  */
936   if (f->ts.type == BT_LOGICAL)
937     return;
938
939   /* Replace the first argument with the corresponding vtab.  */
940   if (a->ts.type == BT_CLASS)
941     gfc_add_vptr_component (a);
942   else if (a->ts.type == BT_DERIVED)
943     {
944       vtab = gfc_find_derived_vtab (a->ts.u.derived);
945       /* Clear the old expr.  */
946       gfc_free_ref_list (a->ref);
947       memset (a, '\0', sizeof (gfc_expr));
948       /* Construct a new one.  */
949       a->expr_type = EXPR_VARIABLE;
950       st = gfc_find_symtree (vtab->ns->sym_root, vtab->name);
951       a->symtree = st;
952       a->ts = vtab->ts;
953     }
954
955   /* Replace the second argument with the corresponding vtab.  */
956   if (mo->ts.type == BT_CLASS)
957     gfc_add_vptr_component (mo);
958   else if (mo->ts.type == BT_DERIVED)
959     {
960       vtab = gfc_find_derived_vtab (mo->ts.u.derived);
961       /* Clear the old expr.  */
962       gfc_free_ref_list (mo->ref);
963       memset (mo, '\0', sizeof (gfc_expr));
964       /* Construct a new one.  */
965       mo->expr_type = EXPR_VARIABLE;
966       st = gfc_find_symtree (vtab->ns->sym_root, vtab->name);
967       mo->symtree = st;
968       mo->ts = vtab->ts;
969     }
970
971   f->ts.type = BT_LOGICAL;
972   f->ts.kind = 4;
973
974   f->value.function.isym->formal->ts = a->ts;
975   f->value.function.isym->formal->next->ts = mo->ts;
976
977   /* Call library function.  */
978   f->value.function.name = gfc_get_string (PREFIX ("is_extension_of"));
979 }
980
981
982 void
983 gfc_resolve_fdate (gfc_expr *f)
984 {
985   f->ts.type = BT_CHARACTER;
986   f->ts.kind = gfc_default_character_kind;
987   f->value.function.name = gfc_get_string (PREFIX ("fdate"));
988 }
989
990
991 void
992 gfc_resolve_floor (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
993 {
994   f->ts.type = BT_INTEGER;
995   f->ts.kind = (kind == NULL)
996              ? gfc_default_integer_kind : mpz_get_si (kind->value.integer);
997   f->value.function.name
998     = gfc_get_string ("__floor%d_%c%d", f->ts.kind,
999                       gfc_type_letter (a->ts.type), a->ts.kind);
1000 }
1001
1002
1003 void
1004 gfc_resolve_fnum (gfc_expr *f, gfc_expr *n)
1005 {
1006   f->ts.type = BT_INTEGER;
1007   f->ts.kind = gfc_default_integer_kind;
1008   if (n->ts.kind != f->ts.kind)
1009     gfc_convert_type (n, &f->ts, 2);
1010   f->value.function.name = gfc_get_string (PREFIX ("fnum_i%d"), f->ts.kind);
1011 }
1012
1013
1014 void
1015 gfc_resolve_fraction (gfc_expr *f, gfc_expr *x)
1016 {
1017   f->ts = x->ts;
1018   f->value.function.name = gfc_get_string ("__fraction_%d", x->ts.kind);
1019 }
1020
1021
1022 /* Resolve single-argument g77 math intrinsics, eg BESY0, ERF.  */
1023
1024 void
1025 gfc_resolve_g77_math1 (gfc_expr *f, gfc_expr *x)
1026 {
1027   f->ts = x->ts;
1028   f->value.function.name = gfc_get_string ("<intrinsic>");
1029 }
1030
1031
1032 void
1033 gfc_resolve_gamma (gfc_expr *f, gfc_expr *x)
1034 {
1035   f->ts = x->ts;
1036   f->value.function.name
1037     = gfc_get_string ("__tgamma_%d", x->ts.kind);
1038 }
1039
1040
1041 void
1042 gfc_resolve_getcwd (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED)
1043 {
1044   f->ts.type = BT_INTEGER;
1045   f->ts.kind = 4;
1046   f->value.function.name = gfc_get_string (PREFIX ("getcwd"));
1047 }
1048
1049
1050 void
1051 gfc_resolve_getgid (gfc_expr *f)
1052 {
1053   f->ts.type = BT_INTEGER;
1054   f->ts.kind = 4;
1055   f->value.function.name = gfc_get_string (PREFIX ("getgid"));
1056 }
1057
1058
1059 void
1060 gfc_resolve_getpid (gfc_expr *f)
1061 {
1062   f->ts.type = BT_INTEGER;
1063   f->ts.kind = 4;
1064   f->value.function.name = gfc_get_string (PREFIX ("getpid"));
1065 }
1066
1067
1068 void
1069 gfc_resolve_getuid (gfc_expr *f)
1070 {
1071   f->ts.type = BT_INTEGER;
1072   f->ts.kind = 4;
1073   f->value.function.name = gfc_get_string (PREFIX ("getuid"));
1074 }
1075
1076
1077 void
1078 gfc_resolve_hostnm (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED)
1079 {
1080   f->ts.type = BT_INTEGER;
1081   f->ts.kind = 4;
1082   f->value.function.name = gfc_get_string (PREFIX ("hostnm"));
1083 }
1084
1085
1086 void
1087 gfc_resolve_hypot (gfc_expr *f, gfc_expr *x, gfc_expr *y ATTRIBUTE_UNUSED)
1088 {
1089   f->ts = x->ts;
1090   f->value.function.name = gfc_get_string ("__hypot_r%d", x->ts.kind);
1091 }
1092
1093
1094 void
1095 gfc_resolve_iall (gfc_expr *f, gfc_expr *array, gfc_expr *dim, gfc_expr *mask)
1096 {
1097   resolve_transformational ("iall", f, array, dim, mask);
1098 }
1099
1100
1101 void
1102 gfc_resolve_iand (gfc_expr *f, gfc_expr *i, gfc_expr *j)
1103 {
1104   /* If the kind of i and j are different, then g77 cross-promoted the
1105      kinds to the largest value.  The Fortran 95 standard requires the 
1106      kinds to match.  */
1107   if (i->ts.kind != j->ts.kind)
1108     {
1109       if (i->ts.kind == gfc_kind_max (i, j))
1110         gfc_convert_type (j, &i->ts, 2);
1111       else
1112         gfc_convert_type (i, &j->ts, 2);
1113     }
1114
1115   f->ts = i->ts;
1116   f->value.function.name = gfc_get_string ("__iand_%d", i->ts.kind);
1117 }
1118
1119
1120 void
1121 gfc_resolve_iany (gfc_expr *f, gfc_expr *array, gfc_expr *dim, gfc_expr *mask)
1122 {
1123   resolve_transformational ("iany", f, array, dim, mask);
1124 }
1125
1126
1127 void
1128 gfc_resolve_ibclr (gfc_expr *f, gfc_expr *i, gfc_expr *pos ATTRIBUTE_UNUSED)
1129 {
1130   f->ts = i->ts;
1131   f->value.function.name = gfc_get_string ("__ibclr_%d", i->ts.kind);
1132 }
1133
1134
1135 void
1136 gfc_resolve_ibits (gfc_expr *f, gfc_expr *i, gfc_expr *pos ATTRIBUTE_UNUSED,
1137                    gfc_expr *len ATTRIBUTE_UNUSED)
1138 {
1139   f->ts = i->ts;
1140   f->value.function.name = gfc_get_string ("__ibits_%d", i->ts.kind);
1141 }
1142
1143
1144 void
1145 gfc_resolve_ibset (gfc_expr *f, gfc_expr *i, gfc_expr *pos ATTRIBUTE_UNUSED)
1146 {
1147   f->ts = i->ts;
1148   f->value.function.name = gfc_get_string ("__ibset_%d", i->ts.kind);
1149 }
1150
1151
1152 void
1153 gfc_resolve_iachar (gfc_expr *f, gfc_expr *c, gfc_expr *kind)
1154 {
1155   f->ts.type = BT_INTEGER;
1156   if (kind)
1157     f->ts.kind = mpz_get_si (kind->value.integer);
1158   else
1159     f->ts.kind = gfc_default_integer_kind;
1160   f->value.function.name = gfc_get_string ("__ichar_%d", c->ts.kind);
1161 }
1162
1163
1164 void
1165 gfc_resolve_ichar (gfc_expr *f, gfc_expr *c, gfc_expr *kind)
1166 {
1167   f->ts.type = BT_INTEGER;
1168   if (kind)
1169     f->ts.kind = mpz_get_si (kind->value.integer);
1170   else
1171     f->ts.kind = gfc_default_integer_kind;
1172   f->value.function.name = gfc_get_string ("__ichar_%d", c->ts.kind);
1173 }
1174
1175
1176 void
1177 gfc_resolve_idnint (gfc_expr *f, gfc_expr *a)
1178 {
1179   gfc_resolve_nint (f, a, NULL);
1180 }
1181
1182
1183 void
1184 gfc_resolve_ierrno (gfc_expr *f)
1185 {
1186   f->ts.type = BT_INTEGER;
1187   f->ts.kind = gfc_default_integer_kind;
1188   f->value.function.name = gfc_get_string (PREFIX ("ierrno_i%d"), f->ts.kind);
1189 }
1190
1191
1192 void
1193 gfc_resolve_ieor (gfc_expr *f, gfc_expr *i, gfc_expr *j)
1194 {
1195   /* If the kind of i and j are different, then g77 cross-promoted the
1196      kinds to the largest value.  The Fortran 95 standard requires the 
1197      kinds to match.  */
1198   if (i->ts.kind != j->ts.kind)
1199     {
1200       if (i->ts.kind == gfc_kind_max (i, j))
1201         gfc_convert_type (j, &i->ts, 2);
1202       else
1203         gfc_convert_type (i, &j->ts, 2);
1204     }
1205
1206   f->ts = i->ts;
1207   f->value.function.name = gfc_get_string ("__ieor_%d", i->ts.kind);
1208 }
1209
1210
1211 void
1212 gfc_resolve_ior (gfc_expr *f, gfc_expr *i, gfc_expr *j)
1213 {
1214   /* If the kind of i and j are different, then g77 cross-promoted the
1215      kinds to the largest value.  The Fortran 95 standard requires the 
1216      kinds to match.  */
1217   if (i->ts.kind != j->ts.kind)
1218     {
1219       if (i->ts.kind == gfc_kind_max (i, j))
1220         gfc_convert_type (j, &i->ts, 2);
1221       else
1222         gfc_convert_type (i, &j->ts, 2);
1223     }
1224
1225   f->ts = i->ts;
1226   f->value.function.name = gfc_get_string ("__ior_%d", i->ts.kind);
1227 }
1228
1229
1230 void
1231 gfc_resolve_index_func (gfc_expr *f, gfc_expr *str,
1232                         gfc_expr *sub_str ATTRIBUTE_UNUSED, gfc_expr *back,
1233                         gfc_expr *kind)
1234 {
1235   gfc_typespec ts;
1236   gfc_clear_ts (&ts);
1237
1238   f->ts.type = BT_INTEGER;
1239   if (kind)
1240     f->ts.kind = mpz_get_si (kind->value.integer);
1241   else
1242     f->ts.kind = gfc_default_integer_kind;
1243
1244   if (back && back->ts.kind != gfc_default_integer_kind)
1245     {
1246       ts.type = BT_LOGICAL;
1247       ts.kind = gfc_default_integer_kind;
1248       ts.u.derived = NULL;
1249       ts.u.cl = NULL;
1250       gfc_convert_type (back, &ts, 2);
1251     }
1252
1253   f->value.function.name
1254     = gfc_get_string ("__index_%d_i%d", str->ts.kind, f->ts.kind);
1255 }
1256
1257
1258 void
1259 gfc_resolve_int (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
1260 {
1261   f->ts.type = BT_INTEGER;
1262   f->ts.kind = (kind == NULL)
1263              ? gfc_default_integer_kind : mpz_get_si (kind->value.integer);
1264   f->value.function.name
1265     = gfc_get_string ("__int_%d_%c%d", f->ts.kind,
1266                       gfc_type_letter (a->ts.type), a->ts.kind);
1267 }
1268
1269
1270 void
1271 gfc_resolve_int2 (gfc_expr *f, gfc_expr *a)
1272 {
1273   f->ts.type = BT_INTEGER;
1274   f->ts.kind = 2;
1275   f->value.function.name
1276     = gfc_get_string ("__int_%d_%c%d", f->ts.kind,
1277                       gfc_type_letter (a->ts.type), a->ts.kind);
1278 }
1279
1280
1281 void
1282 gfc_resolve_int8 (gfc_expr *f, gfc_expr *a)
1283 {
1284   f->ts.type = BT_INTEGER;
1285   f->ts.kind = 8;
1286   f->value.function.name
1287     = gfc_get_string ("__int_%d_%c%d", f->ts.kind,
1288                       gfc_type_letter (a->ts.type), a->ts.kind);
1289 }
1290
1291
1292 void
1293 gfc_resolve_long (gfc_expr *f, gfc_expr *a)
1294 {
1295   f->ts.type = BT_INTEGER;
1296   f->ts.kind = 4;
1297   f->value.function.name
1298     = gfc_get_string ("__int_%d_%c%d", f->ts.kind,
1299                       gfc_type_letter (a->ts.type), a->ts.kind);
1300 }
1301
1302
1303 void
1304 gfc_resolve_iparity (gfc_expr *f, gfc_expr *array, gfc_expr *dim, gfc_expr *mask)
1305 {
1306   resolve_transformational ("iparity", f, array, dim, mask);
1307 }
1308
1309
1310 void
1311 gfc_resolve_isatty (gfc_expr *f, gfc_expr *u)
1312 {
1313   gfc_typespec ts;
1314   gfc_clear_ts (&ts);
1315   
1316   f->ts.type = BT_LOGICAL;
1317   f->ts.kind = gfc_default_integer_kind;
1318   if (u->ts.kind != gfc_c_int_kind)
1319     {
1320       ts.type = BT_INTEGER;
1321       ts.kind = gfc_c_int_kind;
1322       ts.u.derived = NULL;
1323       ts.u.cl = NULL;
1324       gfc_convert_type (u, &ts, 2);
1325     }
1326
1327   f->value.function.name = gfc_get_string (PREFIX ("isatty_l%d"), f->ts.kind);
1328 }
1329
1330
1331 void
1332 gfc_resolve_ishft (gfc_expr *f, gfc_expr *i, gfc_expr *shift)
1333 {
1334   f->ts = i->ts;
1335   f->value.function.name
1336     = gfc_get_string ("__ishft_%d_%d", i->ts.kind, shift->ts.kind);
1337 }
1338
1339
1340 void
1341 gfc_resolve_rshift (gfc_expr *f, gfc_expr *i, gfc_expr *shift)
1342 {
1343   f->ts = i->ts;
1344   f->value.function.name
1345     = gfc_get_string ("__rshift_%d_%d", i->ts.kind, shift->ts.kind);
1346 }
1347
1348
1349 void
1350 gfc_resolve_lshift (gfc_expr *f, gfc_expr *i, gfc_expr *shift)
1351 {
1352   f->ts = i->ts;
1353   f->value.function.name
1354     = gfc_get_string ("__lshift_%d_%d", i->ts.kind, shift->ts.kind);
1355 }
1356
1357
1358 void
1359 gfc_resolve_ishftc (gfc_expr *f, gfc_expr *i, gfc_expr *shift, gfc_expr *size)
1360 {
1361   int s_kind;
1362
1363   s_kind = (size == NULL) ? gfc_default_integer_kind : size->ts.kind;
1364
1365   f->ts = i->ts;
1366   f->value.function.name
1367     = gfc_get_string ("__ishftc_%d_%d_%d", i->ts.kind, shift->ts.kind, s_kind);
1368 }
1369
1370
1371 void
1372 gfc_resolve_kill (gfc_expr *f, gfc_expr *p ATTRIBUTE_UNUSED,
1373                   gfc_expr *s ATTRIBUTE_UNUSED)
1374 {
1375   f->ts.type = BT_INTEGER;
1376   f->ts.kind = gfc_default_integer_kind;
1377   f->value.function.name = gfc_get_string (PREFIX ("kill_i%d"), f->ts.kind);
1378 }
1379
1380
1381 void
1382 gfc_resolve_lbound (gfc_expr *f, gfc_expr *array, gfc_expr *dim, gfc_expr *kind)
1383 {
1384   resolve_bound (f, array, dim, kind, "__lbound", false);
1385 }
1386
1387
1388 void
1389 gfc_resolve_lcobound (gfc_expr *f, gfc_expr *array, gfc_expr *dim, gfc_expr *kind)
1390 {
1391   resolve_bound (f, array, dim, kind, "__lcobound", true);
1392 }
1393
1394
1395 void
1396 gfc_resolve_len (gfc_expr *f, gfc_expr *string, gfc_expr *kind)
1397 {
1398   f->ts.type = BT_INTEGER;
1399   if (kind)
1400     f->ts.kind = mpz_get_si (kind->value.integer);
1401   else
1402     f->ts.kind = gfc_default_integer_kind;
1403   f->value.function.name
1404     = gfc_get_string ("__len_%d_i%d", string->ts.kind,
1405                       gfc_default_integer_kind);
1406 }
1407
1408
1409 void
1410 gfc_resolve_len_trim (gfc_expr *f, gfc_expr *string, gfc_expr *kind)
1411 {
1412   f->ts.type = BT_INTEGER;
1413   if (kind)
1414     f->ts.kind = mpz_get_si (kind->value.integer);
1415   else
1416     f->ts.kind = gfc_default_integer_kind;
1417   f->value.function.name = gfc_get_string ("__len_trim%d", string->ts.kind);
1418 }
1419
1420
1421 void
1422 gfc_resolve_lgamma (gfc_expr *f, gfc_expr *x)
1423 {
1424   f->ts = x->ts;
1425   f->value.function.name
1426     = gfc_get_string ("__lgamma_%d", x->ts.kind);
1427 }
1428
1429
1430 void
1431 gfc_resolve_link (gfc_expr *f, gfc_expr *p1 ATTRIBUTE_UNUSED,
1432                   gfc_expr *p2 ATTRIBUTE_UNUSED)
1433 {
1434   f->ts.type = BT_INTEGER;
1435   f->ts.kind = gfc_default_integer_kind;
1436   f->value.function.name = gfc_get_string (PREFIX ("link_i%d"), f->ts.kind);
1437 }
1438
1439
1440 void
1441 gfc_resolve_loc (gfc_expr *f, gfc_expr *x)
1442 {
1443   f->ts.type= BT_INTEGER;
1444   f->ts.kind = gfc_index_integer_kind;
1445   f->value.function.name = gfc_get_string ("__loc_%d", x->ts.kind);
1446 }
1447
1448
1449 void
1450 gfc_resolve_log (gfc_expr *f, gfc_expr *x)
1451 {
1452   f->ts = x->ts;
1453   f->value.function.name
1454     = gfc_get_string ("__log_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
1455 }
1456
1457
1458 void
1459 gfc_resolve_log10 (gfc_expr *f, gfc_expr *x)
1460 {
1461   f->ts = x->ts;
1462   f->value.function.name
1463     = gfc_get_string ("__log10_%c%d", gfc_type_letter (x->ts.type),
1464                       x->ts.kind);
1465 }
1466
1467
1468 void
1469 gfc_resolve_logical (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
1470 {
1471   f->ts.type = BT_LOGICAL;
1472   f->ts.kind = (kind == NULL)
1473              ? gfc_default_logical_kind : mpz_get_si (kind->value.integer);
1474   f->rank = a->rank;
1475
1476   f->value.function.name
1477     = gfc_get_string ("__logical_%d_%c%d", f->ts.kind,
1478                       gfc_type_letter (a->ts.type), a->ts.kind);
1479 }
1480
1481
1482 void
1483 gfc_resolve_malloc (gfc_expr *f, gfc_expr *size)
1484 {
1485   if (size->ts.kind < gfc_index_integer_kind)
1486     {
1487       gfc_typespec ts;
1488       gfc_clear_ts (&ts);
1489
1490       ts.type = BT_INTEGER;
1491       ts.kind = gfc_index_integer_kind;
1492       gfc_convert_type_warn (size, &ts, 2, 0);
1493     }
1494
1495   f->ts.type = BT_INTEGER;
1496   f->ts.kind = gfc_index_integer_kind;
1497   f->value.function.name = gfc_get_string (PREFIX ("malloc"));
1498 }
1499
1500
1501 void
1502 gfc_resolve_matmul (gfc_expr *f, gfc_expr *a, gfc_expr *b)
1503 {
1504   gfc_expr temp;
1505
1506   if (a->ts.type == BT_LOGICAL && b->ts.type == BT_LOGICAL)
1507     {
1508       f->ts.type = BT_LOGICAL;
1509       f->ts.kind = gfc_default_logical_kind;
1510     }
1511   else
1512     {
1513       temp.expr_type = EXPR_OP;
1514       gfc_clear_ts (&temp.ts);
1515       temp.value.op.op = INTRINSIC_NONE;
1516       temp.value.op.op1 = a;
1517       temp.value.op.op2 = b;
1518       gfc_type_convert_binary (&temp, 1);
1519       f->ts = temp.ts;
1520     }
1521
1522   f->rank = (a->rank == 2 && b->rank == 2) ? 2 : 1;
1523
1524   if (a->rank == 2 && b->rank == 2)
1525     {
1526       if (a->shape && b->shape)
1527         {
1528           f->shape = gfc_get_shape (f->rank);
1529           mpz_init_set (f->shape[0], a->shape[0]);
1530           mpz_init_set (f->shape[1], b->shape[1]);
1531         }
1532     }
1533   else if (a->rank == 1)
1534     {
1535       if (b->shape)
1536         {
1537           f->shape = gfc_get_shape (f->rank);
1538           mpz_init_set (f->shape[0], b->shape[1]);
1539         }
1540     }
1541   else 
1542     {
1543       /* b->rank == 1 and a->rank == 2 here, all other cases have
1544          been caught in check.c.   */
1545       if (a->shape)
1546         {
1547           f->shape = gfc_get_shape (f->rank);
1548           mpz_init_set (f->shape[0], a->shape[0]);
1549         }
1550     }
1551
1552   f->value.function.name
1553     = gfc_get_string (PREFIX ("matmul_%c%d"), gfc_type_letter (f->ts.type),
1554                       f->ts.kind);
1555 }
1556
1557
1558 static void
1559 gfc_resolve_minmax (const char *name, gfc_expr *f, gfc_actual_arglist *args)
1560 {
1561   gfc_actual_arglist *a;
1562
1563   f->ts.type = args->expr->ts.type;
1564   f->ts.kind = args->expr->ts.kind;
1565   /* Find the largest type kind.  */
1566   for (a = args->next; a; a = a->next)
1567     {
1568       if (a->expr->ts.kind > f->ts.kind)
1569         f->ts.kind = a->expr->ts.kind;
1570     }
1571
1572   /* Convert all parameters to the required kind.  */
1573   for (a = args; a; a = a->next)
1574     {
1575       if (a->expr->ts.kind != f->ts.kind)
1576         gfc_convert_type (a->expr, &f->ts, 2);
1577     }
1578
1579   f->value.function.name
1580     = gfc_get_string (name, gfc_type_letter (f->ts.type), f->ts.kind);
1581 }
1582
1583
1584 void
1585 gfc_resolve_max (gfc_expr *f, gfc_actual_arglist *args)
1586 {
1587   gfc_resolve_minmax ("__max_%c%d", f, args);
1588 }
1589
1590
1591 void
1592 gfc_resolve_maxloc (gfc_expr *f, gfc_expr *array, gfc_expr *dim,
1593                     gfc_expr *mask)
1594 {
1595   const char *name;
1596   int i, j, idim;
1597
1598   f->ts.type = BT_INTEGER;
1599   f->ts.kind = gfc_default_integer_kind;
1600
1601   if (dim == NULL)
1602     {
1603       f->rank = 1;
1604       f->shape = gfc_get_shape (1);
1605       mpz_init_set_si (f->shape[0], array->rank);
1606     }
1607   else
1608     {
1609       f->rank = array->rank - 1;
1610       gfc_resolve_dim_arg (dim);
1611       if (array->shape && dim->expr_type == EXPR_CONSTANT)
1612         {
1613           idim = (int) mpz_get_si (dim->value.integer);
1614           f->shape = gfc_get_shape (f->rank);
1615           for (i = 0, j = 0; i < f->rank; i++, j++)
1616             {
1617               if (i == (idim - 1))
1618                 j++;
1619               mpz_init_set (f->shape[i], array->shape[j]);
1620             }
1621         }
1622     }
1623
1624   if (mask)
1625     {
1626       if (mask->rank == 0)
1627         name = "smaxloc";
1628       else
1629         name = "mmaxloc";
1630
1631       resolve_mask_arg (mask);
1632     }
1633   else
1634     name = "maxloc";
1635
1636   f->value.function.name
1637     = gfc_get_string (PREFIX ("%s%d_%d_%c%d"), name, dim != NULL, f->ts.kind,
1638                       gfc_type_letter (array->ts.type), array->ts.kind);
1639 }
1640
1641
1642 void
1643 gfc_resolve_maxval (gfc_expr *f, gfc_expr *array, gfc_expr *dim,
1644                     gfc_expr *mask)
1645 {
1646   const char *name;
1647   int i, j, idim;
1648
1649   f->ts = array->ts;
1650
1651   if (dim != NULL)
1652     {
1653       f->rank = array->rank - 1;
1654       gfc_resolve_dim_arg (dim);
1655
1656       if (f->rank && array->shape && dim->expr_type == EXPR_CONSTANT)
1657         {
1658           idim = (int) mpz_get_si (dim->value.integer);
1659           f->shape = gfc_get_shape (f->rank);
1660           for (i = 0, j = 0; i < f->rank; i++, j++)
1661             {
1662               if (i == (idim - 1))
1663                 j++;
1664               mpz_init_set (f->shape[i], array->shape[j]);
1665             }
1666         }
1667     }
1668
1669   if (mask)
1670     {
1671       if (mask->rank == 0)
1672         name = "smaxval";
1673       else
1674         name = "mmaxval";
1675
1676       resolve_mask_arg (mask);
1677     }
1678   else
1679     name = "maxval";
1680
1681   f->value.function.name
1682     = gfc_get_string (PREFIX ("%s_%c%d"), name,
1683                       gfc_type_letter (array->ts.type), array->ts.kind);
1684 }
1685
1686
1687 void
1688 gfc_resolve_mclock (gfc_expr *f)
1689 {
1690   f->ts.type = BT_INTEGER;
1691   f->ts.kind = 4;
1692   f->value.function.name = PREFIX ("mclock");
1693 }
1694
1695
1696 void
1697 gfc_resolve_mclock8 (gfc_expr *f)
1698 {
1699   f->ts.type = BT_INTEGER;
1700   f->ts.kind = 8;
1701   f->value.function.name = PREFIX ("mclock8");
1702 }
1703
1704
1705 void
1706 gfc_resolve_mask (gfc_expr *f, gfc_expr *i ATTRIBUTE_UNUSED,
1707                   gfc_expr *kind)
1708 {
1709   f->ts.type = BT_INTEGER;
1710   f->ts.kind = kind ? mpz_get_si (kind->value.integer)
1711                     : gfc_default_integer_kind;
1712
1713   if (f->value.function.isym->id == GFC_ISYM_MASKL)
1714     f->value.function.name = gfc_get_string ("__maskl_i%d", f->ts.kind);
1715   else
1716     f->value.function.name = gfc_get_string ("__maskr_i%d", f->ts.kind);
1717 }
1718
1719
1720 void
1721 gfc_resolve_merge (gfc_expr *f, gfc_expr *tsource,
1722                    gfc_expr *fsource ATTRIBUTE_UNUSED,
1723                    gfc_expr *mask ATTRIBUTE_UNUSED)
1724 {
1725   if (tsource->ts.type == BT_CHARACTER && tsource->ref)
1726     gfc_resolve_substring_charlen (tsource);
1727
1728   if (fsource->ts.type == BT_CHARACTER && fsource->ref)
1729     gfc_resolve_substring_charlen (fsource);
1730
1731   if (tsource->ts.type == BT_CHARACTER)
1732     check_charlen_present (tsource);
1733
1734   f->ts = tsource->ts;
1735   f->value.function.name
1736     = gfc_get_string ("__merge_%c%d", gfc_type_letter (tsource->ts.type),
1737                       tsource->ts.kind);
1738 }
1739
1740
1741 void
1742 gfc_resolve_merge_bits (gfc_expr *f, gfc_expr *i,
1743                         gfc_expr *j ATTRIBUTE_UNUSED,
1744                         gfc_expr *mask ATTRIBUTE_UNUSED)
1745 {
1746   f->ts = i->ts;
1747   f->value.function.name = gfc_get_string ("__merge_bits_i%d", i->ts.kind);
1748 }
1749
1750
1751 void
1752 gfc_resolve_min (gfc_expr *f, gfc_actual_arglist *args)
1753 {
1754   gfc_resolve_minmax ("__min_%c%d", f, args);
1755 }
1756
1757
1758 void
1759 gfc_resolve_minloc (gfc_expr *f, gfc_expr *array, gfc_expr *dim,
1760                     gfc_expr *mask)
1761 {
1762   const char *name;
1763   int i, j, idim;
1764
1765   f->ts.type = BT_INTEGER;
1766   f->ts.kind = gfc_default_integer_kind;
1767
1768   if (dim == NULL)
1769     {
1770       f->rank = 1;
1771       f->shape = gfc_get_shape (1);
1772       mpz_init_set_si (f->shape[0], array->rank);
1773     }
1774   else
1775     {
1776       f->rank = array->rank - 1;
1777       gfc_resolve_dim_arg (dim);
1778       if (array->shape && dim->expr_type == EXPR_CONSTANT)
1779         {
1780           idim = (int) mpz_get_si (dim->value.integer);
1781           f->shape = gfc_get_shape (f->rank);
1782           for (i = 0, j = 0; i < f->rank; i++, j++)
1783             {
1784               if (i == (idim - 1))
1785                 j++;
1786               mpz_init_set (f->shape[i], array->shape[j]);
1787             }
1788         }
1789     }
1790
1791   if (mask)
1792     {
1793       if (mask->rank == 0)
1794         name = "sminloc";
1795       else
1796         name = "mminloc";
1797
1798       resolve_mask_arg (mask);
1799     }
1800   else
1801     name = "minloc";
1802
1803   f->value.function.name
1804     = gfc_get_string (PREFIX ("%s%d_%d_%c%d"), name, dim != NULL, f->ts.kind,
1805                       gfc_type_letter (array->ts.type), array->ts.kind);
1806 }
1807
1808
1809 void
1810 gfc_resolve_minval (gfc_expr *f, gfc_expr *array, gfc_expr *dim,
1811                     gfc_expr *mask)
1812 {
1813   const char *name;
1814   int i, j, idim;
1815
1816   f->ts = array->ts;
1817
1818   if (dim != NULL)
1819     {
1820       f->rank = array->rank - 1;
1821       gfc_resolve_dim_arg (dim);
1822
1823       if (f->rank && array->shape && dim->expr_type == EXPR_CONSTANT)
1824         {
1825           idim = (int) mpz_get_si (dim->value.integer);
1826           f->shape = gfc_get_shape (f->rank);
1827           for (i = 0, j = 0; i < f->rank; i++, j++)
1828             {
1829               if (i == (idim - 1))
1830                 j++;
1831               mpz_init_set (f->shape[i], array->shape[j]);
1832             }
1833         }
1834     }
1835
1836   if (mask)
1837     {
1838       if (mask->rank == 0)
1839         name = "sminval";
1840       else
1841         name = "mminval";
1842
1843       resolve_mask_arg (mask);
1844     }
1845   else
1846     name = "minval";
1847
1848   f->value.function.name
1849     = gfc_get_string (PREFIX ("%s_%c%d"), name,
1850                       gfc_type_letter (array->ts.type), array->ts.kind);
1851 }
1852
1853
1854 void
1855 gfc_resolve_mod (gfc_expr *f, gfc_expr *a, gfc_expr *p)
1856 {
1857   f->ts.type = a->ts.type;
1858   if (p != NULL)
1859     f->ts.kind = gfc_kind_max (a,p);
1860   else
1861     f->ts.kind = a->ts.kind;
1862
1863   if (p != NULL && a->ts.kind != p->ts.kind)
1864     {
1865       if (a->ts.kind == gfc_kind_max (a,p))
1866         gfc_convert_type (p, &a->ts, 2);
1867       else
1868         gfc_convert_type (a, &p->ts, 2);
1869     }
1870
1871   f->value.function.name
1872     = gfc_get_string ("__mod_%c%d", gfc_type_letter (f->ts.type), f->ts.kind);
1873 }
1874
1875
1876 void
1877 gfc_resolve_modulo (gfc_expr *f, gfc_expr *a, gfc_expr *p)
1878 {
1879   f->ts.type = a->ts.type;
1880   if (p != NULL)
1881     f->ts.kind = gfc_kind_max (a,p);
1882   else
1883     f->ts.kind = a->ts.kind;
1884
1885   if (p != NULL && a->ts.kind != p->ts.kind)
1886     {
1887       if (a->ts.kind == gfc_kind_max (a,p))
1888         gfc_convert_type (p, &a->ts, 2);
1889       else
1890         gfc_convert_type (a, &p->ts, 2);
1891     }
1892
1893   f->value.function.name
1894     = gfc_get_string ("__modulo_%c%d", gfc_type_letter (f->ts.type),
1895                       f->ts.kind);
1896 }
1897
1898 void
1899 gfc_resolve_nearest (gfc_expr *f, gfc_expr *a, gfc_expr *p)
1900 {
1901   if (p->ts.kind != a->ts.kind)
1902     gfc_convert_type (p, &a->ts, 2);
1903
1904   f->ts = a->ts;
1905   f->value.function.name
1906     = gfc_get_string ("__nearest_%c%d", gfc_type_letter (a->ts.type),
1907                       a->ts.kind);
1908 }
1909
1910 void
1911 gfc_resolve_nint (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
1912 {
1913   f->ts.type = BT_INTEGER;
1914   f->ts.kind = (kind == NULL)
1915              ? gfc_default_integer_kind : mpz_get_si (kind->value.integer);
1916   f->value.function.name
1917     = gfc_get_string ("__nint_%d_%d", f->ts.kind, a->ts.kind);
1918 }
1919
1920
1921 void
1922 gfc_resolve_norm2 (gfc_expr *f, gfc_expr *array, gfc_expr *dim)
1923 {
1924   resolve_transformational ("norm2", f, array, dim, NULL);
1925 }
1926
1927
1928 void
1929 gfc_resolve_not (gfc_expr *f, gfc_expr *i)
1930 {
1931   f->ts = i->ts;
1932   f->value.function.name = gfc_get_string ("__not_%d", i->ts.kind);
1933 }
1934
1935
1936 void
1937 gfc_resolve_or (gfc_expr *f, gfc_expr *i, gfc_expr *j)
1938 {
1939   f->ts.type = i->ts.type;
1940   f->ts.kind = gfc_kind_max (i, j);
1941
1942   if (i->ts.kind != j->ts.kind)
1943     {
1944       if (i->ts.kind == gfc_kind_max (i, j))
1945         gfc_convert_type (j, &i->ts, 2);
1946       else
1947         gfc_convert_type (i, &j->ts, 2);
1948     }
1949
1950   f->value.function.name
1951     = gfc_get_string ("__or_%c%d", gfc_type_letter (i->ts.type), f->ts.kind);
1952 }
1953
1954
1955 void
1956 gfc_resolve_pack (gfc_expr *f, gfc_expr *array, gfc_expr *mask,
1957                   gfc_expr *vector ATTRIBUTE_UNUSED)
1958 {
1959   if (array->ts.type == BT_CHARACTER && array->ref)
1960     gfc_resolve_substring_charlen (array);
1961
1962   f->ts = array->ts;
1963   f->rank = 1;
1964
1965   resolve_mask_arg (mask);
1966
1967   if (mask->rank != 0)
1968     {
1969       if (array->ts.type == BT_CHARACTER)
1970         f->value.function.name
1971           = array->ts.kind == 1 ? PREFIX ("pack_char")
1972                                 : gfc_get_string
1973                                         (PREFIX ("pack_char%d"),
1974                                          array->ts.kind);
1975       else
1976         f->value.function.name = PREFIX ("pack");
1977     }
1978   else
1979     {
1980       if (array->ts.type == BT_CHARACTER)
1981         f->value.function.name
1982           = array->ts.kind == 1 ? PREFIX ("pack_s_char")
1983                                 : gfc_get_string
1984                                         (PREFIX ("pack_s_char%d"),
1985                                          array->ts.kind);
1986       else
1987         f->value.function.name = PREFIX ("pack_s");
1988     }
1989 }
1990
1991
1992 void
1993 gfc_resolve_parity (gfc_expr *f, gfc_expr *array, gfc_expr *dim)
1994 {
1995   resolve_transformational ("parity", f, array, dim, NULL);
1996 }
1997
1998
1999 void
2000 gfc_resolve_product (gfc_expr *f, gfc_expr *array, gfc_expr *dim,
2001                      gfc_expr *mask)
2002 {
2003   resolve_transformational ("product", f, array, dim, mask);
2004 }
2005
2006
2007 void
2008 gfc_resolve_real (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
2009 {
2010   f->ts.type = BT_REAL;
2011
2012   if (kind != NULL)
2013     f->ts.kind = mpz_get_si (kind->value.integer);
2014   else
2015     f->ts.kind = (a->ts.type == BT_COMPLEX)
2016                ? a->ts.kind : gfc_default_real_kind;
2017
2018   f->value.function.name
2019     = gfc_get_string ("__real_%d_%c%d", f->ts.kind,
2020                       gfc_type_letter (a->ts.type), a->ts.kind);
2021 }
2022
2023
2024 void
2025 gfc_resolve_realpart (gfc_expr *f, gfc_expr *a)
2026 {
2027   f->ts.type = BT_REAL;
2028   f->ts.kind = a->ts.kind;
2029   f->value.function.name
2030     = gfc_get_string ("__real_%d_%c%d", f->ts.kind,
2031                       gfc_type_letter (a->ts.type), a->ts.kind);
2032 }
2033
2034
2035 void
2036 gfc_resolve_rename (gfc_expr *f, gfc_expr *p1 ATTRIBUTE_UNUSED,
2037                     gfc_expr *p2 ATTRIBUTE_UNUSED)
2038 {
2039   f->ts.type = BT_INTEGER;
2040   f->ts.kind = gfc_default_integer_kind;
2041   f->value.function.name = gfc_get_string (PREFIX ("rename_i%d"), f->ts.kind);
2042 }
2043
2044
2045 void
2046 gfc_resolve_repeat (gfc_expr *f, gfc_expr *string,
2047                     gfc_expr *ncopies ATTRIBUTE_UNUSED)
2048 {
2049   f->ts.type = BT_CHARACTER;
2050   f->ts.kind = string->ts.kind;
2051   f->value.function.name = gfc_get_string ("__repeat_%d", string->ts.kind);
2052 }
2053
2054
2055 void
2056 gfc_resolve_reshape (gfc_expr *f, gfc_expr *source, gfc_expr *shape,
2057                      gfc_expr *pad ATTRIBUTE_UNUSED,
2058                      gfc_expr *order ATTRIBUTE_UNUSED)
2059 {
2060   mpz_t rank;
2061   int kind;
2062   int i;
2063
2064   if (source->ts.type == BT_CHARACTER && source->ref)
2065     gfc_resolve_substring_charlen (source);
2066
2067   f->ts = source->ts;
2068
2069   gfc_array_size (shape, &rank);
2070   f->rank = mpz_get_si (rank);
2071   mpz_clear (rank);
2072   switch (source->ts.type)
2073     {
2074     case BT_COMPLEX:
2075     case BT_REAL:
2076     case BT_INTEGER:
2077     case BT_LOGICAL:
2078     case BT_CHARACTER:
2079       kind = source->ts.kind;
2080       break;
2081
2082     default:
2083       kind = 0;
2084       break;
2085     }
2086
2087   switch (kind)
2088     {
2089     case 4:
2090     case 8:
2091     case 10:
2092     case 16:
2093       if (source->ts.type == BT_COMPLEX || source->ts.type == BT_REAL)
2094         f->value.function.name
2095           = gfc_get_string (PREFIX ("reshape_%c%d"),
2096                             gfc_type_letter (source->ts.type),
2097                             source->ts.kind);
2098       else if (source->ts.type == BT_CHARACTER)
2099         f->value.function.name = gfc_get_string (PREFIX ("reshape_char%d"),
2100                                                  kind);
2101       else
2102         f->value.function.name
2103           = gfc_get_string (PREFIX ("reshape_%d"), source->ts.kind);
2104       break;
2105
2106     default:
2107       f->value.function.name = (source->ts.type == BT_CHARACTER
2108                                 ? PREFIX ("reshape_char") : PREFIX ("reshape"));
2109       break;
2110     }
2111
2112   /* TODO: Make this work with a constant ORDER parameter.  */
2113   if (shape->expr_type == EXPR_ARRAY
2114       && gfc_is_constant_expr (shape)
2115       && order == NULL)
2116     {
2117       gfc_constructor *c;
2118       f->shape = gfc_get_shape (f->rank);
2119       c = gfc_constructor_first (shape->value.constructor);
2120       for (i = 0; i < f->rank; i++)
2121         {
2122           mpz_init_set (f->shape[i], c->expr->value.integer);
2123           c = gfc_constructor_next (c);
2124         }
2125     }
2126
2127   /* Force-convert both SHAPE and ORDER to index_kind so that we don't need
2128      so many runtime variations.  */
2129   if (shape->ts.kind != gfc_index_integer_kind)
2130     {
2131       gfc_typespec ts = shape->ts;
2132       ts.kind = gfc_index_integer_kind;
2133       gfc_convert_type_warn (shape, &ts, 2, 0);
2134     }
2135   if (order && order->ts.kind != gfc_index_integer_kind)
2136     gfc_convert_type_warn (order, &shape->ts, 2, 0);
2137 }
2138
2139
2140 void
2141 gfc_resolve_rrspacing (gfc_expr *f, gfc_expr *x)
2142 {
2143   f->ts = x->ts;
2144   f->value.function.name = gfc_get_string ("__rrspacing_%d", x->ts.kind);
2145 }
2146
2147
2148 void
2149 gfc_resolve_scale (gfc_expr *f, gfc_expr *x, gfc_expr *i ATTRIBUTE_UNUSED)
2150 {
2151   f->ts = x->ts;
2152   f->value.function.name = gfc_get_string ("__scale_%d", x->ts.kind);
2153 }
2154
2155
2156 void
2157 gfc_resolve_scan (gfc_expr *f, gfc_expr *string,
2158                   gfc_expr *set ATTRIBUTE_UNUSED,
2159                   gfc_expr *back ATTRIBUTE_UNUSED, gfc_expr *kind)
2160 {
2161   f->ts.type = BT_INTEGER;
2162   if (kind)
2163     f->ts.kind = mpz_get_si (kind->value.integer);
2164   else
2165     f->ts.kind = gfc_default_integer_kind;
2166   f->value.function.name = gfc_get_string ("__scan_%d", string->ts.kind);
2167 }
2168
2169
2170 void
2171 gfc_resolve_secnds (gfc_expr *t1, gfc_expr *t0)
2172 {
2173   t1->ts = t0->ts;
2174   t1->value.function.name = gfc_get_string (PREFIX ("secnds"));
2175 }
2176
2177
2178 void
2179 gfc_resolve_set_exponent (gfc_expr *f, gfc_expr *x,
2180                           gfc_expr *i ATTRIBUTE_UNUSED)
2181 {
2182   f->ts = x->ts;
2183   f->value.function.name = gfc_get_string ("__set_exponent_%d", x->ts.kind);
2184 }
2185
2186
2187 void
2188 gfc_resolve_shape (gfc_expr *f, gfc_expr *array)
2189 {
2190   f->ts.type = BT_INTEGER;
2191   f->ts.kind = gfc_default_integer_kind;
2192   f->rank = 1;
2193   f->shape = gfc_get_shape (1);
2194   mpz_init_set_ui (f->shape[0], array->rank);
2195   f->value.function.name = gfc_get_string (PREFIX ("shape_%d"), f->ts.kind);
2196 }
2197
2198
2199 void
2200 gfc_resolve_shift (gfc_expr *f, gfc_expr *i, gfc_expr *shift ATTRIBUTE_UNUSED)
2201 {
2202   f->ts = i->ts;
2203   if (f->value.function.isym->id == GFC_ISYM_SHIFTA)
2204     f->value.function.name = gfc_get_string ("shifta_i%d", f->ts.kind);
2205   else if (f->value.function.isym->id == GFC_ISYM_SHIFTL)
2206     f->value.function.name = gfc_get_string ("shiftl_i%d", f->ts.kind);
2207   else if (f->value.function.isym->id == GFC_ISYM_SHIFTR)
2208     f->value.function.name = gfc_get_string ("shiftr_i%d", f->ts.kind);
2209   else
2210     gcc_unreachable ();
2211 }
2212
2213
2214 void
2215 gfc_resolve_sign (gfc_expr *f, gfc_expr *a, gfc_expr *b ATTRIBUTE_UNUSED)
2216 {
2217   f->ts = a->ts;
2218   f->value.function.name
2219     = gfc_get_string ("__sign_%c%d", gfc_type_letter (a->ts.type), a->ts.kind);
2220 }
2221
2222
2223 void
2224 gfc_resolve_signal (gfc_expr *f, gfc_expr *number, gfc_expr *handler)
2225 {
2226   f->ts.type = BT_INTEGER;
2227   f->ts.kind = gfc_c_int_kind;
2228
2229   /* handler can be either BT_INTEGER or BT_PROCEDURE  */
2230   if (handler->ts.type == BT_INTEGER)
2231     {
2232       if (handler->ts.kind != gfc_c_int_kind)
2233         gfc_convert_type (handler, &f->ts, 2);
2234       f->value.function.name = gfc_get_string (PREFIX ("signal_func_int"));
2235     }
2236   else
2237     f->value.function.name = gfc_get_string (PREFIX ("signal_func"));
2238
2239   if (number->ts.kind != gfc_c_int_kind)
2240     gfc_convert_type (number, &f->ts, 2);
2241 }
2242
2243
2244 void
2245 gfc_resolve_sin (gfc_expr *f, gfc_expr *x)
2246 {
2247   f->ts = x->ts;
2248   f->value.function.name
2249     = gfc_get_string ("__sin_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
2250 }
2251
2252
2253 void
2254 gfc_resolve_sinh (gfc_expr *f, gfc_expr *x)
2255 {
2256   f->ts = x->ts;
2257   f->value.function.name
2258     = gfc_get_string ("__sinh_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
2259 }
2260
2261
2262 void
2263 gfc_resolve_size (gfc_expr *f, gfc_expr *array ATTRIBUTE_UNUSED,
2264                   gfc_expr *dim ATTRIBUTE_UNUSED, gfc_expr *kind)
2265 {
2266   f->ts.type = BT_INTEGER;
2267   if (kind)
2268     f->ts.kind = mpz_get_si (kind->value.integer);
2269   else
2270     f->ts.kind = gfc_default_integer_kind;
2271 }
2272
2273
2274 void
2275 gfc_resolve_spacing (gfc_expr *f, gfc_expr *x)
2276 {
2277   f->ts = x->ts;
2278   f->value.function.name = gfc_get_string ("__spacing_%d", x->ts.kind);
2279 }
2280
2281
2282 void
2283 gfc_resolve_spread (gfc_expr *f, gfc_expr *source, gfc_expr *dim,
2284                     gfc_expr *ncopies)
2285 {
2286   if (source->ts.type == BT_CHARACTER && source->ref)
2287     gfc_resolve_substring_charlen (source);
2288
2289   if (source->ts.type == BT_CHARACTER)
2290     check_charlen_present (source);
2291
2292   f->ts = source->ts;
2293   f->rank = source->rank + 1;
2294   if (source->rank == 0)
2295     {
2296       if (source->ts.type == BT_CHARACTER)
2297         f->value.function.name
2298           = source->ts.kind == 1 ? PREFIX ("spread_char_scalar")
2299                                  : gfc_get_string
2300                                         (PREFIX ("spread_char%d_scalar"),
2301                                          source->ts.kind);
2302       else
2303         f->value.function.name = PREFIX ("spread_scalar");
2304     }
2305   else
2306     {
2307       if (source->ts.type == BT_CHARACTER)
2308         f->value.function.name
2309           = source->ts.kind == 1 ? PREFIX ("spread_char")
2310                                  : gfc_get_string
2311                                         (PREFIX ("spread_char%d"),
2312                                          source->ts.kind);
2313       else
2314         f->value.function.name = PREFIX ("spread");
2315     }
2316
2317   if (dim && gfc_is_constant_expr (dim)
2318       && ncopies && gfc_is_constant_expr (ncopies) && source->shape[0])
2319     {
2320       int i, idim;
2321       idim = mpz_get_ui (dim->value.integer);
2322       f->shape = gfc_get_shape (f->rank);
2323       for (i = 0; i < (idim - 1); i++)
2324         mpz_init_set (f->shape[i], source->shape[i]);
2325
2326       mpz_init_set (f->shape[idim - 1], ncopies->value.integer);
2327
2328       for (i = idim; i < f->rank ; i++)
2329         mpz_init_set (f->shape[i], source->shape[i-1]);
2330     }
2331
2332
2333   gfc_resolve_dim_arg (dim);
2334   gfc_resolve_index (ncopies, 1);
2335 }
2336
2337
2338 void
2339 gfc_resolve_sqrt (gfc_expr *f, gfc_expr *x)
2340 {
2341   f->ts = x->ts;
2342   f->value.function.name
2343     = gfc_get_string ("__sqrt_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
2344 }
2345
2346
2347 /* Resolve the g77 compatibility function STAT AND FSTAT.  */
2348
2349 void
2350 gfc_resolve_stat (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED,
2351                   gfc_expr *a ATTRIBUTE_UNUSED)
2352 {
2353   f->ts.type = BT_INTEGER;
2354   f->ts.kind = gfc_default_integer_kind;
2355   f->value.function.name = gfc_get_string (PREFIX ("stat_i%d"), f->ts.kind);
2356 }
2357
2358
2359 void
2360 gfc_resolve_lstat (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED,
2361                    gfc_expr *a ATTRIBUTE_UNUSED)
2362 {
2363   f->ts.type = BT_INTEGER;
2364   f->ts.kind = gfc_default_integer_kind;
2365   f->value.function.name = gfc_get_string (PREFIX ("lstat_i%d"), f->ts.kind);
2366 }
2367
2368
2369 void
2370 gfc_resolve_fstat (gfc_expr *f, gfc_expr *n, gfc_expr *a ATTRIBUTE_UNUSED)
2371 {
2372   f->ts.type = BT_INTEGER;
2373   f->ts.kind = gfc_default_integer_kind;
2374   if (n->ts.kind != f->ts.kind)
2375     gfc_convert_type (n, &f->ts, 2);
2376
2377   f->value.function.name = gfc_get_string (PREFIX ("fstat_i%d"), f->ts.kind);
2378 }
2379
2380
2381 void
2382 gfc_resolve_fgetc (gfc_expr *f, gfc_expr *u, gfc_expr *c ATTRIBUTE_UNUSED)
2383 {
2384   gfc_typespec ts;
2385   gfc_clear_ts (&ts);
2386
2387   f->ts.type = BT_INTEGER;
2388   f->ts.kind = gfc_c_int_kind;
2389   if (u->ts.kind != gfc_c_int_kind)
2390     {
2391       ts.type = BT_INTEGER;
2392       ts.kind = gfc_c_int_kind;
2393       ts.u.derived = NULL;
2394       ts.u.cl = NULL;
2395       gfc_convert_type (u, &ts, 2);
2396     }
2397
2398   f->value.function.name = gfc_get_string (PREFIX ("fgetc"));
2399 }
2400
2401
2402 void
2403 gfc_resolve_fget (gfc_expr *f, gfc_expr *c ATTRIBUTE_UNUSED)
2404 {
2405   f->ts.type = BT_INTEGER;
2406   f->ts.kind = gfc_c_int_kind;
2407   f->value.function.name = gfc_get_string (PREFIX ("fget"));
2408 }
2409
2410
2411 void
2412 gfc_resolve_fputc (gfc_expr *f, gfc_expr *u, gfc_expr *c ATTRIBUTE_UNUSED)
2413 {
2414   gfc_typespec ts;
2415   gfc_clear_ts (&ts);
2416
2417   f->ts.type = BT_INTEGER;
2418   f->ts.kind = gfc_c_int_kind;
2419   if (u->ts.kind != gfc_c_int_kind)
2420     {
2421       ts.type = BT_INTEGER;
2422       ts.kind = gfc_c_int_kind;
2423       ts.u.derived = NULL;
2424       ts.u.cl = NULL;
2425       gfc_convert_type (u, &ts, 2);
2426     }
2427
2428   f->value.function.name = gfc_get_string (PREFIX ("fputc"));
2429 }
2430
2431
2432 void
2433 gfc_resolve_fput (gfc_expr *f, gfc_expr *c ATTRIBUTE_UNUSED)
2434 {
2435   f->ts.type = BT_INTEGER;
2436   f->ts.kind = gfc_c_int_kind;
2437   f->value.function.name = gfc_get_string (PREFIX ("fput"));
2438 }
2439
2440
2441 void
2442 gfc_resolve_ftell (gfc_expr *f, gfc_expr *u)
2443 {
2444   gfc_typespec ts;
2445   gfc_clear_ts (&ts);
2446
2447   f->ts.type = BT_INTEGER;
2448   f->ts.kind = gfc_index_integer_kind;
2449   if (u->ts.kind != gfc_c_int_kind)
2450     {
2451       ts.type = BT_INTEGER;
2452       ts.kind = gfc_c_int_kind;
2453       ts.u.derived = NULL;
2454       ts.u.cl = NULL;
2455       gfc_convert_type (u, &ts, 2);
2456     }
2457
2458   f->value.function.name = gfc_get_string (PREFIX ("ftell"));
2459 }
2460
2461
2462 void
2463 gfc_resolve_storage_size (gfc_expr *f, gfc_expr *a ATTRIBUTE_UNUSED,
2464                           gfc_expr *kind)
2465 {
2466   f->ts.type = BT_INTEGER;
2467   if (kind)
2468     f->ts.kind = mpz_get_si (kind->value.integer);
2469   else
2470     f->ts.kind = gfc_default_integer_kind;
2471 }
2472
2473
2474 void
2475 gfc_resolve_sum (gfc_expr *f, gfc_expr *array, gfc_expr *dim, gfc_expr *mask)
2476 {
2477   resolve_transformational ("sum", f, array, dim, mask);
2478 }
2479
2480
2481 void
2482 gfc_resolve_symlnk (gfc_expr *f, gfc_expr *p1 ATTRIBUTE_UNUSED,
2483                     gfc_expr *p2 ATTRIBUTE_UNUSED)
2484 {
2485   f->ts.type = BT_INTEGER;
2486   f->ts.kind = gfc_default_integer_kind;
2487   f->value.function.name = gfc_get_string (PREFIX ("symlnk_i%d"), f->ts.kind);
2488 }
2489
2490
2491 /* Resolve the g77 compatibility function SYSTEM.  */
2492
2493 void
2494 gfc_resolve_system (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED)
2495 {
2496   f->ts.type = BT_INTEGER;
2497   f->ts.kind = 4;
2498   f->value.function.name = gfc_get_string (PREFIX ("system"));
2499 }
2500
2501
2502 void
2503 gfc_resolve_tan (gfc_expr *f, gfc_expr *x)
2504 {
2505   f->ts = x->ts;
2506   f->value.function.name
2507     = gfc_get_string ("__tan_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
2508 }
2509
2510
2511 void
2512 gfc_resolve_tanh (gfc_expr *f, gfc_expr *x)
2513 {
2514   f->ts = x->ts;
2515   f->value.function.name
2516     = gfc_get_string ("__tanh_%c%d", gfc_type_letter (x->ts.type), x->ts.kind);
2517 }
2518
2519
2520 void
2521 gfc_resolve_image_index (gfc_expr *f, gfc_expr *array ATTRIBUTE_UNUSED,
2522                          gfc_expr *sub ATTRIBUTE_UNUSED)
2523 {
2524   static char this_image[] = "__image_index";
2525   f->ts.kind = gfc_default_integer_kind;
2526   f->value.function.name = this_image;
2527 }
2528
2529
2530 void
2531 gfc_resolve_this_image (gfc_expr *f, gfc_expr *array, gfc_expr *dim)
2532 {
2533   resolve_bound (f, array, dim, NULL, "__this_image", true);
2534 }
2535
2536
2537 void
2538 gfc_resolve_time (gfc_expr *f)
2539 {
2540   f->ts.type = BT_INTEGER;
2541   f->ts.kind = 4;
2542   f->value.function.name = gfc_get_string (PREFIX ("time_func"));
2543 }
2544
2545
2546 void
2547 gfc_resolve_time8 (gfc_expr *f)
2548 {
2549   f->ts.type = BT_INTEGER;
2550   f->ts.kind = 8;
2551   f->value.function.name = gfc_get_string (PREFIX ("time8_func"));
2552 }
2553
2554
2555 void
2556 gfc_resolve_transfer (gfc_expr *f, gfc_expr *source ATTRIBUTE_UNUSED,
2557                       gfc_expr *mold, gfc_expr *size)
2558 {
2559   /* TODO: Make this do something meaningful.  */
2560   static char transfer0[] = "__transfer0", transfer1[] = "__transfer1";
2561
2562   if (mold->ts.type == BT_CHARACTER
2563         && !mold->ts.u.cl->length
2564         && gfc_is_constant_expr (mold))
2565     {
2566       int len;
2567       if (mold->expr_type == EXPR_CONSTANT)
2568         {
2569           len = mold->value.character.length;
2570           mold->ts.u.cl->length = gfc_get_int_expr (gfc_default_integer_kind,
2571                                                     NULL, len);
2572         }
2573       else
2574         {
2575           gfc_constructor *c = gfc_constructor_first (mold->value.constructor);
2576           len = c->expr->value.character.length;
2577           mold->ts.u.cl->length = gfc_get_int_expr (gfc_default_integer_kind,
2578                                                     NULL, len);
2579         }
2580     }
2581
2582   f->ts = mold->ts;
2583
2584   if (size == NULL && mold->rank == 0)
2585     {
2586       f->rank = 0;
2587       f->value.function.name = transfer0;
2588     }
2589   else
2590     {
2591       f->rank = 1;
2592       f->value.function.name = transfer1;
2593       if (size && gfc_is_constant_expr (size))
2594         {
2595           f->shape = gfc_get_shape (1);
2596           mpz_init_set (f->shape[0], size->value.integer);
2597         }
2598     }
2599 }
2600
2601
2602 void
2603 gfc_resolve_transpose (gfc_expr *f, gfc_expr *matrix)
2604 {
2605
2606   if (matrix->ts.type == BT_CHARACTER && matrix->ref)
2607     gfc_resolve_substring_charlen (matrix);
2608
2609   f->ts = matrix->ts;
2610   f->rank = 2;
2611   if (matrix->shape)
2612     {
2613       f->shape = gfc_get_shape (2);
2614       mpz_init_set (f->shape[0], matrix->shape[1]);
2615       mpz_init_set (f->shape[1], matrix->shape[0]);
2616     }
2617
2618   switch (matrix->ts.kind)
2619     {
2620     case 4:
2621     case 8:
2622     case 10:
2623     case 16:
2624       switch (matrix->ts.type)
2625         {
2626         case BT_REAL:
2627         case BT_COMPLEX:
2628           f->value.function.name
2629             = gfc_get_string (PREFIX ("transpose_%c%d"),
2630                               gfc_type_letter (matrix->ts.type),
2631                               matrix->ts.kind);
2632           break;
2633
2634         case BT_INTEGER:
2635         case BT_LOGICAL:
2636           /* Use the integer routines for real and logical cases.  This
2637              assumes they all have the same alignment requirements.  */
2638           f->value.function.name
2639             = gfc_get_string (PREFIX ("transpose_i%d"), matrix->ts.kind);
2640           break;
2641
2642         default:
2643           if (matrix->ts.type == BT_CHARACTER && matrix->ts.kind == 4)
2644             f->value.function.name = PREFIX ("transpose_char4");
2645           else
2646             f->value.function.name = PREFIX ("transpose");
2647           break;
2648         }
2649       break;
2650
2651     default:
2652       f->value.function.name = (matrix->ts.type == BT_CHARACTER
2653                                 ? PREFIX ("transpose_char")
2654                                 : PREFIX ("transpose"));
2655       break;
2656     }
2657 }
2658
2659
2660 void
2661 gfc_resolve_trim (gfc_expr *f, gfc_expr *string)
2662 {
2663   f->ts.type = BT_CHARACTER;
2664   f->ts.kind = string->ts.kind;
2665   f->value.function.name = gfc_get_string ("__trim_%d", string->ts.kind);
2666 }
2667
2668
2669 void
2670 gfc_resolve_ubound (gfc_expr *f, gfc_expr *array, gfc_expr *dim, gfc_expr *kind)
2671 {
2672   resolve_bound (f, array, dim, kind, "__ubound", false);
2673 }
2674
2675
2676 void
2677 gfc_resolve_ucobound (gfc_expr *f, gfc_expr *array, gfc_expr *dim, gfc_expr *kind)
2678 {
2679   resolve_bound (f, array, dim, kind, "__ucobound", true);
2680 }
2681
2682
2683 /* Resolve the g77 compatibility function UMASK.  */
2684
2685 void
2686 gfc_resolve_umask (gfc_expr *f, gfc_expr *n)
2687 {
2688   f->ts.type = BT_INTEGER;
2689   f->ts.kind = n->ts.kind;
2690   f->value.function.name = gfc_get_string (PREFIX ("umask_i%d"), n->ts.kind);
2691 }
2692
2693
2694 /* Resolve the g77 compatibility function UNLINK.  */
2695
2696 void
2697 gfc_resolve_unlink (gfc_expr *f, gfc_expr *n ATTRIBUTE_UNUSED)
2698 {
2699   f->ts.type = BT_INTEGER;
2700   f->ts.kind = 4;
2701   f->value.function.name = gfc_get_string (PREFIX ("unlink"));
2702 }
2703
2704
2705 void
2706 gfc_resolve_ttynam (gfc_expr *f, gfc_expr *unit)
2707 {
2708   gfc_typespec ts;
2709   gfc_clear_ts (&ts);
2710   
2711   f->ts.type = BT_CHARACTER;
2712   f->ts.kind = gfc_default_character_kind;
2713
2714   if (unit->ts.kind != gfc_c_int_kind)
2715     {
2716       ts.type = BT_INTEGER;
2717       ts.kind = gfc_c_int_kind;
2718       ts.u.derived = NULL;
2719       ts.u.cl = NULL;
2720       gfc_convert_type (unit, &ts, 2);
2721     }
2722
2723   f->value.function.name = gfc_get_string (PREFIX ("ttynam"));
2724 }
2725
2726
2727 void
2728 gfc_resolve_unpack (gfc_expr *f, gfc_expr *vector, gfc_expr *mask,
2729                     gfc_expr *field ATTRIBUTE_UNUSED)
2730 {
2731   if (vector->ts.type == BT_CHARACTER && vector->ref)
2732     gfc_resolve_substring_charlen (vector);
2733
2734   f->ts = vector->ts;
2735   f->rank = mask->rank;
2736   resolve_mask_arg (mask);
2737
2738   if (vector->ts.type == BT_CHARACTER)
2739     {
2740       if (vector->ts.kind == 1)
2741         f->value.function.name
2742           = gfc_get_string (PREFIX ("unpack%d_char"), field->rank > 0 ? 1 : 0);
2743       else
2744         f->value.function.name
2745           = gfc_get_string (PREFIX ("unpack%d_char%d"),
2746                             field->rank > 0 ? 1 : 0, vector->ts.kind);
2747     }
2748   else
2749     f->value.function.name
2750       = gfc_get_string (PREFIX ("unpack%d"), field->rank > 0 ? 1 : 0);
2751 }
2752
2753
2754 void
2755 gfc_resolve_verify (gfc_expr *f, gfc_expr *string,
2756                     gfc_expr *set ATTRIBUTE_UNUSED,
2757                     gfc_expr *back ATTRIBUTE_UNUSED, gfc_expr *kind)
2758 {
2759   f->ts.type = BT_INTEGER;
2760   if (kind)
2761     f->ts.kind = mpz_get_si (kind->value.integer);
2762   else
2763     f->ts.kind = gfc_default_integer_kind;
2764   f->value.function.name = gfc_get_string ("__verify_%d", string->ts.kind);
2765 }
2766
2767
2768 void
2769 gfc_resolve_xor (gfc_expr *f, gfc_expr *i, gfc_expr *j)
2770 {
2771   f->ts.type = i->ts.type;
2772   f->ts.kind = gfc_kind_max (i, j);
2773
2774   if (i->ts.kind != j->ts.kind)
2775     {
2776       if (i->ts.kind == gfc_kind_max (i, j))
2777         gfc_convert_type (j, &i->ts, 2);
2778       else
2779         gfc_convert_type (i, &j->ts, 2);
2780     }
2781
2782   f->value.function.name
2783     = gfc_get_string ("__xor_%c%d", gfc_type_letter (i->ts.type), f->ts.kind);
2784 }
2785
2786
2787 /* Intrinsic subroutine resolution.  */
2788
2789 void
2790 gfc_resolve_alarm_sub (gfc_code *c)
2791 {
2792   const char *name;
2793   gfc_expr *seconds, *handler;
2794   gfc_typespec ts;
2795   gfc_clear_ts (&ts);
2796
2797   seconds = c->ext.actual->expr;
2798   handler = c->ext.actual->next->expr;
2799   ts.type = BT_INTEGER;
2800   ts.kind = gfc_c_int_kind;
2801
2802   /* handler can be either BT_INTEGER or BT_PROCEDURE.
2803      In all cases, the status argument is of default integer kind
2804      (enforced in check.c) so that the function suffix is fixed.  */
2805   if (handler->ts.type == BT_INTEGER)
2806     {
2807       if (handler->ts.kind != gfc_c_int_kind)
2808         gfc_convert_type (handler, &ts, 2);
2809       name = gfc_get_string (PREFIX ("alarm_sub_int_i%d"),
2810                              gfc_default_integer_kind);
2811     }
2812   else
2813     name = gfc_get_string (PREFIX ("alarm_sub_i%d"),
2814                            gfc_default_integer_kind);
2815
2816   if (seconds->ts.kind != gfc_c_int_kind)
2817     gfc_convert_type (seconds, &ts, 2);
2818
2819   c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2820 }
2821
2822 void
2823 gfc_resolve_cpu_time (gfc_code *c)
2824 {
2825   const char *name;
2826   name = gfc_get_string (PREFIX ("cpu_time_%d"), c->ext.actual->expr->ts.kind);
2827   c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2828 }
2829
2830
2831 /* Create a formal arglist based on an actual one and set the INTENTs given.  */
2832
2833 static gfc_formal_arglist*
2834 create_formal_for_intents (gfc_actual_arglist* actual, const sym_intent* ints)
2835 {
2836   gfc_formal_arglist* head;
2837   gfc_formal_arglist* tail;
2838   int i;
2839
2840   if (!actual)
2841     return NULL;
2842
2843   head = tail = gfc_get_formal_arglist ();
2844   for (i = 0; actual; actual = actual->next, tail = tail->next, ++i)
2845     {
2846       gfc_symbol* sym;
2847
2848       sym = gfc_new_symbol ("dummyarg", NULL);
2849       sym->ts = actual->expr->ts;
2850
2851       sym->attr.intent = ints[i];
2852       tail->sym = sym;
2853
2854       if (actual->next)
2855         tail->next = gfc_get_formal_arglist ();
2856     }
2857
2858   return head;
2859 }
2860
2861
2862 void
2863 gfc_resolve_mvbits (gfc_code *c)
2864 {
2865   static const sym_intent INTENTS[] = {INTENT_IN, INTENT_IN, INTENT_IN,
2866                                        INTENT_INOUT, INTENT_IN};
2867
2868   const char *name;
2869   gfc_typespec ts;
2870   gfc_clear_ts (&ts);
2871
2872   /* FROMPOS, LEN and TOPOS are restricted to small values.  As such,
2873      they will be converted so that they fit into a C int.  */
2874   ts.type = BT_INTEGER;
2875   ts.kind = gfc_c_int_kind;
2876   if (c->ext.actual->next->expr->ts.kind != gfc_c_int_kind)
2877     gfc_convert_type (c->ext.actual->next->expr, &ts, 2);
2878   if (c->ext.actual->next->next->expr->ts.kind != gfc_c_int_kind)
2879     gfc_convert_type (c->ext.actual->next->next->expr, &ts, 2);
2880   if (c->ext.actual->next->next->next->next->expr->ts.kind != gfc_c_int_kind)
2881     gfc_convert_type (c->ext.actual->next->next->next->next->expr, &ts, 2);
2882
2883   /* TO and FROM are guaranteed to have the same kind parameter.  */
2884   name = gfc_get_string (PREFIX ("mvbits_i%d"),
2885                          c->ext.actual->expr->ts.kind);
2886   c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2887   /* Mark as elemental subroutine as this does not happen automatically.  */
2888   c->resolved_sym->attr.elemental = 1;
2889
2890   /* Create a dummy formal arglist so the INTENTs are known later for purpose
2891      of creating temporaries.  */
2892   c->resolved_sym->formal = create_formal_for_intents (c->ext.actual, INTENTS);
2893 }
2894
2895
2896 void
2897 gfc_resolve_random_number (gfc_code *c)
2898 {
2899   const char *name;
2900   int kind;
2901
2902   kind = c->ext.actual->expr->ts.kind;
2903   if (c->ext.actual->expr->rank == 0)
2904     name = gfc_get_string (PREFIX ("random_r%d"), kind);
2905   else
2906     name = gfc_get_string (PREFIX ("arandom_r%d"), kind);
2907   
2908   c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2909 }
2910
2911
2912 void
2913 gfc_resolve_random_seed (gfc_code *c)
2914 {
2915   const char *name;
2916
2917   name = gfc_get_string (PREFIX ("random_seed_i%d"), gfc_default_integer_kind);
2918   c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2919 }
2920
2921
2922 void
2923 gfc_resolve_rename_sub (gfc_code *c)
2924 {
2925   const char *name;
2926   int kind;
2927
2928   if (c->ext.actual->next->next->expr != NULL)
2929     kind = c->ext.actual->next->next->expr->ts.kind;
2930   else
2931     kind = gfc_default_integer_kind;
2932
2933   name = gfc_get_string (PREFIX ("rename_i%d_sub"), kind);
2934   c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2935 }
2936
2937
2938 void
2939 gfc_resolve_kill_sub (gfc_code *c)
2940 {
2941   const char *name;
2942   int kind;
2943
2944   if (c->ext.actual->next->next->expr != NULL)
2945     kind = c->ext.actual->next->next->expr->ts.kind;
2946   else
2947     kind = gfc_default_integer_kind;
2948
2949   name = gfc_get_string (PREFIX ("kill_i%d_sub"), kind);
2950   c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2951 }
2952     
2953
2954 void
2955 gfc_resolve_link_sub (gfc_code *c)
2956 {
2957   const char *name;
2958   int kind;
2959
2960   if (c->ext.actual->next->next->expr != NULL)
2961     kind = c->ext.actual->next->next->expr->ts.kind;
2962   else
2963     kind = gfc_default_integer_kind;
2964
2965   name = gfc_get_string (PREFIX ("link_i%d_sub"), kind);
2966   c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2967 }
2968
2969
2970 void
2971 gfc_resolve_symlnk_sub (gfc_code *c)
2972 {
2973   const char *name;
2974   int kind;
2975
2976   if (c->ext.actual->next->next->expr != NULL)
2977     kind = c->ext.actual->next->next->expr->ts.kind;
2978   else
2979     kind = gfc_default_integer_kind;
2980
2981   name = gfc_get_string (PREFIX ("symlnk_i%d_sub"), kind);
2982   c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2983 }
2984
2985
2986 /* G77 compatibility subroutines dtime() and etime().  */
2987
2988 void
2989 gfc_resolve_dtime_sub (gfc_code *c)
2990 {
2991   const char *name;
2992   name = gfc_get_string (PREFIX ("dtime_sub"));
2993   c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
2994 }
2995
2996 void
2997 gfc_resolve_etime_sub (gfc_code *c)
2998 {
2999   const char *name;
3000   name = gfc_get_string (PREFIX ("etime_sub"));
3001   c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3002 }
3003
3004
3005 /* G77 compatibility subroutines itime(), idate(), ltime() and gmtime().  */
3006
3007 void
3008 gfc_resolve_itime (gfc_code *c)
3009 {
3010   c->resolved_sym
3011     = gfc_get_intrinsic_sub_symbol (gfc_get_string (PREFIX ("itime_i%d"),
3012                                                     gfc_default_integer_kind));
3013 }
3014
3015 void
3016 gfc_resolve_idate (gfc_code *c)
3017 {
3018   c->resolved_sym
3019     = gfc_get_intrinsic_sub_symbol (gfc_get_string (PREFIX ("idate_i%d"),
3020                                                     gfc_default_integer_kind));
3021 }
3022
3023 void
3024 gfc_resolve_ltime (gfc_code *c)
3025 {
3026   c->resolved_sym
3027     = gfc_get_intrinsic_sub_symbol (gfc_get_string (PREFIX ("ltime_i%d"),
3028                                                     gfc_default_integer_kind));
3029 }
3030
3031 void
3032 gfc_resolve_gmtime (gfc_code *c)
3033 {
3034   c->resolved_sym
3035     = gfc_get_intrinsic_sub_symbol (gfc_get_string (PREFIX ("gmtime_i%d"),
3036                                                     gfc_default_integer_kind));
3037 }
3038
3039
3040 /* G77 compatibility subroutine second().  */
3041
3042 void
3043 gfc_resolve_second_sub (gfc_code *c)
3044 {
3045   const char *name;
3046   name = gfc_get_string (PREFIX ("second_sub"));
3047   c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3048 }
3049
3050
3051 void
3052 gfc_resolve_sleep_sub (gfc_code *c)
3053 {
3054   const char *name;
3055   int kind;
3056
3057   if (c->ext.actual->expr != NULL)
3058     kind = c->ext.actual->expr->ts.kind;
3059   else
3060     kind = gfc_default_integer_kind;
3061
3062   name = gfc_get_string (PREFIX ("sleep_i%d_sub"), kind);
3063   c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3064 }
3065
3066
3067 /* G77 compatibility function srand().  */
3068
3069 void
3070 gfc_resolve_srand (gfc_code *c)
3071 {
3072   const char *name;
3073   name = gfc_get_string (PREFIX ("srand"));
3074   c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3075 }
3076
3077
3078 /* Resolve the getarg intrinsic subroutine.  */
3079
3080 void
3081 gfc_resolve_getarg (gfc_code *c)
3082 {
3083   const char *name;
3084
3085   if (c->ext.actual->expr->ts.kind != gfc_default_integer_kind)
3086     {
3087       gfc_typespec ts;
3088       gfc_clear_ts (&ts);
3089
3090       ts.type = BT_INTEGER;
3091       ts.kind = gfc_default_integer_kind;
3092
3093       gfc_convert_type (c->ext.actual->expr, &ts, 2);
3094     }
3095
3096   name = gfc_get_string (PREFIX ("getarg_i%d"), gfc_default_integer_kind);
3097   c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3098 }
3099
3100
3101 /* Resolve the getcwd intrinsic subroutine.  */
3102
3103 void
3104 gfc_resolve_getcwd_sub (gfc_code *c)
3105 {
3106   const char *name;
3107   int kind;
3108
3109   if (c->ext.actual->next->expr != NULL)
3110     kind = c->ext.actual->next->expr->ts.kind;
3111   else
3112     kind = gfc_default_integer_kind;
3113
3114   name = gfc_get_string (PREFIX ("getcwd_i%d_sub"), kind);
3115   c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3116 }
3117
3118
3119 /* Resolve the get_command intrinsic subroutine.  */
3120
3121 void
3122 gfc_resolve_get_command (gfc_code *c)
3123 {
3124   const char *name;
3125   int kind;
3126   kind = gfc_default_integer_kind;
3127   name = gfc_get_string (PREFIX ("get_command_i%d"), kind);
3128   c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3129 }
3130
3131
3132 /* Resolve the get_command_argument intrinsic subroutine.  */
3133
3134 void
3135 gfc_resolve_get_command_argument (gfc_code *c)
3136 {
3137   const char *name;
3138   int kind;
3139   kind = gfc_default_integer_kind;
3140   name = gfc_get_string (PREFIX ("get_command_argument_i%d"), kind);
3141   c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3142 }
3143
3144
3145 /* Resolve the get_environment_variable intrinsic subroutine.  */
3146
3147 void
3148 gfc_resolve_get_environment_variable (gfc_code *code)
3149 {
3150   const char *name;
3151   int kind;
3152   kind = gfc_default_integer_kind;
3153   name = gfc_get_string (PREFIX ("get_environment_variable_i%d"), kind);
3154   code->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3155 }
3156
3157
3158 void
3159 gfc_resolve_signal_sub (gfc_code *c)
3160 {
3161   const char *name;
3162   gfc_expr *number, *handler, *status;
3163   gfc_typespec ts;
3164   gfc_clear_ts (&ts);
3165
3166   number = c->ext.actual->expr;
3167   handler = c->ext.actual->next->expr;
3168   status = c->ext.actual->next->next->expr;
3169   ts.type = BT_INTEGER;
3170   ts.kind = gfc_c_int_kind;
3171
3172   /* handler can be either BT_INTEGER or BT_PROCEDURE  */
3173   if (handler->ts.type == BT_INTEGER)
3174     {
3175       if (handler->ts.kind != gfc_c_int_kind)
3176         gfc_convert_type (handler, &ts, 2);
3177       name = gfc_get_string (PREFIX ("signal_sub_int"));
3178     }
3179   else
3180     name = gfc_get_string (PREFIX ("signal_sub"));
3181
3182   if (number->ts.kind != gfc_c_int_kind)
3183     gfc_convert_type (number, &ts, 2);
3184   if (status != NULL && status->ts.kind != gfc_c_int_kind)
3185     gfc_convert_type (status, &ts, 2);
3186
3187   c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3188 }
3189
3190
3191 /* Resolve the SYSTEM intrinsic subroutine.  */
3192
3193 void
3194 gfc_resolve_system_sub (gfc_code *c)
3195 {
3196   const char *name;
3197   name = gfc_get_string (PREFIX ("system_sub"));
3198   c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3199 }
3200
3201
3202 /* Determine if the arguments to SYSTEM_CLOCK are INTEGER(4) or INTEGER(8) */
3203
3204 void
3205 gfc_resolve_system_clock (gfc_code *c)
3206 {
3207   const char *name;
3208   int kind;
3209
3210   if (c->ext.actual->expr != NULL)
3211     kind = c->ext.actual->expr->ts.kind;
3212   else if (c->ext.actual->next->expr != NULL)
3213       kind = c->ext.actual->next->expr->ts.kind;
3214   else if (c->ext.actual->next->next->expr != NULL)
3215       kind = c->ext.actual->next->next->expr->ts.kind;
3216   else
3217     kind = gfc_default_integer_kind;
3218
3219   name = gfc_get_string (PREFIX ("system_clock_%d"), kind);
3220   c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3221 }
3222
3223
3224 /* Resolve the EXECUTE_COMMAND_LINE intrinsic subroutine.  */
3225 void
3226 gfc_resolve_execute_command_line (gfc_code *c)
3227 {
3228   const char *name;
3229   name = gfc_get_string (PREFIX ("execute_command_line_i%d"),
3230                          gfc_default_integer_kind);
3231   c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3232 }
3233
3234
3235 /* Resolve the EXIT intrinsic subroutine.  */
3236
3237 void
3238 gfc_resolve_exit (gfc_code *c)
3239 {
3240   const char *name;
3241   gfc_typespec ts;
3242   gfc_expr *n;
3243   gfc_clear_ts (&ts);
3244
3245   /* The STATUS argument has to be of default kind.  If it is not,
3246      we convert it.  */
3247   ts.type = BT_INTEGER;
3248   ts.kind = gfc_default_integer_kind;
3249   n = c->ext.actual->expr;
3250   if (n != NULL && n->ts.kind != ts.kind)
3251     gfc_convert_type (n, &ts, 2);
3252
3253   name = gfc_get_string (PREFIX ("exit_i%d"), ts.kind);
3254   c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3255 }
3256
3257
3258 /* Resolve the FLUSH intrinsic subroutine.  */
3259
3260 void
3261 gfc_resolve_flush (gfc_code *c)
3262 {
3263   const char *name;
3264   gfc_typespec ts;
3265   gfc_expr *n;
3266   gfc_clear_ts (&ts);
3267
3268   ts.type = BT_INTEGER;
3269   ts.kind = gfc_default_integer_kind;
3270   n = c->ext.actual->expr;
3271   if (n != NULL && n->ts.kind != ts.kind)
3272     gfc_convert_type (n, &ts, 2);
3273
3274   name = gfc_get_string (PREFIX ("flush_i%d"), ts.kind);
3275   c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3276 }
3277
3278
3279 void
3280 gfc_resolve_free (gfc_code *c)
3281 {
3282   gfc_typespec ts;
3283   gfc_expr *n;
3284   gfc_clear_ts (&ts);
3285
3286   ts.type = BT_INTEGER;
3287   ts.kind = gfc_index_integer_kind;
3288   n = c->ext.actual->expr;
3289   if (n->ts.kind != ts.kind)
3290     gfc_convert_type (n, &ts, 2);
3291
3292   c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("free"));
3293 }
3294
3295
3296 void
3297 gfc_resolve_ctime_sub (gfc_code *c)
3298 {
3299   gfc_typespec ts;
3300   gfc_clear_ts (&ts);
3301   
3302   /* ctime TIME argument is a INTEGER(KIND=8), says the doc */
3303   if (c->ext.actual->expr->ts.kind != 8)
3304     {
3305       ts.type = BT_INTEGER;
3306       ts.kind = 8;
3307       ts.u.derived = NULL;
3308       ts.u.cl = NULL;
3309       gfc_convert_type (c->ext.actual->expr, &ts, 2);
3310     }
3311
3312   c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("ctime_sub"));
3313 }
3314
3315
3316 void
3317 gfc_resolve_fdate_sub (gfc_code *c)
3318 {
3319   c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("fdate_sub"));
3320 }
3321
3322
3323 void
3324 gfc_resolve_gerror (gfc_code *c)
3325 {
3326   c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("gerror"));
3327 }
3328
3329
3330 void
3331 gfc_resolve_getlog (gfc_code *c)
3332 {
3333   c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("getlog"));
3334 }
3335
3336
3337 void
3338 gfc_resolve_hostnm_sub (gfc_code *c)
3339 {
3340   const char *name;
3341   int kind;
3342
3343   if (c->ext.actual->next->expr != NULL)
3344     kind = c->ext.actual->next->expr->ts.kind;
3345   else
3346     kind = gfc_default_integer_kind;
3347
3348   name = gfc_get_string (PREFIX ("hostnm_i%d_sub"), kind);
3349   c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3350 }
3351
3352
3353 void
3354 gfc_resolve_perror (gfc_code *c)
3355 {
3356   c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("perror_sub"));
3357 }
3358
3359 /* Resolve the STAT and FSTAT intrinsic subroutines.  */
3360
3361 void
3362 gfc_resolve_stat_sub (gfc_code *c)
3363 {
3364   const char *name;
3365   name = gfc_get_string (PREFIX ("stat_i%d_sub"), gfc_default_integer_kind);
3366   c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3367 }
3368
3369
3370 void
3371 gfc_resolve_lstat_sub (gfc_code *c)
3372 {
3373   const char *name;
3374   name = gfc_get_string (PREFIX ("lstat_i%d_sub"), gfc_default_integer_kind);
3375   c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3376 }
3377
3378
3379 void
3380 gfc_resolve_fstat_sub (gfc_code *c)
3381 {
3382   const char *name;
3383   gfc_expr *u;
3384   gfc_typespec *ts;
3385
3386   u = c->ext.actual->expr;
3387   ts = &c->ext.actual->next->expr->ts;
3388   if (u->ts.kind != ts->kind)
3389     gfc_convert_type (u, ts, 2);
3390   name = gfc_get_string (PREFIX ("fstat_i%d_sub"), ts->kind);
3391   c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3392 }
3393
3394
3395 void
3396 gfc_resolve_fgetc_sub (gfc_code *c)
3397 {
3398   const char *name;
3399   gfc_typespec ts;
3400   gfc_expr *u, *st;
3401   gfc_clear_ts (&ts);
3402
3403   u = c->ext.actual->expr;
3404   st = c->ext.actual->next->next->expr;
3405
3406   if (u->ts.kind != gfc_c_int_kind)
3407     {
3408       ts.type = BT_INTEGER;
3409       ts.kind = gfc_c_int_kind;
3410       ts.u.derived = NULL;
3411       ts.u.cl = NULL;
3412       gfc_convert_type (u, &ts, 2);
3413     }
3414
3415   if (st != NULL)
3416     name = gfc_get_string (PREFIX ("fgetc_i%d_sub"), st->ts.kind);
3417   else
3418     name = gfc_get_string (PREFIX ("fgetc_i%d_sub"), gfc_default_integer_kind);
3419
3420   c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3421 }
3422
3423
3424 void
3425 gfc_resolve_fget_sub (gfc_code *c)
3426 {
3427   const char *name;
3428   gfc_expr *st;
3429
3430   st = c->ext.actual->next->expr;
3431   if (st != NULL)
3432     name = gfc_get_string (PREFIX ("fget_i%d_sub"), st->ts.kind);
3433   else
3434     name = gfc_get_string (PREFIX ("fget_i%d_sub"), gfc_default_integer_kind);
3435
3436   c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3437 }
3438
3439
3440 void
3441 gfc_resolve_fputc_sub (gfc_code *c)
3442 {
3443   const char *name;
3444   gfc_typespec ts;
3445   gfc_expr *u, *st;
3446   gfc_clear_ts (&ts);
3447
3448   u = c->ext.actual->expr;
3449   st = c->ext.actual->next->next->expr;
3450
3451   if (u->ts.kind != gfc_c_int_kind)
3452     {
3453       ts.type = BT_INTEGER;
3454       ts.kind = gfc_c_int_kind;
3455       ts.u.derived = NULL;
3456       ts.u.cl = NULL;
3457       gfc_convert_type (u, &ts, 2);
3458     }
3459
3460   if (st != NULL)
3461     name = gfc_get_string (PREFIX ("fputc_i%d_sub"), st->ts.kind);
3462   else
3463     name = gfc_get_string (PREFIX ("fputc_i%d_sub"), gfc_default_integer_kind);
3464
3465   c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3466 }
3467
3468
3469 void
3470 gfc_resolve_fput_sub (gfc_code *c)
3471 {
3472   const char *name;
3473   gfc_expr *st;
3474
3475   st = c->ext.actual->next->expr;
3476   if (st != NULL)
3477     name = gfc_get_string (PREFIX ("fput_i%d_sub"), st->ts.kind);
3478   else
3479     name = gfc_get_string (PREFIX ("fput_i%d_sub"), gfc_default_integer_kind);
3480
3481   c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3482 }
3483
3484
3485 void 
3486 gfc_resolve_fseek_sub (gfc_code *c)
3487 {
3488   gfc_expr *unit;
3489   gfc_expr *offset;
3490   gfc_expr *whence;
3491   gfc_typespec ts;
3492   gfc_clear_ts (&ts);
3493
3494   unit   = c->ext.actual->expr;
3495   offset = c->ext.actual->next->expr;
3496   whence = c->ext.actual->next->next->expr;
3497
3498   if (unit->ts.kind != gfc_c_int_kind)
3499     {
3500       ts.type = BT_INTEGER;
3501       ts.kind = gfc_c_int_kind;
3502       ts.u.derived = NULL;
3503       ts.u.cl = NULL;
3504       gfc_convert_type (unit, &ts, 2);
3505     }
3506
3507   if (offset->ts.kind != gfc_intio_kind)
3508     {
3509       ts.type = BT_INTEGER;
3510       ts.kind = gfc_intio_kind;
3511       ts.u.derived = NULL;
3512       ts.u.cl = NULL;
3513       gfc_convert_type (offset, &ts, 2);
3514     }
3515
3516   if (whence->ts.kind != gfc_c_int_kind)
3517     {
3518       ts.type = BT_INTEGER;
3519       ts.kind = gfc_c_int_kind;
3520       ts.u.derived = NULL;
3521       ts.u.cl = NULL;
3522       gfc_convert_type (whence, &ts, 2);
3523     }
3524
3525   c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("fseek_sub"));
3526 }
3527
3528 void
3529 gfc_resolve_ftell_sub (gfc_code *c)
3530 {
3531   const char *name;
3532   gfc_expr *unit;
3533   gfc_expr *offset;
3534   gfc_typespec ts;
3535   gfc_clear_ts (&ts);
3536
3537   unit = c->ext.actual->expr;
3538   offset = c->ext.actual->next->expr;
3539
3540   if (unit->ts.kind != gfc_c_int_kind)
3541     {
3542       ts.type = BT_INTEGER;
3543       ts.kind = gfc_c_int_kind;
3544       ts.u.derived = NULL;
3545       ts.u.cl = NULL;
3546       gfc_convert_type (unit, &ts, 2);
3547     }
3548
3549   name = gfc_get_string (PREFIX ("ftell_i%d_sub"), offset->ts.kind);
3550   c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3551 }
3552
3553
3554 void
3555 gfc_resolve_ttynam_sub (gfc_code *c)
3556 {
3557   gfc_typespec ts;
3558   gfc_clear_ts (&ts);
3559   
3560   if (c->ext.actual->expr->ts.kind != gfc_c_int_kind)
3561     {
3562       ts.type = BT_INTEGER;
3563       ts.kind = gfc_c_int_kind;
3564       ts.u.derived = NULL;
3565       ts.u.cl = NULL;
3566       gfc_convert_type (c->ext.actual->expr, &ts, 2);
3567     }
3568
3569   c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("ttynam_sub"));
3570 }
3571
3572
3573 /* Resolve the UMASK intrinsic subroutine.  */
3574
3575 void
3576 gfc_resolve_umask_sub (gfc_code *c)
3577 {
3578   const char *name;
3579   int kind;
3580
3581   if (c->ext.actual->next->expr != NULL)
3582     kind = c->ext.actual->next->expr->ts.kind;
3583   else
3584     kind = gfc_default_integer_kind;
3585
3586   name = gfc_get_string (PREFIX ("umask_i%d_sub"), kind);
3587   c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3588 }
3589
3590 /* Resolve the UNLINK intrinsic subroutine.  */
3591
3592 void
3593 gfc_resolve_unlink_sub (gfc_code *c)
3594 {
3595   const char *name;
3596   int kind;
3597
3598   if (c->ext.actual->next->expr != NULL)
3599     kind = c->ext.actual->next->expr->ts.kind;
3600   else
3601     kind = gfc_default_integer_kind;
3602
3603   name = gfc_get_string (PREFIX ("unlink_i%d_sub"), kind);
3604   c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
3605 }