LCOV - code coverage report
Current view: top level - gcc/fortran - module.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 93.4 % 4072 3803
Test Date: 2026-09-12 16:25:28 Functions: 99.3 % 153 152
Legend: Lines:     hit not hit

            Line data    Source code
       1              : /* Handle modules, which amounts to loading and saving symbols and
       2              :    their attendant structures.
       3              :    Copyright (C) 2000-2026 Free Software Foundation, Inc.
       4              :    Contributed by Andy Vaught
       5              : 
       6              : This file is part of GCC.
       7              : 
       8              : GCC is free software; you can redistribute it and/or modify it under
       9              : the terms of the GNU General Public License as published by the Free
      10              : Software Foundation; either version 3, or (at your option) any later
      11              : version.
      12              : 
      13              : GCC is distributed in the hope that it will be useful, but WITHOUT ANY
      14              : WARRANTY; without even the implied warranty of MERCHANTABILITY or
      15              : FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
      16              : for more details.
      17              : 
      18              : You should have received a copy of the GNU General Public License
      19              : along with GCC; see the file COPYING3.  If not see
      20              : <http://www.gnu.org/licenses/>.  */
      21              : 
      22              : /* The syntax of gfortran modules resembles that of lisp lists, i.e. a
      23              :    sequence of atoms, which can be left or right parenthesis, names,
      24              :    integers or strings.  Parenthesis are always matched which allows
      25              :    us to skip over sections at high speed without having to know
      26              :    anything about the internal structure of the lists.  A "name" is
      27              :    usually a fortran 95 identifier, but can also start with '@' in
      28              :    order to reference a hidden symbol.
      29              : 
      30              :    The first line of a module is an informational message about what
      31              :    created the module, the file it came from and when it was created.
      32              :    The second line is a warning for people not to edit the module.
      33              :    The rest of the module looks like:
      34              : 
      35              :    ( ( <Interface info for UPLUS> )
      36              :      ( <Interface info for UMINUS> )
      37              :      ...
      38              :    )
      39              :    ( ( <name of operator interface> <module of op interface> <i/f1> ... )
      40              :      ...
      41              :    )
      42              :    ( ( <name of generic interface> <module of generic interface> <i/f1> ... )
      43              :      ...
      44              :    )
      45              :    ( ( <common name> <symbol> <saved flag>)
      46              :      ...
      47              :    )
      48              : 
      49              :    ( equivalence list )
      50              : 
      51              :    ( <Symbol Number (in no particular order)>
      52              :      <True name of symbol>
      53              :      <Module name of symbol>
      54              :      ( <symbol information> )
      55              :      ...
      56              :    )
      57              :    ( <Symtree name>
      58              :      <Ambiguous flag>
      59              :      <Symbol number>
      60              :      ...
      61              :    )
      62              : 
      63              :    In general, symbols refer to other symbols by their symbol number,
      64              :    which are zero based.  Symbols are written to the module in no
      65              :    particular order.  */
      66              : 
      67              : #include "config.h"
      68              : #include "system.h"
      69              : #include "coretypes.h"
      70              : #include "options.h"
      71              : #include "tree.h"
      72              : #include "gfortran.h"
      73              : #include "stringpool.h"
      74              : #include "arith.h"
      75              : #include "match.h"
      76              : #include "parse.h" /* FIXME */
      77              : #include "constructor.h"
      78              : #include "cpp.h"
      79              : #include "diagnostic-core.h"
      80              : #include "scanner.h"
      81              : #include <zlib.h>
      82              : 
      83              : #define MODULE_EXTENSION ".mod"
      84              : #define SUBMODULE_EXTENSION ".smod"
      85              : 
      86              : /* Don't put any single quote (') in MOD_VERSION, if you want it to be
      87              :    recognized.  */
      88              : #define MOD_VERSION "16"
      89              : #define MOD_VERSION_NUMERIC 16
      90              : /* Older mod versions we can still parse.  */
      91              : #define COMPAT_MOD_VERSIONS { "15" }
      92              : 
      93              : 
      94              : /* Structure that describes a position within a module file.  */
      95              : 
      96              : typedef struct
      97              : {
      98              :   int column, line;
      99              :   long pos;
     100              : }
     101              : module_locus;
     102              : 
     103              : /* Structure for list of symbols of intrinsic modules.  */
     104              : typedef struct
     105              : {
     106              :   int id;
     107              :   const char *name;
     108              :   int value;
     109              :   int standard;
     110              : }
     111              : intmod_sym;
     112              : 
     113              : 
     114              : typedef enum
     115              : {
     116              :   P_UNKNOWN = 0, P_OTHER, P_NAMESPACE, P_COMPONENT, P_SYMBOL
     117              : }
     118              : pointer_t;
     119              : 
     120              : /* The fixup structure lists pointers to pointers that have to
     121              :    be updated when a pointer value becomes known.  */
     122              : 
     123              : typedef struct fixup_t
     124              : {
     125              :   void **pointer;
     126              :   struct fixup_t *next;
     127              : }
     128              : fixup_t;
     129              : 
     130              : 
     131              : /* Structure for holding extra info needed for pointers being read.  */
     132              : 
     133              : enum gfc_rsym_state
     134              : {
     135              :   UNUSED,
     136              :   NEEDED,
     137              :   USED
     138              : };
     139              : 
     140              : enum gfc_wsym_state
     141              : {
     142              :   UNREFERENCED = 0,
     143              :   NEEDS_WRITE,
     144              :   WRITTEN
     145              : };
     146              : 
     147              : typedef struct pointer_info
     148              : {
     149              :   BBT_HEADER (pointer_info);
     150              :   HOST_WIDE_INT integer;
     151              :   pointer_t type;
     152              : 
     153              :   /* The first component of each member of the union is the pointer
     154              :      being stored.  */
     155              : 
     156              :   fixup_t *fixup;
     157              : 
     158              :   union
     159              :   {
     160              :     void *pointer;      /* Member for doing pointer searches.  */
     161              : 
     162              :     struct
     163              :     {
     164              :       gfc_symbol *sym;
     165              :       char *true_name, *module, *binding_label;
     166              :       fixup_t *stfixup;
     167              :       gfc_symtree *symtree;
     168              :       enum gfc_rsym_state state;
     169              :       int ns, referenced, renamed;
     170              :       module_locus where;
     171              :     }
     172              :     rsym;
     173              : 
     174              :     struct
     175              :     {
     176              :       gfc_symbol *sym;
     177              :       enum gfc_wsym_state state;
     178              :     }
     179              :     wsym;
     180              :   }
     181              :   u;
     182              : 
     183              : }
     184              : pointer_info;
     185              : 
     186              : #define gfc_get_pointer_info() XCNEW (pointer_info)
     187              : 
     188              : 
     189              : /* Local variables */
     190              : 
     191              : /* The gzFile for the module we're reading or writing.  */
     192              : static gzFile module_fp;
     193              : 
     194              : /* Fully qualified module path */
     195              : static char *module_fullpath = NULL;
     196              : 
     197              : /* The name of the module we're reading (USE'ing) or writing.  */
     198              : static const char *module_name;
     199              : /* The name of the .smod file that the submodule will write to.  */
     200              : static const char *submodule_name;
     201              : 
     202              : /* The list of use statements to apply to the current namespace
     203              :    before parsing the non-use statements.  */
     204              : static gfc_use_list *module_list;
     205              : /* The end of the MODULE_LIST list above at the time the recognition
     206              :    of the current statement started.  */
     207              : static gfc_use_list **old_module_list_tail;
     208              : 
     209              : /* If we're reading an intrinsic module, this is its ID.  */
     210              : static intmod_id current_intmod;
     211              : 
     212              : /* Content of module.  */
     213              : static char* module_content;
     214              : 
     215              : static long module_pos;
     216              : static int module_line, module_column, only_flag;
     217              : static int prev_module_line, prev_module_column;
     218              : 
     219              : static enum
     220              : { IO_INPUT, IO_OUTPUT }
     221              : iomode;
     222              : 
     223              : static gfc_use_rename *gfc_rename_list;
     224              : static pointer_info *pi_root;
     225              : static int symbol_number;       /* Counter for assigning symbol numbers */
     226              : 
     227              : /* Tells mio_expr_ref to make symbols for unused equivalence members.  */
     228              : static bool in_load_equiv;
     229              : 
     230              : 
     231              : 
     232              : /*****************************************************************/
     233              : 
     234              : /* Pointer/integer conversion.  Pointers between structures are stored
     235              :    as integers in the module file.  The next couple of subroutines
     236              :    handle this translation for reading and writing.  */
     237              : 
     238              : /* Recursively free the tree of pointer structures.  */
     239              : 
     240              : static void
     241      4338013 : free_pi_tree (pointer_info *p)
     242              : {
     243      4338013 :   if (p == NULL)
     244              :     return;
     245              : 
     246      2156983 :   if (p->fixup != NULL)
     247            0 :     gfc_internal_error ("free_pi_tree(): Unresolved fixup");
     248              : 
     249      2156983 :   free_pi_tree (p->left);
     250      2156983 :   free_pi_tree (p->right);
     251              : 
     252      2156983 :   if (iomode == IO_INPUT)
     253              :     {
     254      1736009 :       XDELETEVEC (p->u.rsym.true_name);
     255      1736009 :       XDELETEVEC (p->u.rsym.module);
     256      1736009 :       XDELETEVEC (p->u.rsym.binding_label);
     257              :     }
     258              : 
     259      2156983 :   free (p);
     260              : }
     261              : 
     262              : 
     263              : /* Compare pointers when searching by pointer.  Used when writing a
     264              :    module.  */
     265              : 
     266              : static int
     267      2443792 : compare_pointers (void *_sn1, void *_sn2)
     268              : {
     269      2443792 :   pointer_info *sn1, *sn2;
     270              : 
     271      2443792 :   sn1 = (pointer_info *) _sn1;
     272      2443792 :   sn2 = (pointer_info *) _sn2;
     273              : 
     274      2443792 :   if (sn1->u.pointer < sn2->u.pointer)
     275              :     return -1;
     276      1439113 :   if (sn1->u.pointer > sn2->u.pointer)
     277      1439113 :     return 1;
     278              : 
     279              :   return 0;
     280              : }
     281              : 
     282              : 
     283              : /* Compare integers when searching by integer.  Used when reading a
     284              :    module.  */
     285              : 
     286              : static int
     287     81503408 : compare_integers (void *_sn1, void *_sn2)
     288              : {
     289     81503408 :   pointer_info *sn1, *sn2;
     290              : 
     291     81503408 :   sn1 = (pointer_info *) _sn1;
     292     81503408 :   sn2 = (pointer_info *) _sn2;
     293              : 
     294     13385024 :   if (sn1->integer < sn2->integer)
     295              :     return -1;
     296     37717157 :   if (sn1->integer > sn2->integer)
     297      9094223 :     return 1;
     298              : 
     299              :   return 0;
     300              : }
     301              : 
     302              : 
     303              : /* Initialize the pointer_info tree.  */
     304              : 
     305              : static void
     306        24047 : init_pi_tree (void)
     307              : {
     308        24047 :   compare_fn compare;
     309        24047 :   pointer_info *p;
     310              : 
     311        24047 :   pi_root = NULL;
     312        24047 :   compare = (iomode == IO_INPUT) ? compare_integers : compare_pointers;
     313              : 
     314              :   /* Pointer 0 is the NULL pointer.  */
     315        24047 :   p = gfc_get_pointer_info ();
     316        24047 :   p->u.pointer = NULL;
     317        24047 :   p->integer = 0;
     318        24047 :   p->type = P_OTHER;
     319              : 
     320        24047 :   gfc_insert_bbt (&pi_root, p, compare);
     321              : 
     322              :   /* Pointer 1 is the current namespace.  */
     323        24047 :   p = gfc_get_pointer_info ();
     324        24047 :   p->u.pointer = gfc_current_ns;
     325        24047 :   p->integer = 1;
     326        24047 :   p->type = P_NAMESPACE;
     327              : 
     328        24047 :   gfc_insert_bbt (&pi_root, p, compare);
     329              : 
     330        24047 :   symbol_number = 2;
     331        24047 : }
     332              : 
     333              : 
     334              : /* During module writing, call here with a pointer to something,
     335              :    returning the pointer_info node.  */
     336              : 
     337              : static pointer_info *
     338      2051788 : find_pointer (void *gp)
     339              : {
     340      2051788 :   pointer_info *p;
     341              : 
     342      2051788 :   p = pi_root;
     343     10811732 :   while (p != NULL)
     344              :     {
     345     10411024 :       if (p->u.pointer == gp)
     346              :         break;
     347      8759944 :       p = (gp < p->u.pointer) ? p->left : p->right;
     348              :     }
     349              : 
     350      2051788 :   return p;
     351              : }
     352              : 
     353              : 
     354              : /* Given a pointer while writing, returns the pointer_info tree node,
     355              :    creating it if it doesn't exist.  */
     356              : 
     357              : static pointer_info *
     358      1922484 : get_pointer (void *gp)
     359              : {
     360      1922484 :   pointer_info *p;
     361              : 
     362      1922484 :   p = find_pointer (gp);
     363      1922484 :   if (p != NULL)
     364              :     return p;
     365              : 
     366              :   /* Pointer doesn't have an integer.  Give it one.  */
     367       400708 :   p = gfc_get_pointer_info ();
     368              : 
     369       400708 :   p->u.pointer = gp;
     370       400708 :   p->integer = symbol_number++;
     371              : 
     372       400708 :   gfc_insert_bbt (&pi_root, p, compare_pointers);
     373              : 
     374       400708 :   return p;
     375              : }
     376              : 
     377              : 
     378              : /* Given an integer during reading, find it in the pointer_info tree,
     379              :    creating the node if not found.  */
     380              : 
     381              : static pointer_info *
     382      8955167 : get_integer (HOST_WIDE_INT integer)
     383              : {
     384      8955167 :   pointer_info *p, t;
     385      8955167 :   int c;
     386              : 
     387      8955167 :   t.integer = integer;
     388              : 
     389      8955167 :   p = pi_root;
     390     69826565 :   while (p != NULL)
     391              :     {
     392     68118384 :       c = compare_integers (&t, p);
     393              :       if (c == 0)
     394              :         break;
     395              : 
     396     60871398 :       p = (c < 0) ? p->left : p->right;
     397              :     }
     398              : 
     399      8955167 :   if (p != NULL)
     400              :     return p;
     401              : 
     402      1708181 :   p = gfc_get_pointer_info ();
     403      1708181 :   p->integer = integer;
     404      1708181 :   p->u.pointer = NULL;
     405              : 
     406      1708181 :   gfc_insert_bbt (&pi_root, p, compare_integers);
     407              : 
     408      1708181 :   return p;
     409              : }
     410              : 
     411              : 
     412              : /* Resolve any fixups using a known pointer.  */
     413              : 
     414              : static void
     415      1751647 : resolve_fixups (fixup_t *f, void *gp)
     416              : {
     417      1751647 :   fixup_t *next;
     418              : 
     419      2643783 :   for (; f; f = next)
     420              :     {
     421       892136 :       next = f->next;
     422       892136 :       *(f->pointer) = gp;
     423       892136 :       free (f);
     424              :     }
     425      1751647 : }
     426              : 
     427              : 
     428              : /* Convert a string such that it starts with a lower-case character. Used
     429              :    to convert the symtree name of a derived-type to the symbol name or to
     430              :    the name of the associated generic function.  */
     431              : 
     432              : const char *
     433      1099668 : gfc_dt_lower_string (const char *name)
     434              : {
     435      1099668 :   if (name[0] != (char) TOLOWER ((unsigned char) name[0]))
     436        64806 :     return gfc_get_string ("%c%s", (char) TOLOWER ((unsigned char) name[0]),
     437        64806 :                            &name[1]);
     438      1034862 :   return gfc_get_string ("%s", name);
     439              : }
     440              : 
     441              : 
     442              : /* Convert a string such that it starts with an upper-case character. Used to
     443              :    return the symtree-name for a derived type; the symbol name itself and the
     444              :    symtree/symbol name of the associated generic function start with a lower-
     445              :    case character.  */
     446              : 
     447              : const char *
     448      1533730 : gfc_dt_upper_string (const char *name)
     449              : {
     450      1533730 :   if (name[0] != (char) TOUPPER ((unsigned char) name[0]))
     451      1507850 :     return gfc_get_string ("%c%s", (char) TOUPPER ((unsigned char) name[0]),
     452      1507850 :                            &name[1]);
     453        25880 :   return gfc_get_string ("%s", name);
     454              : }
     455              : 
     456              : /* Call here during module reading when we know what pointer to
     457              :    associate with an integer.  Any fixups that exist are resolved at
     458              :    this time.  */
     459              : 
     460              : static void
     461      1068798 : associate_integer_pointer (pointer_info *p, void *gp)
     462              : {
     463      1068798 :   if (p->u.pointer != NULL)
     464            0 :     gfc_internal_error ("associate_integer_pointer(): Already associated");
     465              : 
     466      1068798 :   p->u.pointer = gp;
     467              : 
     468      1068798 :   resolve_fixups (p->fixup, gp);
     469              : 
     470      1068798 :   p->fixup = NULL;
     471      1068798 : }
     472              : 
     473              : 
     474              : /* During module reading, given an integer and a pointer to a pointer,
     475              :    either store the pointer from an already-known value or create a
     476              :    fixup structure in order to store things later.  Returns zero if
     477              :    the reference has been actually stored, or nonzero if the reference
     478              :    must be fixed later (i.e., associate_integer_pointer must be called
     479              :    sometime later.  Returns the pointer_info structure.  */
     480              : 
     481              : static pointer_info *
     482      5594003 : add_fixup (HOST_WIDE_INT integer, void *gp)
     483              : {
     484      5594003 :   pointer_info *p;
     485      5594003 :   fixup_t *f;
     486      5594003 :   char **cp;
     487              : 
     488      5594003 :   p = get_integer (integer);
     489              : 
     490      5594003 :   if (p->integer == 0 || p->u.pointer != NULL)
     491              :     {
     492      4713627 :       cp = (char **) gp;
     493      4713627 :       *cp = (char *) p->u.pointer;
     494              :     }
     495              :   else
     496              :     {
     497       880376 :       f = XCNEW (fixup_t);
     498              : 
     499       880376 :       f->next = p->fixup;
     500       880376 :       p->fixup = f;
     501              : 
     502       880376 :       f->pointer = (void **) gp;
     503              :     }
     504              : 
     505      5594003 :   return p;
     506              : }
     507              : 
     508              : 
     509              : /*****************************************************************/
     510              : 
     511              : /* Parser related subroutines */
     512              : 
     513              : /* Free the rename list left behind by a USE statement.  */
     514              : 
     515              : static void
     516        93594 : free_rename (gfc_use_rename *list)
     517              : {
     518        93594 :   gfc_use_rename *next;
     519              : 
     520       104364 :   for (; list; list = next)
     521              :     {
     522        10770 :       next = list->next;
     523        10770 :       free (list);
     524              :     }
     525            0 : }
     526              : 
     527              : 
     528              : /* Match a USE statement.  */
     529              : 
     530              : match
     531        24481 : gfc_match_use (void)
     532              : {
     533        24481 :   char name[GFC_MAX_SYMBOL_LEN + 1], module_nature[GFC_MAX_SYMBOL_LEN + 1];
     534        24481 :   gfc_use_rename *tail = NULL, *new_use;
     535        24481 :   interface_type type, type2;
     536        24481 :   gfc_intrinsic_op op;
     537        24481 :   match m;
     538        24481 :   gfc_use_list *use_list;
     539        24481 :   gfc_symtree *st;
     540        24481 :   locus loc;
     541              : 
     542        24481 :   use_list = gfc_get_use_list ();
     543              : 
     544        24481 :   if (gfc_match (" , ") == MATCH_YES)
     545              :     {
     546         3985 :       if ((m = gfc_match (" %n ::", module_nature)) == MATCH_YES)
     547              :         {
     548         3983 :           if (!gfc_notify_std (GFC_STD_F2003, "module "
     549              :                                "nature in USE statement at %C"))
     550            0 :             goto cleanup;
     551              : 
     552         3983 :           if (strcmp (module_nature, "intrinsic") == 0)
     553         3969 :             use_list->intrinsic = true;
     554              :           else
     555              :             {
     556           14 :               if (strcmp (module_nature, "non_intrinsic") == 0)
     557           13 :                 use_list->non_intrinsic = true;
     558              :               else
     559              :                 {
     560            1 :                   gfc_error ("Module nature in USE statement at %C shall "
     561              :                              "be either INTRINSIC or NON_INTRINSIC");
     562            1 :                   goto cleanup;
     563              :                 }
     564              :             }
     565              :         }
     566              :       else
     567              :         {
     568              :           /* Help output a better error message than "Unclassifiable
     569              :              statement".  */
     570            2 :           gfc_match (" %n", module_nature);
     571            2 :           if (strcmp (module_nature, "intrinsic") == 0
     572            1 :               || strcmp (module_nature, "non_intrinsic") == 0)
     573            2 :             gfc_error ("\"::\" was expected after module nature at %C "
     574              :                        "but was not found");
     575            2 :           free (use_list);
     576            2 :           return m;
     577              :         }
     578              :     }
     579              :   else
     580              :     {
     581        20496 :       m = gfc_match (" ::");
     582        20828 :       if (m == MATCH_YES &&
     583          332 :           !gfc_notify_std(GFC_STD_F2003, "\"USE :: module\" at %C"))
     584            0 :         goto cleanup;
     585              : 
     586        20496 :       if (m != MATCH_YES)
     587              :         {
     588        20164 :           m = gfc_match ("% ");
     589        20164 :           if (m != MATCH_YES)
     590              :             {
     591           17 :               free (use_list);
     592           17 :               return m;
     593              :             }
     594              :         }
     595              :     }
     596              : 
     597        24461 :   use_list->where = gfc_current_locus;
     598              : 
     599        24461 :   m = gfc_match_name (name);
     600        24461 :   if (m != MATCH_YES)
     601              :     {
     602           12 :       free (use_list);
     603           12 :       return m;
     604              :     }
     605              : 
     606        24449 :   use_list->module_name = gfc_get_string ("%s", name);
     607              : 
     608        24449 :   if (gfc_match_eos () == MATCH_YES)
     609        15167 :     goto done;
     610              : 
     611         9282 :   if (gfc_match_char (',') != MATCH_YES)
     612            0 :     goto syntax;
     613              : 
     614         9282 :   if (gfc_match (" only :") == MATCH_YES)
     615         9035 :     use_list->only_flag = true;
     616              : 
     617         9282 :   if (gfc_match_eos () == MATCH_YES)
     618            1 :     goto done;
     619              : 
     620        13882 :   for (;;)
     621              :     {
     622              :       /* Get a new rename struct and add it to the rename list.  */
     623        13882 :       new_use = gfc_get_use_rename ();
     624        13882 :       new_use->where = gfc_current_locus;
     625        13882 :       new_use->found = 0;
     626              : 
     627        13882 :       if (use_list->rename == NULL)
     628         9281 :         use_list->rename = new_use;
     629              :       else
     630         4601 :         tail->next = new_use;
     631        13882 :       tail = new_use;
     632              : 
     633              :       /* See what kind of interface we're dealing with.  Assume it is
     634              :          not an operator.  */
     635        13882 :       new_use->op = INTRINSIC_NONE;
     636        13882 :       if (gfc_match_generic_spec (&type, name, &op) == MATCH_ERROR)
     637            0 :         goto cleanup;
     638              : 
     639        13882 :       switch (type)
     640              :         {
     641            1 :         case INTERFACE_NAMELESS:
     642            1 :           gfc_error ("Missing generic specification in USE statement at %C");
     643            1 :           goto cleanup;
     644              : 
     645        13764 :         case INTERFACE_USER_OP:
     646        13764 :         case INTERFACE_GENERIC:
     647        13764 :         case INTERFACE_DTIO:
     648        13764 :           loc = gfc_current_locus;
     649              : 
     650        13764 :           m = gfc_match (" =>");
     651              : 
     652           80 :           if (type == INTERFACE_USER_OP && m == MATCH_YES
     653        13810 :               && (!gfc_notify_std(GFC_STD_F2003, "Renaming "
     654              :                                   "operators in USE statements at %C")))
     655            2 :             goto cleanup;
     656              : 
     657        13762 :           if (type == INTERFACE_USER_OP)
     658           78 :             new_use->op = INTRINSIC_USER;
     659              : 
     660        13762 :           if (use_list->only_flag)
     661              :             {
     662        13412 :               if (m != MATCH_YES)
     663        13053 :                 strcpy (new_use->use_name, name);
     664              :               else
     665              :                 {
     666          359 :                   strcpy (new_use->local_name, name);
     667          359 :                   m = gfc_match_generic_spec (&type2, new_use->use_name, &op);
     668          359 :                   if (type != type2)
     669            1 :                     goto syntax;
     670          358 :                   if (m == MATCH_NO)
     671            0 :                     goto syntax;
     672          358 :                   if (m == MATCH_ERROR)
     673            0 :                     goto cleanup;
     674              :                 }
     675              :             }
     676              :           else
     677              :             {
     678          350 :               if (m != MATCH_YES)
     679            0 :                 goto syntax;
     680          350 :               strcpy (new_use->local_name, name);
     681              : 
     682          350 :               m = gfc_match_generic_spec (&type2, new_use->use_name, &op);
     683          350 :               if (type != type2)
     684            2 :                 goto syntax;
     685          348 :               if (m == MATCH_NO)
     686            0 :                 goto syntax;
     687          348 :               if (m == MATCH_ERROR)
     688            0 :                 goto cleanup;
     689              :             }
     690              : 
     691        13759 :           st = gfc_find_symtree (gfc_current_ns->sym_root, name);
     692        13759 :           if (st && type != INTERFACE_USER_OP
     693           13 :               && (st->n.sym->module != use_list->module_name
     694            3 :                   || strcmp (st->n.sym->name, new_use->use_name) != 0))
     695              :             {
     696           10 :               if (m == MATCH_YES)
     697            7 :                 gfc_error ("Symbol %qs at %L conflicts with the rename symbol "
     698              :                            "at %L", name, &st->n.sym->declared_at, &loc);
     699              :               else
     700            3 :                 gfc_error ("Symbol %qs at %L conflicts with the symbol "
     701              :                            "at %L", name, &st->n.sym->declared_at, &loc);
     702           10 :               goto cleanup;
     703              :             }
     704              : 
     705        13749 :           if (strcmp (new_use->use_name, use_list->module_name) == 0
     706        13747 :               || strcmp (new_use->local_name, use_list->module_name) == 0)
     707              :             {
     708            3 :               gfc_error ("The name %qs at %C has already been used as "
     709              :                          "an external module name", use_list->module_name);
     710            3 :               goto cleanup;
     711              :             }
     712              :           break;
     713              : 
     714          117 :         case INTERFACE_INTRINSIC_OP:
     715          117 :           new_use->op = op;
     716          117 :           break;
     717              : 
     718            0 :         default:
     719            0 :           gcc_unreachable ();
     720              :         }
     721              : 
     722        13863 :       if (gfc_match_eos () == MATCH_YES)
     723              :         break;
     724         4603 :       if (gfc_match_char (',') != MATCH_YES)
     725            2 :         goto syntax;
     726              :     }
     727              : 
     728         9260 : done:
     729        24428 :   if (module_list)
     730              :     {
     731              :       gfc_use_list *last = module_list;
     732         4224 :       while (last->next)
     733              :         last = last->next;
     734         3378 :       last->next = use_list;
     735              :     }
     736              :   else
     737        21050 :     module_list = use_list;
     738              : 
     739              :   return MATCH_YES;
     740              : 
     741            5 : syntax:
     742            5 :   gfc_syntax_error (ST_USE);
     743              : 
     744           22 : cleanup:
     745           22 :   free_rename (use_list->rename);
     746           22 :   free (use_list);
     747           22 :   return MATCH_ERROR;
     748              : }
     749              : 
     750              : 
     751              : /* Match a SUBMODULE statement.
     752              : 
     753              :    According to F2008:11.2.3.2, "The submodule identifier is the
     754              :    ordered pair whose first element is the ancestor module name and
     755              :    whose second element is the submodule name. 'Submodule_name' is
     756              :    used for the submodule filename and uses '@' as a separator, whilst
     757              :    the name of the symbol for the module uses '.' as a separator.
     758              :    The reasons for these choices are:
     759              :    (i) To follow another leading brand in the submodule filenames;
     760              :    (ii) Since '.' is not particularly visible in the filenames; and
     761              :    (iii) The linker does not permit '@' in mnemonics.  */
     762              : 
     763              : match
     764          270 : gfc_match_submodule (void)
     765              : {
     766          270 :   match m;
     767          270 :   char name[GFC_MAX_SYMBOL_LEN + 1];
     768          270 :   gfc_use_list *use_list;
     769          270 :   bool seen_colon = false;
     770              : 
     771          270 :   if (!gfc_notify_std (GFC_STD_F2008, "SUBMODULE declaration at %C"))
     772              :     return MATCH_ERROR;
     773              : 
     774          269 :   if (gfc_current_state () != COMP_NONE)
     775              :     {
     776            3 :       gfc_error ("SUBMODULE declaration at %C cannot appear within "
     777              :                  "another scoping unit");
     778            3 :       return MATCH_ERROR;
     779              :     }
     780              : 
     781          266 :   gfc_new_block = NULL;
     782          266 :   gcc_assert (module_list == NULL);
     783              : 
     784          266 :   if (gfc_match_char ('(') != MATCH_YES)
     785            0 :     goto syntax;
     786              : 
     787          293 :   while (1)
     788              :     {
     789          293 :       m = gfc_match (" %n", name);
     790          293 :       if (m != MATCH_YES)
     791            0 :         goto syntax;
     792              : 
     793          293 :       use_list = gfc_get_use_list ();
     794          293 :       use_list->where = gfc_current_locus;
     795              : 
     796          293 :       if (module_list)
     797              :         {
     798              :           gfc_use_list *last = module_list;
     799           27 :           while (last->next)
     800              :             last = last->next;
     801           27 :           last->next = use_list;
     802           27 :           use_list->module_name
     803           27 :                 = gfc_get_string ("%s.%s", module_list->module_name, name);
     804           27 :           use_list->submodule_name
     805           27 :                 = gfc_get_string ("%s@%s", module_list->module_name, name);
     806              :         }
     807              :       else
     808              :         {
     809          266 :           module_list = use_list;
     810          266 :           use_list->module_name = gfc_get_string ("%s", name);
     811          266 :           use_list->submodule_name = use_list->module_name;
     812              :         }
     813              : 
     814          293 :       if (gfc_match_char (')') == MATCH_YES)
     815              :         break;
     816              : 
     817           56 :       if (gfc_match_char (':') != MATCH_YES
     818           28 :           || seen_colon)
     819            1 :         goto syntax;
     820              : 
     821              :       seen_colon = true;
     822              :     }
     823              : 
     824          265 :   m = gfc_match (" %s%t", &gfc_new_block);
     825          265 :   if (m != MATCH_YES)
     826            0 :     goto syntax;
     827              : 
     828          265 :   submodule_name = gfc_get_string ("%s@%s", module_list->module_name,
     829              :                                    gfc_new_block->name);
     830              : 
     831          265 :   gfc_new_block->name = gfc_get_string ("%s.%s",
     832              :                                         module_list->module_name,
     833              :                                         gfc_new_block->name);
     834              : 
     835          265 :   if (!gfc_add_flavor (&gfc_new_block->attr, FL_MODULE,
     836              :                        gfc_new_block->name, NULL))
     837              :     return MATCH_ERROR;
     838              : 
     839              :   /* Just retain the ultimate .(s)mod file for reading, since it
     840              :      contains all the information in its ancestors.  */
     841          265 :   use_list = module_list;
     842          291 :   for (; module_list->next; use_list = module_list)
     843              :     {
     844           26 :       module_list = use_list->next;
     845           26 :       free (use_list);
     846              :     }
     847              : 
     848              :   return MATCH_YES;
     849              : 
     850            1 : syntax:
     851            1 :   gfc_error ("Syntax error in SUBMODULE statement at %C");
     852            1 :   return MATCH_ERROR;
     853              : }
     854              : 
     855              : 
     856              : /* Given a name and a number, inst, return the inst name
     857              :    under which to load this symbol. Returns NULL if this
     858              :    symbol shouldn't be loaded. If inst is zero, returns
     859              :    the number of instances of this name. If interface is
     860              :    true, a user-defined operator is sought, otherwise only
     861              :    non-operators are sought.  */
     862              : 
     863              : static const char *
     864      1183253 : find_use_name_n (const char *name, int *inst, bool interface)
     865              : {
     866      1183253 :   gfc_use_rename *u;
     867      1183253 :   const char *low_name = NULL;
     868      1183253 :   int i;
     869              : 
     870              :   /* For derived types.  */
     871      1183253 :   if (name[0] != (char) TOLOWER ((unsigned char) name[0]))
     872        29840 :     low_name = gfc_dt_lower_string (name);
     873              : 
     874      1183253 :   i = 0;
     875      1331091 :   for (u = gfc_rename_list; u; u = u->next)
     876              :     {
     877       152381 :       if ((!low_name && strcmp (u->use_name, name) != 0)
     878         4352 :           || (low_name && strcmp (u->use_name, low_name) != 0)
     879         9127 :           || (u->op == INTRINSIC_USER && !interface)
     880         9125 :           || (u->op != INTRINSIC_USER &&  interface))
     881       143256 :         continue;
     882         9125 :       if (++i == *inst)
     883              :         break;
     884              :     }
     885              : 
     886      1183253 :   if (!*inst)
     887              :     {
     888       591555 :       *inst = i;
     889       591555 :       return NULL;
     890              :     }
     891              : 
     892       591698 :   if (u == NULL)
     893       587155 :     return only_flag ? NULL : name;
     894              : 
     895         4543 :   u->found = 1;
     896              : 
     897         4543 :   if (low_name)
     898              :     {
     899          756 :       if (u->local_name[0] == '\0')
     900              :         return name;
     901          108 :       return gfc_dt_upper_string (u->local_name);
     902              :     }
     903              : 
     904         3787 :   return (u->local_name[0] != '\0') ? u->local_name : name;
     905              : }
     906              : 
     907              : 
     908              : /* Given a name, return the name under which to load this symbol.
     909              :    Returns NULL if this symbol shouldn't be loaded.  */
     910              : 
     911              : static const char *
     912           86 : find_use_name (const char *name, bool interface)
     913              : {
     914           86 :   int i = 1;
     915           50 :   return find_use_name_n (name, &i, interface);
     916              : }
     917              : 
     918              : 
     919              : /* Given a real name, return the number of use names associated with it.  */
     920              : 
     921              : static int
     922       591555 : number_use_names (const char *name, bool interface)
     923              : {
     924       591555 :   int i = 0;
     925            0 :   find_use_name_n (name, &i, interface);
     926       591555 :   return i;
     927              : }
     928              : 
     929              : 
     930              : /* Try to find the operator in the current list.  */
     931              : 
     932              : static gfc_use_rename *
     933        72078 : find_use_operator (gfc_intrinsic_op op)
     934              : {
     935        72078 :   gfc_use_rename *u;
     936              : 
     937       180792 :   for (u = gfc_rename_list; u; u = u->next)
     938       108922 :     if (u->op == op)
     939              :       return u;
     940              : 
     941              :   return NULL;
     942              : }
     943              : 
     944              : 
     945              : /*****************************************************************/
     946              : 
     947              : /* The next couple of subroutines maintain a tree used to avoid a
     948              :    brute-force search for a combination of true name and module name.
     949              :    While symtree names, the name that a particular symbol is known by
     950              :    can changed with USE statements, we still have to keep track of the
     951              :    true names to generate the correct reference, and also avoid
     952              :    loading the same real symbol twice in a program unit.
     953              : 
     954              :    When we start reading, the true name tree is built and maintained
     955              :    as symbols are read.  The tree is searched as we load new symbols
     956              :    to see if it already exists someplace in the namespace.  */
     957              : 
     958              : typedef struct true_name
     959              : {
     960              :   BBT_HEADER (true_name);
     961              :   const char *name;
     962              :   gfc_symbol *sym;
     963              : }
     964              : true_name;
     965              : 
     966              : static true_name *true_name_root;
     967              : 
     968              : 
     969              : /* Compare two true_name structures.  */
     970              : 
     971              : static int
     972      3324648 : compare_true_names (void *_t1, void *_t2)
     973              : {
     974      3324648 :   true_name *t1, *t2;
     975      3324648 :   int c;
     976              : 
     977      3324648 :   t1 = (true_name *) _t1;
     978      3324648 :   t2 = (true_name *) _t2;
     979              : 
     980      3324648 :   c = ((t1->sym->module > t2->sym->module)
     981      3324648 :        - (t1->sym->module < t2->sym->module));
     982      3324648 :   if (c != 0)
     983              :     return c;
     984              : 
     985      1039551 :   return strcmp (t1->name, t2->name);
     986              : }
     987              : 
     988              : 
     989              : /* Given a true name, search the true name tree to see if it exists
     990              :    within the main namespace.  */
     991              : 
     992              : static gfc_symbol *
     993      1378958 : find_true_name (const char *name, const char *module)
     994              : {
     995      1378958 :   true_name t, *p;
     996      1378958 :   gfc_symbol sym;
     997      1378958 :   int c;
     998              : 
     999      1378958 :   t.name = gfc_get_string ("%s", name);
    1000      1378958 :   if (module != NULL)
    1001      1357512 :     sym.module = gfc_get_string ("%s", module);
    1002              :   else
    1003              :     sym.module = NULL;
    1004      1378958 :   t.sym = &sym;
    1005              : 
    1006      1378958 :   p = true_name_root;
    1007      4234978 :   while (p != NULL)
    1008              :     {
    1009      2906731 :       c = compare_true_names ((void *) (&t), (void *) p);
    1010      2906731 :       if (c == 0)
    1011        50711 :         return p->sym;
    1012              : 
    1013      2856020 :       p = (c < 0) ? p->left : p->right;
    1014              :     }
    1015              : 
    1016              :   return NULL;
    1017              : }
    1018              : 
    1019              : 
    1020              : /* Given a gfc_symbol pointer that is not in the true name tree, add it.  */
    1021              : 
    1022              : static void
    1023       104435 : add_true_name (gfc_symbol *sym)
    1024              : {
    1025       104435 :   true_name *t;
    1026              : 
    1027       104435 :   t = XCNEW (true_name);
    1028       104435 :   t->sym = sym;
    1029       104435 :   if (gfc_fl_struct (sym->attr.flavor))
    1030         5796 :     t->name = gfc_dt_upper_string (sym->name);
    1031              :   else
    1032        98639 :     t->name = sym->name;
    1033              : 
    1034       104435 :   gfc_insert_bbt (&true_name_root, t, compare_true_names);
    1035       104435 : }
    1036              : 
    1037              : 
    1038              : /* Recursive function to build the initial true name tree by
    1039              :    recursively traversing the current namespace.  */
    1040              : 
    1041              : static void
    1042       224324 : build_tnt (gfc_symtree *st)
    1043              : {
    1044       224324 :   const char *name;
    1045       224324 :   if (st == NULL)
    1046              :     return;
    1047              : 
    1048       105205 :   build_tnt (st->left);
    1049       105205 :   build_tnt (st->right);
    1050              : 
    1051       105205 :   if (gfc_fl_struct (st->n.sym->attr.flavor))
    1052         6238 :     name = gfc_dt_upper_string (st->n.sym->name);
    1053              :   else
    1054        98967 :     name = st->n.sym->name;
    1055              : 
    1056       105205 :   if (find_true_name (name, st->n.sym->module) != NULL)
    1057              :     return;
    1058              : 
    1059       104435 :   add_true_name (st->n.sym);
    1060              : }
    1061              : 
    1062              : 
    1063              : /* Initialize the true name tree with the current namespace.  */
    1064              : 
    1065              : static void
    1066        13914 : init_true_name_tree (void)
    1067              : {
    1068        13914 :   true_name_root = NULL;
    1069        13914 :   build_tnt (gfc_current_ns->sym_root);
    1070        13914 : }
    1071              : 
    1072              : 
    1073              : /* Recursively free a true name tree node.  */
    1074              : 
    1075              : static void
    1076       222784 : free_true_name (true_name *t)
    1077              : {
    1078       222784 :   if (t == NULL)
    1079              :     return;
    1080       104435 :   free_true_name (t->left);
    1081       104435 :   free_true_name (t->right);
    1082              : 
    1083       104435 :   free (t);
    1084              : }
    1085              : 
    1086              : 
    1087              : /*****************************************************************/
    1088              : 
    1089              : /* Module reading and writing.  */
    1090              : 
    1091              : /* The following are versions similar to the ones in scanner.cc, but
    1092              :    for dealing with compressed module files.  */
    1093              : 
    1094              : static gzFile
    1095        10134 : gzopen_included_file_1 (const char *name, gfc_directorylist *list,
    1096              :                      bool module, bool system)
    1097              : {
    1098        10134 :   char *fullname;
    1099        10134 :   gfc_directorylist *p;
    1100        10134 :   gzFile f;
    1101              : 
    1102        35247 :   for (p = list; p; p = p->next)
    1103              :     {
    1104        27358 :       if (module && !p->use_for_modules)
    1105         4277 :        continue;
    1106              : 
    1107        23081 :       fullname = (char *) alloca(strlen (p->path) + strlen (name) + 2);
    1108        23081 :       strcpy (fullname, p->path);
    1109        23081 :       strcat (fullname, "/");
    1110        23081 :       strcat (fullname, name);
    1111              : 
    1112        23081 :       f = gzopen (fullname, "r");
    1113        23081 :       if (f != NULL)
    1114              :        {
    1115         2245 :          if (gfc_cpp_makedep ())
    1116            0 :            gfc_cpp_add_dep (fullname, system);
    1117              : 
    1118         2245 :          free (module_fullpath);
    1119         2245 :          module_fullpath = xstrdup (fullname);
    1120         2245 :          return f;
    1121              :        }
    1122              :     }
    1123              : 
    1124              :   return NULL;
    1125              : }
    1126              : 
    1127              : static gzFile
    1128        20564 : gzopen_included_file (const char *name, bool include_cwd, bool module)
    1129              : {
    1130        20564 :   gzFile f = NULL;
    1131              : 
    1132        20564 :   if (IS_ABSOLUTE_PATH (name) || include_cwd)
    1133              :     {
    1134        20564 :       f = gzopen (name, "r");
    1135        20564 :       if (f)
    1136              :         {
    1137        11669 :           if (gfc_cpp_makedep ())
    1138            0 :             gfc_cpp_add_dep (name, false);
    1139              : 
    1140        11669 :           free (module_fullpath);
    1141        11669 :           module_fullpath = xstrdup (name);
    1142              :         }
    1143              :     }
    1144              : 
    1145        11669 :   if (!f)
    1146         8895 :     f = gzopen_included_file_1 (name, include_dirs, module, false);
    1147              : 
    1148        20564 :   return f;
    1149              : }
    1150              : 
    1151              : static gzFile
    1152         1239 : gzopen_intrinsic_module (const char* name)
    1153              : {
    1154         1239 :   gzFile f = NULL;
    1155              : 
    1156         1239 :   if (IS_ABSOLUTE_PATH (name))
    1157              :     {
    1158            0 :       f = gzopen (name, "r");
    1159            0 :       if (f)
    1160              :         {
    1161            0 :           if (gfc_cpp_makedep ())
    1162            0 :             gfc_cpp_add_dep (name, true);
    1163              : 
    1164            0 :           free (module_fullpath);
    1165            0 :           module_fullpath = xstrdup (name);
    1166              :         }
    1167              :     }
    1168              : 
    1169            0 :   if (!f)
    1170         1239 :     f = gzopen_included_file_1 (name, intrinsic_modules_dirs, true, true);
    1171              : 
    1172         1239 :   return f;
    1173              : }
    1174              : 
    1175              : 
    1176              : enum atom_type
    1177              : {
    1178              :   ATOM_NAME, ATOM_LPAREN, ATOM_RPAREN, ATOM_INTEGER, ATOM_STRING
    1179              : };
    1180              : 
    1181              : static atom_type last_atom;
    1182              : 
    1183              : 
    1184              : /* The name buffer must be at least as long as a symbol name.  Right
    1185              :    now it's not clear how we're going to store numeric constants--
    1186              :    probably as a hexadecimal string, since this will allow the exact
    1187              :    number to be preserved (this can't be done by a decimal
    1188              :    representation).  Worry about that later.  TODO!  */
    1189              : 
    1190              : #define MAX_ATOM_SIZE 100
    1191              : 
    1192              : static HOST_WIDE_INT atom_int;
    1193              : static char *atom_string, atom_name[MAX_ATOM_SIZE];
    1194              : 
    1195              : 
    1196              : /* Report problems with a module.  Error reporting is not very
    1197              :    elaborate, since this sorts of errors shouldn't really happen.
    1198              :    This subroutine never returns.  */
    1199              : 
    1200              : static void bad_module (const char *) ATTRIBUTE_NORETURN;
    1201              : 
    1202              : static void
    1203            0 : bad_module (const char *msgid)
    1204              : {
    1205            0 :   XDELETEVEC (module_content);
    1206            0 :   module_content = NULL;
    1207              : 
    1208            0 :   switch (iomode)
    1209              :     {
    1210            0 :     case IO_INPUT:
    1211            0 :       gfc_fatal_error ("Reading module %qs at line %d column %d: %s",
    1212              :                        module_fullpath, module_line, module_column, msgid);
    1213            0 :       break;
    1214            0 :     case IO_OUTPUT:
    1215            0 :       gfc_fatal_error ("Writing module %qs at line %d column %d: %s",
    1216              :                        module_name, module_line, module_column, msgid);
    1217            0 :       break;
    1218            0 :     default:
    1219            0 :       gfc_fatal_error ("Module %qs at line %d column %d: %s",
    1220              :                        module_name, module_line, module_column, msgid);
    1221              :       break;
    1222              :     }
    1223              : }
    1224              : 
    1225              : 
    1226              : /* Set the module's input pointer.  */
    1227              : 
    1228              : static void
    1229      1123497 : set_module_locus (module_locus *m)
    1230              : {
    1231      1123497 :   module_column = m->column;
    1232      1123497 :   module_line = m->line;
    1233      1123497 :   module_pos = m->pos;
    1234            0 : }
    1235              : 
    1236              : 
    1237              : /* Get the module's input pointer so that we can restore it later.  */
    1238              : 
    1239              : static void
    1240      1329429 : get_module_locus (module_locus *m)
    1241              : {
    1242      1329429 :   m->column = module_column;
    1243      1329429 :   m->line = module_line;
    1244      1329429 :   m->pos = module_pos;
    1245            0 : }
    1246              : 
    1247              : /* Peek at the next character in the module.  */
    1248              : 
    1249              : static int
    1250          616 : module_peek_char (void)
    1251              : {
    1252          616 :   return module_content[module_pos];
    1253              : }
    1254              : 
    1255              : /* Get the next character in the module, updating our reckoning of
    1256              :    where we are.  */
    1257              : 
    1258              : static int
    1259    567869266 : module_char (void)
    1260              : {
    1261    567869266 :   const char c = module_content[module_pos++];
    1262    567869266 :   if (c == '\0')
    1263            0 :     bad_module ("Unexpected EOF");
    1264              : 
    1265    567869266 :   prev_module_line = module_line;
    1266    567869266 :   prev_module_column = module_column;
    1267              : 
    1268    567869266 :   if (c == '\n')
    1269              :     {
    1270     12181510 :       module_line++;
    1271     12181510 :       module_column = 0;
    1272              :     }
    1273              : 
    1274    567869266 :   module_column++;
    1275    567869266 :   return c;
    1276              : }
    1277              : 
    1278              : /* Unget a character while remembering the line and column.  Works for
    1279              :    a single character only.  */
    1280              : 
    1281              : static void
    1282     83811373 : module_unget_char (void)
    1283              : {
    1284     83811373 :   module_line = prev_module_line;
    1285     83811373 :   module_column = prev_module_column;
    1286     83811373 :   module_pos--;
    1287            0 : }
    1288              : 
    1289              : /* Parse a string constant.  The delimiter is guaranteed to be a
    1290              :    single quote.  */
    1291              : 
    1292              : static void
    1293      5772942 : parse_string (void)
    1294              : {
    1295      5772942 :   int c;
    1296      5772942 :   size_t cursz = 30;
    1297      5772942 :   size_t len = 0;
    1298              : 
    1299      5772942 :   atom_string = XNEWVEC (char, cursz);
    1300              : 
    1301     87164972 :   for ( ; ; )
    1302              :     {
    1303     46468957 :       c = module_char ();
    1304              : 
    1305     46468957 :       if (c == '\'')
    1306              :         {
    1307      5772942 :           int c2 = module_char ();
    1308      5772942 :           if (c2 != '\'')
    1309              :             {
    1310      5772942 :               module_unget_char ();
    1311      5772942 :               break;
    1312              :             }
    1313              :         }
    1314              : 
    1315     40696015 :       if (len >= cursz)
    1316              :         {
    1317        67047 :           cursz *= 2;
    1318        67047 :           atom_string = XRESIZEVEC (char, atom_string, cursz);
    1319              :         }
    1320     40696015 :       atom_string[len] = c;
    1321     40696015 :       len++;
    1322     40696015 :     }
    1323              : 
    1324      5772942 :   atom_string = XRESIZEVEC (char, atom_string, len + 1);
    1325      5772942 :   atom_string[len] = '\0';      /* C-style string for debug purposes.  */
    1326      5772942 : }
    1327              : 
    1328              : 
    1329              : /* Parse an integer. Should fit in a HOST_WIDE_INT.  */
    1330              : 
    1331              : static void
    1332     37480544 : parse_integer (int c)
    1333              : {
    1334     37480544 :   int sign = 1;
    1335              : 
    1336     37480544 :   atom_int = 0;
    1337     37480544 :   switch (c)
    1338              :     {
    1339              :     case ('-'):
    1340     37480544 :       sign = -1;
    1341              :     case ('+'):
    1342              :       break;
    1343     37479928 :     default:
    1344     37479928 :       atom_int = c - '0';
    1345     37479928 :       break;
    1346              :     }
    1347              : 
    1348     55931180 :   for (;;)
    1349              :     {
    1350     46705862 :       c = module_char ();
    1351     46705862 :       if (!ISDIGIT (c))
    1352              :         {
    1353     37480544 :           module_unget_char ();
    1354     37480544 :           break;
    1355              :         }
    1356              : 
    1357      9225318 :       atom_int = 10 * atom_int + c - '0';
    1358              :     }
    1359              : 
    1360     37480544 :   atom_int *= sign;
    1361     37480544 : }
    1362              : 
    1363              : 
    1364              : /* Parse a name.  */
    1365              : 
    1366              : static void
    1367     27260994 : parse_name (int c)
    1368              : {
    1369     27260994 :   char *p;
    1370     27260994 :   int len;
    1371              : 
    1372     27260994 :   p = atom_name;
    1373              : 
    1374     27260994 :   *p++ = c;
    1375     27260994 :   len = 1;
    1376              : 
    1377    232476170 :   for (;;)
    1378              :     {
    1379    232476170 :       c = module_char ();
    1380    232476170 :       if (!ISALNUM (c) && c != '_' && c != '-')
    1381              :         {
    1382     27260994 :           module_unget_char ();
    1383     27260994 :           break;
    1384              :         }
    1385              : 
    1386    205215176 :       *p++ = c;
    1387    205215176 :       if (++len > GFC_MAX_SYMBOL_LEN)
    1388            0 :         bad_module ("Name too long");
    1389              :     }
    1390              : 
    1391     27260994 :   *p = '\0';
    1392              : 
    1393     27260994 : }
    1394              : 
    1395              : 
    1396              : /* Read the next atom in the module's input stream.  */
    1397              : 
    1398              : static atom_type
    1399    131795602 : parse_atom (void)
    1400              : {
    1401    220233704 :   int c;
    1402              : 
    1403    220233704 :   do
    1404              :     {
    1405    220233704 :       c = module_char ();
    1406              :     }
    1407    220233704 :   while (c == ' ' || c == '\r' || c == '\n');
    1408              : 
    1409    131795602 :   switch (c)
    1410              :     {
    1411              :     case '(':
    1412              :       return ATOM_LPAREN;
    1413              : 
    1414     30654465 :     case ')':
    1415     30654465 :       return ATOM_RPAREN;
    1416              : 
    1417      5772942 :     case '\'':
    1418      5772942 :       parse_string ();
    1419      5772942 :       return ATOM_STRING;
    1420              : 
    1421     37479928 :     case '0':
    1422     37479928 :     case '1':
    1423     37479928 :     case '2':
    1424     37479928 :     case '3':
    1425     37479928 :     case '4':
    1426     37479928 :     case '5':
    1427     37479928 :     case '6':
    1428     37479928 :     case '7':
    1429     37479928 :     case '8':
    1430     37479928 :     case '9':
    1431     37479928 :       parse_integer (c);
    1432     37479928 :       return ATOM_INTEGER;
    1433              : 
    1434          616 :     case '+':
    1435          616 :     case '-':
    1436          616 :       if (ISDIGIT (module_peek_char ()))
    1437              :         {
    1438          616 :           parse_integer (c);
    1439          616 :           return ATOM_INTEGER;
    1440              :         }
    1441              :       else
    1442            0 :         bad_module ("Bad name");
    1443              : 
    1444     27219252 :     case 'a':
    1445     27219252 :     case 'b':
    1446     27219252 :     case 'c':
    1447     27219252 :     case 'd':
    1448     27219252 :     case 'e':
    1449     27219252 :     case 'f':
    1450     27219252 :     case 'g':
    1451     27219252 :     case 'h':
    1452     27219252 :     case 'i':
    1453     27219252 :     case 'j':
    1454     27219252 :     case 'k':
    1455     27219252 :     case 'l':
    1456     27219252 :     case 'm':
    1457     27219252 :     case 'n':
    1458     27219252 :     case 'o':
    1459     27219252 :     case 'p':
    1460     27219252 :     case 'q':
    1461     27219252 :     case 'r':
    1462     27219252 :     case 's':
    1463     27219252 :     case 't':
    1464     27219252 :     case 'u':
    1465     27219252 :     case 'v':
    1466     27219252 :     case 'w':
    1467     27219252 :     case 'x':
    1468     27219252 :     case 'y':
    1469     27219252 :     case 'z':
    1470     27219252 :     case 'A':
    1471     27219252 :     case 'B':
    1472     27219252 :     case 'C':
    1473     27219252 :     case 'D':
    1474     27219252 :     case 'E':
    1475     27219252 :     case 'F':
    1476     27219252 :     case 'G':
    1477     27219252 :     case 'H':
    1478     27219252 :     case 'I':
    1479     27219252 :     case 'J':
    1480     27219252 :     case 'K':
    1481     27219252 :     case 'L':
    1482     27219252 :     case 'M':
    1483     27219252 :     case 'N':
    1484     27219252 :     case 'O':
    1485     27219252 :     case 'P':
    1486     27219252 :     case 'Q':
    1487     27219252 :     case 'R':
    1488     27219252 :     case 'S':
    1489     27219252 :     case 'T':
    1490     27219252 :     case 'U':
    1491     27219252 :     case 'V':
    1492     27219252 :     case 'W':
    1493     27219252 :     case 'X':
    1494     27219252 :     case 'Y':
    1495     27219252 :     case 'Z':
    1496     27219252 :       parse_name (c);
    1497     27219252 :       return ATOM_NAME;
    1498              : 
    1499            0 :     default:
    1500            0 :       bad_module ("Bad name");
    1501              :     }
    1502              : 
    1503              :   /* Not reached.  */
    1504              : }
    1505              : 
    1506              : 
    1507              : /* Peek at the next atom on the input.  */
    1508              : 
    1509              : static atom_type
    1510     13296893 : peek_atom (void)
    1511              : {
    1512     15697503 :   int c;
    1513              : 
    1514     15697503 :   do
    1515              :     {
    1516     15697503 :       c = module_char ();
    1517              :     }
    1518     15697503 :   while (c == ' ' || c == '\r' || c == '\n');
    1519              : 
    1520     13296893 :   switch (c)
    1521              :     {
    1522       315143 :     case '(':
    1523       315143 :       module_unget_char ();
    1524       315143 :       return ATOM_LPAREN;
    1525              : 
    1526     10493588 :     case ')':
    1527     10493588 :       module_unget_char ();
    1528     10493588 :       return ATOM_RPAREN;
    1529              : 
    1530       531396 :     case '\'':
    1531       531396 :       module_unget_char ();
    1532       531396 :       return ATOM_STRING;
    1533              : 
    1534      1951648 :     case '0':
    1535      1951648 :     case '1':
    1536      1951648 :     case '2':
    1537      1951648 :     case '3':
    1538      1951648 :     case '4':
    1539      1951648 :     case '5':
    1540      1951648 :     case '6':
    1541      1951648 :     case '7':
    1542      1951648 :     case '8':
    1543      1951648 :     case '9':
    1544      1951648 :       module_unget_char ();
    1545      1951648 :       return ATOM_INTEGER;
    1546              : 
    1547            0 :     case '+':
    1548            0 :     case '-':
    1549            0 :       if (ISDIGIT (module_peek_char ()))
    1550              :         {
    1551            0 :           module_unget_char ();
    1552            0 :           return ATOM_INTEGER;
    1553              :         }
    1554              :       else
    1555            0 :         bad_module ("Bad name");
    1556              : 
    1557         5118 :     case 'a':
    1558         5118 :     case 'b':
    1559         5118 :     case 'c':
    1560         5118 :     case 'd':
    1561         5118 :     case 'e':
    1562         5118 :     case 'f':
    1563         5118 :     case 'g':
    1564         5118 :     case 'h':
    1565         5118 :     case 'i':
    1566         5118 :     case 'j':
    1567         5118 :     case 'k':
    1568         5118 :     case 'l':
    1569         5118 :     case 'm':
    1570         5118 :     case 'n':
    1571         5118 :     case 'o':
    1572         5118 :     case 'p':
    1573         5118 :     case 'q':
    1574         5118 :     case 'r':
    1575         5118 :     case 's':
    1576         5118 :     case 't':
    1577         5118 :     case 'u':
    1578         5118 :     case 'v':
    1579         5118 :     case 'w':
    1580         5118 :     case 'x':
    1581         5118 :     case 'y':
    1582         5118 :     case 'z':
    1583         5118 :     case 'A':
    1584         5118 :     case 'B':
    1585         5118 :     case 'C':
    1586         5118 :     case 'D':
    1587         5118 :     case 'E':
    1588         5118 :     case 'F':
    1589         5118 :     case 'G':
    1590         5118 :     case 'H':
    1591         5118 :     case 'I':
    1592         5118 :     case 'J':
    1593         5118 :     case 'K':
    1594         5118 :     case 'L':
    1595         5118 :     case 'M':
    1596         5118 :     case 'N':
    1597         5118 :     case 'O':
    1598         5118 :     case 'P':
    1599         5118 :     case 'Q':
    1600         5118 :     case 'R':
    1601         5118 :     case 'S':
    1602         5118 :     case 'T':
    1603         5118 :     case 'U':
    1604         5118 :     case 'V':
    1605         5118 :     case 'W':
    1606         5118 :     case 'X':
    1607         5118 :     case 'Y':
    1608         5118 :     case 'Z':
    1609         5118 :       module_unget_char ();
    1610         5118 :       return ATOM_NAME;
    1611              : 
    1612            0 :     default:
    1613            0 :       bad_module ("Bad name");
    1614              :     }
    1615              : }
    1616              : 
    1617              : 
    1618              : /* Read the next atom from the input, requiring that it be a
    1619              :    particular kind.  */
    1620              : 
    1621              : static void
    1622     60299085 : require_atom (atom_type type)
    1623              : {
    1624     60299085 :   atom_type t;
    1625     60299085 :   const char *p;
    1626     60299085 :   int column, line;
    1627              : 
    1628     60299085 :   column = module_column;
    1629     60299085 :   line = module_line;
    1630              : 
    1631     60299085 :   t = parse_atom ();
    1632     60299085 :   if (t != type)
    1633              :     {
    1634            0 :       switch (type)
    1635              :         {
    1636            0 :         case ATOM_NAME:
    1637            0 :           p = _("Expected name");
    1638            0 :           break;
    1639            0 :         case ATOM_LPAREN:
    1640            0 :           p = _("Expected left parenthesis");
    1641            0 :           break;
    1642            0 :         case ATOM_RPAREN:
    1643            0 :           p = _("Expected right parenthesis");
    1644            0 :           break;
    1645            0 :         case ATOM_INTEGER:
    1646            0 :           p = _("Expected integer");
    1647            0 :           break;
    1648            0 :         case ATOM_STRING:
    1649            0 :           p = _("Expected string");
    1650            0 :           break;
    1651            0 :         default:
    1652            0 :           gfc_internal_error ("require_atom(): bad atom type required");
    1653              :         }
    1654              : 
    1655            0 :       module_column = column;
    1656            0 :       module_line = line;
    1657            0 :       bad_module (p);
    1658              :     }
    1659     60299085 : }
    1660              : 
    1661              : 
    1662              : /* Given a pointer to an mstring array, require that the current input
    1663              :    be one of the strings in the array.  We return the enum value.  */
    1664              : 
    1665              : static int
    1666     12458331 : find_enum (const mstring *m)
    1667              : {
    1668     12458331 :   int i;
    1669              : 
    1670     12458331 :   i = gfc_string2code (m, atom_name);
    1671     12458331 :   if (i >= 0)
    1672     12458331 :     return i;
    1673              : 
    1674            0 :   bad_module ("find_enum(): Enum not found");
    1675              : 
    1676              :   /* Not reached.  */
    1677              : }
    1678              : 
    1679              : 
    1680              : /* Read a string. The caller is responsible for freeing.  */
    1681              : 
    1682              : static char*
    1683      3821467 : read_string (void)
    1684              : {
    1685      3821467 :   char* p;
    1686            0 :   require_atom (ATOM_STRING);
    1687      3821467 :   p = atom_string;
    1688      3821467 :   atom_string = NULL;
    1689      3821467 :   return p;
    1690              : }
    1691              : 
    1692              : 
    1693              : /**************** Module output subroutines ***************************/
    1694              : 
    1695              : /* Output a character to a module file.  */
    1696              : 
    1697              : static void
    1698     69184391 : write_char (char out)
    1699              : {
    1700     69184391 :   if (gzputc (module_fp, out) == EOF)
    1701            0 :     gfc_fatal_error ("Error writing modules file: %s", xstrerror (errno));
    1702              : 
    1703     69184391 :   if (out != '\n')
    1704     67924660 :     module_column++;
    1705              :   else
    1706              :     {
    1707      1259731 :       module_column = 1;
    1708      1259731 :       module_line++;
    1709              :     }
    1710     69184391 : }
    1711              : 
    1712              : 
    1713              : /* Write an atom to a module.  The line wrapping isn't perfect, but it
    1714              :    should work most of the time.  This isn't that big of a deal, since
    1715              :    the file really isn't meant to be read by people anyway.  */
    1716              : 
    1717              : static void
    1718     18408790 : write_atom (atom_type atom, const void *v)
    1719              : {
    1720     18408790 :   char buffer[32];
    1721              : 
    1722              :   /* Workaround -Wmaybe-uninitialized false positive during
    1723              :      profiledbootstrap by initializing them.  */
    1724     18408790 :   int len;
    1725     18408790 :   HOST_WIDE_INT i = 0;
    1726     18408790 :   const char *p;
    1727              : 
    1728     18408790 :   switch (atom)
    1729              :     {
    1730              :     case ATOM_STRING:
    1731              :     case ATOM_NAME:
    1732              :       p = (const char *) v;
    1733              :       break;
    1734              : 
    1735              :     case ATOM_LPAREN:
    1736              :       p = "(";
    1737              :       break;
    1738              : 
    1739              :     case ATOM_RPAREN:
    1740              :       p = ")";
    1741              :       break;
    1742              : 
    1743      5002100 :     case ATOM_INTEGER:
    1744      5002100 :       i = *((const HOST_WIDE_INT *) v);
    1745              : 
    1746      5002100 :       snprintf (buffer, sizeof (buffer), HOST_WIDE_INT_PRINT_DEC, i);
    1747      5002100 :       p = buffer;
    1748      5002100 :       break;
    1749              : 
    1750            0 :     default:
    1751            0 :       gfc_internal_error ("write_atom(): Trying to write dab atom");
    1752              : 
    1753              :     }
    1754              : 
    1755     18408790 :   if(p == NULL || *p == '\0')
    1756              :      len = 0;
    1757              :   else
    1758     18023803 :   len = strlen (p);
    1759              : 
    1760     18408790 :   if (atom != ATOM_RPAREN)
    1761              :     {
    1762     14186926 :       if (module_column + len > 72)
    1763       859244 :         write_char ('\n');
    1764              :       else
    1765              :         {
    1766              : 
    1767     13327682 :           if (last_atom != ATOM_LPAREN && module_column != 1)
    1768     11579113 :             write_char (' ');
    1769              :         }
    1770              :     }
    1771              : 
    1772     14186926 :   if (atom == ATOM_STRING)
    1773      1143921 :     write_char ('\'');
    1774              : 
    1775     72466495 :   while (p != NULL && *p)
    1776              :     {
    1777     54057705 :       if (atom == ATOM_STRING && *p == '\'')
    1778            0 :         write_char ('\'');
    1779     54057705 :       write_char (*p++);
    1780              :     }
    1781              : 
    1782     18408790 :   if (atom == ATOM_STRING)
    1783      1143921 :     write_char ('\'');
    1784              : 
    1785     18408790 :   last_atom = atom;
    1786     18408790 : }
    1787              : 
    1788              : 
    1789              : 
    1790              : /***************** Mid-level I/O subroutines *****************/
    1791              : 
    1792              : /* These subroutines let their caller read or write atoms without
    1793              :    caring about which of the two is actually happening.  This lets a
    1794              :    subroutine concentrate on the actual format of the data being
    1795              :    written.  */
    1796              : 
    1797              : static void mio_expr (gfc_expr **);
    1798              : pointer_info *mio_symbol_ref (gfc_symbol **);
    1799              : pointer_info *mio_interface_rest (gfc_interface **);
    1800              : static void mio_symtree_ref (gfc_symtree **);
    1801              : 
    1802              : /* Read or write an enumerated value.  On writing, we return the input
    1803              :    value for the convenience of callers.  We avoid using an integer
    1804              :    pointer because enums are sometimes inside bitfields.  */
    1805              : 
    1806              : static int
    1807     13685723 : mio_name (int t, const mstring *m)
    1808              : {
    1809     13685723 :   if (iomode == IO_OUTPUT)
    1810      3817727 :     write_atom (ATOM_NAME, gfc_code2string (m, t));
    1811              :   else
    1812              :     {
    1813      9867996 :       require_atom (ATOM_NAME);
    1814      9867996 :       t = find_enum (m);
    1815              :     }
    1816              : 
    1817     13685723 :   return t;
    1818              : }
    1819              : 
    1820              : /* Specialization of mio_name.  */
    1821              : 
    1822              : #define DECL_MIO_NAME(TYPE) \
    1823              :  static inline TYPE \
    1824              :  MIO_NAME(TYPE) (TYPE t, const mstring *m) \
    1825              :  { \
    1826              :    return (TYPE) mio_name ((int) t, m); \
    1827              :  }
    1828              : #define MIO_NAME(TYPE) mio_name_##TYPE
    1829              : 
    1830              : static void
    1831     18281628 : mio_lparen (void)
    1832              : {
    1833     18281628 :   if (iomode == IO_OUTPUT)
    1834      4221864 :     write_atom (ATOM_LPAREN, NULL);
    1835              :   else
    1836     14059764 :     require_atom (ATOM_LPAREN);
    1837     18281628 : }
    1838              : 
    1839              : 
    1840              : static void
    1841     16765371 : mio_rparen (void)
    1842              : {
    1843     16765371 :   if (iomode == IO_OUTPUT)
    1844      4221864 :     write_atom (ATOM_RPAREN, NULL);
    1845              :   else
    1846     12543507 :     require_atom (ATOM_RPAREN);
    1847     16765371 : }
    1848              : 
    1849              : 
    1850              : static void
    1851     13861573 : mio_integer (int *ip)
    1852              : {
    1853     13861573 :   if (iomode == IO_OUTPUT)
    1854              :     {
    1855      3080953 :       HOST_WIDE_INT hwi = *ip;
    1856      3080953 :       write_atom (ATOM_INTEGER, &hwi);
    1857              :     }
    1858              :   else
    1859              :     {
    1860     10780620 :       require_atom (ATOM_INTEGER);
    1861     10780620 :       *ip = atom_int;
    1862              :     }
    1863     13861573 : }
    1864              : 
    1865              : static void
    1866       407640 : mio_hwi (HOST_WIDE_INT *hwi)
    1867              : {
    1868       407640 :   if (iomode == IO_OUTPUT)
    1869       242382 :     write_atom (ATOM_INTEGER, hwi);
    1870              :   else
    1871              :     {
    1872       165258 :       require_atom (ATOM_INTEGER);
    1873       165258 :       *hwi = atom_int;
    1874              :     }
    1875       407640 : }
    1876              : 
    1877              : 
    1878              : /* Read or write a gfc_intrinsic_op value.  */
    1879              : 
    1880              : static void
    1881         1344 : mio_intrinsic_op (gfc_intrinsic_op* op)
    1882              : {
    1883              :   /* FIXME: Would be nicer to do this via the operators symbolic name.  */
    1884         1344 :   if (iomode == IO_OUTPUT)
    1885              :     {
    1886          714 :       HOST_WIDE_INT converted = (HOST_WIDE_INT) *op;
    1887          714 :       write_atom (ATOM_INTEGER, &converted);
    1888              :     }
    1889              :   else
    1890              :     {
    1891          630 :       require_atom (ATOM_INTEGER);
    1892          630 :       *op = (gfc_intrinsic_op) atom_int;
    1893              :     }
    1894         1344 : }
    1895              : 
    1896              : 
    1897              : /* Read or write a character pointer that points to a string on the heap.  */
    1898              : 
    1899              : static const char *
    1900         9477 : mio_allocated_string (const char *s)
    1901              : {
    1902         9477 :   if (iomode == IO_OUTPUT)
    1903              :     {
    1904         9477 :       write_atom (ATOM_STRING, s);
    1905         9477 :       return s;
    1906              :     }
    1907              :   else
    1908              :     {
    1909            0 :       require_atom (ATOM_STRING);
    1910            0 :       return atom_string;
    1911              :     }
    1912              : }
    1913              : 
    1914              : 
    1915              : /* Functions for quoting and unquoting strings.  */
    1916              : 
    1917              : static char *
    1918         5550 : quote_string (const gfc_char_t *s, const size_t slength)
    1919              : {
    1920         5550 :   const gfc_char_t *p;
    1921         5550 :   char *res, *q;
    1922         5550 :   size_t len = 0, i;
    1923              : 
    1924              :   /* Calculate the length we'll need: a backslash takes two ("\\"),
    1925              :      non-printable characters take 10 ("\Uxxxxxxxx") and others take 1.  */
    1926        20653 :   for (p = s, i = 0; i < slength; p++, i++)
    1927              :     {
    1928        15103 :       if (*p == '\\')
    1929            1 :         len += 2;
    1930        15102 :       else if (!gfc_wide_is_printable (*p))
    1931         4795 :         len += 10;
    1932              :       else
    1933        10307 :         len++;
    1934              :     }
    1935              : 
    1936         5550 :   q = res = XCNEWVEC (char, len + 1);
    1937        26203 :   for (p = s, i = 0; i < slength; p++, i++)
    1938              :     {
    1939        15103 :       if (*p == '\\')
    1940            1 :         *q++ = '\\', *q++ = '\\';
    1941        15102 :       else if (!gfc_wide_is_printable (*p))
    1942              :         {
    1943         4795 :           sprintf (q, "\\U%08" HOST_WIDE_INT_PRINT "x",
    1944         4795 :                    (unsigned HOST_WIDE_INT) *p);
    1945         4795 :           q += 10;
    1946              :         }
    1947              :       else
    1948        10307 :         *q++ = (unsigned char) *p;
    1949              :     }
    1950              : 
    1951         5550 :   res[len] = '\0';
    1952         5550 :   return res;
    1953              : }
    1954              : 
    1955              : static gfc_char_t *
    1956         3010 : unquote_string (const char *s)
    1957              : {
    1958         3010 :   size_t len, i;
    1959         3010 :   const char *p;
    1960         3010 :   gfc_char_t *res;
    1961              : 
    1962        14746 :   for (p = s, len = 0; *p; p++, len++)
    1963              :     {
    1964        11736 :       if (*p != '\\')
    1965         9534 :         continue;
    1966              : 
    1967         2202 :       if (p[1] == '\\')
    1968            0 :         p++;
    1969         2202 :       else if (p[1] == 'U')
    1970         2202 :         p += 9; /* That is a "\U????????".  */
    1971              :       else
    1972            0 :         gfc_internal_error ("unquote_string(): got bad string");
    1973              :     }
    1974              : 
    1975         3010 :   res = gfc_get_wide_string (len + 1);
    1976        17756 :   for (i = 0, p = s; i < len; i++, p++)
    1977              :     {
    1978        11736 :       gcc_assert (*p);
    1979              : 
    1980        11736 :       if (*p != '\\')
    1981         9534 :         res[i] = (unsigned char) *p;
    1982         2202 :       else if (p[1] == '\\')
    1983              :         {
    1984            0 :           res[i] = (unsigned char) '\\';
    1985            0 :           p++;
    1986              :         }
    1987              :       else
    1988              :         {
    1989              :           /* We read the 8-digits hexadecimal constant that follows.  */
    1990         2202 :           int j;
    1991         2202 :           unsigned n;
    1992         2202 :           gfc_char_t c = 0;
    1993              : 
    1994         2202 :           gcc_assert (p[1] == 'U');
    1995        19818 :           for (j = 0; j < 8; j++)
    1996              :             {
    1997        17616 :               c = c << 4;
    1998        17616 :               gcc_assert (sscanf (&p[j+2], "%01x", &n) == 1);
    1999        17616 :               c += n;
    2000              :             }
    2001              : 
    2002         2202 :           res[i] = c;
    2003         2202 :           p += 9;
    2004              :         }
    2005              :     }
    2006              : 
    2007         3010 :   res[len] = '\0';
    2008         3010 :   return res;
    2009              : }
    2010              : 
    2011              : 
    2012              : /* Read or write a character pointer that points to a wide string on the
    2013              :    heap, performing quoting/unquoting of nonprintable characters using the
    2014              :    form \U???????? (where each ? is a hexadecimal digit).
    2015              :    Length is the length of the string, only known and used in output mode.  */
    2016              : 
    2017              : static const gfc_char_t *
    2018         8560 : mio_allocated_wide_string (const gfc_char_t *s, const size_t length)
    2019              : {
    2020         8560 :   if (iomode == IO_OUTPUT)
    2021              :     {
    2022         5550 :       char *quoted = quote_string (s, length);
    2023         5550 :       write_atom (ATOM_STRING, quoted);
    2024         5550 :       free (quoted);
    2025         5550 :       return s;
    2026              :     }
    2027              :   else
    2028              :     {
    2029         3010 :       gfc_char_t *unquoted;
    2030              : 
    2031         3010 :       require_atom (ATOM_STRING);
    2032         3010 :       unquoted = unquote_string (atom_string);
    2033         3010 :       free (atom_string);
    2034         3010 :       return unquoted;
    2035              :     }
    2036              : }
    2037              : 
    2038              : 
    2039              : /* Read or write a string that is in static memory.  */
    2040              : 
    2041              : static void
    2042      1044604 : mio_pool_string (const char **stringp)
    2043              : {
    2044              :   /* TODO: one could write the string only once, and refer to it via a
    2045              :      fixup pointer.  */
    2046              : 
    2047              :   /* As a special case we have to deal with a NULL string.  This
    2048              :      happens for the 'module' member of 'gfc_symbol's that are not in a
    2049              :      module.  We read / write these as the empty string.  */
    2050      1044604 :   if (iomode == IO_OUTPUT)
    2051              :     {
    2052       808826 :       const char *p = *stringp == NULL ? "" : *stringp;
    2053       808826 :       write_atom (ATOM_STRING, p);
    2054              :     }
    2055              :   else
    2056              :     {
    2057       235778 :       require_atom (ATOM_STRING);
    2058       471556 :       *stringp = (atom_string[0] == '\0'
    2059       235778 :                   ? NULL : gfc_get_string ("%s", atom_string));
    2060       235778 :       free (atom_string);
    2061              :     }
    2062      1044604 : }
    2063              : 
    2064              : 
    2065              : /* Read or write a string that is inside of some already-allocated
    2066              :    structure.  */
    2067              : 
    2068              : static void
    2069       653518 : mio_internal_string (char *string)
    2070              : {
    2071       653518 :   if (iomode == IO_OUTPUT)
    2072            0 :     write_atom (ATOM_STRING, string);
    2073              :   else
    2074              :     {
    2075       653518 :       require_atom (ATOM_STRING);
    2076       653518 :       strcpy (string, atom_string);
    2077       653518 :       free (atom_string);
    2078              :     }
    2079       653518 : }
    2080              : 
    2081              : 
    2082              : enum ab_attribute
    2083              : { AB_ALLOCATABLE, AB_DIMENSION, AB_EXTERNAL, AB_INTRINSIC, AB_OPTIONAL,
    2084              :   AB_POINTER, AB_TARGET, AB_DUMMY, AB_RESULT, AB_DATA,
    2085              :   AB_IN_NAMELIST, AB_IN_COMMON, AB_FUNCTION, AB_SUBROUTINE, AB_SEQUENCE,
    2086              :   AB_ELEMENTAL, AB_PURE, AB_RECURSIVE, AB_GENERIC, AB_ALWAYS_EXPLICIT,
    2087              :   AB_CRAY_POINTER, AB_CRAY_POINTEE, AB_THREADPRIVATE,
    2088              :   AB_ALLOC_COMP, AB_POINTER_COMP, AB_PROC_POINTER_COMP, AB_PRIVATE_COMP,
    2089              :   AB_VALUE, AB_VOLATILE, AB_PROTECTED, AB_LOCK_COMP, AB_EVENT_COMP,
    2090              :   AB_IS_BIND_C, AB_IS_C_INTEROP, AB_IS_ISO_C, AB_ABSTRACT, AB_ZERO_COMP,
    2091              :   AB_IS_CLASS, AB_PROCEDURE, AB_PROC_POINTER, AB_ASYNCHRONOUS, AB_CODIMENSION,
    2092              :   AB_COARRAY_COMP, AB_VTYPE, AB_VTAB, AB_CONTIGUOUS, AB_CLASS_POINTER,
    2093              :   AB_IMPLICIT_PURE, AB_ARTIFICIAL, AB_UNLIMITED_POLY, AB_OMP_DECLARE_TARGET,
    2094              :   AB_ARRAY_OUTER_DEPENDENCY, AB_MODULE_PROCEDURE, AB_OACC_DECLARE_CREATE,
    2095              :   AB_OACC_DECLARE_COPYIN, AB_OACC_DECLARE_DEVICEPTR,
    2096              :   AB_OACC_DECLARE_DEVICE_RESIDENT, AB_OACC_DECLARE_LINK,
    2097              :   AB_OMP_DECLARE_TARGET_LINK, AB_OMP_DECLARE_TARGET_LOCAL,
    2098              :   AB_PDT_KIND, AB_PDT_LEN, AB_PDT_TYPE,
    2099              :   AB_PDT_COMP, AB_PDT_TEMPLATE, AB_PDT_ARRAY, AB_PDT_STRING,
    2100              :   AB_OACC_ROUTINE_LOP_GANG, AB_OACC_ROUTINE_LOP_WORKER,
    2101              :   AB_OACC_ROUTINE_LOP_VECTOR, AB_OACC_ROUTINE_LOP_SEQ,
    2102              :   AB_OACC_ROUTINE_NOHOST,
    2103              :   AB_OMP_REQ_REVERSE_OFFLOAD, AB_OMP_REQ_UNIFIED_ADDRESS, AB_OMP_REQ_SELF_MAPS,
    2104              :   AB_OMP_REQ_UNIFIED_SHARED_MEMORY, AB_OMP_REQ_DYNAMIC_ALLOCATORS,
    2105              :   AB_OMP_REQ_MEM_ORDER_SEQ_CST, AB_OMP_REQ_MEM_ORDER_ACQ_REL,
    2106              :   AB_OMP_REQ_MEM_ORDER_ACQUIRE, AB_OMP_REQ_MEM_ORDER_RELEASE,
    2107              :   AB_OMP_REQ_MEM_ORDER_RELAXED, AB_OMP_DEVICE_TYPE_NOHOST,
    2108              :   AB_OMP_DEVICE_TYPE_HOST, AB_OMP_DEVICE_TYPE_ANY, AB_OMP_GROUPPRIVATE
    2109              : };
    2110              : 
    2111              : static const mstring attr_bits[] =
    2112              : {
    2113              :     minit ("ALLOCATABLE", AB_ALLOCATABLE),
    2114              :     minit ("ARTIFICIAL", AB_ARTIFICIAL),
    2115              :     minit ("ASYNCHRONOUS", AB_ASYNCHRONOUS),
    2116              :     minit ("DIMENSION", AB_DIMENSION),
    2117              :     minit ("CODIMENSION", AB_CODIMENSION),
    2118              :     minit ("CONTIGUOUS", AB_CONTIGUOUS),
    2119              :     minit ("EXTERNAL", AB_EXTERNAL),
    2120              :     minit ("INTRINSIC", AB_INTRINSIC),
    2121              :     minit ("OPTIONAL", AB_OPTIONAL),
    2122              :     minit ("POINTER", AB_POINTER),
    2123              :     minit ("VOLATILE", AB_VOLATILE),
    2124              :     minit ("TARGET", AB_TARGET),
    2125              :     minit ("THREADPRIVATE", AB_THREADPRIVATE),
    2126              :     minit ("DUMMY", AB_DUMMY),
    2127              :     minit ("RESULT", AB_RESULT),
    2128              :     minit ("DATA", AB_DATA),
    2129              :     minit ("IN_NAMELIST", AB_IN_NAMELIST),
    2130              :     minit ("IN_COMMON", AB_IN_COMMON),
    2131              :     minit ("FUNCTION", AB_FUNCTION),
    2132              :     minit ("SUBROUTINE", AB_SUBROUTINE),
    2133              :     minit ("SEQUENCE", AB_SEQUENCE),
    2134              :     minit ("ELEMENTAL", AB_ELEMENTAL),
    2135              :     minit ("PURE", AB_PURE),
    2136              :     minit ("RECURSIVE", AB_RECURSIVE),
    2137              :     minit ("GENERIC", AB_GENERIC),
    2138              :     minit ("ALWAYS_EXPLICIT", AB_ALWAYS_EXPLICIT),
    2139              :     minit ("CRAY_POINTER", AB_CRAY_POINTER),
    2140              :     minit ("CRAY_POINTEE", AB_CRAY_POINTEE),
    2141              :     minit ("IS_BIND_C", AB_IS_BIND_C),
    2142              :     minit ("IS_C_INTEROP", AB_IS_C_INTEROP),
    2143              :     minit ("IS_ISO_C", AB_IS_ISO_C),
    2144              :     minit ("VALUE", AB_VALUE),
    2145              :     minit ("ALLOC_COMP", AB_ALLOC_COMP),
    2146              :     minit ("COARRAY_COMP", AB_COARRAY_COMP),
    2147              :     minit ("LOCK_COMP", AB_LOCK_COMP),
    2148              :     minit ("EVENT_COMP", AB_EVENT_COMP),
    2149              :     minit ("POINTER_COMP", AB_POINTER_COMP),
    2150              :     minit ("PROC_POINTER_COMP", AB_PROC_POINTER_COMP),
    2151              :     minit ("PRIVATE_COMP", AB_PRIVATE_COMP),
    2152              :     minit ("ZERO_COMP", AB_ZERO_COMP),
    2153              :     minit ("PROTECTED", AB_PROTECTED),
    2154              :     minit ("ABSTRACT", AB_ABSTRACT),
    2155              :     minit ("IS_CLASS", AB_IS_CLASS),
    2156              :     minit ("PROCEDURE", AB_PROCEDURE),
    2157              :     minit ("PROC_POINTER", AB_PROC_POINTER),
    2158              :     minit ("VTYPE", AB_VTYPE),
    2159              :     minit ("VTAB", AB_VTAB),
    2160              :     minit ("CLASS_POINTER", AB_CLASS_POINTER),
    2161              :     minit ("IMPLICIT_PURE", AB_IMPLICIT_PURE),
    2162              :     minit ("UNLIMITED_POLY", AB_UNLIMITED_POLY),
    2163              :     minit ("OMP_DECLARE_TARGET", AB_OMP_DECLARE_TARGET),
    2164              :     minit ("ARRAY_OUTER_DEPENDENCY", AB_ARRAY_OUTER_DEPENDENCY),
    2165              :     minit ("MODULE_PROCEDURE", AB_MODULE_PROCEDURE),
    2166              :     minit ("OACC_DECLARE_CREATE", AB_OACC_DECLARE_CREATE),
    2167              :     minit ("OACC_DECLARE_COPYIN", AB_OACC_DECLARE_COPYIN),
    2168              :     minit ("OACC_DECLARE_DEVICEPTR", AB_OACC_DECLARE_DEVICEPTR),
    2169              :     minit ("OACC_DECLARE_DEVICE_RESIDENT", AB_OACC_DECLARE_DEVICE_RESIDENT),
    2170              :     minit ("OACC_DECLARE_LINK", AB_OACC_DECLARE_LINK),
    2171              :     minit ("OMP_DECLARE_TARGET_LINK", AB_OMP_DECLARE_TARGET_LINK),
    2172              :     minit ("OMP_DECLARE_TARGET_LOCAL", AB_OMP_DECLARE_TARGET_LOCAL),
    2173              :     minit ("OMP_GROUPPRIVATE", AB_OMP_GROUPPRIVATE),
    2174              :     minit ("PDT_KIND", AB_PDT_KIND),
    2175              :     minit ("PDT_LEN", AB_PDT_LEN),
    2176              :     minit ("PDT_TYPE", AB_PDT_TYPE),
    2177              :     minit ("PDT_TEMPLATE", AB_PDT_TEMPLATE),
    2178              :     minit ("PDT_ARRAY", AB_PDT_ARRAY),
    2179              :     minit ("PDT_STRING", AB_PDT_STRING),
    2180              :     minit ("PDT_COMP", AB_PDT_COMP),
    2181              :     minit ("OACC_ROUTINE_LOP_GANG", AB_OACC_ROUTINE_LOP_GANG),
    2182              :     minit ("OACC_ROUTINE_LOP_WORKER", AB_OACC_ROUTINE_LOP_WORKER),
    2183              :     minit ("OACC_ROUTINE_LOP_VECTOR", AB_OACC_ROUTINE_LOP_VECTOR),
    2184              :     minit ("OACC_ROUTINE_LOP_SEQ", AB_OACC_ROUTINE_LOP_SEQ),
    2185              :     minit ("OACC_ROUTINE_NOHOST", AB_OACC_ROUTINE_NOHOST),
    2186              :     minit ("OMP_REQ_REVERSE_OFFLOAD", AB_OMP_REQ_REVERSE_OFFLOAD),
    2187              :     minit ("OMP_REQ_UNIFIED_ADDRESS", AB_OMP_REQ_UNIFIED_ADDRESS),
    2188              :     minit ("OMP_REQ_UNIFIED_SHARED_MEMORY", AB_OMP_REQ_UNIFIED_SHARED_MEMORY),
    2189              :     minit ("OMP_REQ_SELF_MAPS", AB_OMP_REQ_SELF_MAPS),
    2190              :     minit ("OMP_REQ_DYNAMIC_ALLOCATORS", AB_OMP_REQ_DYNAMIC_ALLOCATORS),
    2191              :     minit ("OMP_REQ_MEM_ORDER_SEQ_CST", AB_OMP_REQ_MEM_ORDER_SEQ_CST),
    2192              :     minit ("OMP_REQ_MEM_ORDER_ACQ_REL", AB_OMP_REQ_MEM_ORDER_ACQ_REL),
    2193              :     minit ("OMP_REQ_MEM_ORDER_ACQUIRE", AB_OMP_REQ_MEM_ORDER_ACQUIRE),
    2194              :     minit ("OMP_REQ_MEM_ORDER_RELAXED", AB_OMP_REQ_MEM_ORDER_RELAXED),
    2195              :     minit ("OMP_REQ_MEM_ORDER_RELEASE", AB_OMP_REQ_MEM_ORDER_RELEASE),
    2196              :     minit ("OMP_DEVICE_TYPE_HOST", AB_OMP_DEVICE_TYPE_HOST),
    2197              :     minit ("OMP_DEVICE_TYPE_NOHOST", AB_OMP_DEVICE_TYPE_NOHOST),
    2198              :     minit ("OMP_DEVICE_TYPE_ANYHOST", AB_OMP_DEVICE_TYPE_ANY),
    2199              :     minit (NULL, -1)
    2200              : };
    2201              : 
    2202              : /* For binding attributes.  */
    2203              : static const mstring binding_passing[] =
    2204              : {
    2205              :     minit ("PASS", 0),
    2206              :     minit ("NOPASS", 1),
    2207              :     minit (NULL, -1)
    2208              : };
    2209              : static const mstring binding_overriding[] =
    2210              : {
    2211              :     minit ("OVERRIDABLE", 0),
    2212              :     minit ("NON_OVERRIDABLE", 1),
    2213              :     minit ("DEFERRED", 2),
    2214              :     minit (NULL, -1)
    2215              : };
    2216              : static const mstring binding_generic[] =
    2217              : {
    2218              :     minit ("SPECIFIC", 0),
    2219              :     minit ("GENERIC", 1),
    2220              :     minit (NULL, -1)
    2221              : };
    2222              : static const mstring binding_ppc[] =
    2223              : {
    2224              :     minit ("NO_PPC", 0),
    2225              :     minit ("PPC", 1),
    2226              :     minit (NULL, -1)
    2227              : };
    2228              : 
    2229              : /* Specialization of mio_name.  */
    2230       636314 : DECL_MIO_NAME (ab_attribute)
    2231         3614 : DECL_MIO_NAME (ar_type)
    2232       174092 : DECL_MIO_NAME (array_type)
    2233      6102018 : DECL_MIO_NAME (bt)
    2234       103091 : DECL_MIO_NAME (expr_t)
    2235       626726 : DECL_MIO_NAME (gfc_access)
    2236         1629 : DECL_MIO_NAME (gfc_intrinsic_op)
    2237      1586119 : DECL_MIO_NAME (ifsrc)
    2238      1586119 : DECL_MIO_NAME (save_state)
    2239      1586119 : DECL_MIO_NAME (procedure_type)
    2240         5278 : DECL_MIO_NAME (ref_type)
    2241      1586119 : DECL_MIO_NAME (sym_flavor)
    2242      1586119 : DECL_MIO_NAME (sym_intent)
    2243            0 : DECL_MIO_NAME (inquiry_type)
    2244              : #undef DECL_MIO_NAME
    2245              : 
    2246              : /* Verify OACC_ROUTINE_LOP_NONE.  */
    2247              : 
    2248              : static void
    2249           96 : verify_OACC_ROUTINE_LOP_NONE (enum oacc_routine_lop lop)
    2250              : {
    2251            0 :   if (lop != OACC_ROUTINE_LOP_NONE)
    2252            0 :     bad_module ("Unsupported: multiple OpenACC 'routine' levels of parallelism");
    2253            0 : }
    2254              : 
    2255              : /* Symbol attributes are stored in list with the first three elements
    2256              :    being the enumerated fields, while the remaining elements (if any)
    2257              :    indicate the individual attribute bits.  The access field is not
    2258              :    saved-- it controls what symbols are exported when a module is
    2259              :    written.  */
    2260              : 
    2261              : static void
    2262      1586119 : mio_symbol_attribute (symbol_attribute *attr)
    2263              : {
    2264      1586119 :   atom_type t;
    2265      1586119 :   unsigned ext_attr,extension_level;
    2266              : 
    2267      1586119 :   mio_lparen ();
    2268              : 
    2269      1586119 :   attr->flavor = MIO_NAME (sym_flavor) (attr->flavor, flavors);
    2270      1586119 :   attr->intent = MIO_NAME (sym_intent) (attr->intent, intents);
    2271      1586119 :   attr->proc = MIO_NAME (procedure_type) (attr->proc, procedures);
    2272      1586119 :   attr->if_source = MIO_NAME (ifsrc) (attr->if_source, ifsrc_types);
    2273      1586119 :   attr->save = MIO_NAME (save_state) (attr->save, save_status);
    2274              : 
    2275      1586119 :   ext_attr = attr->ext_attr;
    2276      1586119 :   mio_integer ((int *) &ext_attr);
    2277      1586119 :   attr->ext_attr = ext_attr;
    2278              : 
    2279      1586119 :   extension_level = attr->extension;
    2280      1586119 :   mio_integer ((int *) &extension_level);
    2281      1586119 :   attr->extension = extension_level;
    2282              : 
    2283      1586119 :   if (iomode == IO_OUTPUT)
    2284              :     {
    2285       356040 :       if (attr->allocatable)
    2286         5053 :         MIO_NAME (ab_attribute) (AB_ALLOCATABLE, attr_bits);
    2287       356040 :       if (attr->artificial)
    2288       105165 :         MIO_NAME (ab_attribute) (AB_ARTIFICIAL, attr_bits);
    2289       356040 :       if (attr->asynchronous)
    2290            0 :         MIO_NAME (ab_attribute) (AB_ASYNCHRONOUS, attr_bits);
    2291       356040 :       if (attr->dimension)
    2292        19076 :         MIO_NAME (ab_attribute) (AB_DIMENSION, attr_bits);
    2293       356040 :       if (attr->codimension)
    2294          107 :         MIO_NAME (ab_attribute) (AB_CODIMENSION, attr_bits);
    2295       356040 :       if (attr->contiguous)
    2296         3313 :         MIO_NAME (ab_attribute) (AB_CONTIGUOUS, attr_bits);
    2297       356040 :       if (attr->external)
    2298        15481 :         MIO_NAME (ab_attribute) (AB_EXTERNAL, attr_bits);
    2299       356040 :       if (attr->intrinsic)
    2300         5589 :         MIO_NAME (ab_attribute) (AB_INTRINSIC, attr_bits);
    2301       356040 :       if (attr->optional)
    2302         5344 :         MIO_NAME (ab_attribute) (AB_OPTIONAL, attr_bits);
    2303       356040 :       if (attr->pointer)
    2304        33124 :         MIO_NAME (ab_attribute) (AB_POINTER, attr_bits);
    2305       356040 :       if (attr->class_pointer)
    2306          477 :         MIO_NAME (ab_attribute) (AB_CLASS_POINTER, attr_bits);
    2307       356040 :       if (attr->is_protected)
    2308           70 :         MIO_NAME (ab_attribute) (AB_PROTECTED, attr_bits);
    2309       356040 :       if (attr->value)
    2310        11370 :         MIO_NAME (ab_attribute) (AB_VALUE, attr_bits);
    2311       356040 :       if (attr->volatile_)
    2312           14 :         MIO_NAME (ab_attribute) (AB_VOLATILE, attr_bits);
    2313       356040 :       if (attr->target)
    2314        20269 :         MIO_NAME (ab_attribute) (AB_TARGET, attr_bits);
    2315       356040 :       if (attr->threadprivate)
    2316           42 :         MIO_NAME (ab_attribute) (AB_THREADPRIVATE, attr_bits);
    2317       356040 :       if (attr->dummy)
    2318        84425 :         MIO_NAME (ab_attribute) (AB_DUMMY, attr_bits);
    2319       356040 :       if (attr->result)
    2320         7332 :         MIO_NAME (ab_attribute) (AB_RESULT, attr_bits);
    2321              :       /* We deliberately don't preserve the "entry" flag.  */
    2322              : 
    2323       356040 :       if (attr->data)
    2324           22 :         MIO_NAME (ab_attribute) (AB_DATA, attr_bits);
    2325       356040 :       if (attr->in_namelist)
    2326           78 :         MIO_NAME (ab_attribute) (AB_IN_NAMELIST, attr_bits);
    2327       356040 :       if (attr->in_common)
    2328          392 :         MIO_NAME (ab_attribute) (AB_IN_COMMON, attr_bits);
    2329              : 
    2330       356040 :       if (attr->function)
    2331        34860 :         MIO_NAME (ab_attribute) (AB_FUNCTION, attr_bits);
    2332       356040 :       if (attr->subroutine)
    2333        30029 :         MIO_NAME (ab_attribute) (AB_SUBROUTINE, attr_bits);
    2334       356040 :       if (attr->generic)
    2335         9798 :         MIO_NAME (ab_attribute) (AB_GENERIC, attr_bits);
    2336       356040 :       if (attr->abstract)
    2337         3089 :         MIO_NAME (ab_attribute) (AB_ABSTRACT, attr_bits);
    2338              : 
    2339       356040 :       if (attr->sequence)
    2340          125 :         MIO_NAME (ab_attribute) (AB_SEQUENCE, attr_bits);
    2341       356040 :       if (attr->elemental)
    2342        16073 :         MIO_NAME (ab_attribute) (AB_ELEMENTAL, attr_bits);
    2343       356040 :       if (attr->pure)
    2344        19640 :         MIO_NAME (ab_attribute) (AB_PURE, attr_bits);
    2345       356040 :       if (attr->implicit_pure)
    2346         4371 :         MIO_NAME (ab_attribute) (AB_IMPLICIT_PURE, attr_bits);
    2347       356040 :       if (attr->unlimited_polymorphic)
    2348          376 :         MIO_NAME (ab_attribute) (AB_UNLIMITED_POLY, attr_bits);
    2349       356040 :       if (attr->recursive)
    2350         3045 :         MIO_NAME (ab_attribute) (AB_RECURSIVE, attr_bits);
    2351       356040 :       if (attr->always_explicit)
    2352        30955 :         MIO_NAME (ab_attribute) (AB_ALWAYS_EXPLICIT, attr_bits);
    2353       356040 :       if (attr->cray_pointer)
    2354           13 :         MIO_NAME (ab_attribute) (AB_CRAY_POINTER, attr_bits);
    2355       356040 :       if (attr->cray_pointee)
    2356           13 :         MIO_NAME (ab_attribute) (AB_CRAY_POINTEE, attr_bits);
    2357       356040 :       if (attr->is_bind_c)
    2358         6678 :         MIO_NAME(ab_attribute) (AB_IS_BIND_C, attr_bits);
    2359       356040 :       if (attr->is_c_interop)
    2360        30649 :         MIO_NAME(ab_attribute) (AB_IS_C_INTEROP, attr_bits);
    2361       356040 :       if (attr->is_iso_c)
    2362        26700 :         MIO_NAME(ab_attribute) (AB_IS_ISO_C, attr_bits);
    2363       356040 :       if (attr->alloc_comp)
    2364         3103 :         MIO_NAME (ab_attribute) (AB_ALLOC_COMP, attr_bits);
    2365       356040 :       if (attr->pointer_comp)
    2366          946 :         MIO_NAME (ab_attribute) (AB_POINTER_COMP, attr_bits);
    2367       356040 :       if (attr->proc_pointer_comp)
    2368          269 :         MIO_NAME (ab_attribute) (AB_PROC_POINTER_COMP, attr_bits);
    2369       356040 :       if (attr->private_comp)
    2370         3285 :         MIO_NAME (ab_attribute) (AB_PRIVATE_COMP, attr_bits);
    2371       356040 :       if (attr->coarray_comp)
    2372           33 :         MIO_NAME (ab_attribute) (AB_COARRAY_COMP, attr_bits);
    2373       356040 :       if (attr->lock_comp)
    2374            4 :         MIO_NAME (ab_attribute) (AB_LOCK_COMP, attr_bits);
    2375       356040 :       if (attr->event_comp)
    2376            0 :         MIO_NAME (ab_attribute) (AB_EVENT_COMP, attr_bits);
    2377       356040 :       if (attr->zero_comp)
    2378         2237 :         MIO_NAME (ab_attribute) (AB_ZERO_COMP, attr_bits);
    2379       356040 :       if (attr->is_class)
    2380         4850 :         MIO_NAME (ab_attribute) (AB_IS_CLASS, attr_bits);
    2381       356040 :       if (attr->procedure)
    2382         5764 :         MIO_NAME (ab_attribute) (AB_PROCEDURE, attr_bits);
    2383       356040 :       if (attr->proc_pointer)
    2384        38176 :         MIO_NAME (ab_attribute) (AB_PROC_POINTER, attr_bits);
    2385       356040 :       if (attr->vtype)
    2386        10943 :         MIO_NAME (ab_attribute) (AB_VTYPE, attr_bits);
    2387       356040 :       if (attr->vtab)
    2388        10398 :         MIO_NAME (ab_attribute) (AB_VTAB, attr_bits);
    2389       356040 :       if (attr->omp_declare_target)
    2390          423 :         MIO_NAME (ab_attribute) (AB_OMP_DECLARE_TARGET, attr_bits);
    2391       356040 :       if (attr->array_outer_dependency)
    2392        18235 :         MIO_NAME (ab_attribute) (AB_ARRAY_OUTER_DEPENDENCY, attr_bits);
    2393       356040 :       if (attr->module_procedure)
    2394         1636 :         MIO_NAME (ab_attribute) (AB_MODULE_PROCEDURE, attr_bits);
    2395       356040 :       if (attr->oacc_declare_create)
    2396           39 :         MIO_NAME (ab_attribute) (AB_OACC_DECLARE_CREATE, attr_bits);
    2397       356040 :       if (attr->oacc_declare_copyin)
    2398            7 :         MIO_NAME (ab_attribute) (AB_OACC_DECLARE_COPYIN, attr_bits);
    2399       356040 :       if (attr->oacc_declare_deviceptr)
    2400            1 :         MIO_NAME (ab_attribute) (AB_OACC_DECLARE_DEVICEPTR, attr_bits);
    2401       356040 :       if (attr->oacc_declare_device_resident)
    2402           33 :         MIO_NAME (ab_attribute) (AB_OACC_DECLARE_DEVICE_RESIDENT, attr_bits);
    2403       356040 :       if (attr->oacc_declare_link)
    2404            1 :         MIO_NAME (ab_attribute) (AB_OACC_DECLARE_LINK, attr_bits);
    2405       356040 :       if (attr->omp_declare_target_link)
    2406           15 :         MIO_NAME (ab_attribute) (AB_OMP_DECLARE_TARGET_LINK, attr_bits);
    2407       356040 :       if (attr->omp_declare_target_local)
    2408           12 :         MIO_NAME (ab_attribute) (AB_OMP_DECLARE_TARGET_LOCAL, attr_bits);
    2409       356040 :       if (attr->omp_groupprivate)
    2410           12 :         MIO_NAME (ab_attribute) (AB_OMP_GROUPPRIVATE, attr_bits);
    2411       356040 :       if (attr->pdt_kind)
    2412          934 :         MIO_NAME (ab_attribute) (AB_PDT_KIND, attr_bits);
    2413       356040 :       if (attr->pdt_len)
    2414          464 :         MIO_NAME (ab_attribute) (AB_PDT_LEN, attr_bits);
    2415       356040 :       if (attr->pdt_type)
    2416          384 :         MIO_NAME (ab_attribute) (AB_PDT_TYPE, attr_bits);
    2417       356040 :       if (attr->pdt_comp)
    2418           27 :         MIO_NAME (ab_attribute) (AB_PDT_COMP , attr_bits);
    2419       356040 :       if (attr->pdt_template)
    2420          373 :         MIO_NAME (ab_attribute) (AB_PDT_TEMPLATE, attr_bits);
    2421       356040 :       if (attr->pdt_array)
    2422           75 :         MIO_NAME (ab_attribute) (AB_PDT_ARRAY, attr_bits);
    2423       356040 :       if (attr->pdt_string)
    2424            2 :         MIO_NAME (ab_attribute) (AB_PDT_STRING, attr_bits);
    2425       356040 :       switch (attr->oacc_routine_lop)
    2426              :         {
    2427              :         case OACC_ROUTINE_LOP_NONE:
    2428              :           /* This is the default anyway, and for maintaining compatibility with
    2429              :              the current MOD_VERSION, we're not emitting anything in that
    2430              :              case.  */
    2431              :           break;
    2432           12 :         case OACC_ROUTINE_LOP_GANG:
    2433           12 :           MIO_NAME (ab_attribute) (AB_OACC_ROUTINE_LOP_GANG, attr_bits);
    2434           12 :           break;
    2435           10 :         case OACC_ROUTINE_LOP_WORKER:
    2436           10 :           MIO_NAME (ab_attribute) (AB_OACC_ROUTINE_LOP_WORKER, attr_bits);
    2437           10 :           break;
    2438            8 :         case OACC_ROUTINE_LOP_VECTOR:
    2439            8 :           MIO_NAME (ab_attribute) (AB_OACC_ROUTINE_LOP_VECTOR, attr_bits);
    2440            8 :           break;
    2441           81 :         case OACC_ROUTINE_LOP_SEQ:
    2442           81 :           MIO_NAME (ab_attribute) (AB_OACC_ROUTINE_LOP_SEQ, attr_bits);
    2443           81 :           break;
    2444            0 :         case OACC_ROUTINE_LOP_ERROR:
    2445              :           /* ... intentionally omitted here; it's only used internally.  */
    2446            0 :         default:
    2447            0 :           gcc_unreachable ();
    2448              :         }
    2449       356040 :       if (attr->oacc_routine_nohost)
    2450           21 :         MIO_NAME (ab_attribute) (AB_OACC_ROUTINE_NOHOST, attr_bits);
    2451              : 
    2452       356040 :       if (attr->flavor == FL_MODULE && gfc_current_ns->omp_requires)
    2453              :         {
    2454           29 :           if (gfc_current_ns->omp_requires & OMP_REQ_REVERSE_OFFLOAD)
    2455           15 :             MIO_NAME (ab_attribute) (AB_OMP_REQ_REVERSE_OFFLOAD, attr_bits);
    2456           29 :           if (gfc_current_ns->omp_requires & OMP_REQ_UNIFIED_ADDRESS)
    2457            1 :             MIO_NAME (ab_attribute) (AB_OMP_REQ_UNIFIED_ADDRESS, attr_bits);
    2458           29 :           if (gfc_current_ns->omp_requires & OMP_REQ_UNIFIED_SHARED_MEMORY)
    2459            3 :             MIO_NAME (ab_attribute) (AB_OMP_REQ_UNIFIED_SHARED_MEMORY, attr_bits);
    2460           29 :           if (gfc_current_ns->omp_requires & OMP_REQ_SELF_MAPS)
    2461            1 :             MIO_NAME (ab_attribute) (AB_OMP_REQ_SELF_MAPS, attr_bits);
    2462           29 :           if (gfc_current_ns->omp_requires & OMP_REQ_DYNAMIC_ALLOCATORS)
    2463            2 :             MIO_NAME (ab_attribute) (AB_OMP_REQ_DYNAMIC_ALLOCATORS, attr_bits);
    2464           29 :           if ((gfc_current_ns->omp_requires & OMP_REQ_ATOMIC_MEM_ORDER_MASK)
    2465              :               == OMP_REQ_ATOMIC_MEM_ORDER_SEQ_CST)
    2466            3 :             MIO_NAME (ab_attribute) (AB_OMP_REQ_MEM_ORDER_SEQ_CST, attr_bits);
    2467           29 :           if ((gfc_current_ns->omp_requires & OMP_REQ_ATOMIC_MEM_ORDER_MASK)
    2468              :               == OMP_REQ_ATOMIC_MEM_ORDER_ACQ_REL)
    2469            3 :             MIO_NAME (ab_attribute) (AB_OMP_REQ_MEM_ORDER_ACQ_REL, attr_bits);
    2470           29 :           if ((gfc_current_ns->omp_requires & OMP_REQ_ATOMIC_MEM_ORDER_MASK)
    2471              :               == OMP_REQ_ATOMIC_MEM_ORDER_ACQUIRE)
    2472            0 :             MIO_NAME (ab_attribute) (AB_OMP_REQ_MEM_ORDER_ACQUIRE, attr_bits);
    2473           29 :           if ((gfc_current_ns->omp_requires & OMP_REQ_ATOMIC_MEM_ORDER_MASK)
    2474              :               == OMP_REQ_ATOMIC_MEM_ORDER_RELAXED)
    2475            3 :             MIO_NAME (ab_attribute) (AB_OMP_REQ_MEM_ORDER_RELAXED, attr_bits);
    2476           29 :           if ((gfc_current_ns->omp_requires & OMP_REQ_ATOMIC_MEM_ORDER_MASK)
    2477              :               == OMP_REQ_ATOMIC_MEM_ORDER_RELEASE)
    2478            0 :             MIO_NAME (ab_attribute) (AB_OMP_REQ_MEM_ORDER_RELEASE, attr_bits);
    2479              :         }
    2480       356040 :       switch (attr->omp_device_type)
    2481              :         {
    2482              :         case OMP_DEVICE_TYPE_UNSET:
    2483              :           break;
    2484           16 :         case OMP_DEVICE_TYPE_HOST:
    2485           16 :           MIO_NAME (ab_attribute) (AB_OMP_DEVICE_TYPE_HOST, attr_bits);
    2486           16 :           break;
    2487            9 :         case OMP_DEVICE_TYPE_NOHOST:
    2488            9 :           MIO_NAME (ab_attribute) (AB_OMP_DEVICE_TYPE_NOHOST, attr_bits);
    2489            9 :           break;
    2490          288 :         case OMP_DEVICE_TYPE_ANY:
    2491          288 :           MIO_NAME (ab_attribute) (AB_OMP_DEVICE_TYPE_ANY, attr_bits);
    2492          288 :           break;
    2493            0 :         default:
    2494            0 :           gcc_unreachable ();
    2495              :         }
    2496       356040 :       mio_rparen ();
    2497              :     }
    2498              :   else
    2499              :     {
    2500      3475785 :       for (;;)
    2501              :         {
    2502      3475785 :           t = parse_atom ();
    2503      3475785 :           if (t == ATOM_RPAREN)
    2504              :             break;
    2505      2245706 :           if (t != ATOM_NAME)
    2506            0 :             bad_module ("Expected attribute bit name");
    2507              : 
    2508      2245706 :           switch ((ab_attribute) find_enum (attr_bits))
    2509              :             {
    2510         4886 :             case AB_ALLOCATABLE:
    2511         4886 :               attr->allocatable = 1;
    2512         4886 :               break;
    2513       145379 :             case AB_ARTIFICIAL:
    2514       145379 :               attr->artificial = 1;
    2515       145379 :               break;
    2516            0 :             case AB_ASYNCHRONOUS:
    2517            0 :               attr->asynchronous = 1;
    2518            0 :               break;
    2519        67822 :             case AB_DIMENSION:
    2520        67822 :               attr->dimension = 1;
    2521        67822 :               break;
    2522          103 :             case AB_CODIMENSION:
    2523          103 :               attr->codimension = 1;
    2524          103 :               break;
    2525         8799 :             case AB_CONTIGUOUS:
    2526         8799 :               attr->contiguous = 1;
    2527         8799 :               break;
    2528       196584 :             case AB_EXTERNAL:
    2529       196584 :               attr->external = 1;
    2530       196584 :               break;
    2531         3663 :             case AB_INTRINSIC:
    2532         3663 :               attr->intrinsic = 1;
    2533         3663 :               break;
    2534         9514 :             case AB_OPTIONAL:
    2535         9514 :               attr->optional = 1;
    2536         9514 :               break;
    2537        45049 :             case AB_POINTER:
    2538        45049 :               attr->pointer = 1;
    2539        45049 :               break;
    2540          417 :             case AB_CLASS_POINTER:
    2541          417 :               attr->class_pointer = 1;
    2542          417 :               break;
    2543           62 :             case AB_PROTECTED:
    2544           62 :               attr->is_protected = 1;
    2545           62 :               break;
    2546        89049 :             case AB_VALUE:
    2547        89049 :               attr->value = 1;
    2548        89049 :               break;
    2549           15 :             case AB_VOLATILE:
    2550           15 :               attr->volatile_ = 1;
    2551           15 :               break;
    2552        28314 :             case AB_TARGET:
    2553        28314 :               attr->target = 1;
    2554        28314 :               break;
    2555           52 :             case AB_THREADPRIVATE:
    2556           52 :               attr->threadprivate = 1;
    2557           52 :               break;
    2558       435115 :             case AB_DUMMY:
    2559       435115 :               attr->dummy = 1;
    2560       435115 :               break;
    2561        34167 :             case AB_RESULT:
    2562        34167 :               attr->result = 1;
    2563        34167 :               break;
    2564           22 :             case AB_DATA:
    2565           22 :               attr->data = 1;
    2566           22 :               break;
    2567           83 :             case AB_IN_NAMELIST:
    2568           83 :               attr->in_namelist = 1;
    2569           83 :               break;
    2570          301 :             case AB_IN_COMMON:
    2571          301 :               attr->in_common = 1;
    2572          301 :               break;
    2573       191543 :             case AB_FUNCTION:
    2574       191543 :               attr->function = 1;
    2575       191543 :               break;
    2576        88068 :             case AB_SUBROUTINE:
    2577        88068 :               attr->subroutine = 1;
    2578        88068 :               break;
    2579        28514 :             case AB_GENERIC:
    2580        28514 :               attr->generic = 1;
    2581        28514 :               break;
    2582         2368 :             case AB_ABSTRACT:
    2583         2368 :               attr->abstract = 1;
    2584         2368 :               break;
    2585          137 :             case AB_SEQUENCE:
    2586          137 :               attr->sequence = 1;
    2587          137 :               break;
    2588        93320 :             case AB_ELEMENTAL:
    2589        93320 :               attr->elemental = 1;
    2590        93320 :               break;
    2591       118820 :             case AB_PURE:
    2592       118820 :               attr->pure = 1;
    2593       118820 :               break;
    2594         4400 :             case AB_IMPLICIT_PURE:
    2595         4400 :               attr->implicit_pure = 1;
    2596         4400 :               break;
    2597          341 :             case AB_UNLIMITED_POLY:
    2598          341 :               attr->unlimited_polymorphic = 1;
    2599          341 :               break;
    2600         3019 :             case AB_RECURSIVE:
    2601         3019 :               attr->recursive = 1;
    2602         3019 :               break;
    2603       156991 :             case AB_ALWAYS_EXPLICIT:
    2604       156991 :               attr->always_explicit = 1;
    2605       156991 :               break;
    2606           13 :             case AB_CRAY_POINTER:
    2607           13 :               attr->cray_pointer = 1;
    2608           13 :               break;
    2609           13 :             case AB_CRAY_POINTEE:
    2610           13 :               attr->cray_pointee = 1;
    2611           13 :               break;
    2612        47409 :             case AB_IS_BIND_C:
    2613        47409 :               attr->is_bind_c = 1;
    2614        47409 :               break;
    2615        80067 :             case AB_IS_C_INTEROP:
    2616        80067 :               attr->is_c_interop = 1;
    2617        80067 :               break;
    2618        28506 :             case AB_IS_ISO_C:
    2619        28506 :               attr->is_iso_c = 1;
    2620        28506 :               break;
    2621         2920 :             case AB_ALLOC_COMP:
    2622         2920 :               attr->alloc_comp = 1;
    2623         2920 :               break;
    2624           22 :             case AB_COARRAY_COMP:
    2625           22 :               attr->coarray_comp = 1;
    2626           22 :               break;
    2627            4 :             case AB_LOCK_COMP:
    2628            4 :               attr->lock_comp = 1;
    2629            4 :               break;
    2630            0 :             case AB_EVENT_COMP:
    2631            0 :               attr->event_comp = 1;
    2632            0 :               break;
    2633          884 :             case AB_POINTER_COMP:
    2634          884 :               attr->pointer_comp = 1;
    2635          884 :               break;
    2636          257 :             case AB_PROC_POINTER_COMP:
    2637          257 :               attr->proc_pointer_comp = 1;
    2638          257 :               break;
    2639        20594 :             case AB_PRIVATE_COMP:
    2640        20594 :               attr->private_comp = 1;
    2641        20594 :               break;
    2642         1883 :             case AB_ZERO_COMP:
    2643         1883 :               attr->zero_comp = 1;
    2644         1883 :               break;
    2645         4318 :             case AB_IS_CLASS:
    2646         4318 :               attr->is_class = 1;
    2647         4318 :               break;
    2648         5137 :             case AB_PROCEDURE:
    2649         5137 :               attr->procedure = 1;
    2650         5137 :               break;
    2651        51089 :             case AB_PROC_POINTER:
    2652        51089 :               attr->proc_pointer = 1;
    2653        51089 :               break;
    2654        15433 :             case AB_VTYPE:
    2655        15433 :               attr->vtype = 1;
    2656        15433 :               break;
    2657        15127 :             case AB_VTAB:
    2658        15127 :               attr->vtab = 1;
    2659        15127 :               break;
    2660          444 :             case AB_OMP_DECLARE_TARGET:
    2661          444 :               attr->omp_declare_target = 1;
    2662          444 :               break;
    2663           10 :             case AB_OMP_DECLARE_TARGET_LINK:
    2664           10 :               attr->omp_declare_target_link = 1;
    2665           10 :               break;
    2666            0 :             case AB_OMP_DECLARE_TARGET_LOCAL:
    2667            0 :               attr->omp_declare_target_local = 1;
    2668            0 :               break;
    2669            0 :             case AB_OMP_GROUPPRIVATE:
    2670            0 :               attr->omp_groupprivate = 1;
    2671            0 :               break;
    2672       210833 :             case AB_ARRAY_OUTER_DEPENDENCY:
    2673       210833 :               attr->array_outer_dependency =1;
    2674       210833 :               break;
    2675         1092 :             case AB_MODULE_PROCEDURE:
    2676         1092 :               attr->module_procedure =1;
    2677         1092 :               break;
    2678          110 :             case AB_OACC_DECLARE_CREATE:
    2679          110 :               attr->oacc_declare_create = 1;
    2680          110 :               break;
    2681            2 :             case AB_OACC_DECLARE_COPYIN:
    2682            2 :               attr->oacc_declare_copyin = 1;
    2683            2 :               break;
    2684            0 :             case AB_OACC_DECLARE_DEVICEPTR:
    2685            0 :               attr->oacc_declare_deviceptr = 1;
    2686            0 :               break;
    2687           34 :             case AB_OACC_DECLARE_DEVICE_RESIDENT:
    2688           34 :               attr->oacc_declare_device_resident = 1;
    2689           34 :               break;
    2690            2 :             case AB_OACC_DECLARE_LINK:
    2691            2 :               attr->oacc_declare_link = 1;
    2692            2 :               break;
    2693          886 :             case AB_PDT_KIND:
    2694          886 :               attr->pdt_kind = 1;
    2695          886 :               break;
    2696          466 :             case AB_PDT_LEN:
    2697          466 :               attr->pdt_len = 1;
    2698          466 :               break;
    2699          338 :             case AB_PDT_TYPE:
    2700          338 :               attr->pdt_type = 1;
    2701          338 :               break;
    2702           16 :             case AB_PDT_COMP:
    2703           16 :               attr->pdt_comp = 1;
    2704           16 :               break;
    2705          348 :             case AB_PDT_TEMPLATE:
    2706          348 :               attr->pdt_template = 1;
    2707          348 :               break;
    2708           75 :             case AB_PDT_ARRAY:
    2709           75 :               attr->pdt_array = 1;
    2710           75 :               break;
    2711            0 :             case AB_PDT_STRING:
    2712            0 :               attr->pdt_string = 1;
    2713            0 :               break;
    2714            8 :             case AB_OACC_ROUTINE_LOP_GANG:
    2715            8 :               verify_OACC_ROUTINE_LOP_NONE (attr->oacc_routine_lop);
    2716            8 :               attr->oacc_routine_lop = OACC_ROUTINE_LOP_GANG;
    2717            8 :               break;
    2718            8 :             case AB_OACC_ROUTINE_LOP_WORKER:
    2719            8 :               verify_OACC_ROUTINE_LOP_NONE (attr->oacc_routine_lop);
    2720            8 :               attr->oacc_routine_lop = OACC_ROUTINE_LOP_WORKER;
    2721            8 :               break;
    2722            8 :             case AB_OACC_ROUTINE_LOP_VECTOR:
    2723            8 :               verify_OACC_ROUTINE_LOP_NONE (attr->oacc_routine_lop);
    2724            8 :               attr->oacc_routine_lop = OACC_ROUTINE_LOP_VECTOR;
    2725            8 :               break;
    2726           72 :             case AB_OACC_ROUTINE_LOP_SEQ:
    2727           72 :               verify_OACC_ROUTINE_LOP_NONE (attr->oacc_routine_lop);
    2728           72 :               attr->oacc_routine_lop = OACC_ROUTINE_LOP_SEQ;
    2729           72 :               break;
    2730           20 :             case AB_OACC_ROUTINE_NOHOST:
    2731           20 :               attr->oacc_routine_nohost = 1;
    2732           20 :               break;
    2733           24 :             case AB_OMP_REQ_REVERSE_OFFLOAD:
    2734           24 :               gfc_omp_requires_add_clause (OMP_REQ_REVERSE_OFFLOAD,
    2735              :                                            "reverse_offload",
    2736              :                                            &gfc_current_locus,
    2737              :                                            module_name);
    2738           24 :               break;
    2739            0 :             case AB_OMP_REQ_UNIFIED_ADDRESS:
    2740            0 :               gfc_omp_requires_add_clause (OMP_REQ_UNIFIED_ADDRESS,
    2741              :                                            "unified_address",
    2742              :                                            &gfc_current_locus,
    2743              :                                            module_name);
    2744            0 :               break;
    2745            0 :             case AB_OMP_REQ_UNIFIED_SHARED_MEMORY:
    2746            0 :               gfc_omp_requires_add_clause (OMP_REQ_UNIFIED_SHARED_MEMORY,
    2747              :                                            "unified_shared_memory",
    2748              :                                            &gfc_current_locus,
    2749              :                                            module_name);
    2750            0 :               break;
    2751            1 :             case AB_OMP_REQ_SELF_MAPS:
    2752            1 :               gfc_omp_requires_add_clause (OMP_REQ_SELF_MAPS,
    2753              :                                            "self_maps",
    2754              :                                            &gfc_current_locus,
    2755              :                                            module_name);
    2756            1 :               break;
    2757            0 :             case AB_OMP_REQ_DYNAMIC_ALLOCATORS:
    2758            0 :               gfc_omp_requires_add_clause (OMP_REQ_DYNAMIC_ALLOCATORS,
    2759              :                                            "dynamic_allocators",
    2760              :                                            &gfc_current_locus,
    2761              :                                            module_name);
    2762            0 :               break;
    2763            2 :             case AB_OMP_REQ_MEM_ORDER_SEQ_CST:
    2764            2 :               gfc_omp_requires_add_clause (OMP_REQ_ATOMIC_MEM_ORDER_SEQ_CST,
    2765              :                                            "seq_cst", &gfc_current_locus,
    2766              :                                            module_name);
    2767            2 :               break;
    2768            2 :             case AB_OMP_REQ_MEM_ORDER_ACQ_REL:
    2769            2 :               gfc_omp_requires_add_clause (OMP_REQ_ATOMIC_MEM_ORDER_ACQ_REL,
    2770              :                                            "acq_rel", &gfc_current_locus,
    2771              :                                            module_name);
    2772            2 :               break;
    2773            0 :             case AB_OMP_REQ_MEM_ORDER_ACQUIRE:
    2774            0 :               gfc_omp_requires_add_clause (OMP_REQ_ATOMIC_MEM_ORDER_ACQUIRE,
    2775              :                                            "acquires", &gfc_current_locus,
    2776              :                                            module_name);
    2777            0 :               break;
    2778            2 :             case AB_OMP_REQ_MEM_ORDER_RELAXED:
    2779            2 :               gfc_omp_requires_add_clause (OMP_REQ_ATOMIC_MEM_ORDER_RELAXED,
    2780              :                                            "relaxed", &gfc_current_locus,
    2781              :                                            module_name);
    2782            2 :               break;
    2783            0 :             case AB_OMP_REQ_MEM_ORDER_RELEASE:
    2784            0 :               gfc_omp_requires_add_clause (OMP_REQ_ATOMIC_MEM_ORDER_RELEASE,
    2785              :                                            "release", &gfc_current_locus,
    2786              :                                            module_name);
    2787            0 :               break;
    2788            8 :             case AB_OMP_DEVICE_TYPE_HOST:
    2789            8 :               attr->omp_device_type = OMP_DEVICE_TYPE_HOST;
    2790            8 :               break;
    2791            5 :             case AB_OMP_DEVICE_TYPE_NOHOST:
    2792            5 :               attr->omp_device_type = OMP_DEVICE_TYPE_NOHOST;
    2793            5 :               break;
    2794          297 :             case AB_OMP_DEVICE_TYPE_ANY:
    2795          297 :               attr->omp_device_type = OMP_DEVICE_TYPE_ANY;
    2796          297 :               break;
    2797              :             }
    2798              :         }
    2799              :     }
    2800      1586119 : }
    2801              : 
    2802              : 
    2803              : static const mstring bt_types[] = {
    2804              :     minit ("INTEGER", BT_INTEGER),
    2805              :     minit ("REAL", BT_REAL),
    2806              :     minit ("COMPLEX", BT_COMPLEX),
    2807              :     minit ("LOGICAL", BT_LOGICAL),
    2808              :     minit ("CHARACTER", BT_CHARACTER),
    2809              :     minit ("UNION", BT_UNION),
    2810              :     minit ("DERIVED", BT_DERIVED),
    2811              :     minit ("CLASS", BT_CLASS),
    2812              :     minit ("PROCEDURE", BT_PROCEDURE),
    2813              :     minit ("UNKNOWN", BT_UNKNOWN),
    2814              :     minit ("VOID", BT_VOID),
    2815              :     minit ("ASSUMED", BT_ASSUMED),
    2816              :     minit ("UNSIGNED", BT_UNSIGNED),
    2817              :     minit (NULL, -1)
    2818              : };
    2819              : 
    2820              : 
    2821              : static void
    2822        41613 : mio_charlen (gfc_charlen **clp)
    2823              : {
    2824        41613 :   gfc_charlen *cl;
    2825              : 
    2826        41613 :   mio_lparen ();
    2827              : 
    2828        41613 :   if (iomode == IO_OUTPUT)
    2829              :     {
    2830        19560 :       cl = *clp;
    2831        19560 :       if (cl != NULL)
    2832        18794 :         mio_expr (&cl->length);
    2833              :     }
    2834              :   else
    2835              :     {
    2836        22053 :       if (peek_atom () != ATOM_RPAREN)
    2837              :         {
    2838        21589 :           cl = gfc_new_charlen (gfc_current_ns, NULL);
    2839        21589 :           mio_expr (&cl->length);
    2840        21589 :           *clp = cl;
    2841              :         }
    2842              :     }
    2843              : 
    2844        41613 :   mio_rparen ();
    2845        41613 : }
    2846              : 
    2847              : 
    2848              : /* See if a name is a generated name.  */
    2849              : 
    2850              : static int
    2851       782048 : check_unique_name (const char *name)
    2852              : {
    2853       782048 :   return *name == '@';
    2854              : }
    2855              : 
    2856              : 
    2857              : static void
    2858      2034006 : mio_typespec (gfc_typespec *ts)
    2859              : {
    2860      2034006 :   mio_lparen ();
    2861              : 
    2862      2034006 :   ts->type = MIO_NAME (bt) (ts->type, bt_types);
    2863              : 
    2864      2034006 :   if (!gfc_bt_struct (ts->type) && ts->type != BT_CLASS)
    2865      1722449 :     mio_integer (&ts->kind);
    2866              :   else
    2867       311557 :     mio_symbol_ref (&ts->u.derived);
    2868              : 
    2869      2034006 :   mio_symbol_ref (&ts->interface);
    2870              : 
    2871              :   /* Add info for C interop and is_iso_c.  */
    2872      2034006 :   mio_integer (&ts->is_c_interop);
    2873      2034006 :   mio_integer (&ts->is_iso_c);
    2874              : 
    2875              :   /* If the typespec is for an identifier either from iso_c_binding, or
    2876              :      a constant that was initialized to an identifier from it, use the
    2877              :      f90_type.  Otherwise, use the ts->type, since it shouldn't matter.  */
    2878      2034006 :   if (ts->is_iso_c)
    2879       126729 :     ts->f90_type = MIO_NAME (bt) (ts->f90_type, bt_types);
    2880              :   else
    2881      1907277 :     ts->f90_type = MIO_NAME (bt) (ts->type, bt_types);
    2882              : 
    2883      2034006 :   if (ts->type != BT_CHARACTER)
    2884              :     {
    2885              :       /* ts->u.cl is only valid for BT_CHARACTER.  */
    2886      1992399 :       mio_lparen ();
    2887      1992399 :       mio_rparen ();
    2888              :     }
    2889              :   else
    2890        41607 :     mio_charlen (&ts->u.cl);
    2891              : 
    2892              :   /* So as not to disturb the existing API, use an ATOM_NAME to
    2893              :      transmit deferred characteristic for characters (F2003).  */
    2894      2034006 :   if (iomode == IO_OUTPUT)
    2895              :     {
    2896       459221 :       if (ts->type == BT_CHARACTER && ts->deferred)
    2897          742 :         write_atom (ATOM_NAME, "DEFERRED_CL");
    2898              :     }
    2899      1574785 :   else if (peek_atom () != ATOM_RPAREN)
    2900              :     {
    2901         4879 :       if (parse_atom () != ATOM_NAME)
    2902            0 :         bad_module ("Expected string");
    2903         4879 :       ts->deferred = 1;
    2904              :     }
    2905              : 
    2906      2034006 :   mio_rparen ();
    2907      2034006 : }
    2908              : 
    2909              : 
    2910              : static const mstring array_spec_types[] = {
    2911              :     minit ("EXPLICIT", AS_EXPLICIT),
    2912              :     minit ("ASSUMED_RANK", AS_ASSUMED_RANK),
    2913              :     minit ("ASSUMED_SHAPE", AS_ASSUMED_SHAPE),
    2914              :     minit ("DEFERRED", AS_DEFERRED),
    2915              :     minit ("ASSUMED_SIZE", AS_ASSUMED_SIZE),
    2916              :     minit (NULL, -1)
    2917              : };
    2918              : 
    2919              : 
    2920              : static void
    2921      1586099 : mio_array_spec (gfc_array_spec **asp)
    2922              : {
    2923      1586099 :   gfc_array_spec *as;
    2924      1586099 :   int i;
    2925              : 
    2926      1586099 :   mio_lparen ();
    2927              : 
    2928      1586099 :   if (iomode == IO_OUTPUT)
    2929              :     {
    2930       356040 :       int rank;
    2931              : 
    2932       356040 :       if (*asp == NULL)
    2933       336893 :         goto done;
    2934        19147 :       as = *asp;
    2935              : 
    2936              :       /* mio_integer expects nonnegative values.  */
    2937        19147 :       rank = as->rank > 0 ? as->rank : 0;
    2938        19147 :       mio_integer (&rank);
    2939              :     }
    2940              :   else
    2941              :     {
    2942      1230059 :       if (peek_atom () == ATOM_RPAREN)
    2943              :         {
    2944      1162160 :           *asp = NULL;
    2945      1162160 :           goto done;
    2946              :         }
    2947              : 
    2948        67899 :       *asp = as = gfc_get_array_spec ();
    2949        67899 :       mio_integer (&as->rank);
    2950              :     }
    2951              : 
    2952        87046 :   mio_integer (&as->corank);
    2953        87046 :   as->type = MIO_NAME (array_type) (as->type, array_spec_types);
    2954              : 
    2955        87046 :   if (iomode == IO_INPUT && as->type == AS_ASSUMED_RANK)
    2956        24946 :     as->rank = -1;
    2957        87046 :   if (iomode == IO_INPUT && as->corank)
    2958          166 :     as->cotype = (as->type == AS_DEFERRED) ? AS_DEFERRED : AS_EXPLICIT;
    2959              : 
    2960        87046 :   if (as->rank + as->corank > 0)
    2961       121455 :     for (i = 0; i < as->rank + as->corank; i++)
    2962              :       {
    2963        63540 :         mio_expr (&as->lower[i]);
    2964        63540 :         mio_expr (&as->upper[i]);
    2965              :       }
    2966              : 
    2967        29131 : done:
    2968      1586099 :   mio_rparen ();
    2969      1586099 : }
    2970              : 
    2971              : 
    2972              : /* Given a pointer to an array reference structure (which lives in a
    2973              :    gfc_ref structure), find the corresponding array specification
    2974              :    structure.  Storing the pointer in the ref structure doesn't quite
    2975              :    work when loading from a module. Generating code for an array
    2976              :    reference also needs more information than just the array spec.  */
    2977              : 
    2978              : static const mstring array_ref_types[] = {
    2979              :     minit ("FULL", AR_FULL),
    2980              :     minit ("ELEMENT", AR_ELEMENT),
    2981              :     minit ("SECTION", AR_SECTION),
    2982              :     minit (NULL, -1)
    2983              : };
    2984              : 
    2985              : 
    2986              : static void
    2987         1807 : mio_array_ref (gfc_array_ref *ar)
    2988              : {
    2989         1807 :   int i;
    2990              : 
    2991         1807 :   mio_lparen ();
    2992         1807 :   ar->type = MIO_NAME (ar_type) (ar->type, array_ref_types);
    2993         1807 :   mio_integer (&ar->dimen);
    2994              : 
    2995         1807 :   switch (ar->type)
    2996              :     {
    2997              :     case AR_FULL:
    2998              :       break;
    2999              : 
    3000              :     case AR_ELEMENT:
    3001          982 :       for (i = 0; i < ar->dimen; i++)
    3002          505 :         mio_expr (&ar->start[i]);
    3003              : 
    3004              :       break;
    3005              : 
    3006              :     case AR_SECTION:
    3007            0 :       for (i = 0; i < ar->dimen; i++)
    3008              :         {
    3009            0 :           mio_expr (&ar->start[i]);
    3010            0 :           mio_expr (&ar->end[i]);
    3011            0 :           mio_expr (&ar->stride[i]);
    3012              :         }
    3013              : 
    3014              :       break;
    3015              : 
    3016            0 :     case AR_UNKNOWN:
    3017            0 :       gfc_internal_error ("mio_array_ref(): Unknown array ref");
    3018              :     }
    3019              : 
    3020              :   /* Unfortunately, ar->dimen_type is an anonymous enumerated type so
    3021              :      we can't call mio_integer directly.  Instead loop over each element
    3022              :      and cast it to/from an integer.  */
    3023         1807 :   if (iomode == IO_OUTPUT)
    3024              :     {
    3025         2030 :       for (i = 0; i < ar->dimen; i++)
    3026              :         {
    3027         1132 :           HOST_WIDE_INT tmp = (HOST_WIDE_INT)ar->dimen_type[i];
    3028         1132 :           write_atom (ATOM_INTEGER, &tmp);
    3029              :         }
    3030              :     }
    3031              :   else
    3032              :     {
    3033         2084 :       for (i = 0; i < ar->dimen; i++)
    3034              :         {
    3035         1175 :           require_atom (ATOM_INTEGER);
    3036         1175 :           ar->dimen_type[i] = (enum gfc_array_ref_dimen_type) atom_int;
    3037              :         }
    3038              :     }
    3039              : 
    3040         1807 :   if (iomode == IO_INPUT)
    3041              :     {
    3042          909 :       ar->where = gfc_current_locus;
    3043              : 
    3044         2084 :       for (i = 0; i < ar->dimen; i++)
    3045         1175 :         ar->c_where[i] = gfc_current_locus;
    3046              :     }
    3047              : 
    3048         1807 :   mio_rparen ();
    3049         1807 : }
    3050              : 
    3051              : 
    3052              : /* Saves or restores a pointer.  The pointer is converted back and
    3053              :    forth from an integer.  We return the pointer_info pointer so that
    3054              :    the caller can take additional action based on the pointer type.  */
    3055              : 
    3056              : static pointer_info *
    3057      7270910 : mio_pointer_ref (void *gp)
    3058              : {
    3059      7270910 :   pointer_info *p;
    3060              : 
    3061      7270910 :   if (iomode == IO_OUTPUT)
    3062              :     {
    3063      1676919 :       p = get_pointer (*((char **) gp));
    3064      1676919 :       HOST_WIDE_INT hwi = p->integer;
    3065      1676919 :       write_atom (ATOM_INTEGER, &hwi);
    3066              :     }
    3067              :   else
    3068              :     {
    3069      5593991 :       require_atom (ATOM_INTEGER);
    3070      5593991 :       p = add_fixup (atom_int, gp);
    3071              :     }
    3072              : 
    3073      7270910 :   return p;
    3074              : }
    3075              : 
    3076              : 
    3077              : /* Save and load references to components that occur within
    3078              :    expressions.  We have to describe these references by a number and
    3079              :    by name.  The number is necessary for forward references during
    3080              :    reading, and the name is necessary if the symbol already exists in
    3081              :    the namespace and is not loaded again.  */
    3082              : 
    3083              : static void
    3084          826 : mio_component_ref (gfc_component **cp)
    3085              : {
    3086          826 :   pointer_info *p;
    3087              : 
    3088          826 :   p = mio_pointer_ref (cp);
    3089          826 :   if (p->type == P_UNKNOWN)
    3090          181 :     p->type = P_COMPONENT;
    3091          826 : }
    3092              : 
    3093              : 
    3094              : static void mio_namespace_ref (gfc_namespace **nsp);
    3095              : static void mio_formal_arglist (gfc_formal_arglist **formal);
    3096              : static void mio_typebound_proc (gfc_typebound_proc** proc);
    3097              : static void mio_actual_arglist (gfc_actual_arglist **ap, bool pdt);
    3098              : 
    3099              : static void
    3100       269832 : mio_component (gfc_component *c, int vtype)
    3101              : {
    3102       269832 :   pointer_info *p;
    3103              : 
    3104       269832 :   mio_lparen ();
    3105              : 
    3106       269832 :   if (iomode == IO_OUTPUT)
    3107              :     {
    3108       107566 :       p = get_pointer (c);
    3109       107566 :       mio_hwi (&p->integer);
    3110              :     }
    3111              :   else
    3112              :     {
    3113       162266 :       HOST_WIDE_INT n;
    3114       162266 :       mio_hwi (&n);
    3115       162266 :       p = get_integer (n);
    3116       162266 :       associate_integer_pointer (p, c);
    3117              :     }
    3118              : 
    3119       269832 :   if (p->type == P_UNKNOWN)
    3120       269681 :     p->type = P_COMPONENT;
    3121              : 
    3122       269832 :   mio_pool_string (&c->name);
    3123       269832 :   mio_typespec (&c->ts);
    3124       269832 :   mio_array_spec (&c->as);
    3125              : 
    3126              :   /* PDT templates store the expression for the kind of a component here.  */
    3127       269832 :   mio_expr (&c->kind_expr);
    3128              : 
    3129              :   /* PDT types store the component specification list here. */
    3130       269832 :   mio_actual_arglist (&c->param_list, true);
    3131              : 
    3132       269832 :   mio_symbol_attribute (&c->attr);
    3133       269832 :   if (c->ts.type == BT_CLASS)
    3134         2209 :     c->attr.class_ok = 1;
    3135       269832 :   c->attr.access = MIO_NAME (gfc_access) (c->attr.access, access_types);
    3136              : 
    3137       269832 :   if (!vtype || strcmp (c->name, "_final") == 0
    3138       167574 :       || strcmp (c->name, "_hash") == 0)
    3139       128634 :     mio_expr (&c->initializer);
    3140              : 
    3141       269832 :   if (c->attr.proc_pointer)
    3142        88912 :     mio_typebound_proc (&c->tb);
    3143              : 
    3144       269832 :   c->loc = gfc_current_locus;
    3145              : 
    3146       269832 :   mio_rparen ();
    3147       269832 : }
    3148              : 
    3149              : 
    3150              : static void
    3151      1316267 : mio_component_list (gfc_component **cp, int vtype)
    3152              : {
    3153      1316267 :   gfc_component *c, *tail;
    3154              : 
    3155      1316267 :   mio_lparen ();
    3156              : 
    3157      1316267 :   if (iomode == IO_OUTPUT)
    3158              :     {
    3159       356040 :       for (c = *cp; c; c = c->next)
    3160       107566 :         mio_component (c, vtype);
    3161              :     }
    3162              :   else
    3163              :     {
    3164      1067793 :       *cp = NULL;
    3165      1067793 :       tail = NULL;
    3166              : 
    3167      1392325 :       for (;;)
    3168              :         {
    3169      1230059 :           if (peek_atom () == ATOM_RPAREN)
    3170              :             break;
    3171              : 
    3172       162266 :           c = gfc_get_component ();
    3173       162266 :           mio_component (c, vtype);
    3174              : 
    3175       162266 :           if (tail == NULL)
    3176        50844 :             *cp = c;
    3177              :           else
    3178       111422 :             tail->next = c;
    3179              : 
    3180       162266 :           tail = c;
    3181              :         }
    3182              :     }
    3183              : 
    3184      1316267 :   mio_rparen ();
    3185      1316267 : }
    3186              : 
    3187              : 
    3188              : static void
    3189         7907 : mio_actual_arg (gfc_actual_arglist *a, bool pdt)
    3190              : {
    3191         7907 :   mio_lparen ();
    3192         7907 :   mio_pool_string (&a->name);
    3193         7907 :   mio_expr (&a->expr);
    3194         7907 :   if (pdt)
    3195         1805 :     mio_integer ((int *)&a->spec_type);
    3196         7907 :   mio_rparen ();
    3197         7907 : }
    3198              : 
    3199              : 
    3200              : static void
    3201      2036737 : mio_actual_arglist (gfc_actual_arglist **ap, bool pdt)
    3202              : {
    3203      2036737 :   gfc_actual_arglist *a, *tail;
    3204              : 
    3205      2036737 :   mio_lparen ();
    3206              : 
    3207      2036737 :   if (iomode == IO_OUTPUT)
    3208              :     {
    3209       464657 :       for (a = *ap; a; a = a->next)
    3210         4029 :         mio_actual_arg (a, pdt);
    3211              : 
    3212              :     }
    3213              :   else
    3214              :     {
    3215              :       tail = NULL;
    3216              : 
    3217      1583865 :       for (;;)
    3218              :         {
    3219      1579987 :           if (peek_atom () != ATOM_LPAREN)
    3220              :             break;
    3221              : 
    3222         3878 :           a = gfc_get_actual_arglist ();
    3223              : 
    3224         3878 :           if (tail == NULL)
    3225         2039 :             *ap = a;
    3226              :           else
    3227         1839 :             tail->next = a;
    3228              : 
    3229         3878 :           tail = a;
    3230         3878 :           mio_actual_arg (a, pdt);
    3231              :         }
    3232              :     }
    3233              : 
    3234      2036737 :   mio_rparen ();
    3235      2036737 : }
    3236              : 
    3237              : 
    3238              : /* Read and write formal argument lists.  */
    3239              : 
    3240              : static void
    3241      1316267 : mio_formal_arglist (gfc_formal_arglist **formal)
    3242              : {
    3243      1316267 :   gfc_formal_arglist *f, *tail;
    3244              : 
    3245      1316267 :   mio_lparen ();
    3246              : 
    3247      1316267 :   if (iomode == IO_OUTPUT)
    3248              :     {
    3249       333165 :       for (f = *formal; f; f = f->next)
    3250        84691 :         mio_symbol_ref (&f->sym);
    3251              :     }
    3252              :   else
    3253              :     {
    3254      1067793 :       *formal = tail = NULL;
    3255              : 
    3256      1503085 :       while (peek_atom () != ATOM_RPAREN)
    3257              :         {
    3258       435292 :           f = gfc_get_formal_arglist ();
    3259       435292 :           mio_symbol_ref (&f->sym);
    3260              : 
    3261       435292 :           if (*formal == NULL)
    3262       230174 :             *formal = f;
    3263              :           else
    3264       205118 :             tail->next = f;
    3265              : 
    3266       435292 :           tail = f;
    3267              :         }
    3268              :     }
    3269              : 
    3270      1316267 :   mio_rparen ();
    3271      1316267 : }
    3272              : 
    3273              : 
    3274              : /* Save or restore a reference to a symbol node.  */
    3275              : 
    3276              : pointer_info *
    3277      5705319 : mio_symbol_ref (gfc_symbol **symp)
    3278              : {
    3279      5705319 :   pointer_info *p;
    3280              : 
    3281      5705319 :   p = mio_pointer_ref (symp);
    3282      5705319 :   if (p->type == P_UNKNOWN)
    3283       143398 :     p->type = P_SYMBOL;
    3284              : 
    3285      5705319 :   if (iomode == IO_OUTPUT)
    3286              :     {
    3287      1179467 :       if (p->u.wsym.state == UNREFERENCED)
    3288       161160 :         p->u.wsym.state = NEEDS_WRITE;
    3289              :     }
    3290              :   else
    3291              :     {
    3292      4525852 :       if (p->u.rsym.state == UNUSED)
    3293       645954 :         p->u.rsym.state = NEEDED;
    3294              :     }
    3295      5705319 :   return p;
    3296              : }
    3297              : 
    3298              : 
    3299              : /* Save or restore a reference to a symtree node.  */
    3300              : 
    3301              : static void
    3302        30925 : mio_symtree_ref (gfc_symtree **stp)
    3303              : {
    3304        30925 :   pointer_info *p;
    3305        30925 :   fixup_t *f;
    3306              : 
    3307        30925 :   if (iomode == IO_OUTPUT)
    3308        15445 :     mio_symbol_ref (&(*stp)->n.sym);
    3309              :   else
    3310              :     {
    3311        15480 :       require_atom (ATOM_INTEGER);
    3312        15480 :       p = get_integer (atom_int);
    3313              : 
    3314              :       /* An unused equivalence member; make a symbol and a symtree
    3315              :          for it.  */
    3316        15480 :       if (in_load_equiv && p->u.rsym.symtree == NULL)
    3317              :         {
    3318              :           /* Since this is not used, it must have a unique name.  */
    3319           87 :           p->u.rsym.symtree = gfc_get_unique_symtree (gfc_current_ns);
    3320              : 
    3321              :           /* Make the symbol.  */
    3322           87 :           if (p->u.rsym.sym == NULL)
    3323              :             {
    3324           75 :               p->u.rsym.sym = gfc_new_symbol (p->u.rsym.true_name,
    3325              :                                               gfc_current_ns);
    3326           75 :               p->u.rsym.sym->module = gfc_get_string ("%s", p->u.rsym.module);
    3327              :             }
    3328              : 
    3329           87 :           p->u.rsym.symtree->n.sym = p->u.rsym.sym;
    3330           87 :           p->u.rsym.symtree->n.sym->refs++;
    3331           87 :           p->u.rsym.referenced = 1;
    3332              : 
    3333              :           /* If the symbol is PRIVATE and in COMMON, load_commons will
    3334              :              generate a fixup symbol, which must be associated.  */
    3335           87 :           if (p->fixup)
    3336            2 :             resolve_fixups (p->fixup, p->u.rsym.sym);
    3337           87 :           p->fixup = NULL;
    3338              :         }
    3339              : 
    3340        15480 :       if (p->type == P_UNKNOWN)
    3341            0 :         p->type = P_SYMBOL;
    3342              : 
    3343        15480 :       if (p->u.rsym.state == UNUSED)
    3344         2765 :         p->u.rsym.state = NEEDED;
    3345              : 
    3346        15480 :       if (p->u.rsym.symtree != NULL)
    3347              :         {
    3348         3716 :           *stp = p->u.rsym.symtree;
    3349              :         }
    3350              :       else
    3351              :         {
    3352        11764 :           f = XCNEW (fixup_t);
    3353              : 
    3354        11764 :           f->next = p->u.rsym.stfixup;
    3355        11764 :           p->u.rsym.stfixup = f;
    3356              : 
    3357        11764 :           f->pointer = (void **) stp;
    3358              :         }
    3359              :     }
    3360        30925 : }
    3361              : 
    3362              : 
    3363              : static void
    3364        35049 : mio_iterator (gfc_iterator **ip)
    3365              : {
    3366        35049 :   gfc_iterator *iter;
    3367              : 
    3368        35049 :   mio_lparen ();
    3369              : 
    3370        35049 :   if (iomode == IO_OUTPUT)
    3371              :     {
    3372         9928 :       if (*ip == NULL)
    3373         9922 :         goto done;
    3374              :     }
    3375              :   else
    3376              :     {
    3377        25121 :       if (peek_atom () == ATOM_RPAREN)
    3378              :         {
    3379        25115 :           *ip = NULL;
    3380        25115 :           goto done;
    3381              :         }
    3382              : 
    3383            6 :       *ip = gfc_get_iterator ();
    3384              :     }
    3385              : 
    3386           12 :   iter = *ip;
    3387              : 
    3388           12 :   mio_expr (&iter->var);
    3389           12 :   mio_expr (&iter->start);
    3390           12 :   mio_expr (&iter->end);
    3391           12 :   mio_expr (&iter->step);
    3392              : 
    3393        35049 : done:
    3394        35049 :   mio_rparen ();
    3395        35049 : }
    3396              : 
    3397              : 
    3398              : static void
    3399        21424 : mio_constructor (gfc_constructor_base *cp)
    3400              : {
    3401        21424 :   gfc_constructor *c;
    3402              : 
    3403        21424 :   mio_lparen ();
    3404              : 
    3405        21424 :   if (iomode == IO_OUTPUT)
    3406              :     {
    3407        14177 :       for (c = gfc_constructor_first (*cp); c; c = gfc_constructor_next (c))
    3408              :         {
    3409         9928 :           mio_lparen ();
    3410         9928 :           mio_expr (&c->expr);
    3411         9928 :           mio_iterator (&c->iterator);
    3412         9928 :           mio_rparen ();
    3413              :         }
    3414              :     }
    3415              :   else
    3416              :     {
    3417        42296 :       while (peek_atom () != ATOM_RPAREN)
    3418              :         {
    3419        25121 :           c = gfc_constructor_append_expr (cp, NULL, NULL);
    3420              : 
    3421        25121 :           mio_lparen ();
    3422        25121 :           mio_expr (&c->expr);
    3423        25121 :           mio_iterator (&c->iterator);
    3424        25121 :           mio_rparen ();
    3425              :         }
    3426              :     }
    3427              : 
    3428        21424 :   mio_rparen ();
    3429        21424 : }
    3430              : 
    3431              : 
    3432              : static const mstring ref_types[] = {
    3433              :     minit ("ARRAY", REF_ARRAY),
    3434              :     minit ("COMPONENT", REF_COMPONENT),
    3435              :     minit ("SUBSTRING", REF_SUBSTRING),
    3436              :     minit ("INQUIRY", REF_INQUIRY),
    3437              :     minit (NULL, -1)
    3438              : };
    3439              : 
    3440              : static const mstring inquiry_types[] = {
    3441              :     minit ("RE", INQUIRY_RE),
    3442              :     minit ("IM", INQUIRY_IM),
    3443              :     minit ("KIND", INQUIRY_KIND),
    3444              :     minit ("LEN", INQUIRY_LEN),
    3445              :     minit (NULL, -1)
    3446              : };
    3447              : 
    3448              : 
    3449              : static void
    3450         2639 : mio_ref (gfc_ref **rp)
    3451              : {
    3452         2639 :   gfc_ref *r;
    3453              : 
    3454         2639 :   mio_lparen ();
    3455              : 
    3456         2639 :   r = *rp;
    3457         2639 :   r->type = MIO_NAME (ref_type) (r->type, ref_types);
    3458              : 
    3459         2639 :   switch (r->type)
    3460              :     {
    3461         1807 :     case REF_ARRAY:
    3462         1807 :       mio_array_ref (&r->u.ar);
    3463         1807 :       break;
    3464              : 
    3465          826 :     case REF_COMPONENT:
    3466          826 :       mio_symbol_ref (&r->u.c.sym);
    3467          826 :       mio_component_ref (&r->u.c.component);
    3468          826 :       break;
    3469              : 
    3470            6 :     case REF_SUBSTRING:
    3471            6 :       mio_expr (&r->u.ss.start);
    3472            6 :       mio_expr (&r->u.ss.end);
    3473            6 :       mio_charlen (&r->u.ss.length);
    3474            6 :       break;
    3475              : 
    3476            0 :     case REF_INQUIRY:
    3477            0 :       r->u.i = MIO_NAME (inquiry_type) (r->u.i, inquiry_types);
    3478            0 :       break;
    3479              :     }
    3480              : 
    3481         2639 :   mio_rparen ();
    3482         2639 : }
    3483              : 
    3484              : 
    3485              : static void
    3486        16872 : mio_ref_list (gfc_ref **rp)
    3487              : {
    3488        16872 :   gfc_ref *ref, *head, *tail;
    3489              : 
    3490        16872 :   mio_lparen ();
    3491              : 
    3492        16872 :   if (iomode == IO_OUTPUT)
    3493              :     {
    3494         9415 :       for (ref = *rp; ref; ref = ref->next)
    3495         1389 :         mio_ref (&ref);
    3496              :     }
    3497              :   else
    3498              :     {
    3499         8846 :       head = tail = NULL;
    3500              : 
    3501        10096 :       while (peek_atom () != ATOM_RPAREN)
    3502              :         {
    3503         1250 :           if (head == NULL)
    3504         1093 :             head = tail = gfc_get_ref ();
    3505              :           else
    3506              :             {
    3507          157 :               tail->next = gfc_get_ref ();
    3508          157 :               tail = tail->next;
    3509              :             }
    3510              : 
    3511         1250 :           mio_ref (&tail);
    3512              :         }
    3513              : 
    3514         8846 :       *rp = head;
    3515              :     }
    3516              : 
    3517        16872 :   mio_rparen ();
    3518        16872 : }
    3519              : 
    3520              : 
    3521              : /* Read and write an integer value.  */
    3522              : 
    3523              : static void
    3524       371911 : mio_gmp_integer (mpz_t *integer)
    3525              : {
    3526       371911 :   char *p;
    3527              : 
    3528       371911 :   if (iomode == IO_INPUT)
    3529              :     {
    3530       299448 :       if (parse_atom () != ATOM_STRING)
    3531            0 :         bad_module ("Expected integer string");
    3532              : 
    3533       299448 :       mpz_init (*integer);
    3534       299448 :       if (mpz_set_str (*integer, atom_string, 10))
    3535            0 :         bad_module ("Error converting integer");
    3536              : 
    3537       299448 :       free (atom_string);
    3538              :     }
    3539              :   else
    3540              :     {
    3541        72463 :       p = mpz_get_str (NULL, 10, *integer);
    3542        72463 :       write_atom (ATOM_STRING, p);
    3543        72463 :       free (p);
    3544              :     }
    3545       371911 : }
    3546              : 
    3547              : 
    3548              : static void
    3549         2075 : mio_gmp_real (mpfr_t *real)
    3550              : {
    3551         2075 :   mpfr_exp_t exponent;
    3552         2075 :   char *p;
    3553              : 
    3554         2075 :   if (iomode == IO_INPUT)
    3555              :     {
    3556          968 :       if (parse_atom () != ATOM_STRING)
    3557            0 :         bad_module ("Expected real string");
    3558              : 
    3559          968 :       mpfr_init (*real);
    3560          968 :       mpfr_set_str (*real, atom_string, 16, GFC_RND_MODE);
    3561          968 :       free (atom_string);
    3562              :     }
    3563              :   else
    3564              :     {
    3565         1107 :       p = mpfr_get_str (NULL, &exponent, 16, 0, *real, GFC_RND_MODE);
    3566              : 
    3567         1107 :       if (mpfr_nan_p (*real) || mpfr_inf_p (*real))
    3568              :         {
    3569           18 :           write_atom (ATOM_STRING, p);
    3570           18 :           free (p);
    3571           18 :           return;
    3572              :         }
    3573              : 
    3574         1089 :       atom_string = XCNEWVEC (char, strlen (p) + 20);
    3575              : 
    3576         1089 :       sprintf (atom_string, "0.%s@%ld", p, exponent);
    3577              : 
    3578              :       /* Fix negative numbers.  */
    3579         1089 :       if (atom_string[2] == '-')
    3580              :         {
    3581           45 :           atom_string[0] = '-';
    3582           45 :           atom_string[1] = '0';
    3583           45 :           atom_string[2] = '.';
    3584              :         }
    3585              : 
    3586         1089 :       write_atom (ATOM_STRING, atom_string);
    3587              : 
    3588         1089 :       free (atom_string);
    3589         1089 :       free (p);
    3590              :     }
    3591              : }
    3592              : 
    3593              : 
    3594              : /* Save and restore the shape of an array constructor.  */
    3595              : 
    3596              : static void
    3597        21424 : mio_shape (mpz_t **pshape, int rank)
    3598              : {
    3599        21424 :   mpz_t *shape;
    3600        21424 :   atom_type t;
    3601        21424 :   int n;
    3602              : 
    3603              :   /* A NULL shape is represented by ().  */
    3604        21424 :   mio_lparen ();
    3605              : 
    3606        21424 :   if (iomode == IO_OUTPUT)
    3607              :     {
    3608         4249 :       shape = *pshape;
    3609         4249 :       if (!shape)
    3610              :         {
    3611         3663 :           mio_rparen ();
    3612         3663 :           return;
    3613              :         }
    3614              :     }
    3615              :   else
    3616              :     {
    3617        17175 :       t = peek_atom ();
    3618        17175 :       if (t == ATOM_RPAREN)
    3619              :         {
    3620        15814 :           *pshape = NULL;
    3621        15814 :           mio_rparen ();
    3622        15814 :           return;
    3623              :         }
    3624              : 
    3625         1361 :       shape = gfc_get_shape (rank);
    3626         1361 :       *pshape = shape;
    3627              :     }
    3628              : 
    3629         4033 :   for (n = 0; n < rank; n++)
    3630         2086 :     mio_gmp_integer (&shape[n]);
    3631              : 
    3632         1947 :   mio_rparen ();
    3633              : }
    3634              : 
    3635              : 
    3636              : static const mstring expr_types[] = {
    3637              :     minit ("OP", EXPR_OP),
    3638              :     minit ("FUNCTION", EXPR_FUNCTION),
    3639              :     minit ("CONSTANT", EXPR_CONSTANT),
    3640              :     minit ("VARIABLE", EXPR_VARIABLE),
    3641              :     minit ("SUBSTRING", EXPR_SUBSTRING),
    3642              :     minit ("STRUCTURE", EXPR_STRUCTURE),
    3643              :     minit ("ARRAY", EXPR_ARRAY),
    3644              :     minit ("NULL", EXPR_NULL),
    3645              :     minit ("COMPCALL", EXPR_COMPCALL),
    3646              :     minit ("PPC", EXPR_PPC),
    3647              :     minit ("CONDITIONAL", EXPR_CONDITIONAL),
    3648              :     minit (NULL, -1),
    3649              : };
    3650              : 
    3651              : /* INTRINSIC_ASSIGN is missing because it is used as an index for
    3652              :    generic operators, not in expressions.  INTRINSIC_USER is also
    3653              :    replaced by the correct function name by the time we see it.  */
    3654              : 
    3655              : static const mstring intrinsics[] =
    3656              : {
    3657              :     minit ("UPLUS", INTRINSIC_UPLUS),
    3658              :     minit ("UMINUS", INTRINSIC_UMINUS),
    3659              :     minit ("PLUS", INTRINSIC_PLUS),
    3660              :     minit ("MINUS", INTRINSIC_MINUS),
    3661              :     minit ("TIMES", INTRINSIC_TIMES),
    3662              :     minit ("DIVIDE", INTRINSIC_DIVIDE),
    3663              :     minit ("POWER", INTRINSIC_POWER),
    3664              :     minit ("CONCAT", INTRINSIC_CONCAT),
    3665              :     minit ("AND", INTRINSIC_AND),
    3666              :     minit ("OR", INTRINSIC_OR),
    3667              :     minit ("EQV", INTRINSIC_EQV),
    3668              :     minit ("NEQV", INTRINSIC_NEQV),
    3669              :     minit ("EQ_SIGN", INTRINSIC_EQ),
    3670              :     minit ("EQ", INTRINSIC_EQ_OS),
    3671              :     minit ("NE_SIGN", INTRINSIC_NE),
    3672              :     minit ("NE", INTRINSIC_NE_OS),
    3673              :     minit ("GT_SIGN", INTRINSIC_GT),
    3674              :     minit ("GT", INTRINSIC_GT_OS),
    3675              :     minit ("GE_SIGN", INTRINSIC_GE),
    3676              :     minit ("GE", INTRINSIC_GE_OS),
    3677              :     minit ("LT_SIGN", INTRINSIC_LT),
    3678              :     minit ("LT", INTRINSIC_LT_OS),
    3679              :     minit ("LE_SIGN", INTRINSIC_LE),
    3680              :     minit ("LE", INTRINSIC_LE_OS),
    3681              :     minit ("NOT", INTRINSIC_NOT),
    3682              :     minit ("PARENTHESES", INTRINSIC_PARENTHESES),
    3683              :     minit ("USER", INTRINSIC_USER),
    3684              :     minit (NULL, -1)
    3685              : };
    3686              : 
    3687              : 
    3688              : /* Remedy a couple of situations where the gfc_expr's can be defective.  */
    3689              : 
    3690              : static void
    3691       447720 : fix_mio_expr (gfc_expr *e)
    3692              : {
    3693       447720 :   gfc_symtree *ns_st = NULL;
    3694       447720 :   const char *fname;
    3695              : 
    3696       447720 :   if (iomode != IO_OUTPUT)
    3697              :     return;
    3698              : 
    3699       103091 :   if (e->symtree)
    3700              :     {
    3701              :       /* If this is a symtree for a symbol that came from a contained module
    3702              :          namespace, it has a unique name and we should look in the current
    3703              :          namespace to see if the required, non-contained symbol is available
    3704              :          yet. If so, the latter should be written.  */
    3705        10793 :       if (e->symtree->n.sym && check_unique_name (e->symtree->name))
    3706              :         {
    3707          768 :           const char *name = e->symtree->n.sym->name;
    3708          768 :           if (gfc_fl_struct (e->symtree->n.sym->attr.flavor))
    3709            0 :             name = gfc_dt_upper_string (name);
    3710          768 :           ns_st = gfc_find_symtree (gfc_current_ns->sym_root, name);
    3711              :         }
    3712              : 
    3713              :       /* On the other hand, if the existing symbol is the module name or the
    3714              :          new symbol is a dummy argument, do not do the promotion.  */
    3715          768 :       if (ns_st && ns_st->n.sym
    3716           23 :           && ns_st->n.sym->attr.flavor != FL_MODULE
    3717           22 :           && !e->symtree->n.sym->attr.dummy)
    3718           21 :         e->symtree = ns_st;
    3719              :     }
    3720        92298 :   else if (e->expr_type == EXPR_FUNCTION
    3721            2 :            && (e->value.function.name || e->value.function.isym))
    3722              :     {
    3723            2 :       gfc_symbol *sym;
    3724              : 
    3725              :       /* In some circumstances, a function used in an initialization
    3726              :          expression, in one use associated module, can fail to be
    3727              :          coupled to its symtree when used in a specification
    3728              :          expression in another module.  */
    3729            2 :       fname = e->value.function.esym ? e->value.function.esym->name
    3730            2 :                                      : e->value.function.isym->name;
    3731            2 :       e->symtree = gfc_find_symtree (gfc_current_ns->sym_root, fname);
    3732              : 
    3733            2 :       if (e->symtree)
    3734            1 :         return;
    3735              : 
    3736              :       /* This is probably a reference to a private procedure from another
    3737              :          module.  To prevent a segfault, make a generic with no specific
    3738              :          instances.  If this module is used, without the required
    3739              :          specific coming from somewhere, the appropriate error message
    3740              :          is issued.  */
    3741            1 :       gfc_get_symbol (fname, gfc_current_ns, &sym);
    3742            1 :       sym->attr.flavor = FL_PROCEDURE;
    3743            1 :       sym->attr.generic = 1;
    3744            1 :       e->symtree = gfc_find_symtree (gfc_current_ns->sym_root, fname);
    3745            1 :       gfc_commit_symbol (sym);
    3746              :     }
    3747              : }
    3748              : 
    3749              : 
    3750              : /* Read and write expressions.  The form "()" is allowed to indicate a
    3751              :    NULL expression.  */
    3752              : 
    3753              : static void
    3754       872181 : mio_expr (gfc_expr **ep)
    3755              : {
    3756       872181 :   HOST_WIDE_INT hwi;
    3757       872181 :   gfc_expr *e;
    3758       872181 :   atom_type t;
    3759       872181 :   int flag;
    3760              : 
    3761       872181 :   mio_lparen ();
    3762              : 
    3763       872181 :   if (iomode == IO_OUTPUT)
    3764              :     {
    3765       260571 :       if (*ep == NULL)
    3766              :         {
    3767       157480 :           mio_rparen ();
    3768       581941 :           return;
    3769              :         }
    3770              : 
    3771       103091 :       e = *ep;
    3772       103091 :       MIO_NAME (expr_t) (e->expr_type, expr_types);
    3773              :     }
    3774              :   else
    3775              :     {
    3776       611610 :       t = parse_atom ();
    3777       611610 :       if (t == ATOM_RPAREN)
    3778              :         {
    3779       266981 :           *ep = NULL;
    3780       266981 :           return;
    3781              :         }
    3782              : 
    3783       344629 :       if (t != ATOM_NAME)
    3784            0 :         bad_module ("Expected expression type");
    3785              : 
    3786       344629 :       e = *ep = gfc_get_expr ();
    3787       344629 :       e->where = gfc_current_locus;
    3788       344629 :       e->expr_type = (expr_t) find_enum (expr_types);
    3789              :     }
    3790              : 
    3791       447720 :   mio_typespec (&e->ts);
    3792       447720 :   mio_integer (&e->rank);
    3793              : 
    3794       447720 :   fix_mio_expr (e);
    3795              : 
    3796       447720 :   switch (e->expr_type)
    3797              :     {
    3798         1629 :     case EXPR_OP:
    3799         1629 :       e->value.op.op
    3800         1629 :         = MIO_NAME (gfc_intrinsic_op) (e->value.op.op, intrinsics);
    3801              : 
    3802         1629 :       switch (e->value.op.op)
    3803              :         {
    3804          447 :         case INTRINSIC_UPLUS:
    3805          447 :         case INTRINSIC_UMINUS:
    3806          447 :         case INTRINSIC_NOT:
    3807          447 :         case INTRINSIC_PARENTHESES:
    3808          447 :           mio_expr (&e->value.op.op1);
    3809          447 :           break;
    3810              : 
    3811         1112 :         case INTRINSIC_PLUS:
    3812         1112 :         case INTRINSIC_MINUS:
    3813         1112 :         case INTRINSIC_TIMES:
    3814         1112 :         case INTRINSIC_DIVIDE:
    3815         1112 :         case INTRINSIC_POWER:
    3816         1112 :         case INTRINSIC_CONCAT:
    3817         1112 :         case INTRINSIC_AND:
    3818         1112 :         case INTRINSIC_OR:
    3819         1112 :         case INTRINSIC_EQV:
    3820         1112 :         case INTRINSIC_NEQV:
    3821         1112 :         case INTRINSIC_EQ:
    3822         1112 :         case INTRINSIC_EQ_OS:
    3823         1112 :         case INTRINSIC_NE:
    3824         1112 :         case INTRINSIC_NE_OS:
    3825         1112 :         case INTRINSIC_GT:
    3826         1112 :         case INTRINSIC_GT_OS:
    3827         1112 :         case INTRINSIC_GE:
    3828         1112 :         case INTRINSIC_GE_OS:
    3829         1112 :         case INTRINSIC_LT:
    3830         1112 :         case INTRINSIC_LT_OS:
    3831         1112 :         case INTRINSIC_LE:
    3832         1112 :         case INTRINSIC_LE_OS:
    3833         1112 :           mio_expr (&e->value.op.op1);
    3834         1112 :           mio_expr (&e->value.op.op2);
    3835         1112 :           break;
    3836              : 
    3837           70 :         case INTRINSIC_USER:
    3838              :           /* INTRINSIC_USER should not appear in resolved expressions,
    3839              :              though for UDRs we need to stream unresolved ones.  */
    3840           70 :           if (iomode == IO_OUTPUT)
    3841           34 :             write_atom (ATOM_STRING, e->value.op.uop->name);
    3842              :           else
    3843              :             {
    3844           36 :               char *name = read_string ();
    3845           36 :               const char *uop_name = find_use_name (name, true);
    3846           36 :               if (uop_name == NULL)
    3847              :                 {
    3848            0 :                   size_t len = strlen (name);
    3849            0 :                   char *name2 = XCNEWVEC (char, len + 2);
    3850            0 :                   memcpy (name2, name, len);
    3851            0 :                   name2[len] = ' ';
    3852            0 :                   name2[len + 1] = '\0';
    3853            0 :                   free (name);
    3854            0 :                   uop_name = name = name2;
    3855              :                 }
    3856           36 :               e->value.op.uop = gfc_get_uop (uop_name);
    3857           36 :               free (name);
    3858              :             }
    3859           70 :           mio_expr (&e->value.op.op1);
    3860           70 :           mio_expr (&e->value.op.op2);
    3861           70 :           break;
    3862              : 
    3863            0 :         default:
    3864            0 :           bad_module ("Bad operator");
    3865              :         }
    3866              : 
    3867              :       break;
    3868              : 
    3869            2 :     case EXPR_CONDITIONAL:
    3870            2 :       mio_expr (&e->value.conditional.condition);
    3871            2 :       mio_expr (&e->value.conditional.true_expr);
    3872            2 :       mio_expr (&e->value.conditional.false_expr);
    3873            2 :       break;
    3874              : 
    3875         2810 :     case EXPR_FUNCTION:
    3876         2810 :       mio_symtree_ref (&e->symtree);
    3877         2810 :       mio_actual_arglist (&e->value.function.actual, false);
    3878              : 
    3879         2810 :       if (iomode == IO_OUTPUT)
    3880              :         {
    3881         1443 :           e->value.function.name
    3882         1443 :             = mio_allocated_string (e->value.function.name);
    3883         1443 :           if (e->value.function.esym)
    3884          131 :             flag = 1;
    3885         1312 :           else if (e->ref)
    3886          104 :             flag = 2;
    3887         1208 :           else if (e->value.function.isym == NULL)
    3888          310 :             flag = 3;
    3889              :           else
    3890          898 :             flag = 0;
    3891         1443 :           mio_integer (&flag);
    3892         1443 :           switch (flag)
    3893              :             {
    3894          131 :             case 1:
    3895          131 :               mio_symbol_ref (&e->value.function.esym);
    3896          131 :               break;
    3897          104 :             case 2:
    3898          104 :               mio_ref_list (&e->ref);
    3899          104 :               break;
    3900              :             case 3:
    3901              :               break;
    3902          898 :             default:
    3903          898 :               write_atom (ATOM_STRING, e->value.function.isym->name);
    3904              :             }
    3905              :         }
    3906              :       else
    3907              :         {
    3908         1367 :           require_atom (ATOM_STRING);
    3909         1367 :           if (atom_string[0] == '\0')
    3910              :             e->value.function.name = NULL;
    3911              :           else
    3912          566 :             e->value.function.name = gfc_get_string ("%s", atom_string);
    3913         1367 :           free (atom_string);
    3914              : 
    3915         1367 :           mio_integer (&flag);
    3916         1367 :           switch (flag)
    3917              :             {
    3918          138 :             case 1:
    3919          138 :               mio_symbol_ref (&e->value.function.esym);
    3920          138 :               break;
    3921           72 :             case 2:
    3922           72 :               mio_ref_list (&e->ref);
    3923           72 :               break;
    3924              :             case 3:
    3925              :               break;
    3926          880 :             default:
    3927          880 :               require_atom (ATOM_STRING);
    3928          880 :               e->value.function.isym = gfc_find_function (atom_string);
    3929          880 :               free (atom_string);
    3930              :             }
    3931              :         }
    3932              : 
    3933              :       break;
    3934              : 
    3935        16696 :     case EXPR_VARIABLE:
    3936        16696 :       mio_symtree_ref (&e->symtree);
    3937        16696 :       mio_ref_list (&e->ref);
    3938        16696 :       break;
    3939              : 
    3940            0 :     case EXPR_SUBSTRING:
    3941            0 :       e->value.character.string = const_cast<gfc_char_t *>
    3942            0 :         (mio_allocated_wide_string (e->value.character.string,
    3943            0 :                                     e->value.character.length));
    3944            0 :       mio_ref_list (&e->ref);
    3945            0 :       break;
    3946              : 
    3947        21424 :     case EXPR_STRUCTURE:
    3948        21424 :     case EXPR_ARRAY:
    3949        21424 :       mio_constructor (&e->value.constructor);
    3950        21424 :       mio_shape (&e->shape, e->rank);
    3951        21424 :       break;
    3952              : 
    3953       380631 :     case EXPR_CONSTANT:
    3954       380631 :       switch (e->ts.type)
    3955              :         {
    3956       369825 :         case BT_INTEGER:
    3957       369825 :         case BT_UNSIGNED:
    3958       369825 :           mio_gmp_integer (&e->value.integer);
    3959       369825 :           break;
    3960              : 
    3961         1939 :         case BT_REAL:
    3962         1939 :           gfc_set_model_kind (e->ts.kind);
    3963         1939 :           mio_gmp_real (&e->value.real);
    3964         1939 :           break;
    3965              : 
    3966           68 :         case BT_COMPLEX:
    3967           68 :           gfc_set_model_kind (e->ts.kind);
    3968           68 :           mio_gmp_real (&mpc_realref (e->value.complex));
    3969           68 :           mio_gmp_real (&mpc_imagref (e->value.complex));
    3970           68 :           break;
    3971              : 
    3972          295 :         case BT_LOGICAL:
    3973          295 :           mio_integer (&e->value.logical);
    3974          295 :           break;
    3975              : 
    3976         8504 :         case BT_CHARACTER:
    3977         8504 :           hwi = e->value.character.length;
    3978         8504 :           mio_hwi (&hwi);
    3979         8504 :           e->value.character.length = hwi;
    3980        17008 :           e->value.character.string = const_cast<gfc_char_t *>
    3981         8504 :             (mio_allocated_wide_string (e->value.character.string,
    3982              :                                         e->value.character.length));
    3983         8504 :           break;
    3984              : 
    3985            0 :         default:
    3986            0 :           bad_module ("Bad type in constant expression");
    3987              :         }
    3988              : 
    3989              :       break;
    3990              : 
    3991              :     case EXPR_NULL:
    3992              :       break;
    3993              : 
    3994            0 :     case EXPR_COMPCALL:
    3995            0 :     case EXPR_PPC:
    3996            0 :     case EXPR_UNKNOWN:
    3997            0 :       gcc_unreachable ();
    3998       447720 :       break;
    3999              :     }
    4000              : 
    4001              :   /* PDT types store the expression specification list here. */
    4002       447720 :   mio_actual_arglist (&e->param_list, true);
    4003              : 
    4004       447720 :   mio_rparen ();
    4005              : }
    4006              : 
    4007              : 
    4008              : /* Read and write namelists.  */
    4009              : 
    4010              : static void
    4011      1316267 : mio_namelist (gfc_symbol *sym)
    4012              : {
    4013      1316267 :   gfc_namelist *n, *m;
    4014              : 
    4015      1316267 :   mio_lparen ();
    4016              : 
    4017      1316267 :   if (iomode == IO_OUTPUT)
    4018              :     {
    4019       248558 :       for (n = sym->namelist; n; n = n->next)
    4020           84 :         mio_symbol_ref (&n->sym);
    4021              :     }
    4022              :   else
    4023              :     {
    4024              :       m = NULL;
    4025      1067882 :       while (peek_atom () != ATOM_RPAREN)
    4026              :         {
    4027           89 :           n = gfc_get_namelist ();
    4028           89 :           mio_symbol_ref (&n->sym);
    4029              : 
    4030           89 :           if (sym->namelist == NULL)
    4031           53 :             sym->namelist = n;
    4032              :           else
    4033           36 :             m->next = n;
    4034              : 
    4035           89 :           m = n;
    4036              :         }
    4037      1067793 :       sym->namelist_tail = m;
    4038              :     }
    4039              : 
    4040      1316267 :   mio_rparen ();
    4041      1316267 : }
    4042              : 
    4043              : 
    4044              : /* Save/restore lists of gfc_interface structures.  When loading an
    4045              :    interface, we are really appending to the existing list of
    4046              :    interfaces.  Checking for duplicate and ambiguous interfaces has to
    4047              :    be done later when all symbols have been loaded.  */
    4048              : 
    4049              : pointer_info *
    4050       670911 : mio_interface_rest (gfc_interface **ip)
    4051              : {
    4052       670911 :   gfc_interface *tail, *p;
    4053       670911 :   pointer_info *pi = NULL;
    4054              : 
    4055       670911 :   if (iomode == IO_OUTPUT)
    4056              :     {
    4057       285021 :       if (ip != NULL)
    4058       276052 :         for (p = *ip; p; p = p->next)
    4059        17208 :           mio_symbol_ref (&p->sym);
    4060              :     }
    4061              :   else
    4062              :     {
    4063       385890 :       if (*ip == NULL)
    4064       385890 :         tail = NULL;
    4065              :       else
    4066              :         {
    4067              :           tail = *ip;
    4068         5182 :           while (tail->next)
    4069              :             tail = tail->next;
    4070              :         }
    4071              : 
    4072       729810 :       for (;;)
    4073              :         {
    4074       557850 :           if (peek_atom () == ATOM_RPAREN)
    4075              :             break;
    4076              : 
    4077       171960 :           p = gfc_get_interface ();
    4078       171960 :           p->where = gfc_current_locus;
    4079       171960 :           pi = mio_symbol_ref (&p->sym);
    4080              : 
    4081       171960 :           if (tail == NULL)
    4082        59172 :             *ip = p;
    4083              :           else
    4084       112788 :             tail->next = p;
    4085              : 
    4086       171960 :           tail = p;
    4087              :         }
    4088              :     }
    4089              : 
    4090       670911 :   mio_rparen ();
    4091       670911 :   return pi;
    4092              : }
    4093              : 
    4094              : 
    4095              : /* Save/restore a nameless operator interface.  */
    4096              : 
    4097              : static void
    4098       599523 : mio_interface (gfc_interface **ip)
    4099              : {
    4100       273591 :   mio_lparen ();
    4101       325932 :   mio_interface_rest (ip);
    4102            0 : }
    4103              : 
    4104              : 
    4105              : /* Save/restore a named operator interface.  */
    4106              : 
    4107              : static void
    4108        11430 : mio_symbol_interface (const char **name, const char **module,
    4109              :                       gfc_interface **ip)
    4110              : {
    4111        11430 :   mio_lparen ();
    4112        11430 :   mio_pool_string (name);
    4113        11430 :   mio_pool_string (module);
    4114        11430 :   mio_interface_rest (ip);
    4115        11430 : }
    4116              : 
    4117              : 
    4118              : static void
    4119      1316267 : mio_namespace_ref (gfc_namespace **nsp)
    4120              : {
    4121      1316267 :   gfc_namespace *ns;
    4122      1316267 :   pointer_info *p;
    4123              : 
    4124      1316267 :   p = mio_pointer_ref (nsp);
    4125              : 
    4126      1316267 :   if (p->type == P_UNKNOWN)
    4127       267181 :     p->type = P_NAMESPACE;
    4128              : 
    4129      1316267 :   if (iomode == IO_INPUT && p->integer != 0)
    4130              :     {
    4131       237254 :       ns = (gfc_namespace *) p->u.pointer;
    4132       237254 :       if (ns == NULL)
    4133              :         {
    4134       236936 :           ns = gfc_get_namespace (NULL, 0);
    4135       236936 :           associate_integer_pointer (p, ns);
    4136              :         }
    4137              :       else
    4138          318 :         ns->refs++;
    4139              :     }
    4140      1316267 : }
    4141              : 
    4142              : 
    4143              : /* Save/restore the f2k_derived namespace of a derived-type symbol.  */
    4144              : 
    4145              : static gfc_namespace* current_f2k_derived;
    4146              : 
    4147              : static void
    4148       101422 : mio_typebound_proc (gfc_typebound_proc** proc)
    4149              : {
    4150       101422 :   int flag;
    4151       101422 :   int overriding_flag;
    4152              : 
    4153       101422 :   if (iomode == IO_INPUT)
    4154              :     {
    4155        56772 :       *proc = gfc_get_typebound_proc (NULL);
    4156        56772 :       (*proc)->where = gfc_current_locus;
    4157              :     }
    4158       101422 :   gcc_assert (*proc);
    4159              : 
    4160       101422 :   mio_lparen ();
    4161              : 
    4162       101422 :   (*proc)->access = MIO_NAME (gfc_access) ((*proc)->access, access_types);
    4163              : 
    4164              :   /* IO the NON_OVERRIDABLE/DEFERRED combination.  */
    4165       101422 :   gcc_assert (!((*proc)->deferred && (*proc)->non_overridable));
    4166       101422 :   overriding_flag = ((*proc)->deferred << 1) | (*proc)->non_overridable;
    4167       101422 :   overriding_flag = mio_name (overriding_flag, binding_overriding);
    4168       101422 :   (*proc)->deferred = ((overriding_flag & 2) != 0);
    4169       101422 :   (*proc)->non_overridable = ((overriding_flag & 1) != 0);
    4170       101422 :   gcc_assert (!((*proc)->deferred && (*proc)->non_overridable));
    4171              : 
    4172       101422 :   (*proc)->nopass = mio_name ((*proc)->nopass, binding_passing);
    4173       101422 :   (*proc)->is_generic = mio_name ((*proc)->is_generic, binding_generic);
    4174       101422 :   (*proc)->ppc = mio_name((*proc)->ppc, binding_ppc);
    4175              : 
    4176       101422 :   mio_pool_string (&((*proc)->pass_arg));
    4177              : 
    4178       101422 :   flag = (int) (*proc)->pass_arg_num;
    4179       101422 :   mio_integer (&flag);
    4180       101422 :   (*proc)->pass_arg_num = (unsigned) flag;
    4181              : 
    4182       101422 :   if ((*proc)->is_generic)
    4183              :     {
    4184         2890 :       gfc_tbp_generic* g;
    4185         2890 :       int iop;
    4186              : 
    4187         2890 :       mio_lparen ();
    4188              : 
    4189         2890 :       if (iomode == IO_OUTPUT)
    4190         3452 :         for (g = (*proc)->u.generic; g; g = g->next)
    4191              :           {
    4192         1931 :             iop = (int) g->is_operator;
    4193         1931 :             mio_integer (&iop);
    4194         1931 :             mio_allocated_string (g->specific_st->name);
    4195              :           }
    4196              :       else
    4197              :         {
    4198         1369 :           (*proc)->u.generic = NULL;
    4199         3051 :           while (peek_atom () != ATOM_RPAREN)
    4200              :             {
    4201         1682 :               gfc_symtree** sym_root;
    4202              : 
    4203         1682 :               g = gfc_get_tbp_generic ();
    4204         1682 :               g->specific = NULL;
    4205              : 
    4206         1682 :               mio_integer (&iop);
    4207         1682 :               g->is_operator = (bool) iop;
    4208              : 
    4209         1682 :               require_atom (ATOM_STRING);
    4210         1682 :               sym_root = &current_f2k_derived->tb_sym_root;
    4211         1682 :               g->specific_st = gfc_get_tbp_symtree (sym_root, atom_string);
    4212         1682 :               free (atom_string);
    4213              : 
    4214         1682 :               g->next = (*proc)->u.generic;
    4215         1682 :               (*proc)->u.generic = g;
    4216              :             }
    4217              :         }
    4218              : 
    4219         2890 :       mio_rparen ();
    4220              :     }
    4221        98532 :   else if (!(*proc)->ppc)
    4222         9620 :     mio_symtree_ref (&(*proc)->u.specific);
    4223              : 
    4224       101422 :   mio_rparen ();
    4225       101422 : }
    4226              : 
    4227              : /* Walker-callback function for this purpose.  */
    4228              : static void
    4229        11166 : mio_typebound_symtree (gfc_symtree* st)
    4230              : {
    4231        11166 :   if (iomode == IO_OUTPUT && !st->n.tb)
    4232              :     return;
    4233              : 
    4234        11166 :   if (iomode == IO_OUTPUT)
    4235              :     {
    4236         5939 :       mio_lparen ();
    4237         5939 :       mio_allocated_string (st->name);
    4238              :     }
    4239              :   /* For IO_INPUT, the above is done in mio_f2k_derived.  */
    4240              : 
    4241        11166 :   mio_typebound_proc (&st->n.tb);
    4242        11166 :   mio_rparen ();
    4243              : }
    4244              : 
    4245              : /* IO a full symtree (in all depth).  */
    4246              : static void
    4247        66394 : mio_full_typebound_tree (gfc_symtree** root)
    4248              : {
    4249        66394 :   mio_lparen ();
    4250              : 
    4251        66394 :   if (iomode == IO_OUTPUT)
    4252        28590 :     gfc_traverse_symtree (*root, &mio_typebound_symtree);
    4253              :   else
    4254              :     {
    4255        43031 :       while (peek_atom () == ATOM_LPAREN)
    4256              :         {
    4257         5227 :           gfc_symtree* st;
    4258              : 
    4259         5227 :           mio_lparen ();
    4260              : 
    4261         5227 :           require_atom (ATOM_STRING);
    4262         5227 :           st = gfc_get_tbp_symtree (root, atom_string);
    4263         5227 :           free (atom_string);
    4264              : 
    4265         5227 :           mio_typebound_symtree (st);
    4266              :         }
    4267              :     }
    4268              : 
    4269        66394 :   mio_rparen ();
    4270        66394 : }
    4271              : 
    4272              : static void
    4273         1377 : mio_finalizer (gfc_finalizer **f)
    4274              : {
    4275         1377 :   if (iomode == IO_OUTPUT)
    4276              :     {
    4277          660 :       gcc_assert (*f);
    4278          660 :       gcc_assert ((*f)->proc_tree); /* Should already be resolved.  */
    4279          660 :       mio_symtree_ref (&(*f)->proc_tree);
    4280              :     }
    4281              :   else
    4282              :     {
    4283          717 :       *f = gfc_get_finalizer ();
    4284          717 :       (*f)->where = gfc_current_locus; /* Value should not matter.  */
    4285          717 :       (*f)->next = NULL;
    4286              : 
    4287          717 :       mio_symtree_ref (&(*f)->proc_tree);
    4288          717 :       (*f)->proc_sym = NULL;
    4289              :     }
    4290         1377 : }
    4291              : 
    4292              : static void
    4293        33197 : mio_f2k_derived (gfc_namespace *f2k)
    4294              : {
    4295        33197 :   current_f2k_derived = f2k;
    4296              : 
    4297              :   /* Handle the list of finalizer procedures.  */
    4298        33197 :   mio_lparen ();
    4299        33197 :   if (iomode == IO_OUTPUT)
    4300              :     {
    4301        14295 :       gfc_finalizer *f;
    4302        14955 :       for (f = f2k->finalizers; f; f = f->next)
    4303          660 :         mio_finalizer (&f);
    4304              :     }
    4305              :   else
    4306              :     {
    4307        18902 :       f2k->finalizers = NULL;
    4308        19619 :       while (peek_atom () != ATOM_RPAREN)
    4309              :         {
    4310          717 :           gfc_finalizer *cur = NULL;
    4311          717 :           mio_finalizer (&cur);
    4312          717 :           cur->next = f2k->finalizers;
    4313          717 :           f2k->finalizers = cur;
    4314              :         }
    4315              :     }
    4316        33197 :   mio_rparen ();
    4317              : 
    4318              :   /* Handle type-bound procedures.  */
    4319        33197 :   mio_full_typebound_tree (&f2k->tb_sym_root);
    4320              : 
    4321              :   /* Type-bound user operators.  */
    4322        33197 :   mio_full_typebound_tree (&f2k->tb_uop_root);
    4323              : 
    4324              :   /* Type-bound intrinsic operators.  */
    4325        33197 :   mio_lparen ();
    4326        33197 :   if (iomode == IO_OUTPUT)
    4327              :     {
    4328              :       int op;
    4329       414555 :       for (op = GFC_INTRINSIC_BEGIN; op != GFC_INTRINSIC_END; ++op)
    4330              :         {
    4331       400260 :           gfc_intrinsic_op realop;
    4332              : 
    4333       400260 :           if (op == INTRINSIC_USER || !f2k->tb_op[op])
    4334       399546 :             continue;
    4335              : 
    4336          714 :           mio_lparen ();
    4337          714 :           realop = (gfc_intrinsic_op) op;
    4338          714 :           mio_intrinsic_op (&realop);
    4339          714 :           mio_typebound_proc (&f2k->tb_op[op]);
    4340          714 :           mio_rparen ();
    4341              :         }
    4342              :     }
    4343              :   else
    4344        19532 :     while (peek_atom () != ATOM_RPAREN)
    4345              :       {
    4346          630 :         gfc_intrinsic_op op = GFC_INTRINSIC_BEGIN; /* Silence GCC.  */
    4347              : 
    4348          630 :         mio_lparen ();
    4349          630 :         mio_intrinsic_op (&op);
    4350          630 :         mio_typebound_proc (&f2k->tb_op[op]);
    4351          630 :         mio_rparen ();
    4352              :       }
    4353        33197 :   mio_rparen ();
    4354        33197 : }
    4355              : 
    4356              : 
    4357              : static void
    4358      1316267 : mio_full_f2k_derived (gfc_symbol *sym)
    4359              : {
    4360      1316267 :   mio_lparen ();
    4361              : 
    4362      1316267 :   if (iomode == IO_OUTPUT)
    4363              :     {
    4364       248474 :       if (sym->f2k_derived)
    4365        14295 :         mio_f2k_derived (sym->f2k_derived);
    4366              :     }
    4367              :   else
    4368              :     {
    4369      1067793 :       if (peek_atom () != ATOM_RPAREN)
    4370              :         {
    4371        18902 :           sym->f2k_derived = gfc_get_namespace (NULL, 0);
    4372              : 
    4373              :           /* PDT type-parameter namespaces are reconstructed
    4374              :              after all needed module symbols are loaded.  */
    4375        18902 :           mio_f2k_derived (sym->f2k_derived);
    4376              :         }
    4377              :       else
    4378      1048891 :         gcc_assert (!sym->f2k_derived);
    4379              :     }
    4380              : 
    4381      1316267 :   mio_rparen ();
    4382      1316267 : }
    4383              : 
    4384              : static const mstring omp_declare_simd_clauses[] =
    4385              : {
    4386              :     minit ("INBRANCH", 0),
    4387              :     minit ("NOTINBRANCH", 1),
    4388              :     minit ("SIMDLEN", 2),
    4389              :     minit ("UNIFORM", 3),
    4390              :     minit ("LINEAR", 4),
    4391              :     minit ("ALIGNED", 5),
    4392              :     minit ("LINEAR_REF", 33),
    4393              :     minit ("LINEAR_VAL", 34),
    4394              :     minit ("LINEAR_UVAL", 35),
    4395              :     minit (NULL, -1)
    4396              : };
    4397              : 
    4398              : /* Handle OpenMP's declare-simd clauses.  */
    4399              : 
    4400              : static void
    4401          149 : mio_omp_declare_simd_clauses (gfc_omp_clauses **clausesp)
    4402              : {
    4403          149 :   if (iomode == IO_OUTPUT)
    4404              :     {
    4405           95 :       gfc_omp_clauses *clauses = *clausesp;
    4406           95 :       gfc_omp_namelist *n;
    4407              : 
    4408           95 :       write_atom (ATOM_NAME, "OMP_DECLARE_SIMD");
    4409           95 :       if (clauses->inbranch)
    4410           10 :         mio_name (0, omp_declare_simd_clauses);
    4411           95 :       if (clauses->notinbranch)
    4412           23 :         mio_name (1, omp_declare_simd_clauses);
    4413           95 :       if (clauses->simdlen_expr)
    4414              :         {
    4415           37 :           mio_name (2, omp_declare_simd_clauses);
    4416           37 :           mio_expr (&clauses->simdlen_expr);
    4417              :         }
    4418          152 :       for (n = clauses->lists[OMP_LIST_UNIFORM]; n; n = n->next)
    4419              :         {
    4420           57 :           mio_name (3, omp_declare_simd_clauses);
    4421           57 :           mio_symbol_ref (&n->sym);
    4422              :         }
    4423          148 :       for (n = clauses->lists[OMP_LIST_LINEAR]; n; n = n->next)
    4424              :         {
    4425           53 :           if (n->u.linear.op == OMP_LINEAR_DEFAULT)
    4426           34 :             mio_name (4, omp_declare_simd_clauses);
    4427              :           else
    4428           19 :             mio_name (32 + n->u.linear.op, omp_declare_simd_clauses);
    4429           53 :           mio_symbol_ref (&n->sym);
    4430           53 :           mio_expr (&n->expr);
    4431              :         }
    4432          101 :       for (n = clauses->lists[OMP_LIST_ALIGNED]; n; n = n->next)
    4433              :         {
    4434            6 :           mio_name (5, omp_declare_simd_clauses);
    4435            6 :           mio_symbol_ref (&n->sym);
    4436            6 :           mio_expr (&n->expr);
    4437              :         }
    4438              :     }
    4439              :   else
    4440              :     {
    4441           54 :       if (peek_atom () != ATOM_NAME)
    4442           18 :         return;
    4443              : 
    4444           36 :       gfc_omp_namelist **ptrs[3] = { NULL, NULL, NULL };
    4445           36 :       gfc_omp_clauses *clauses = *clausesp = gfc_get_omp_clauses ();
    4446           36 :       ptrs[0] = &clauses->lists[OMP_LIST_UNIFORM];
    4447           36 :       ptrs[1] = &clauses->lists[OMP_LIST_LINEAR];
    4448           36 :       ptrs[2] = &clauses->lists[OMP_LIST_ALIGNED];
    4449              : 
    4450          181 :       while (peek_atom () == ATOM_NAME)
    4451              :         {
    4452          109 :           gfc_omp_namelist *n;
    4453          109 :           int t = mio_name (0, omp_declare_simd_clauses);
    4454              : 
    4455          109 :           switch (t)
    4456              :             {
    4457            0 :             case 0: clauses->inbranch = true; break;
    4458           10 :             case 1: clauses->notinbranch = true; break;
    4459           19 :             case 2: mio_expr (&clauses->simdlen_expr); break;
    4460           77 :             case 3:
    4461           77 :             case 4:
    4462           77 :             case 5:
    4463           77 :               *ptrs[t - 3] = n = gfc_get_omp_namelist ();
    4464           80 :             finish_namelist:
    4465           80 :               n->where = gfc_current_locus;
    4466           80 :               ptrs[t - 3] = &n->next;
    4467           80 :               mio_symbol_ref (&n->sym);
    4468           80 :               if (t != 3)
    4469           32 :                 mio_expr (&n->expr);
    4470              :               break;
    4471            3 :             case 33:
    4472            3 :             case 34:
    4473            3 :             case 35:
    4474            3 :               *ptrs[1] = n = gfc_get_omp_namelist ();
    4475            3 :               n->u.linear.op = (enum gfc_omp_linear_op) (t - 32);
    4476            3 :               t = 4;
    4477            3 :               goto finish_namelist;
    4478              :             }
    4479              :         }
    4480              :     }
    4481              : }
    4482              : 
    4483              : 
    4484              : /* Handle !$omp declare simd.  */
    4485              : 
    4486              : static void
    4487       267089 : mio_omp_declare_simd (gfc_namespace *ns, gfc_omp_declare_simd **odsp)
    4488              : {
    4489       267089 :   if (iomode == IO_OUTPUT)
    4490              :     {
    4491        29781 :       if (*odsp == NULL)
    4492              :         {
    4493        29700 :           if (ns->omp_declare_variant)
    4494              :             {
    4495           98 :               mio_lparen ();
    4496           98 :               mio_rparen ();
    4497              :             }
    4498              :           return;
    4499              :         }
    4500              :     }
    4501       237308 :   else if (peek_atom () != ATOM_LPAREN)
    4502              :     return;
    4503              : 
    4504          170 :   gfc_omp_declare_simd *ods = *odsp;
    4505              : 
    4506          170 :   mio_lparen ();
    4507          170 :   if (iomode == IO_OUTPUT)
    4508              :     {
    4509           81 :       if (ods->clauses)
    4510           81 :         mio_omp_declare_simd_clauses (&ods->clauses);
    4511              :     }
    4512              :   else
    4513              :     {
    4514           89 :       if (peek_atom () == ATOM_RPAREN)
    4515              :         {
    4516           35 :           mio_rparen ();
    4517           35 :           return;
    4518              :         }
    4519              : 
    4520           54 :       require_atom (ATOM_NAME);
    4521           54 :       *odsp = ods = gfc_get_omp_declare_simd ();
    4522           54 :       ods->where = gfc_current_locus;
    4523           54 :       ods->proc_name = ns->proc_name;
    4524           54 :       mio_omp_declare_simd_clauses (&ods->clauses);
    4525              :     }
    4526              : 
    4527          135 :   mio_omp_declare_simd (ns, &ods->next);
    4528              : 
    4529          135 :   mio_rparen ();
    4530              : }
    4531              : 
    4532              : /* Handle !$omp declare variant.  */
    4533              : 
    4534              : static void
    4535       287149 : mio_omp_declare_variant (gfc_namespace *ns, gfc_omp_declare_variant **odvp)
    4536              : {
    4537       287149 :   if (iomode == IO_OUTPUT)
    4538              :     {
    4539        49852 :       if (*odvp == NULL)
    4540              :         return;
    4541              :     }
    4542       237297 :   else if (peek_atom () != ATOM_LPAREN)
    4543              :     return;
    4544              : 
    4545          157 :   gfc_omp_declare_variant *odv;
    4546              : 
    4547          157 :   mio_lparen ();
    4548          157 :   if (iomode == IO_OUTPUT)
    4549              :     {
    4550          117 :       odv = *odvp;
    4551          117 :       write_atom (ATOM_NAME, "OMP_DECLARE_VARIANT");
    4552          117 :       gfc_symtree *st;
    4553          234 :       st = (odv->base_proc_symtree
    4554          117 :             ? odv->base_proc_symtree
    4555          108 :             : gfc_find_symtree (ns->sym_root, ns->proc_name->name));
    4556          117 :       mio_symtree_ref (&st);
    4557          234 :       st = (st->n.sym->attr.if_source == IFSRC_IFBODY
    4558           31 :             && st->n.sym->formal_ns == ns
    4559          118 :             ? gfc_find_symtree (ns->parent->sym_root,
    4560           30 :                                 odv->variant_proc_symtree->name)
    4561              :             : odv->variant_proc_symtree);
    4562          117 :       mio_symtree_ref (&st);
    4563              : 
    4564          117 :       mio_lparen ();
    4565          117 :       write_atom (ATOM_NAME, "SEL");
    4566          253 :       for (gfc_omp_set_selector *set = odv->set_selectors; set; set = set->next)
    4567              :         {
    4568          136 :           int set_code = set->code;
    4569          136 :           mio_integer (&set_code);
    4570          136 :           mio_lparen ();
    4571          312 :           for (gfc_omp_selector *sel = set->trait_selectors; sel;
    4572          176 :                sel = sel->next)
    4573              :             {
    4574          176 :               int sel_code = sel->code;
    4575          176 :               mio_integer (&sel_code);
    4576          176 :               mio_expr (&sel->score);
    4577          176 :               mio_lparen ();
    4578          232 :               for (gfc_omp_trait_property *prop = sel->properties; prop;
    4579           56 :                    prop = prop->next)
    4580              :                 {
    4581           56 :                   int kind = prop->property_kind;
    4582           56 :                   mio_integer (&kind);
    4583           56 :                   int is_name = prop->is_name;
    4584           56 :                   mio_integer (&is_name);
    4585           56 :                   switch (prop->property_kind)
    4586              :                     {
    4587           11 :                     case OMP_TRAIT_PROPERTY_DEV_NUM_EXPR:
    4588           11 :                     case OMP_TRAIT_PROPERTY_BOOL_EXPR:
    4589           11 :                       mio_expr (&prop->expr);
    4590           11 :                       break;
    4591            3 :                     case OMP_TRAIT_PROPERTY_ID:
    4592            3 :                       write_atom (ATOM_STRING, prop->name);
    4593            3 :                       break;
    4594           28 :                     case OMP_TRAIT_PROPERTY_NAME_LIST:
    4595           28 :                       if (prop->is_name)
    4596           25 :                         write_atom (ATOM_STRING, prop->name);
    4597              :                       else
    4598            3 :                         mio_expr (&prop->expr);
    4599              :                       break;
    4600           14 :                     case OMP_TRAIT_PROPERTY_CLAUSE_LIST:
    4601           14 :                       {
    4602              :                         /* Currently only declare simd.  */
    4603           14 :                         mio_lparen ();
    4604           14 :                         mio_omp_declare_simd_clauses (&prop->clauses);
    4605           14 :                         mio_rparen ();
    4606              :                       }
    4607           14 :                       break;
    4608            0 :                     default:
    4609            0 :                       gcc_unreachable ();
    4610              :                     }
    4611              :                 }
    4612          176 :               mio_rparen ();
    4613              :             }
    4614          136 :           mio_rparen ();
    4615              :         }
    4616          117 :       mio_rparen ();
    4617              : 
    4618          117 :       mio_lparen ();
    4619          117 :       write_atom (ATOM_NAME, "ADJ");
    4620          225 :       for (gfc_omp_namelist *arg = odv->adjust_args_list; arg; arg = arg->next)
    4621              :         {
    4622          108 :           int need_ptr = arg->u.adj_args.need_ptr;
    4623          108 :           int need_addr = arg->u.adj_args.need_addr;
    4624          108 :           int range_start = arg->u.adj_args.range_start;
    4625          108 :           int omp_num_args_plus = arg->u.adj_args.omp_num_args_plus;
    4626          108 :           int omp_num_args_minus = arg->u.adj_args.omp_num_args_minus;
    4627          108 :           mio_integer (&need_ptr);
    4628          108 :           mio_integer (&need_addr);
    4629          108 :           mio_integer (&range_start);
    4630          108 :           mio_integer (&omp_num_args_plus);
    4631          108 :           mio_integer (&omp_num_args_minus);
    4632          108 :           mio_expr (&arg->expr);
    4633              :         }
    4634          117 :       mio_rparen ();
    4635              : 
    4636          117 :       mio_lparen ();
    4637          117 :       write_atom (ATOM_NAME, "APP");
    4638          155 :       for (gfc_omp_namelist *arg = odv->append_args_list; arg; arg = arg->next)
    4639              :         {
    4640           38 :           int target = arg->u.init.target;
    4641           38 :           int targetsync = arg->u.init.targetsync;
    4642           38 :           mio_integer (&target);
    4643           38 :           mio_integer (&targetsync);
    4644           38 :           mio_integer (&arg->u.init.len);
    4645           38 :           gfc_char_t *p = XALLOCAVEC (gfc_char_t, arg->u.init.len);
    4646          409 :           for (int i = 0; i < arg->u.init.len; i++)
    4647          371 :             p[i] = arg->u2.init_interop[i];
    4648           38 :           mio_allocated_wide_string (p, arg->u.init.len);
    4649              :         }
    4650          117 :       mio_rparen ();
    4651              :     }
    4652              :   else
    4653              :     {
    4654           40 :       if (peek_atom () == ATOM_RPAREN)
    4655              :         {
    4656            0 :           mio_rparen ();
    4657            0 :           return;
    4658              :         }
    4659              : 
    4660           40 :       require_atom (ATOM_NAME);
    4661           40 :       odv = *odvp = gfc_get_omp_declare_variant ();
    4662           40 :       odv->where = gfc_current_locus;
    4663              : 
    4664           40 :       mio_symtree_ref (&odv->base_proc_symtree);
    4665           40 :       mio_symtree_ref (&odv->variant_proc_symtree);
    4666              : 
    4667           40 :       mio_lparen ();
    4668           40 :       require_atom (ATOM_NAME);  /* SEL */
    4669           40 :       gfc_omp_set_selector **set = &odv->set_selectors;
    4670           82 :       while (peek_atom () != ATOM_RPAREN)
    4671              :         {
    4672           42 :           *set = gfc_get_omp_set_selector ();
    4673           42 :           int set_code;
    4674           42 :           mio_integer (&set_code);
    4675           42 :           (*set)->code = (enum omp_tss_code) set_code;
    4676              : 
    4677           42 :           mio_lparen ();
    4678           42 :           gfc_omp_selector **sel = &(*set)->trait_selectors;
    4679           86 :           while (peek_atom () != ATOM_RPAREN)
    4680              :             {
    4681           44 :               *sel = gfc_get_omp_selector ();
    4682           44 :               int sel_code = 0;
    4683           44 :               mio_integer (&sel_code);
    4684           44 :               (*sel)->code = (enum omp_ts_code) sel_code;
    4685           44 :               mio_expr (&(*sel)->score);
    4686              : 
    4687           44 :               mio_lparen ();
    4688           44 :               gfc_omp_trait_property **prop = &(*sel)->properties;
    4689           47 :               while (peek_atom () != ATOM_RPAREN)
    4690              :                 {
    4691            3 :                   *prop = gfc_get_omp_trait_property ();
    4692            3 :                   int kind = 0, is_name = 0;
    4693            3 :                   mio_integer (&kind);
    4694            3 :                   mio_integer (&is_name);
    4695            3 :                   (*prop)->property_kind = (enum omp_tp_type) kind;
    4696            3 :                   (*prop)->is_name = is_name;
    4697            3 :                   switch ((*prop)->property_kind)
    4698              :                     {
    4699            0 :                     case OMP_TRAIT_PROPERTY_DEV_NUM_EXPR:
    4700            0 :                     case OMP_TRAIT_PROPERTY_BOOL_EXPR:
    4701            0 :                       mio_expr (&(*prop)->expr);
    4702            0 :                       break;
    4703            0 :                     case OMP_TRAIT_PROPERTY_ID:
    4704            0 :                       (*prop)->name = read_string ();
    4705            0 :                       break;
    4706            3 :                     case OMP_TRAIT_PROPERTY_NAME_LIST:
    4707            3 :                       if ((*prop)->is_name)
    4708            2 :                         (*prop)->name = read_string ();
    4709              :                       else
    4710            1 :                         mio_expr (&(*prop)->expr);
    4711              :                       break;
    4712            0 :                     case OMP_TRAIT_PROPERTY_CLAUSE_LIST:
    4713            0 :                       {
    4714              :                         /* Currently only declare simd.  */
    4715            0 :                         mio_lparen ();
    4716            0 :                         mio_omp_declare_simd_clauses (&(*prop)->clauses);
    4717            0 :                         mio_rparen ();
    4718              :                       }
    4719            0 :                       break;
    4720            0 :                     default:
    4721            0 :                       gcc_unreachable ();
    4722              :                     }
    4723            3 :                   prop = &(*prop)->next;
    4724              :                 }
    4725           44 :               mio_rparen ();
    4726           44 :               sel = &(*sel)->next;
    4727              :             }
    4728           42 :           mio_rparen ();
    4729           42 :           set = &(*set)->next;
    4730              :         }
    4731           40 :       mio_rparen ();
    4732              : 
    4733           40 :       mio_lparen ();
    4734           40 :       require_atom (ATOM_NAME);  /* ADJ */
    4735           40 :       gfc_omp_namelist **nl = &odv->adjust_args_list;
    4736          122 :       while (peek_atom () != ATOM_RPAREN)
    4737              :         {
    4738           82 :           *nl = gfc_get_omp_namelist ();
    4739           82 :           (*nl)->where = gfc_current_locus;
    4740           82 :           int need_ptr, need_addr, range_start;
    4741           82 :           int omp_num_args_plus, omp_num_args_minus;
    4742           82 :           mio_integer (&need_ptr);
    4743           82 :           mio_integer (&need_addr);
    4744           82 :           mio_integer (&range_start);
    4745           82 :           mio_integer (&omp_num_args_plus);
    4746           82 :           mio_integer (&omp_num_args_minus);
    4747           82 :           (*nl)->u.adj_args.need_ptr = need_ptr;
    4748           82 :           (*nl)->u.adj_args.need_addr = need_addr;
    4749           82 :           (*nl)->u.adj_args.range_start = range_start;
    4750           82 :           (*nl)->u.adj_args.omp_num_args_plus = omp_num_args_minus;
    4751           82 :           (*nl)->u.adj_args.omp_num_args_plus = omp_num_args_minus;
    4752           82 :           mio_expr (&(*nl)->expr);
    4753           82 :           nl = &(*nl)->next;
    4754              :         }
    4755           40 :       mio_rparen ();
    4756              : 
    4757           40 :       mio_lparen ();
    4758           40 :       require_atom (ATOM_NAME);  /* APP */
    4759           40 :       nl = &odv->append_args_list;
    4760           58 :       while (peek_atom () != ATOM_RPAREN)
    4761              :         {
    4762           18 :           *nl = gfc_get_omp_namelist ();
    4763           18 :           (*nl)->where = gfc_current_locus;
    4764           18 :           int target, targetsync;
    4765           18 :           mio_integer (&target);
    4766           18 :           mio_integer (&targetsync);
    4767           18 :           mio_integer (&(*nl)->u.init.len);
    4768           18 :           (*nl)->u.init.target = target;
    4769           18 :           (*nl)->u.init.targetsync = targetsync;
    4770           18 :           const gfc_char_t *p = XALLOCAVEC (gfc_char_t, (*nl)->u.init.len); // FIXME: memory handling?
    4771           18 :           (*nl)->u2.init_interop = XCNEWVEC (char,  (*nl)->u.init.len);
    4772           18 :           p = mio_allocated_wide_string (NULL, (*nl)->u.init.len);
    4773          119 :           for (int i = 0; i < (*nl)->u.init.len; i++)
    4774           83 :             (*nl)->u2.init_interop[i] = p[i];
    4775           18 :           nl = &(*nl)->next;
    4776              :         }
    4777           40 :       mio_rparen ();
    4778              :     }
    4779              : 
    4780          157 :   mio_omp_declare_variant (ns, &odv->next);
    4781              : 
    4782          157 :   mio_rparen ();
    4783              : }
    4784              : 
    4785              : static const mstring omp_declare_reduction_stmt[] =
    4786              : {
    4787              :     minit ("ASSIGN", 0),
    4788              :     minit ("CALL", 1),
    4789              :     minit (NULL, -1)
    4790              : };
    4791              : 
    4792              : 
    4793              : static void
    4794          293 : mio_omp_udr_expr (gfc_omp_udr *udr, gfc_symbol **sym1, gfc_symbol **sym2,
    4795              :                   gfc_namespace *ns, bool is_initializer)
    4796              : {
    4797          293 :   if (iomode == IO_OUTPUT)
    4798              :     {
    4799          144 :       if ((*sym1)->module == NULL)
    4800              :         {
    4801          108 :           (*sym1)->module = module_name;
    4802          108 :           (*sym2)->module = module_name;
    4803              :         }
    4804          144 :       mio_symbol_ref (sym1);
    4805          144 :       mio_symbol_ref (sym2);
    4806          144 :       if (ns->code->op == EXEC_ASSIGN)
    4807              :         {
    4808           90 :           mio_name (0, omp_declare_reduction_stmt);
    4809           90 :           mio_expr (&ns->code->expr1);
    4810           90 :           mio_expr (&ns->code->expr2);
    4811              :         }
    4812              :       else
    4813              :         {
    4814           54 :           int flag;
    4815           54 :           mio_name (1, omp_declare_reduction_stmt);
    4816           54 :           mio_symtree_ref (&ns->code->symtree);
    4817           54 :           mio_actual_arglist (&ns->code->ext.actual, false);
    4818              : 
    4819           54 :           flag = ns->code->resolved_isym != NULL;
    4820           54 :           mio_integer (&flag);
    4821           54 :           if (flag)
    4822            0 :             write_atom (ATOM_STRING, ns->code->resolved_isym->name);
    4823              :           else
    4824           54 :             mio_symbol_ref (&ns->code->resolved_sym);
    4825              :         }
    4826              :     }
    4827              :   else
    4828              :     {
    4829          149 :       pointer_info *p1 = mio_symbol_ref (sym1);
    4830          149 :       pointer_info *p2 = mio_symbol_ref (sym2);
    4831          149 :       gfc_symbol *sym;
    4832          149 :       gcc_assert (p1->u.rsym.ns == p2->u.rsym.ns);
    4833          149 :       gcc_assert (p1->u.rsym.sym == NULL);
    4834              :       /* Add hidden symbols to the symtree.  */
    4835          149 :       pointer_info *q = get_integer (p1->u.rsym.ns);
    4836          149 :       q->u.pointer = (void *) ns;
    4837          231 :       sym = gfc_new_symbol (is_initializer ? "omp_priv" : "omp_out", ns);
    4838          149 :       sym->ts = udr->ts;
    4839          149 :       sym->module = gfc_get_string ("%s", p1->u.rsym.module);
    4840          149 :       associate_integer_pointer (p1, sym);
    4841          149 :       sym->attr.omp_udr_artificial_var = 1;
    4842          149 :       gcc_assert (p2->u.rsym.sym == NULL);
    4843          231 :       sym = gfc_new_symbol (is_initializer ? "omp_orig" : "omp_in", ns);
    4844          149 :       sym->ts = udr->ts;
    4845          149 :       sym->module = gfc_get_string ("%s", p2->u.rsym.module);
    4846          149 :       associate_integer_pointer (p2, sym);
    4847          149 :       sym->attr.omp_udr_artificial_var = 1;
    4848          149 :       if (mio_name (0, omp_declare_reduction_stmt) == 0)
    4849              :         {
    4850           95 :           ns->code = gfc_get_code (EXEC_ASSIGN);
    4851           95 :           mio_expr (&ns->code->expr1);
    4852           95 :           mio_expr (&ns->code->expr2);
    4853              :         }
    4854              :       else
    4855              :         {
    4856           54 :           int flag;
    4857           54 :           ns->code = gfc_get_code (EXEC_CALL);
    4858           54 :           mio_symtree_ref (&ns->code->symtree);
    4859           54 :           mio_actual_arglist (&ns->code->ext.actual, false);
    4860              : 
    4861           54 :           mio_integer (&flag);
    4862           54 :           if (flag)
    4863              :             {
    4864            0 :               require_atom (ATOM_STRING);
    4865            0 :               ns->code->resolved_isym = gfc_find_subroutine (atom_string);
    4866            0 :               free (atom_string);
    4867              :             }
    4868              :           else
    4869           54 :             mio_symbol_ref (&ns->code->resolved_sym);
    4870              :         }
    4871          149 :       ns->code->loc = gfc_current_locus;
    4872          149 :       ns->omp_udr_ns = 1;
    4873              :     }
    4874          293 : }
    4875              : 
    4876              : 
    4877              : /* Unlike most other routines, the address of the symbol node is already
    4878              :    fixed on input and the name/module has already been filled in.
    4879              :    If you update the symbol format here, don't forget to update read_module
    4880              :    as well (look for "seek to the symbol's component list").   */
    4881              : 
    4882              : static void
    4883      1316267 : mio_symbol (gfc_symbol *sym)
    4884              : {
    4885      1316267 :   int intmod = INTMOD_NONE;
    4886              : 
    4887      1316267 :   mio_lparen ();
    4888              : 
    4889      1316267 :   mio_symbol_attribute (&sym->attr);
    4890              : 
    4891      1316267 :   if (sym->attr.pdt_type)
    4892          722 :     sym->name = gfc_dt_upper_string (sym->name);
    4893              : 
    4894              :   /* Note that components are always saved, even if they are supposed
    4895              :      to be private.  Component access is checked during searching.  */
    4896      1316267 :   mio_component_list (&sym->components, sym->attr.vtype);
    4897      1316267 :   if (sym->components != NULL)
    4898        77025 :     sym->component_access
    4899        77025 :       = MIO_NAME (gfc_access) (sym->component_access, access_types);
    4900              : 
    4901      1316267 :   mio_typespec (&sym->ts);
    4902      1316267 :   if (sym->ts.type == BT_CLASS)
    4903        15638 :     sym->attr.class_ok = 1;
    4904              : 
    4905      1316267 :   if (iomode == IO_OUTPUT)
    4906       248474 :     mio_namespace_ref (&sym->formal_ns);
    4907              :   else
    4908              :     {
    4909      1067793 :       mio_namespace_ref (&sym->formal_ns);
    4910      1067793 :       if (sym->formal_ns)
    4911       237254 :         sym->formal_ns->proc_name = sym;
    4912              :     }
    4913              : 
    4914              :   /* Save/restore common block links.  */
    4915      1316267 :   mio_symbol_ref (&sym->common_next);
    4916              : 
    4917      1316267 :   mio_formal_arglist (&sym->formal);
    4918              : 
    4919      1316267 :   if (sym->attr.flavor == FL_PARAMETER)
    4920       258507 :     mio_expr (&sym->value);
    4921              : 
    4922      1316267 :   mio_array_spec (&sym->as);
    4923              : 
    4924      1316267 :   mio_symbol_ref (&sym->result);
    4925              : 
    4926      1316267 :   if (sym->attr.cray_pointee)
    4927           26 :     mio_symbol_ref (&sym->cp_pointer);
    4928              : 
    4929              :   /* Load/save the f2k_derived namespace of a derived-type symbol.  */
    4930      1316267 :   mio_full_f2k_derived (sym);
    4931              : 
    4932              :   /* PDT types store the symbol specification list here. */
    4933      1316267 :   mio_actual_arglist (&sym->param_list, true);
    4934              : 
    4935      1316267 :   mio_namelist (sym);
    4936              : 
    4937              :   /* Add the fields that say whether this is from an intrinsic module,
    4938              :      and if so, what symbol it is within the module.  */
    4939              : /*   mio_integer (&(sym->from_intmod)); */
    4940      1316267 :   if (iomode == IO_OUTPUT)
    4941              :     {
    4942       248474 :       intmod = sym->from_intmod;
    4943       248474 :       mio_integer (&intmod);
    4944              :     }
    4945              :   else
    4946              :     {
    4947      1067793 :       mio_integer (&intmod);
    4948      1067793 :       if (current_intmod)
    4949       317189 :         sym->from_intmod = current_intmod;
    4950              :       else
    4951       750604 :         sym->from_intmod = (intmod_id) intmod;
    4952              :     }
    4953              : 
    4954      1316267 :   mio_integer (&(sym->intmod_sym_id));
    4955              : 
    4956      1316267 :   if (gfc_fl_struct (sym->attr.flavor))
    4957        80464 :     mio_integer (&(sym->hash_value));
    4958              : 
    4959      1316267 :   if (sym->formal_ns
    4960       267557 :       && sym->formal_ns->proc_name == sym
    4961       266954 :       && sym->formal_ns->entries == NULL)
    4962              :     {
    4963       266954 :       mio_omp_declare_simd (sym->formal_ns, &sym->formal_ns->omp_declare_simd);
    4964       266954 :       mio_omp_declare_variant (sym->formal_ns,
    4965       266954 :                                &sym->formal_ns->omp_declare_variant);
    4966              :     }
    4967       218774 :   else if ((iomode == IO_OUTPUT && sym->ns->proc_name == sym)
    4968      1248052 :            || (iomode == IO_INPUT && peek_atom () == ATOM_LPAREN))
    4969        20038 :     mio_omp_declare_variant (sym->ns, &sym->ns->omp_declare_variant);
    4970              : 
    4971      1316267 :   mio_rparen ();
    4972      1316267 : }
    4973              : 
    4974              : 
    4975              : /************************* Top level subroutines *************************/
    4976              : 
    4977              : /* A recursive function to look for a specific symbol by name and by
    4978              :    module.  Whilst several symtrees might point to one symbol, its
    4979              :    is sufficient for the purposes here than one exist.  Note that
    4980              :    generic interfaces are distinguished as are symbols that have been
    4981              :    renamed in another module.  */
    4982              : static gfc_symtree *
    4983     47287823 : find_symbol (gfc_symtree *st, const char *name,
    4984              :              const char *module, int generic)
    4985              : {
    4986     94052344 :   int c;
    4987     94052344 :   gfc_symtree *retval, *s;
    4988              : 
    4989     94052344 :   if (st == NULL || st->n.sym == NULL)
    4990              :     return NULL;
    4991              : 
    4992     46766935 :   c = strcmp (name, st->n.sym->name);
    4993        98963 :   if (c == 0 && st->n.sym->module
    4994        98957 :              && strcmp (module, st->n.sym->module) == 0
    4995     46808742 :              && !check_unique_name (st->name))
    4996              :     {
    4997        41723 :       s = gfc_find_symtree (gfc_current_ns->sym_root, name);
    4998              : 
    4999              :       /* Detect symbols that are renamed by use association in another
    5000              :          module by the absence of a symtree and null attr.use_rename,
    5001              :          since the latter is not transmitted in the module file.  */
    5002        41723 :       if (((!generic && !st->n.sym->attr.generic)
    5003        33367 :                 || (generic && st->n.sym->attr.generic))
    5004         8396 :             && !(s == NULL && !st->n.sym->attr.use_rename))
    5005              :         return st;
    5006              :     }
    5007              : 
    5008     46766341 :   retval = find_symbol (st->left, name, module, generic);
    5009              : 
    5010     46766341 :   if (retval == NULL)
    5011     46764521 :     retval = find_symbol (st->right, name, module, generic);
    5012              : 
    5013              :   return retval;
    5014              : }
    5015              : 
    5016              : 
    5017              : /* Skip a list between balanced left and right parens.
    5018              :    By setting NEST_LEVEL one assumes that a number of NEST_LEVEL opening parens
    5019              :    have been already parsed by hand, and the remaining of the content is to be
    5020              :    skipped here.  The default value is 0 (balanced parens).  */
    5021              : 
    5022              : static void
    5023      1424333 : skip_list (int nest_level = 0)
    5024              : {
    5025      1424333 :   int level;
    5026              : 
    5027      1424333 :   level = nest_level;
    5028     67068026 :   do
    5029              :     {
    5030     67068026 :       switch (parse_atom ())
    5031              :         {
    5032     16594721 :         case ATOM_LPAREN:
    5033     16594721 :           level++;
    5034     16594721 :           break;
    5035              : 
    5036     16612063 :         case ATOM_RPAREN:
    5037     16612063 :           level--;
    5038     16612063 :           break;
    5039              : 
    5040       735683 :         case ATOM_STRING:
    5041       735683 :           free (atom_string);
    5042       735683 :           break;
    5043              : 
    5044              :         case ATOM_NAME:
    5045              :         case ATOM_INTEGER:
    5046              :           break;
    5047              :         }
    5048              :     }
    5049     67068026 :   while (level > 0);
    5050      1424333 : }
    5051              : 
    5052              : 
    5053              : /* Load operator interfaces from the module.  Interfaces are unusual
    5054              :    in that they attach themselves to existing symbols.  */
    5055              : 
    5056              : static void
    5057        13914 : load_operator_interfaces (void)
    5058              : {
    5059        13914 :   const char *p;
    5060              :   /* "module" must be large enough for the case of submodules in which the name
    5061              :      has the form module.submodule */
    5062        13914 :   char name[GFC_MAX_SYMBOL_LEN + 1], module[2 * GFC_MAX_SYMBOL_LEN + 2];
    5063        13914 :   gfc_user_op *uop;
    5064        13914 :   pointer_info *pi = NULL;
    5065        13914 :   int n, i;
    5066              : 
    5067        13914 :   mio_lparen ();
    5068              : 
    5069        27992 :   while (peek_atom () != ATOM_RPAREN)
    5070              :     {
    5071          164 :       mio_lparen ();
    5072              : 
    5073          164 :       mio_internal_string (name);
    5074          164 :       mio_internal_string (module);
    5075              : 
    5076          164 :       n = number_use_names (name, true);
    5077          164 :       n = n ? n : 1;
    5078              : 
    5079          346 :       for (i = 1; i <= n; i++)
    5080              :         {
    5081              :           /* Decide if we need to load this one or not.  */
    5082          182 :           p = find_use_name_n (name, &i, true);
    5083              : 
    5084          182 :           if (p == NULL)
    5085              :             {
    5086           14 :               while (parse_atom () != ATOM_RPAREN);
    5087            7 :               continue;
    5088              :             }
    5089              : 
    5090          175 :           if (i == 1)
    5091              :             {
    5092          157 :               uop = gfc_get_uop (p);
    5093          157 :               pi = mio_interface_rest (&uop->op);
    5094              :             }
    5095              :           else
    5096              :             {
    5097           18 :               if (gfc_find_uop (p, NULL))
    5098            6 :                 continue;
    5099           12 :               uop = gfc_get_uop (p);
    5100           12 :               uop->op = gfc_get_interface ();
    5101           12 :               uop->op->where = gfc_current_locus;
    5102           12 :               add_fixup (pi->integer, &uop->op->sym);
    5103              :             }
    5104              :         }
    5105              :     }
    5106              : 
    5107        13914 :   mio_rparen ();
    5108        13914 : }
    5109              : 
    5110              : 
    5111              : /* Load interfaces from the module.  Interfaces are unusual in that
    5112              :    they attach themselves to existing symbols.  */
    5113              : 
    5114              : static void
    5115        13914 : load_generic_interfaces (void)
    5116              : {
    5117        13914 :   const char *p;
    5118              :   /* "module" must be large enough for the case of submodules in which the name
    5119              :      has the form module.submodule */
    5120        13914 :   char name[GFC_MAX_SYMBOL_LEN + 1], module[2 * GFC_MAX_SYMBOL_LEN + 2];
    5121        13914 :   gfc_symbol *sym;
    5122        13914 :   gfc_interface *generic = NULL, *gen = NULL;
    5123        13914 :   int n, i, renamed;
    5124        13914 :   bool ambiguous_set = false;
    5125              : 
    5126        13914 :   mio_lparen ();
    5127              : 
    5128        89457 :   while (peek_atom () != ATOM_RPAREN)
    5129              :     {
    5130        61629 :       mio_lparen ();
    5131              : 
    5132        61629 :       mio_internal_string (name);
    5133        61629 :       mio_internal_string (module);
    5134              : 
    5135        61629 :       n = number_use_names (name, false);
    5136        61629 :       renamed = n ? 1 : 0;
    5137        60816 :       n = n ? n : 1;
    5138              : 
    5139       123262 :       for (i = 1; i <= n; i++)
    5140              :         {
    5141        61633 :           gfc_symtree *st;
    5142              :           /* Decide if we need to load this one or not.  */
    5143        61633 :           p = find_use_name_n (name, &i, false);
    5144              : 
    5145        61633 :           if (!p || gfc_find_symbol (p, NULL, 0, &sym))
    5146              :             {
    5147              :               /* Skip the specific names for these cases.  */
    5148         9787 :               while (i == 1 && parse_atom () != ATOM_RPAREN);
    5149              : 
    5150         1828 :               continue;
    5151              :             }
    5152              : 
    5153        59805 :           st = find_symbol (gfc_current_ns->sym_root,
    5154              :                             name, module_name, 1);
    5155              : 
    5156              :           /* If the symbol exists already and is being USEd without being
    5157              :              in an ONLY clause, do not load a new symtree(11.3.2).  */
    5158        59805 :           if (!only_flag && st)
    5159           44 :             sym = st->n.sym;
    5160              : 
    5161        59805 :           if (!sym)
    5162              :             {
    5163        28961 :               if (st)
    5164              :                 {
    5165            1 :                   sym = st->n.sym;
    5166            1 :                   if (strcmp (st->name, p) != 0)
    5167              :                     {
    5168            1 :                       st = gfc_new_symtree (&gfc_current_ns->sym_root, p);
    5169            1 :                       st->n.sym = sym;
    5170            1 :                       sym->refs++;
    5171              :                     }
    5172              :                 }
    5173              : 
    5174              :               /* Since we haven't found a valid generic interface, we had
    5175              :                  better make one.  */
    5176        28961 :               if (!sym)
    5177              :                 {
    5178        28960 :                   gfc_get_symbol (p, NULL, &sym);
    5179        28960 :                   sym->name = gfc_get_string ("%s", name);
    5180        28960 :                   sym->module = module_name;
    5181        28960 :                   sym->attr.flavor = FL_PROCEDURE;
    5182        28960 :                   sym->attr.generic = 1;
    5183        28960 :                   sym->attr.use_assoc = 1;
    5184              :                 }
    5185              :             }
    5186              :           else
    5187              :             {
    5188              :               /* Unless sym is a generic interface, this reference
    5189              :                  is ambiguous.  */
    5190        30844 :               if (st == NULL)
    5191        30799 :                 st = gfc_find_symtree (gfc_current_ns->sym_root, p);
    5192              : 
    5193        30844 :               sym = st->n.sym;
    5194              : 
    5195        30844 :               if (st && !sym->attr.generic
    5196        28471 :                      && !st->ambiguous
    5197        28471 :                      && sym->module
    5198        28470 :                      && strcmp (module, sym->module))
    5199              :                 {
    5200            1 :                   ambiguous_set = true;
    5201            1 :                   st->ambiguous = 1;
    5202              :                 }
    5203              :             }
    5204              : 
    5205        59805 :           sym->attr.use_only = only_flag;
    5206        59805 :           sym->attr.use_rename = renamed;
    5207              : 
    5208        59805 :           if (i == 1)
    5209              :             {
    5210        59801 :               mio_interface_rest (&sym->generic);
    5211        59801 :               generic = sym->generic;
    5212              :             }
    5213            4 :           else if (!sym->generic)
    5214              :             {
    5215            0 :               sym->generic = generic;
    5216            0 :               sym->attr.generic_copy = 1;
    5217              :             }
    5218              : 
    5219              :           /* If a procedure that is not generic has generic interfaces
    5220              :              that include itself, it is generic! We need to take care
    5221              :              to retain symbols ambiguous that were already so.  */
    5222        59805 :           if (sym->attr.use_assoc
    5223        31335 :                 && !sym->attr.generic
    5224            2 :                 && sym->attr.flavor == FL_PROCEDURE)
    5225              :             {
    5226            4 :               for (gen = generic; gen; gen = gen->next)
    5227              :                 {
    5228            3 :                   if (gen->sym == sym)
    5229              :                     {
    5230            1 :                       sym->attr.generic = 1;
    5231            1 :                       if (ambiguous_set)
    5232            0 :                         st->ambiguous = 0;
    5233              :                       break;
    5234              :                     }
    5235              :                 }
    5236              :             }
    5237              : 
    5238              :         }
    5239              :     }
    5240              : 
    5241        13914 :   mio_rparen ();
    5242        13914 : }
    5243              : 
    5244              : 
    5245              : /* Load common blocks.  */
    5246              : 
    5247              : static void
    5248        13914 : load_commons (void)
    5249              : {
    5250        13914 :   char name[GFC_MAX_SYMBOL_LEN + 1];
    5251        13914 :   gfc_common_head *p;
    5252              : 
    5253        13914 :   mio_lparen ();
    5254              : 
    5255        27998 :   while (peek_atom () != ATOM_RPAREN)
    5256              :     {
    5257          170 :       int flags = 0;
    5258          170 :       char* label;
    5259          170 :       mio_lparen ();
    5260          170 :       mio_internal_string (name);
    5261              : 
    5262          170 :       p = gfc_get_common (name, 1);
    5263              : 
    5264          170 :       mio_symbol_ref (&p->head);
    5265          170 :       mio_integer (&flags);
    5266          170 :       if (flags & 1)
    5267            0 :         p->saved = 1;
    5268          170 :       if (flags & 2)
    5269            0 :         p->threadprivate = 1;
    5270          170 :       p->omp_device_type = (gfc_omp_device_type) ((flags >> 2) & 3);
    5271          170 :       if ((flags >> 4) & 1)
    5272            0 :         p->omp_groupprivate = 1;
    5273          170 :       p->use_assoc = 1;
    5274              : 
    5275              :       /* Get whether this was a bind(c) common or not.  */
    5276          170 :       mio_integer (&p->is_bind_c);
    5277              :       /* Get the binding label.  */
    5278          170 :       label = read_string ();
    5279          170 :       if (strlen (label))
    5280           22 :         p->binding_label = IDENTIFIER_POINTER (get_identifier (label));
    5281          170 :       XDELETEVEC (label);
    5282              : 
    5283          170 :       mio_rparen ();
    5284              :     }
    5285              : 
    5286        13914 :   mio_rparen ();
    5287        13914 : }
    5288              : 
    5289              : 
    5290              : /* Load equivalences.  The flag in_load_equiv informs mio_expr_ref of this
    5291              :    so that unused variables are not loaded and so that the expression can
    5292              :    be safely freed.  */
    5293              : 
    5294              : static void
    5295        13914 : load_equiv (void)
    5296              : {
    5297        13914 :   gfc_equiv *head, *tail, *end, *eq, *equiv;
    5298        13914 :   bool duplicate;
    5299              : 
    5300        13914 :   mio_lparen ();
    5301        13914 :   in_load_equiv = true;
    5302              : 
    5303        13914 :   end = gfc_current_ns->equiv;
    5304        13920 :   while (end != NULL && end->next != NULL)
    5305              :     end = end->next;
    5306              : 
    5307        14047 :   while (peek_atom () != ATOM_RPAREN) {
    5308          133 :     mio_lparen ();
    5309          133 :     head = tail = NULL;
    5310              : 
    5311          532 :     while(peek_atom () != ATOM_RPAREN)
    5312              :       {
    5313          266 :         if (head == NULL)
    5314          133 :           head = tail = gfc_get_equiv ();
    5315              :         else
    5316              :           {
    5317          133 :             tail->eq = gfc_get_equiv ();
    5318          133 :             tail = tail->eq;
    5319              :           }
    5320              : 
    5321          266 :         mio_pool_string (&tail->module);
    5322          266 :         mio_expr (&tail->expr);
    5323              :       }
    5324              : 
    5325              :     /* Check for duplicate equivalences being loaded from different modules */
    5326          133 :     duplicate = false;
    5327          192 :     for (equiv = gfc_current_ns->equiv; equiv; equiv = equiv->next)
    5328              :       {
    5329           65 :         if (equiv->module && head->module
    5330           65 :             && strcmp (equiv->module, head->module) == 0)
    5331              :           {
    5332              :             duplicate = true;
    5333              :             break;
    5334              :           }
    5335              :       }
    5336              : 
    5337          133 :     if (duplicate)
    5338              :       {
    5339           18 :         for (eq = head; eq; eq = head)
    5340              :           {
    5341           12 :             head = eq->eq;
    5342           12 :             gfc_free_expr (eq->expr);
    5343           12 :             free (eq);
    5344              :           }
    5345              :       }
    5346              : 
    5347          133 :     if (end == NULL)
    5348           80 :       gfc_current_ns->equiv = head;
    5349              :     else
    5350           53 :       end->next = head;
    5351              : 
    5352          133 :     if (head != NULL)
    5353          127 :       end = head;
    5354              : 
    5355          133 :     mio_rparen ();
    5356              :   }
    5357              : 
    5358        13914 :   mio_rparen ();
    5359        13914 :   in_load_equiv = false;
    5360        13914 : }
    5361              : 
    5362              : 
    5363              : /* This function loads OpenMP user defined reductions.  */
    5364              : static void
    5365        13914 : load_omp_udrs (void)
    5366              : {
    5367        13914 :   mio_lparen ();
    5368        27916 :   while (peek_atom () != ATOM_RPAREN)
    5369              :     {
    5370           88 :       const char *name = NULL, *newname;
    5371           88 :       char *altname;
    5372           88 :       gfc_typespec ts;
    5373           88 :       gfc_symtree *st;
    5374           88 :       gfc_omp_reduction_op rop = OMP_REDUCTION_USER;
    5375              : 
    5376           88 :       mio_lparen ();
    5377           88 :       mio_pool_string (&name);
    5378           88 :       gfc_clear_ts (&ts);
    5379           88 :       mio_typespec (&ts);
    5380           88 :       if (startswith (name, "operator "))
    5381              :         {
    5382           38 :           const char *p = name + sizeof ("operator ") - 1;
    5383           38 :           if (strcmp (p, "+") == 0)
    5384              :             rop = OMP_REDUCTION_PLUS;
    5385            0 :           else if (strcmp (p, "*") == 0)
    5386              :             rop = OMP_REDUCTION_TIMES;
    5387            0 :           else if (strcmp (p, "-") == 0)
    5388              :             rop = OMP_REDUCTION_MINUS;
    5389            0 :           else if (strcmp (p, ".and.") == 0)
    5390              :             rop = OMP_REDUCTION_AND;
    5391            0 :           else if (strcmp (p, ".or.") == 0)
    5392              :             rop = OMP_REDUCTION_OR;
    5393            0 :           else if (strcmp (p, ".eqv.") == 0)
    5394              :             rop = OMP_REDUCTION_EQV;
    5395            0 :           else if (strcmp (p, ".neqv.") == 0)
    5396              :             rop = OMP_REDUCTION_NEQV;
    5397              :         }
    5398           50 :       altname = NULL;
    5399           50 :       if (rop == OMP_REDUCTION_USER && name[0] == '.')
    5400              :         {
    5401           50 :           size_t len = strlen (name + 1);
    5402           50 :           altname = XALLOCAVEC (char, len);
    5403           50 :           gcc_assert (name[len] == '.');
    5404           50 :           memcpy (altname, name + 1, len - 1);
    5405           50 :           altname[len - 1] = '\0';
    5406              :         }
    5407           88 :       newname = name;
    5408           88 :       if (rop == OMP_REDUCTION_USER)
    5409          100 :         newname = find_use_name (altname ? altname : name, !!altname);
    5410           44 :       else if (only_flag && find_use_operator ((gfc_intrinsic_op) rop) == NULL)
    5411              :         newname = NULL;
    5412           88 :       if (newname == NULL)
    5413              :         {
    5414            0 :           skip_list (1);
    5415            6 :           continue;
    5416              :         }
    5417           88 :       if (altname && newname != altname)
    5418              :         {
    5419           18 :           size_t len = strlen (newname);
    5420           18 :           altname = XALLOCAVEC (char, len + 3);
    5421           18 :           altname[0] = '.';
    5422           18 :           memcpy (altname + 1, newname, len);
    5423           18 :           altname[len + 1] = '.';
    5424           18 :           altname[len + 2] = '\0';
    5425           18 :           name = gfc_get_string ("%s", altname);
    5426              :         }
    5427           88 :       st = gfc_find_symtree (gfc_current_ns->omp_udr_root, name);
    5428           88 :       gfc_omp_udr *udr = gfc_omp_udr_find (st, &ts);
    5429           88 :       if (udr)
    5430              :         {
    5431            6 :           require_atom (ATOM_INTEGER);
    5432            6 :           pointer_info *p = get_integer (atom_int);
    5433            6 :           if (strcmp (p->u.rsym.module, udr->omp_out->module))
    5434              :             {
    5435            6 :               gcc_assert (!gfc_buffered_p ());  /* Cf. PR80012 comment 15.  */
    5436            6 :               auto_diagnostic_group d;
    5437            6 :               gfc_error ("Ambiguous !$OMP DECLARE REDUCTION %qs for type %qs "
    5438              :                          "from module %qs at %L", udr->name,
    5439              :                          gfc_typename (&ts), module_name, &gfc_current_locus);
    5440            6 :               inform (gfc_get_location (&udr->where),
    5441              :                       "Previous !$OMP DECLARE REDUCTION from module %qs",
    5442            6 :                       udr->omp_out->module);
    5443            6 :             }
    5444            6 :           skip_list (1);
    5445            6 :           continue;
    5446            6 :         }
    5447           82 :       udr = gfc_get_omp_udr ();
    5448           82 :       udr->name = name;
    5449           82 :       udr->rop = rop;
    5450           82 :       udr->ts = ts;
    5451           82 :       udr->where = gfc_current_locus;
    5452           82 :       udr->combiner_ns = gfc_get_namespace (gfc_current_ns, 1);
    5453           82 :       udr->combiner_ns->proc_name = gfc_current_ns->proc_name;
    5454           82 :       mio_omp_udr_expr (udr, &udr->omp_out, &udr->omp_in, udr->combiner_ns,
    5455              :                         false);
    5456           82 :       if (peek_atom () != ATOM_RPAREN)
    5457              :         {
    5458           67 :           udr->initializer_ns = gfc_get_namespace (gfc_current_ns, 1);
    5459           67 :           udr->initializer_ns->proc_name = gfc_current_ns->proc_name;
    5460           67 :           mio_omp_udr_expr (udr, &udr->omp_priv, &udr->omp_orig,
    5461              :                             udr->initializer_ns, true);
    5462              :         }
    5463           82 :       if (st)
    5464              :         {
    5465            1 :           udr->next = st->n.omp_udr;
    5466            1 :           st->n.omp_udr = udr;
    5467              :         }
    5468              :       else
    5469              :         {
    5470           81 :           st = gfc_new_symtree (&gfc_current_ns->omp_udr_root, name);
    5471           81 :           st->n.omp_udr = udr;
    5472              :         }
    5473           82 :       mio_rparen ();
    5474              :     }
    5475        13914 :   mio_rparen ();
    5476        13914 : }
    5477              : 
    5478              : 
    5479              : /* In declare mapper, not all map types are permitted; hence, only
    5480              :    a subset is needed.  */
    5481              : 
    5482              : static const mstring omp_map_clause_ops[] =
    5483              : {
    5484              :     minit ("ALLOC", OMP_MAP_ALLOC),
    5485              :     minit ("TO", OMP_MAP_TO),
    5486              :     minit ("FROM", OMP_MAP_FROM),
    5487              :     minit ("TOFROM", OMP_MAP_TOFROM),
    5488              :     minit ("ALWAYS_TO", OMP_MAP_ALWAYS_TO),
    5489              :     minit ("ALWAYS_FROM", OMP_MAP_ALWAYS_FROM),
    5490              :     minit ("ALWAYS_TOFROM", OMP_MAP_ALWAYS_TOFROM),
    5491              :     minit ("UNSET", OMP_MAP_UNSET),
    5492              :     minit (NULL, -1)
    5493              : };
    5494              : 
    5495              : /* This function loads OpenMP user-defined mappers.  */
    5496              : 
    5497              : static void
    5498            8 : load_omp_udms (void)
    5499              : {
    5500           17 :   while (peek_atom () != ATOM_RPAREN)
    5501              :     {
    5502            9 :       const char *mapper_id = NULL;
    5503            9 :       gfc_symtree *st;
    5504              : 
    5505            9 :       mio_lparen ();
    5506            9 :       gfc_omp_udm *udm = gfc_get_omp_udm ();
    5507              : 
    5508            9 :       require_atom (ATOM_INTEGER);
    5509            9 :       pointer_info *udmpi = get_integer (atom_int);
    5510            9 :       associate_integer_pointer (udmpi, udm);
    5511              : 
    5512            9 :       mio_pool_string (&mapper_id);
    5513              : 
    5514              :       /* Note: for a derived-type typespec, we might not have loaded the
    5515              :          "u.derived" symbol yet.  Defer checking duplicates until
    5516              :          check_omp_declare_mappers is called after loading all symbols.  */
    5517            9 :       mio_typespec (&udm->ts);
    5518              : 
    5519            9 :       if (mapper_id == NULL)
    5520            8 :         mapper_id = gfc_get_string ("%s", "");
    5521              : 
    5522            9 :       st = gfc_find_symtree (gfc_current_ns->omp_udm_root, mapper_id);
    5523              : 
    5524            9 :       pointer_info *p = mio_symbol_ref (&udm->var_sym);
    5525            9 :       pointer_info *q = get_integer (p->u.rsym.ns);
    5526              : 
    5527            9 :       udm->where = gfc_current_locus;
    5528            9 :       udm->mapper_id = mapper_id;
    5529            9 :       udm->mapper_ns = gfc_get_namespace (gfc_current_ns, 1);
    5530            9 :       udm->mapper_ns->proc_name = gfc_current_ns->proc_name;
    5531            9 :       udm->mapper_ns->omp_udm_ns = 1;
    5532              : 
    5533            9 :       associate_integer_pointer (q, udm->mapper_ns);
    5534              : 
    5535            9 :       gfc_omp_namelist *clauses = NULL;
    5536            9 :       gfc_omp_namelist **clausep = &clauses;
    5537              : 
    5538            9 :       mio_lparen ();
    5539           35 :       while (peek_atom () != ATOM_RPAREN)
    5540              :         {
    5541              :           /* Read each map clause.  */
    5542           17 :           gfc_omp_namelist *n = gfc_get_omp_namelist ();
    5543              : 
    5544           17 :           mio_lparen ();
    5545              : 
    5546           17 :           n->u.map.op = (gfc_omp_map_op) mio_name (0, omp_map_clause_ops);
    5547           17 :           mio_symbol_ref (&n->sym);
    5548           17 :           mio_expr (&n->expr);
    5549              : 
    5550           17 :           mio_lparen ();
    5551              : 
    5552           17 :           if (peek_atom () != ATOM_RPAREN)
    5553              :             {
    5554            7 :               n->u3.udm = gfc_get_omp_namelist_udm ();
    5555            7 :               mio_pool_string (&n->u3.udm->requested_mapper_id);
    5556              : 
    5557            7 :               if (n->u3.udm->requested_mapper_id == NULL)
    5558            7 :                 n->u3.udm->requested_mapper_id = gfc_get_string ("%s", "");
    5559              : 
    5560            7 :               mio_pointer_ref (&n->u3.udm->resolved_udm);
    5561              :             }
    5562              : 
    5563           17 :           mio_rparen ();
    5564              : 
    5565           17 :           n->where = gfc_current_locus;
    5566              : 
    5567           17 :           mio_rparen ();
    5568              : 
    5569           17 :           *clausep = n;
    5570           17 :           clausep = &n->next;
    5571              :         }
    5572            9 :       mio_rparen ();
    5573              : 
    5574            9 :       udm->clauses = gfc_get_omp_clauses ();
    5575            9 :       udm->clauses->lists[OMP_LIST_MAP] = clauses;
    5576              : 
    5577            9 :       if (st)
    5578              :         {
    5579            3 :           udm->next = st->n.omp_udm;
    5580            3 :           st->n.omp_udm = udm;
    5581              :         }
    5582              :       else
    5583              :         {
    5584            6 :           st = gfc_new_symtree (&gfc_current_ns->omp_udm_root, mapper_id);
    5585            6 :           st->n.omp_udm = udm;
    5586              :         }
    5587              : 
    5588            9 :       mio_rparen ();
    5589              :     }
    5590            8 : }
    5591              : 
    5592              : 
    5593              : /* Recursive function to traverse the pointer_info tree and load a
    5594              :    needed symbol.  We return nonzero if we load a symbol and stop the
    5595              :    traversal, because the act of loading can alter the tree.  */
    5596              : 
    5597              : static int
    5598     10282343 : load_needed (pointer_info *p)
    5599              : {
    5600     10282343 :   gfc_namespace *ns;
    5601     10282343 :   pointer_info *q;
    5602     10282343 :   gfc_symbol *sym;
    5603     10282343 :   int rv;
    5604              : 
    5605     10282343 :   rv = 0;
    5606     10282343 :   if (p == NULL)
    5607              :     return rv;
    5608              : 
    5609      5121516 :   rv |= load_needed (p->left);
    5610      5121516 :   rv |= load_needed (p->right);
    5611              : 
    5612      5121516 :   if (p->type != P_SYMBOL || p->u.rsym.state != NEEDED)
    5613              :     return rv;
    5614              : 
    5615      1067793 :   p->u.rsym.state = USED;
    5616              : 
    5617      1067793 :   set_module_locus (&p->u.rsym.where);
    5618              : 
    5619      1067793 :   sym = p->u.rsym.sym;
    5620      1067793 :   if (sym == NULL)
    5621              :     {
    5622       634475 :       q = get_integer (p->u.rsym.ns);
    5623              : 
    5624       634475 :       ns = (gfc_namespace *) q->u.pointer;
    5625       634475 :       if (ns == NULL)
    5626              :         {
    5627              :           /* Create an interface namespace if necessary.  These are
    5628              :              the namespaces that hold the formal parameters of module
    5629              :              procedures.  */
    5630              : 
    5631        22313 :           ns = gfc_get_namespace (NULL, 0);
    5632        22313 :           associate_integer_pointer (q, ns);
    5633              :         }
    5634              : 
    5635              :       /* Use the module sym as 'proc_name' so that gfc_get_symbol_decl
    5636              :          doesn't go pear-shaped if the symbol is used.  */
    5637       634475 :       if (!ns->proc_name)
    5638        31110 :         gfc_find_symbol (p->u.rsym.module, gfc_current_ns,
    5639              :                                  1, &ns->proc_name);
    5640              : 
    5641       634475 :       sym = gfc_new_symbol (p->u.rsym.true_name, ns);
    5642       634475 :       sym->name = gfc_dt_lower_string (p->u.rsym.true_name);
    5643       634475 :       sym->module = gfc_get_string ("%s", p->u.rsym.module);
    5644       634475 :       if (p->u.rsym.binding_label)
    5645           21 :         sym->binding_label = IDENTIFIER_POINTER (get_identifier
    5646              :                                                  (p->u.rsym.binding_label));
    5647              : 
    5648       634475 :       associate_integer_pointer (p, sym);
    5649              :     }
    5650              : 
    5651      1067793 :   mio_symbol (sym);
    5652      1067793 :   sym->attr.use_assoc = 1;
    5653              : 
    5654              :   /* Unliked derived types, a STRUCTURE may share names with other symbols.
    5655              :      We greedily converted the symbol name to lowercase before we knew its
    5656              :      type, so now we must fix it. */
    5657      1067793 :   if (sym->attr.flavor == FL_STRUCT)
    5658           60 :     sym->name = gfc_dt_upper_string (sym->name);
    5659              : 
    5660              :   /* Mark as only or rename for later diagnosis for explicitly imported
    5661              :      but not used warnings; don't mark internal symbols such as __vtab,
    5662              :      __def_init etc. Only mark them if they have been explicitly loaded.  */
    5663              : 
    5664      1067793 :   if (only_flag && sym->name[0] != '_' && sym->name[1] != '_')
    5665              :     {
    5666        13049 :       gfc_use_rename *u;
    5667              : 
    5668              :       /* Search the use/rename list for the variable; if the variable is
    5669              :          found, mark it.  */
    5670        33023 :       for (u = gfc_rename_list; u; u = u->next)
    5671              :         {
    5672        23147 :           if (strcmp (u->use_name, sym->name) == 0)
    5673              :             {
    5674         3173 :               sym->attr.use_only = 1;
    5675         3173 :               break;
    5676              :             }
    5677              :         }
    5678              :     }
    5679              : 
    5680      1067793 :   if (p->u.rsym.renamed)
    5681         3558 :     sym->attr.use_rename = 1;
    5682              : 
    5683              :   return 1;
    5684              : }
    5685              : 
    5686              : 
    5687              : /* Recursive function for cleaning up things after a module has been read.  */
    5688              : 
    5689              : static void
    5690      3485932 : read_cleanup (pointer_info *p)
    5691              : {
    5692      3485932 :   gfc_symtree *st;
    5693      3485932 :   pointer_info *q;
    5694              : 
    5695      3485932 :   if (p == NULL)
    5696              :     return;
    5697              : 
    5698      1736009 :   read_cleanup (p->left);
    5699      1736009 :   read_cleanup (p->right);
    5700              : 
    5701      1736009 :   if (p->type == P_SYMBOL && p->u.rsym.state == USED
    5702      1117709 :       && (!p->u.rsym.referenced
    5703       434862 :           || (p->u.rsym.sym && (p->u.rsym.sym->attr.pdt_kind
    5704       434862 :                                 || p->u.rsym.sym->attr.pdt_len))))
    5705              :     {
    5706       682847 :       gfc_namespace *ns;
    5707              : 
    5708              :       /* Add hidden symbols and PDT parameters to the symtree.  */
    5709       682847 :       q = get_integer (p->u.rsym.ns);
    5710       682847 :       ns = (gfc_namespace *) q->u.pointer;
    5711              : 
    5712              :       /* PDT parameters have no namespace so return.  */
    5713       682847 :       if (ns == NULL)
    5714              :         {
    5715            0 :           gcc_assert (p->u.rsym.sym->attr.pdt_kind
    5716              :                       || p->u.rsym.sym->attr.pdt_len);
    5717              :           return;
    5718              :         }
    5719              : 
    5720       682847 :       if (p->u.rsym.sym->attr.pdt_kind || p->u.rsym.sym->attr.pdt_len
    5721       682359 :           || p->u.rsym.sym->attr.vtype || p->u.rsym.sym->attr.vtab)
    5722              :         {
    5723              :           /* There is no reason to use 'unique_symtrees' for vtabs or
    5724              :              vtypes - their name is fine for a symtree and reduces the
    5725              :              namespace pollution.  PDT parameters need their source name.  */
    5726         4118 :           st = gfc_find_symtree (ns->sym_root, p->u.rsym.sym->name);
    5727         4118 :           if (!st)
    5728         2400 :             st = gfc_new_symtree (&ns->sym_root, p->u.rsym.sym->name);
    5729              :         }
    5730              :       else
    5731       678729 :         st = gfc_get_unique_symtree (ns);
    5732              : 
    5733       682847 :       st->n.sym = p->u.rsym.sym;
    5734       682847 :       st->n.sym->refs++;
    5735              : 
    5736              :       /* Fixup any symtree references.  */
    5737       682847 :       p->u.rsym.symtree = st;
    5738       682847 :       resolve_fixups (p->u.rsym.stfixup, st);
    5739       682847 :       p->u.rsym.stfixup = NULL;
    5740              :     }
    5741              : 
    5742              :   /* Free unused symbols.  */
    5743      1736009 :   if (p->type == P_SYMBOL && p->u.rsym.state == UNUSED)
    5744       156044 :     gfc_free_symbol (p->u.rsym.sym);
    5745              : }
    5746              : 
    5747              : 
    5748              : /* Reconstruct PDT parameter namespaces after all needed module symbols have
    5749              :    been loaded.  read_cleanup installs named symtrees for the type-parameter
    5750              :    symbols first.  */
    5751              : 
    5752              : static void
    5753      3485932 : fixup_pdt_parameter_namespaces (pointer_info *p)
    5754              : {
    5755      3485932 :   gfc_symbol *sym;
    5756      3485932 :   gfc_formal_arglist *f, *fp;
    5757      3485932 :   gfc_namespace *ns;
    5758      3485932 :   gfc_symbol *super;
    5759              : 
    5760      3485932 :   if (p == NULL)
    5761      3485596 :     return;
    5762              : 
    5763      1736009 :   fixup_pdt_parameter_namespaces (p->left);
    5764      1736009 :   fixup_pdt_parameter_namespaces (p->right);
    5765              : 
    5766      1736009 :   if (p->type != P_SYMBOL || p->u.rsym.state != USED)
    5767              :     return;
    5768              : 
    5769      1117709 :   sym = p->u.rsym.sym;
    5770              : 
    5771              : /* Transfer the sym_root of the namespace containing locally-declared PDT
    5772              :    type-parameter symbols to that the derived type's namespace.  */
    5773      1117709 :   if (sym == NULL
    5774      1117709 :       || !sym->attr.pdt_template
    5775          366 :       || sym->f2k_derived == NULL
    5776          366 :       || sym->f2k_derived->sym_root != NULL)
    5777              :     return;
    5778              : 
    5779          348 :   f = sym->formal;
    5780          348 :   super = gfc_get_derived_super_type (sym);
    5781          348 :   if (super && super->attr.pdt_template)
    5782          222 :     for (fp = super->formal; fp && f; fp = fp->next)
    5783          150 :       f = f->next;
    5784              : 
    5785          348 :   if (f == NULL || f->sym == NULL || f->sym->ns == NULL
    5786          336 :       || f->sym->ns->sym_root == NULL)
    5787              :     return;
    5788              : 
    5789          336 :   ns = f->sym->ns;
    5790          336 :   sym->f2k_derived->sym_root = ns->sym_root;
    5791          336 :   ns->sym_root = NULL;
    5792          336 :   ns->refs++;
    5793          336 :   gfc_free_namespace (ns);
    5794              : }
    5795              : 
    5796              : 
    5797              : /* It is not quite enough to check for ambiguity in the symbols by
    5798              :    the loaded symbol and the new symbol not being identical.  */
    5799              : static bool
    5800        43583 : check_for_ambiguous (gfc_symtree *st, pointer_info *info)
    5801              : {
    5802        43583 :   gfc_symbol *rsym;
    5803        43583 :   module_locus locus;
    5804        43583 :   symbol_attribute attr;
    5805        43583 :   gfc_symbol *st_sym;
    5806              : 
    5807        43583 :   if (gfc_current_ns->proc_name && st->name == gfc_current_ns->proc_name->name)
    5808              :     {
    5809            6 :       gfc_error ("%qs of module %qs, imported at %C, is also the name of the "
    5810              :                  "current program unit", st->name, module_name);
    5811            6 :       return true;
    5812              :     }
    5813              : 
    5814        43577 :   st_sym = st->n.sym;
    5815        43577 :   rsym = info->u.rsym.sym;
    5816        43577 :   if (st_sym == rsym)
    5817              :     return false;
    5818              : 
    5819          516 :   if (st_sym->attr.vtab || st_sym->attr.vtype)
    5820              :     return false;
    5821              : 
    5822              :   /* If the existing symbol is generic from a different module and
    5823              :      the new symbol is generic there can be no ambiguity.  */
    5824          416 :   if (st_sym->attr.generic
    5825           20 :         && st_sym->module
    5826           20 :         && st_sym->module != module_name)
    5827              :     {
    5828              :       /* The new symbol's attributes have not yet been read.  Since
    5829              :          we need attr.generic, read it directly.  */
    5830           20 :       get_module_locus (&locus);
    5831           20 :       set_module_locus (&info->u.rsym.where);
    5832           20 :       mio_lparen ();
    5833           20 :       attr.generic = 0;
    5834           20 :       mio_symbol_attribute (&attr);
    5835           20 :       set_module_locus (&locus);
    5836           20 :       if (attr.generic)
    5837           19 :         return false;
    5838              :     }
    5839              : 
    5840              :   return true;
    5841              : }
    5842              : 
    5843              : 
    5844              : static void
    5845        13932 : check_omp_declare_mappers (gfc_symtree *st)
    5846              : {
    5847        13932 :   if (!st)
    5848        13923 :     return;
    5849              : 
    5850            9 :   check_omp_declare_mappers (st->left);
    5851            9 :   check_omp_declare_mappers (st->right);
    5852              : 
    5853            9 :   gfc_omp_udm **udmp = &st->n.omp_udm;
    5854            9 :   gfc_symtree tmp_st;
    5855              : 
    5856           21 :   while (*udmp)
    5857              :     {
    5858           12 :       gfc_omp_udm *udm = *udmp;
    5859           12 :       tmp_st.n.omp_udm = udm->next;
    5860           12 :       gfc_omp_udm *prev_udm = gfc_omp_udm_find (&tmp_st, &udm->ts);
    5861           12 :       if (prev_udm)
    5862              :         {
    5863            2 :           gcc_assert (!gfc_buffered_p ());  /* Cf. PR80012 comment 15.  */
    5864            2 :           auto_diagnostic_group d;
    5865            2 :           gfc_error ("Ambiguous !$OMP DECLARE MAPPER %qs for type %qs from "
    5866              :                      "module %qs at %L",
    5867            2 :                      st->n.omp_udm->mapper_id[0] != '\0'
    5868              :                      ? st->n.omp_udm->mapper_id : "default",
    5869            2 :                      udm->ts.u.derived->name, module_name,
    5870              :                      &udm->where);
    5871            2 :           inform (gfc_get_location (&prev_udm->where),
    5872              :                   "Previous !$OMP DECLARE MAPPER from module %qs",
    5873            2 :                   prev_udm->var_sym->module);
    5874              :           /* Delete the duplicate.  */
    5875            2 :           *udmp = (*udmp)->next;
    5876            2 :         }
    5877              :       else
    5878           10 :         udmp = &(*udmp)->next;
    5879              :     }
    5880              : }
    5881              : 
    5882              : 
    5883              : /* Read a module file.  */
    5884              : 
    5885              : static void
    5886        13914 : read_module (void)
    5887              : {
    5888        13914 :   module_locus operator_interfaces, user_operators, omp_udrs, omp_udms;
    5889        13914 :   bool has_omp_udms = false;
    5890        13914 :   const char *p;
    5891        13914 :   char name[GFC_MAX_SYMBOL_LEN + 1];
    5892        13914 :   int i;
    5893              :   /* Workaround -Wmaybe-uninitialized false positive during
    5894              :      profiledbootstrap by initializing them.  */
    5895        13914 :   int ambiguous = 0, j, nuse, symbol = 0;
    5896        13914 :   pointer_info *info, *q;
    5897        13914 :   gfc_use_rename *u = NULL;
    5898        13914 :   gfc_symtree *st;
    5899        13914 :   gfc_symbol *sym;
    5900              : 
    5901        13914 :   get_module_locus (&operator_interfaces);  /* Skip these for now.  */
    5902        13914 :   skip_list ();
    5903              : 
    5904        13914 :   get_module_locus (&user_operators);
    5905        13914 :   skip_list ();
    5906        13914 :   skip_list ();
    5907              : 
    5908              :   /* Skip commons and equivalences for now.  */
    5909        13914 :   skip_list ();
    5910        13914 :   skip_list ();
    5911              : 
    5912              :   /* Skip OpenMP UDRs.  */
    5913        13914 :   get_module_locus (&omp_udrs);
    5914        13914 :   skip_list ();
    5915              : 
    5916              :   /* Skip OpenMP's user-defined 'declare mapper' (UDM); some extra code is
    5917              :      required to permit reading files without USM; see write_module for
    5918              :      details.  */
    5919        13914 :   get_module_locus (&omp_udms);
    5920        13914 :   if (peek_atom () == ATOM_LPAREN
    5921        13914 :       && parse_atom ()
    5922        13914 :       && module_char () == 'U'
    5923            8 :       && module_char () == 'D'
    5924        13922 :       && module_char () == 'M')
    5925              :     has_omp_udms = true;
    5926        13914 :   set_module_locus (&omp_udms);
    5927        13914 :   if (has_omp_udms)
    5928            8 :     skip_list ();
    5929              : 
    5930        13914 :   mio_lparen ();
    5931              : 
    5932              :   /* Create the fixup nodes for all the symbols.  */
    5933              : 
    5934      1301581 :   while (peek_atom () != ATOM_RPAREN)
    5935              :     {
    5936      1273753 :       char* bind_label;
    5937      1273753 :       require_atom (ATOM_INTEGER);
    5938      1273753 :       info = get_integer (atom_int);
    5939              : 
    5940      1273753 :       info->type = P_SYMBOL;
    5941      1273753 :       info->u.rsym.state = UNUSED;
    5942              : 
    5943      1273753 :       info->u.rsym.true_name = read_string ();
    5944      1273753 :       info->u.rsym.module = read_string ();
    5945      1273753 :       bind_label = read_string ();
    5946      1273753 :       if (strlen (bind_label))
    5947        39400 :         info->u.rsym.binding_label = bind_label;
    5948              :       else
    5949      1234353 :         XDELETEVEC (bind_label);
    5950              : 
    5951      1273753 :       require_atom (ATOM_INTEGER);
    5952      1273753 :       info->u.rsym.ns = atom_int;
    5953              : 
    5954      1273753 :       get_module_locus (&info->u.rsym.where);
    5955              : 
    5956              :       /* See if the symbol has already been loaded by a previous module.
    5957              :          If so, we reference the existing symbol and prevent it from
    5958              :          being loaded again.  This should not happen if the symbol being
    5959              :          read is an index for an assumed shape dummy array (ns != 1).  */
    5960              : 
    5961      1273753 :       sym = find_true_name (info->u.rsym.true_name, info->u.rsym.module);
    5962              : 
    5963      1273753 :       if (sym == NULL
    5964        49941 :           || (sym->attr.flavor == FL_VARIABLE && info->u.rsym.ns !=1))
    5965              :         {
    5966      1223837 :           skip_list ();
    5967      1223837 :           continue;
    5968              :         }
    5969              : 
    5970        49916 :       info->u.rsym.state = USED;
    5971        49916 :       info->u.rsym.sym = sym;
    5972              :       /* The current symbol has already been loaded, so we can avoid loading
    5973              :          it again.  However, if it is a derived type, some of its components
    5974              :          can be used in expressions in the module.  To avoid the module loading
    5975              :          failing, we need to associate the module's component pointer indexes
    5976              :          with the existing symbol's component pointers.  */
    5977        49916 :       if (gfc_fl_struct (sym->attr.flavor))
    5978              :         {
    5979         4844 :           gfc_component *c;
    5980              : 
    5981              :           /* First seek to the symbol's component list.  */
    5982         4844 :           mio_lparen (); /* symbol opening.  */
    5983         4844 :           skip_list (); /* skip symbol attribute.  */
    5984              : 
    5985         4844 :           mio_lparen (); /* component list opening.  */
    5986        17336 :           for (c = sym->components; c; c = c->next)
    5987              :             {
    5988        12492 :               pointer_info *p;
    5989        12492 :               const char *comp_name = NULL;
    5990        12492 :               int n = 0;
    5991              : 
    5992        12492 :               mio_lparen (); /* component opening.  */
    5993        12492 :               mio_integer (&n);
    5994        12492 :               p = get_integer (n);
    5995        12492 :               if (p->u.pointer == NULL)
    5996        12492 :                 associate_integer_pointer (p, c);
    5997        12492 :               mio_pool_string (&comp_name);
    5998        12492 :               if (comp_name != c->name)
    5999              :                 {
    6000            0 :                   gfc_fatal_error ("Mismatch in components of derived type "
    6001              :                                    "%qs from %qs at %C: expecting %qs, "
    6002              :                                    "but got %qs", sym->name, sym->module,
    6003              :                                    c->name, comp_name);
    6004              :                 }
    6005        12492 :               skip_list (1); /* component end.  */
    6006              :             }
    6007         4844 :           mio_rparen (); /* component list closing.  */
    6008              : 
    6009         4844 :           skip_list (1); /* symbol end.  */
    6010         4844 :         }
    6011              :       else
    6012        45072 :         skip_list ();
    6013              : 
    6014              :       /* Some symbols do not have a namespace (eg. formal arguments),
    6015              :          so the automatic "unique symtree" mechanism must be suppressed
    6016              :          by marking them as referenced.  */
    6017        49916 :       q = get_integer (info->u.rsym.ns);
    6018        49916 :       if (q->u.pointer == NULL)
    6019              :         {
    6020         1718 :           info->u.rsym.referenced = 1;
    6021         1718 :           continue;
    6022              :         }
    6023              :     }
    6024              : 
    6025        13914 :   mio_rparen ();
    6026              : 
    6027              :   /* Parse the symtree lists.  This lets us mark which symbols need to
    6028              :      be loaded.  Renaming is also done at this point by replacing the
    6029              :      symtree name.  */
    6030              : 
    6031        13914 :   mio_lparen ();
    6032              : 
    6033       557590 :   while (peek_atom () != ATOM_RPAREN)
    6034              :     {
    6035       529762 :       mio_internal_string (name);
    6036       529762 :       mio_integer (&ambiguous);
    6037       529762 :       mio_integer (&symbol);
    6038              : 
    6039       529762 :       info = get_integer (symbol);
    6040              : 
    6041              :       /* See how many use names there are.  If none, go through the start
    6042              :          of the loop at least once.  */
    6043       529762 :       nuse = number_use_names (name, false);
    6044       529762 :       info->u.rsym.renamed = nuse ? 1 : 0;
    6045              : 
    6046       526181 :       if (nuse == 0)
    6047       526181 :         nuse = 1;
    6048              : 
    6049      1059559 :       for (j = 1; j <= nuse; j++)
    6050              :         {
    6051              :           /* Get the jth local name for this symbol.  */
    6052       529797 :           p = find_use_name_n (name, &j, false);
    6053              : 
    6054       529797 :           if (p == NULL && strcmp (name, module_name) == 0)
    6055              :             p = name;
    6056              : 
    6057              :           /* Exception: Always import vtabs & vtypes.  */
    6058        52574 :           if (p == NULL && name[0] == '_'
    6059         3601 :               && (startswith (name, "__vtab_")
    6060         2372 :                   || startswith (name, "__vtype_")))
    6061              :             p = name;
    6062              : 
    6063              :           /* Include pdt_types if their associated pdt_template is in a
    6064              :              USE, ONLY list.  */
    6065        50116 :           if (p == NULL && name[0] == 'P'
    6066          136 :               && startswith (name, PDT_PREFIX)
    6067       527409 :               && module_list)
    6068              :             {
    6069          158 :               gfc_use_list *ml = module_list;
    6070          158 :               for (; ml; ml = ml->next)
    6071           88 :                 if (ml->rename
    6072           88 :                     && !strncmp (&name[PDT_PREFIX_LEN],
    6073              :                                  ml->rename->use_name,
    6074           88 :                                  strlen (ml->rename->use_name)))
    6075           88 :                   p = name;
    6076              :             }
    6077              : 
    6078              :           /* Skip symtree nodes not in an ONLY clause, unless there
    6079              :              is an existing symtree loaded from another USE statement.  */
    6080       529797 :           if (p == NULL)
    6081              :             {
    6082        50088 :               st = gfc_find_symtree (gfc_current_ns->sym_root, name);
    6083        50088 :               if (st != NULL
    6084          582 :                   && strcmp (st->n.sym->name, info->u.rsym.true_name) == 0
    6085          516 :                   && st->n.sym->module != NULL
    6086          214 :                   && strcmp (st->n.sym->module, info->u.rsym.module) == 0)
    6087              :                 {
    6088          206 :                   info->u.rsym.symtree = st;
    6089          206 :                   info->u.rsym.sym = st->n.sym;
    6090              :                 }
    6091        50088 :               continue;
    6092              :             }
    6093              : 
    6094              :           /* If a symbol of the same name and module exists already,
    6095              :              this symbol, which is not in an ONLY clause, must not be
    6096              :              added to the namespace(11.3.2).  Note that find_symbol
    6097              :              only returns the first occurrence that it finds.  */
    6098       472498 :           if (!only_flag && !info->u.rsym.renamed
    6099       472145 :                 && strcmp (name, module_name) != 0
    6100       941386 :                 && find_symbol (gfc_current_ns->sym_root, name,
    6101              :                                 module_name, 0))
    6102          548 :             continue;
    6103              : 
    6104              :           /* Skip re-importing a derived type already visible via host
    6105              :              association from the same module.  Walk the symtree since
    6106              :              using gfc_find_symbol can give a wrong error.  */
    6107       479161 :           if (!only_flag && !info->u.rsym.renamed
    6108       471597 :                 && strcmp (name, module_name) != 0
    6109       461129 :                 && gfc_current_ns->parent)
    6110              :             {
    6111       366371 :               gfc_symbol *host_sym = NULL;
    6112       366371 :               for (gfc_namespace *pns = gfc_current_ns; pns; pns = pns->parent)
    6113              :                 {
    6114       329236 :                   gfc_symtree *host_st = gfc_find_symtree (pns->sym_root, name);
    6115       329236 :                   if (host_st)
    6116              :                     {
    6117       137511 :                       host_sym = host_st->n.sym;
    6118       137511 :                       break;
    6119              :                     }
    6120              :                 }
    6121       174646 :               if (host_sym && host_sym->attr.flavor == FL_DERIVED
    6122         4239 :                   && host_sym->module
    6123         3512 :                   && strcmp (host_sym->module, module_name) == 0)
    6124         2470 :                 continue;
    6125              :             }
    6126              : 
    6127       476691 :           st = gfc_find_symtree (gfc_current_ns->sym_root, p);
    6128              : 
    6129       476691 :           if (st != NULL
    6130        43619 :               && !(st->n.sym && st->n.sym->attr.used_in_submodule))
    6131              :             {
    6132              :               /* Check for ambiguous symbols.  */
    6133        43583 :               if (check_for_ambiguous (st, info))
    6134          403 :                 st->ambiguous = 1;
    6135              :               else
    6136        43180 :                 info->u.rsym.symtree = st;
    6137              :             }
    6138              :           else
    6139              :             {
    6140       433108 :               if (st)
    6141              :                 {
    6142              :                   /* This symbol is host associated from a module in a
    6143              :                      submodule.  Hide it with a unique symtree.  */
    6144           36 :                   gfc_symtree *s = gfc_get_unique_symtree (gfc_current_ns);
    6145           36 :                   s->n.sym = st->n.sym;
    6146           36 :                   st->n.sym = NULL;
    6147              :                 }
    6148              :               else
    6149              :                 {
    6150              :                   /* Create a symtree node in the current namespace for this
    6151              :                      symbol.  */
    6152       433072 :                   st = check_unique_name (p)
    6153       433072 :                        ? gfc_get_unique_symtree (gfc_current_ns)
    6154       433072 :                        : gfc_new_symtree (&gfc_current_ns->sym_root, p);
    6155       433072 :                   st->ambiguous = ambiguous;
    6156              :                 }
    6157              : 
    6158       433108 :               sym = info->u.rsym.sym;
    6159              : 
    6160              :               /* Create a symbol node if it doesn't already exist.  */
    6161       433108 :               if (sym == NULL)
    6162              :                 {
    6163       432945 :                   info->u.rsym.sym = gfc_new_symbol (info->u.rsym.true_name,
    6164              :                                                      gfc_current_ns);
    6165       432945 :                   info->u.rsym.sym->name = gfc_dt_lower_string (info->u.rsym.true_name);
    6166       432945 :                   sym = info->u.rsym.sym;
    6167       432945 :                   sym->module = gfc_get_string ("%s", info->u.rsym.module);
    6168              : 
    6169       432945 :                   if (info->u.rsym.binding_label)
    6170              :                     {
    6171        28567 :                       tree id = get_identifier (info->u.rsym.binding_label);
    6172        28567 :                       sym->binding_label = IDENTIFIER_POINTER (id);
    6173              :                     }
    6174              :                 }
    6175              : 
    6176       433108 :               st->n.sym = sym;
    6177       433108 :               st->n.sym->refs++;
    6178              : 
    6179       433108 :               if (strcmp (name, p) != 0)
    6180          536 :                 sym->attr.use_rename = 1;
    6181              : 
    6182       433108 :               if (name[0] != '_'
    6183       433108 :                   || (!startswith (name, "__vtab_")
    6184        30083 :                       && !startswith (name, "__vtype_")))
    6185       404466 :                 sym->attr.use_only = only_flag;
    6186              : 
    6187              :               /* Store the symtree pointing to this symbol.  */
    6188       433108 :               info->u.rsym.symtree = st;
    6189              : 
    6190       433108 :               if (info->u.rsym.state == UNUSED)
    6191       432945 :                 info->u.rsym.state = NEEDED;
    6192       433108 :               info->u.rsym.referenced = 1;
    6193              :             }
    6194              :         }
    6195              :     }
    6196              : 
    6197        13914 :   mio_rparen ();
    6198              : 
    6199              :   /* Load intrinsic operator interfaces.  */
    6200        13914 :   set_module_locus (&operator_interfaces);
    6201        13914 :   mio_lparen ();
    6202              : 
    6203       417420 :   for (i = GFC_INTRINSIC_BEGIN; i != GFC_INTRINSIC_END; i++)
    6204              :     {
    6205       389592 :       gfc_use_rename *u = NULL, *v = NULL;
    6206       389592 :       int j = i;
    6207              : 
    6208       389592 :       if (i == INTRINSIC_USER)
    6209        13914 :         continue;
    6210              : 
    6211       375678 :       if (only_flag)
    6212              :         {
    6213        49896 :           u = find_use_operator ((gfc_intrinsic_op) i);
    6214              : 
    6215              :           /* F2018:10.1.5.5.1 requires same interpretation of old and new-style
    6216              :              relational operators.  Special handling for USE, ONLY.  */
    6217        49896 :           switch (i)
    6218              :             {
    6219              :             case INTRINSIC_EQ:
    6220              :               j = INTRINSIC_EQ_OS;
    6221              :               break;
    6222              :             case INTRINSIC_EQ_OS:
    6223              :               j = INTRINSIC_EQ;
    6224              :               break;
    6225              :             case INTRINSIC_NE:
    6226              :               j = INTRINSIC_NE_OS;
    6227              :               break;
    6228              :             case INTRINSIC_NE_OS:
    6229              :               j = INTRINSIC_NE;
    6230              :               break;
    6231              :             case INTRINSIC_GT:
    6232              :               j = INTRINSIC_GT_OS;
    6233              :               break;
    6234              :             case INTRINSIC_GT_OS:
    6235              :               j = INTRINSIC_GT;
    6236              :               break;
    6237              :             case INTRINSIC_GE:
    6238              :               j = INTRINSIC_GE_OS;
    6239              :               break;
    6240              :             case INTRINSIC_GE_OS:
    6241              :               j = INTRINSIC_GE;
    6242              :               break;
    6243              :             case INTRINSIC_LT:
    6244              :               j = INTRINSIC_LT_OS;
    6245              :               break;
    6246              :             case INTRINSIC_LT_OS:
    6247              :               j = INTRINSIC_LT;
    6248              :               break;
    6249              :             case INTRINSIC_LE:
    6250              :               j = INTRINSIC_LE_OS;
    6251              :               break;
    6252              :             case INTRINSIC_LE_OS:
    6253              :               j = INTRINSIC_LE;
    6254              :               break;
    6255              :             default:
    6256              :               break;
    6257              :             }
    6258              : 
    6259              :           if (j != i)
    6260        22176 :             v = find_use_operator ((gfc_intrinsic_op) j);
    6261              : 
    6262        49896 :           if (u == NULL && v == NULL)
    6263              :             {
    6264        49746 :               skip_list ();
    6265        49746 :               continue;
    6266              :             }
    6267              : 
    6268          150 :           if (u)
    6269          113 :             u->found = 1;
    6270          150 :           if (v)
    6271           89 :             v->found = 1;
    6272              :         }
    6273              : 
    6274       325932 :       mio_interface (&gfc_current_ns->op[i]);
    6275       325932 :       if (!gfc_current_ns->op[i] && !gfc_current_ns->op[j])
    6276              :         {
    6277       324226 :           if (u)
    6278           15 :             u->found = 0;
    6279       324226 :           if (v)
    6280           26 :             v->found = 0;
    6281              :         }
    6282              :     }
    6283              : 
    6284        13914 :   mio_rparen ();
    6285              : 
    6286              :   /* Load generic and user operator interfaces.  These must follow the
    6287              :      loading of symtree because otherwise symbols can be marked as
    6288              :      ambiguous.  */
    6289              : 
    6290        13914 :   set_module_locus (&user_operators);
    6291              : 
    6292        13914 :   load_operator_interfaces ();
    6293        13914 :   load_generic_interfaces ();
    6294              : 
    6295        13914 :   load_commons ();
    6296        13914 :   load_equiv ();
    6297              : 
    6298              :   /* Load OpenMP user defined reductions.  */
    6299        13914 :   set_module_locus (&omp_udrs);
    6300        13914 :   load_omp_udrs ();
    6301              : 
    6302              :   /* Load OpenMP user defined mappers.  */
    6303        13914 :   if (has_omp_udms)
    6304              :     {
    6305            8 :       set_module_locus (&omp_udms);
    6306            8 :       mio_lparen ();
    6307              :       /* Skip 'UDM' marker, cf. above.  */
    6308            8 :       (void) module_char ();
    6309            8 :       (void) module_char ();
    6310            8 :       (void) module_char ();
    6311            8 :       load_omp_udms ();
    6312            8 :       mio_rparen ();
    6313              :     }
    6314              : 
    6315              :   /* At this point, we read those symbols that are needed but haven't
    6316              :      been loaded yet.  If one symbol requires another, the other gets
    6317              :      marked as NEEDED if its previous state was UNUSED.  */
    6318              : 
    6319        39311 :   while (load_needed (pi_root));
    6320              : 
    6321              :   /* Make sure all elements of the rename-list were found in the module.  */
    6322              : 
    6323        17024 :   for (u = gfc_rename_list; u; u = u->next)
    6324              :     {
    6325         3110 :       if (u->found)
    6326         3102 :         continue;
    6327              : 
    6328            8 :       if (u->op == INTRINSIC_NONE)
    6329              :         {
    6330            3 :           gfc_error ("Symbol %qs referenced at %L not found in module %qs",
    6331            3 :                      u->use_name, &u->where, module_name);
    6332            3 :           continue;
    6333              :         }
    6334              : 
    6335            5 :       if (u->op == INTRINSIC_USER)
    6336              :         {
    6337            2 :           gfc_error ("User operator %qs referenced at %L not found "
    6338            2 :                      "in module %qs", u->use_name, &u->where, module_name);
    6339            2 :           continue;
    6340              :         }
    6341              : 
    6342            3 :       gfc_error ("Intrinsic operator %qs referenced at %L not found "
    6343              :                  "in module %qs", gfc_op2string (u->op), &u->where,
    6344              :                  module_name);
    6345              :     }
    6346              : 
    6347              :   /* Check "omp declare mappers" for duplicates from different modules.  */
    6348        13914 :   check_omp_declare_mappers (gfc_current_ns->omp_udm_root);
    6349              : 
    6350              :   /* Clean up symbol nodes that were never loaded, create references
    6351              :      to hidden symbols.  */
    6352              : 
    6353        13914 :   read_cleanup (pi_root);
    6354              : 
    6355              :   /* Reconstruct PDT type-parameter namespaces now that inherited
    6356              :      and local formal parameter lists have been loaded completely.  */
    6357        13914 :   fixup_pdt_parameter_namespaces (pi_root);
    6358        13914 : }
    6359              : 
    6360              : 
    6361              : /* Given an access type that is specific to an entity and the default
    6362              :    access, return nonzero if the entity is publicly accessible.  If the
    6363              :    element is declared as PUBLIC, then it is public; if declared
    6364              :    PRIVATE, then private, and otherwise it is public unless the default
    6365              :    access in this context has been declared PRIVATE.  */
    6366              : 
    6367              : static bool dump_smod = false;
    6368              : 
    6369              : static bool
    6370      1077966 : check_access (gfc_access specific_access, gfc_access default_access)
    6371              : {
    6372      1077966 :   if (dump_smod)
    6373              :     return true;
    6374              : 
    6375      1053131 :   if (specific_access == ACCESS_PUBLIC)
    6376              :     return true;
    6377      1022294 :   if (specific_access == ACCESS_PRIVATE)
    6378              :     return false;
    6379              : 
    6380      1019945 :   if (flag_module_private)
    6381           91 :     return default_access == ACCESS_PUBLIC;
    6382              :   else
    6383      1019854 :     return default_access != ACCESS_PRIVATE;
    6384              : }
    6385              : 
    6386              : 
    6387              : bool
    6388       897160 : gfc_check_symbol_access (gfc_symbol *sym)
    6389              : {
    6390       897160 :   if (sym->attr.vtab || sym->attr.vtype)
    6391              :     return true;
    6392              :   else
    6393       804171 :     return check_access (sym->attr.access, sym->ns->default_access);
    6394              : }
    6395              : 
    6396              : 
    6397              : /* A structure to remember which commons we've already written.  */
    6398              : 
    6399              : struct written_common
    6400              : {
    6401              :   BBT_HEADER(written_common);
    6402              :   const char *name, *label;
    6403              : };
    6404              : 
    6405              : static struct written_common *written_commons = NULL;
    6406              : 
    6407              : /* Comparison function used for balancing the binary tree.  */
    6408              : 
    6409              : static int
    6410          127 : compare_written_commons (void *a1, void *b1)
    6411              : {
    6412          127 :   const char *aname = ((struct written_common *) a1)->name;
    6413          127 :   const char *alabel = ((struct written_common *) a1)->label;
    6414          127 :   const char *bname = ((struct written_common *) b1)->name;
    6415          127 :   const char *blabel = ((struct written_common *) b1)->label;
    6416          127 :   int c = strcmp (aname, bname);
    6417              : 
    6418          127 :   return (c != 0 ? c : strcmp (alabel, blabel));
    6419              : }
    6420              : 
    6421              : /* Free a list of written commons.  */
    6422              : 
    6423              : static void
    6424        10202 : free_written_common (struct written_common *w)
    6425              : {
    6426        10202 :   if (!w)
    6427              :     return;
    6428              : 
    6429          211 :   if (w->left)
    6430           27 :     free_written_common (w->left);
    6431          211 :   if (w->right)
    6432           42 :     free_written_common (w->right);
    6433              : 
    6434          211 :   free (w);
    6435              : }
    6436              : 
    6437              : /* Write a common block to the module -- recursive helper function.  */
    6438              : 
    6439              : static void
    6440        20736 : write_common_0 (gfc_symtree *st, bool this_module)
    6441              : {
    6442        21206 :   gfc_common_head *p;
    6443        21206 :   const char * name;
    6444        21206 :   int flags;
    6445        21206 :   const char *label;
    6446        21206 :   struct written_common *w;
    6447        21206 :   bool write_me = true;
    6448              : 
    6449        21206 :   if (st == NULL)
    6450        20736 :     return;
    6451              : 
    6452          470 :   write_common_0 (st->left, this_module);
    6453              : 
    6454              :   /* We will write out the binding label, or "" if no label given.  */
    6455          470 :   name = st->n.common->name;
    6456          470 :   p = st->n.common;
    6457          470 :   label = (p->is_bind_c && p->binding_label) ? p->binding_label : "";
    6458              : 
    6459              :   /* Check if we've already output this common.  */
    6460          470 :   w = written_commons;
    6461          988 :   while (w)
    6462              :     {
    6463          518 :       int c = strcmp (name, w->name);
    6464          518 :       c = (c != 0 ? c : strcmp (label, w->label));
    6465          206 :       if (c == 0)
    6466              :         write_me = false;
    6467              : 
    6468          518 :       w = (c < 0) ? w->left : w->right;
    6469              :     }
    6470              : 
    6471          470 :   if (this_module && p->use_assoc)
    6472              :     write_me = false;
    6473              : 
    6474          417 :   if (write_me)
    6475              :     {
    6476              :       /* Write the common to the module.  */
    6477          211 :       mio_lparen ();
    6478          211 :       mio_pool_string (&name);
    6479              : 
    6480          211 :       mio_symbol_ref (&p->head);
    6481          211 :       flags = p->saved ? 1 : 0;
    6482          211 :       if (p->threadprivate)
    6483            0 :         flags |= 2;
    6484          211 :       flags |= p->omp_device_type << 2;
    6485          211 :       flags |= p->omp_groupprivate << 4;
    6486          211 :       mio_integer (&flags);
    6487              : 
    6488              :       /* Write out whether the common block is bind(c) or not.  */
    6489          211 :       mio_integer (&(p->is_bind_c));
    6490              : 
    6491          211 :       mio_pool_string (&label);
    6492          211 :       mio_rparen ();
    6493              : 
    6494              :       /* Record that we have written this common.  */
    6495          211 :       w = XCNEW (struct written_common);
    6496          211 :       w->name = p->name;
    6497          211 :       w->label = label;
    6498          211 :       gfc_insert_bbt (&written_commons, w, compare_written_commons);
    6499              :     }
    6500              : 
    6501          470 :   write_common_0 (st->right, this_module);
    6502              : }
    6503              : 
    6504              : 
    6505              : /* Write a common, by initializing the list of written commons, calling
    6506              :    the recursive function write_common_0() and cleaning up afterwards.  */
    6507              : 
    6508              : static void
    6509        10133 : write_common (gfc_symtree *st)
    6510              : {
    6511        10133 :   written_commons = NULL;
    6512        10133 :   write_common_0 (st, true);
    6513        10133 :   write_common_0 (st, false);
    6514        10133 :   free_written_common (written_commons);
    6515        10133 :   written_commons = NULL;
    6516        10133 : }
    6517              : 
    6518              : 
    6519              : /* Write the blank common block to the module.  */
    6520              : 
    6521              : static void
    6522        10133 : write_blank_common (void)
    6523              : {
    6524        10133 :   const char * name = BLANK_COMMON_NAME;
    6525        10133 :   int saved;
    6526              :   /* TODO: Blank commons are not bind(c).  The F2003 standard probably says
    6527              :      this, but it hasn't been checked.  Just making it so for now.  */
    6528        10133 :   int is_bind_c = 0;
    6529              : 
    6530        10133 :   if (gfc_current_ns->blank_common.head == NULL)
    6531              :     return;
    6532              : 
    6533            7 :   mio_lparen ();
    6534              : 
    6535            7 :   mio_pool_string (&name);
    6536              : 
    6537            7 :   mio_symbol_ref (&gfc_current_ns->blank_common.head);
    6538            7 :   saved = gfc_current_ns->blank_common.saved;
    6539            7 :   mio_integer (&saved);
    6540              : 
    6541              :   /* Write out whether the common block is bind(c) or not.  */
    6542            7 :   mio_integer (&is_bind_c);
    6543              : 
    6544              :   /* Write out an empty binding label.  */
    6545            7 :   write_atom (ATOM_STRING, "");
    6546              : 
    6547            7 :   mio_rparen ();
    6548              : }
    6549              : 
    6550              : 
    6551              : /* Write equivalences to the module.  */
    6552              : 
    6553              : static void
    6554        10133 : write_equiv (void)
    6555              : {
    6556        10133 :   gfc_equiv *eq, *e;
    6557        10133 :   int num;
    6558              : 
    6559        10133 :   num = 0;
    6560        10215 :   for (eq = gfc_current_ns->equiv; eq; eq = eq->next)
    6561              :     {
    6562           82 :       mio_lparen ();
    6563              : 
    6564          328 :       for (e = eq; e; e = e->eq)
    6565              :         {
    6566          164 :           if (e->module == NULL)
    6567          142 :             e->module = gfc_get_string ("%s.eq.%d", module_name, num);
    6568          164 :           mio_allocated_string (e->module);
    6569          164 :           mio_expr (&e->expr);
    6570              :         }
    6571              : 
    6572           82 :       num++;
    6573           82 :       mio_rparen ();
    6574              :     }
    6575        10133 : }
    6576              : 
    6577              : 
    6578              : /* Write a symbol to the module.  */
    6579              : 
    6580              : static void
    6581       248474 : write_symbol (int n, gfc_symbol *sym)
    6582              : {
    6583       248474 :   const char *label;
    6584              : 
    6585       248474 :   if (sym->attr.flavor == FL_UNKNOWN || sym->attr.flavor == FL_LABEL)
    6586            0 :     gfc_internal_error ("write_symbol(): bad module symbol %qs", sym->name);
    6587              : 
    6588       248474 :   mio_integer (&n);
    6589              : 
    6590       248474 :   if (gfc_fl_struct (sym->attr.flavor))
    6591              :     {
    6592        28055 :       const char *name;
    6593        28055 :       name = gfc_dt_upper_string (sym->name);
    6594        28055 :       mio_pool_string (&name);
    6595        28055 :     }
    6596              :   else
    6597       220419 :     mio_pool_string (&sym->name);
    6598              : 
    6599       248474 :   mio_pool_string (&sym->module);
    6600       248474 :   if ((sym->attr.is_bind_c || sym->attr.is_iso_c) && sym->binding_label)
    6601              :     {
    6602         2943 :       label = sym->binding_label;
    6603         2943 :       mio_pool_string (&label);
    6604              :     }
    6605              :   else
    6606       245531 :     write_atom (ATOM_STRING, "");
    6607              : 
    6608       248474 :   mio_pointer_ref (&sym->ns);
    6609              : 
    6610       248474 :   mio_symbol (sym);
    6611       248474 :   write_char ('\n');
    6612       248474 : }
    6613              : 
    6614              : 
    6615              : /* Recursive traversal function to write the initial set of symbols to
    6616              :    the module.  We check to see if the symbol should be written
    6617              :    according to the access specification.  */
    6618              : 
    6619              : static void
    6620       168510 : write_symbol0 (gfc_symtree *st)
    6621              : {
    6622       326887 :   gfc_symbol *sym;
    6623       326887 :   pointer_info *p;
    6624       326887 :   bool dont_write = false;
    6625              : 
    6626       326887 :   if (st == NULL)
    6627       168510 :     return;
    6628              : 
    6629       158377 :   write_symbol0 (st->left);
    6630              : 
    6631       158377 :   sym = st->n.sym;
    6632       158377 :   if (sym->module == NULL)
    6633        72231 :     sym->module = module_name;
    6634              : 
    6635       158377 :   if (sym->attr.flavor == FL_PROCEDURE && sym->attr.generic
    6636        12298 :       && !sym->attr.subroutine && !sym->attr.function)
    6637       158377 :     dont_write = true;
    6638              : 
    6639       158377 :   if (!gfc_check_symbol_access (sym))
    6640              :     dont_write = true;
    6641              : 
    6642       139477 :   if (!dont_write)
    6643              :     {
    6644       137999 :       p = get_pointer (sym);
    6645       137999 :       if (p->type == P_UNKNOWN)
    6646       105076 :         p->type = P_SYMBOL;
    6647              : 
    6648       137999 :       if (p->u.wsym.state != WRITTEN)
    6649              :         {
    6650       135128 :           write_symbol (p->integer, sym);
    6651       135128 :           p->u.wsym.state = WRITTEN;
    6652              :         }
    6653              :     }
    6654              : 
    6655       158377 :   write_symbol0 (st->right);
    6656              : }
    6657              : 
    6658              : 
    6659              : static void
    6660          101 : write_omp_udr (gfc_omp_udr *udr)
    6661              : {
    6662          101 :   switch (udr->rop)
    6663              :     {
    6664           66 :     case OMP_REDUCTION_USER:
    6665              :       /* Non-operators can't be used outside of the module.  */
    6666           66 :       if (udr->name[0] != '.')
    6667              :         return;
    6668              :       else
    6669              :         {
    6670           47 :           gfc_symtree *st;
    6671           47 :           size_t len = strlen (udr->name + 1);
    6672           47 :           char *name = XALLOCAVEC (char, len);
    6673           47 :           memcpy (name, udr->name, len - 1);
    6674           47 :           name[len - 1] = '\0';
    6675           47 :           st = gfc_find_symtree (gfc_current_ns->uop_root, name);
    6676              :           /* If corresponding user operator is private, don't write
    6677              :              the UDR.  */
    6678           47 :           if (st != NULL)
    6679              :             {
    6680            0 :               gfc_user_op *uop = st->n.uop;
    6681            0 :               if (!check_access (uop->access, uop->ns->default_access))
    6682              :                 return;
    6683              :             }
    6684              :         }
    6685              :       break;
    6686           35 :     case OMP_REDUCTION_PLUS:
    6687           35 :     case OMP_REDUCTION_MINUS:
    6688           35 :     case OMP_REDUCTION_TIMES:
    6689           35 :     case OMP_REDUCTION_AND:
    6690           35 :     case OMP_REDUCTION_OR:
    6691           35 :     case OMP_REDUCTION_EQV:
    6692           35 :     case OMP_REDUCTION_NEQV:
    6693              :       /* If corresponding operator is private, don't write the UDR.  */
    6694           35 :       if (!check_access (gfc_current_ns->operator_access[udr->rop],
    6695              :                          gfc_current_ns->default_access))
    6696              :         return;
    6697              :       break;
    6698              :     default:
    6699              :       break;
    6700              :     }
    6701           81 :   if (udr->ts.type == BT_DERIVED || udr->ts.type == BT_CLASS)
    6702              :     {
    6703              :       /* If derived type is private, don't write the UDR.  */
    6704           45 :       if (!gfc_check_symbol_access (udr->ts.u.derived))
    6705              :         return;
    6706              :     }
    6707              : 
    6708           80 :   mio_lparen ();
    6709           80 :   mio_pool_string (&udr->name);
    6710           80 :   mio_typespec (&udr->ts);
    6711           80 :   mio_omp_udr_expr (udr, &udr->omp_out, &udr->omp_in, udr->combiner_ns, false);
    6712           80 :   if (udr->initializer_ns)
    6713           64 :     mio_omp_udr_expr (udr, &udr->omp_priv, &udr->omp_orig,
    6714              :                       udr->initializer_ns, true);
    6715           80 :   mio_rparen ();
    6716              : }
    6717              : 
    6718              : 
    6719              : /* Write OpenMP's declare reduction (used defined reductions). */
    6720              : 
    6721              : static void
    6722        10234 : write_omp_udrs (gfc_symtree *st)
    6723              : {
    6724        10335 :   if (st == NULL)
    6725        10234 :     return;
    6726              : 
    6727          101 :   write_omp_udrs (st->left);
    6728          101 :   gfc_omp_udr *udr;
    6729          202 :   for (udr = st->n.omp_udr; udr; udr = udr->next)
    6730          101 :     write_omp_udr (udr);
    6731          101 :   write_omp_udrs (st->right);
    6732              : }
    6733              : 
    6734              : 
    6735              : /* Write OpenMP's declare mapper (used defined mapper). */
    6736              : 
    6737              : static void
    6738           10 : write_omp_udm (gfc_omp_udm *udm)
    6739              : {
    6740           10 :   mio_lparen ();
    6741              :   /* We need this pointer ref to identify this mapper so that other mappers
    6742              :      can refer to it.  */
    6743           10 :   mio_pointer_ref (&udm);
    6744           10 :   mio_pool_string (&udm->mapper_id);
    6745           10 :   mio_typespec (&udm->ts);
    6746              : 
    6747           10 :   if (udm->var_sym->module == NULL)
    6748           10 :     udm->var_sym->module = module_name;
    6749              : 
    6750           10 :   mio_symbol_ref (&udm->var_sym);
    6751           10 :   mio_lparen ();
    6752           10 :   gfc_omp_namelist *n;
    6753           28 :   for (n = udm->clauses->lists[OMP_LIST_MAP]; n; n = n->next)
    6754              :     {
    6755           18 :       mio_lparen ();
    6756              : 
    6757           18 :       mio_name (n->u.map.op, omp_map_clause_ops);
    6758           18 :       mio_symbol_ref (&n->sym);
    6759           18 :       mio_expr (&n->expr);
    6760              : 
    6761           18 :       mio_lparen ();
    6762              : 
    6763           18 :       if (n->u3.udm)
    6764              :         {
    6765            7 :           mio_pool_string (&n->u3.udm->requested_mapper_id);
    6766            7 :           mio_pointer_ref (&n->u3.udm->resolved_udm);
    6767              :         }
    6768              : 
    6769           18 :       mio_rparen ();
    6770              : 
    6771           18 :       mio_rparen ();
    6772              :     }
    6773           10 :   mio_rparen ();
    6774           10 :   mio_rparen ();
    6775           10 : }
    6776              : 
    6777              : 
    6778              : static void
    6779           19 : write_omp_udms (gfc_symtree *st)
    6780              : {
    6781           29 :   if (st == NULL)
    6782           19 :     return;
    6783              : 
    6784           10 :   write_omp_udms (st->left);
    6785           10 :   gfc_omp_udm *udm;
    6786           20 :   for (udm = st->n.omp_udm; udm; udm = udm->next)
    6787           10 :     write_omp_udm (udm);
    6788           10 :   write_omp_udms (st->right);
    6789              : }
    6790              : 
    6791              : 
    6792              : /* Type for the temporary tree used when writing secondary symbols.  */
    6793              : 
    6794              : struct sorted_pointer_info
    6795              : {
    6796              :   BBT_HEADER (sorted_pointer_info);
    6797              : 
    6798              :   pointer_info *p;
    6799              : };
    6800              : 
    6801              : #define gfc_get_sorted_pointer_info() XCNEW (sorted_pointer_info)
    6802              : 
    6803              : /* Recursively traverse the temporary tree, free its contents.  */
    6804              : 
    6805              : static void
    6806       242367 : free_sorted_pointer_info_tree (sorted_pointer_info *p)
    6807              : {
    6808       242367 :   if (!p)
    6809              :     return;
    6810              : 
    6811       113346 :   free_sorted_pointer_info_tree (p->left);
    6812       113346 :   free_sorted_pointer_info_tree (p->right);
    6813              : 
    6814       113346 :   free (p);
    6815              : }
    6816              : 
    6817              : /* Comparison function for the temporary tree.  */
    6818              : 
    6819              : static int
    6820       384493 : compare_sorted_pointer_info (void *_spi1, void *_spi2)
    6821              : {
    6822       384493 :   sorted_pointer_info *spi1, *spi2;
    6823       384493 :   spi1 = (sorted_pointer_info *)_spi1;
    6824       384493 :   spi2 = (sorted_pointer_info *)_spi2;
    6825              : 
    6826       384493 :   if (spi1->p->integer < spi2->p->integer)
    6827              :     return -1;
    6828       218855 :   if (spi1->p->integer > spi2->p->integer)
    6829       218855 :     return 1;
    6830              :   return 0;
    6831              : }
    6832              : 
    6833              : 
    6834              : /* Finds the symbols that need to be written and collects them in the
    6835              :    sorted_pi tree so that they can be traversed in an order
    6836              :    independent of memory addresses.  */
    6837              : 
    6838              : static void
    6839      1266069 : find_symbols_to_write(sorted_pointer_info **tree, pointer_info *p)
    6840              : {
    6841      2506330 :   if (!p)
    6842      1266069 :     return;
    6843              : 
    6844      1240261 :   if (p->type == P_SYMBOL && p->u.wsym.state == NEEDS_WRITE)
    6845              :     {
    6846       113346 :       sorted_pointer_info *sp = gfc_get_sorted_pointer_info();
    6847       113346 :       sp->p = p;
    6848              : 
    6849       113346 :       gfc_insert_bbt (tree, sp, compare_sorted_pointer_info);
    6850              :    }
    6851              : 
    6852      1240261 :   find_symbols_to_write (tree, p->left);
    6853      1240261 :   find_symbols_to_write (tree, p->right);
    6854              : }
    6855              : 
    6856              : 
    6857              : /* Recursive function that traverses the tree of symbols that need to be
    6858              :    written and writes them in order.  */
    6859              : 
    6860              : static void
    6861       129021 : write_symbol1_recursion (sorted_pointer_info *sp)
    6862              : {
    6863       242367 :   if (!sp)
    6864       129021 :     return;
    6865              : 
    6866       113346 :   write_symbol1_recursion (sp->left);
    6867              : 
    6868       113346 :   pointer_info *p1 = sp->p;
    6869       113346 :   gcc_assert (p1->type == P_SYMBOL && p1->u.wsym.state == NEEDS_WRITE);
    6870              : 
    6871       113346 :   p1->u.wsym.state = WRITTEN;
    6872       113346 :   write_symbol (p1->integer, p1->u.wsym.sym);
    6873       113346 :   p1->u.wsym.sym->attr.public_used = 1;
    6874              : 
    6875       113346 :   write_symbol1_recursion (sp->right);
    6876              : }
    6877              : 
    6878              : 
    6879              : /* Write the secondary set of symbols to the module file.  These are
    6880              :    symbols that were not public yet are needed by the public symbols
    6881              :    or another dependent symbol.  The act of writing a symbol can add
    6882              :    symbols to the pointer_info tree, so we return nonzero if a symbol
    6883              :    was written and pass that information upwards.  The caller will
    6884              :    then call this function again until nothing was written.  It uses
    6885              :    the utility functions and a temporary tree to ensure a reproducible
    6886              :    ordering of the symbol output and thus the module file.  */
    6887              : 
    6888              : static int
    6889        25808 : write_symbol1 (pointer_info *p)
    6890              : {
    6891        25808 :   if (!p)
    6892              :     return 0;
    6893              : 
    6894              :   /* Put symbols that need to be written into a tree sorted on the
    6895              :      integer field.  */
    6896              : 
    6897        25808 :   sorted_pointer_info *spi_root = NULL;
    6898        25808 :   find_symbols_to_write (&spi_root, p);
    6899              : 
    6900              :   /* No symbols to write, return.  */
    6901        25808 :   if (!spi_root)
    6902              :     return 0;
    6903              : 
    6904              :   /* Otherwise, write and free the tree again.  */
    6905        15675 :   write_symbol1_recursion (spi_root);
    6906        15675 :   free_sorted_pointer_info_tree (spi_root);
    6907              : 
    6908        15675 :   return 1;
    6909              : }
    6910              : 
    6911              : 
    6912              : /* Write operator interfaces associated with a symbol.  */
    6913              : 
    6914              : static void
    6915          169 : write_operator (gfc_user_op *uop)
    6916              : {
    6917          169 :   static char nullstring[] = "";
    6918          169 :   const char *p = nullstring;
    6919              : 
    6920          169 :   if (uop->op == NULL || !check_access (uop->access, uop->ns->default_access))
    6921            1 :     return;
    6922              : 
    6923          168 :   mio_symbol_interface (&uop->name, &p, &uop->op);
    6924              : }
    6925              : 
    6926              : 
    6927              : /* Write generic interfaces from the namespace sym_root.  */
    6928              : 
    6929              : static void
    6930       168510 : write_generic (gfc_symtree *st)
    6931              : {
    6932       326887 :   gfc_symbol *sym;
    6933              : 
    6934       326887 :   if (st == NULL)
    6935       168510 :     return;
    6936              : 
    6937       158377 :   write_generic (st->left);
    6938              : 
    6939       158377 :   sym = st->n.sym;
    6940       158377 :   if (sym && !check_unique_name (st->name)
    6941       309325 :       && sym->generic && gfc_check_symbol_access (sym))
    6942              :     {
    6943        11262 :       if (!sym->module)
    6944         7380 :         sym->module = module_name;
    6945              : 
    6946        11262 :       mio_symbol_interface (&st->name, &sym->module, &sym->generic);
    6947              :     }
    6948              : 
    6949       158377 :   write_generic (st->right);
    6950              : }
    6951              : 
    6952              : 
    6953              : static void
    6954       158378 : write_symtree (gfc_symtree *st)
    6955              : {
    6956       158378 :   gfc_symbol *sym;
    6957       158378 :   pointer_info *p;
    6958              : 
    6959       158378 :   sym = st->n.sym;
    6960              : 
    6961              :   /* A symbol in an interface body must not be visible in the
    6962              :      module file.  */
    6963       158378 :   if (sym->ns != gfc_current_ns
    6964          450 :         && sym->ns->proc_name
    6965          450 :         && sym->ns->proc_name->attr.if_source == IFSRC_IFBODY)
    6966              :     return;
    6967              : 
    6968       158378 :   if ((!gfc_check_symbol_access (sym)
    6969        18900 :        && (!sym->attr.public_used || submodule_name == NULL))
    6970       158378 :       || (sym->attr.flavor == FL_PROCEDURE && sym->attr.generic
    6971        11390 :           && !sym->attr.subroutine && !sym->attr.function))
    6972              :     return;
    6973              : 
    6974       137999 :   if (check_unique_name (st->name))
    6975              :     return;
    6976              : 
    6977              :   /* From F2003 onwards, intrinsic procedures are no longer subject to
    6978              :      the restriction, "that an elemental intrinsic function here be of
    6979              :      type integer or character and each argument must be an initialization
    6980              :      expr of type integer or character" is lifted so that intrinsic
    6981              :      procedures can be over-ridden. This requires that the intrinsic
    6982              :      symbol not appear in the module file, thereby preventing ambiguity
    6983              :      when USEd.  */
    6984       131543 :   if (strcmp (sym->module, "(intrinsic)") == 0
    6985         2240 :       && (gfc_option.allow_std & GFC_STD_F2003))
    6986              :     return;
    6987              : 
    6988       129304 :   p = find_pointer (sym);
    6989       129304 :   if (p == NULL)
    6990            0 :     gfc_internal_error ("write_symtree(): Symbol not written");
    6991              : 
    6992       129304 :   mio_pool_string (&st->name);
    6993       129304 :   mio_integer (&st->ambiguous);
    6994       129304 :   mio_hwi (&p->integer);
    6995              : }
    6996              : 
    6997              : 
    6998              : static void
    6999        10133 : write_module (void)
    7000              : {
    7001        10133 :   int i;
    7002              : 
    7003              :   /* Initialize the column counter. */
    7004        10133 :   module_column = 1;
    7005              : 
    7006              :   /* Write the operator interfaces.  */
    7007        10133 :   mio_lparen ();
    7008              : 
    7009       303990 :   for (i = GFC_INTRINSIC_BEGIN; i != GFC_INTRINSIC_END; i++)
    7010              :     {
    7011       283724 :       if (i == INTRINSIC_USER)
    7012        10133 :         continue;
    7013              : 
    7014       547182 :       mio_interface (check_access (gfc_current_ns->operator_access[i],
    7015              :                                    gfc_current_ns->default_access)
    7016              :                      ? &gfc_current_ns->op[i] : NULL);
    7017              :     }
    7018              : 
    7019        10133 :   mio_rparen ();
    7020        10133 :   write_char ('\n');
    7021        10133 :   write_char ('\n');
    7022              : 
    7023        10133 :   mio_lparen ();
    7024        10133 :   gfc_traverse_user_op (gfc_current_ns, write_operator);
    7025        10133 :   mio_rparen ();
    7026        10133 :   write_char ('\n');
    7027        10133 :   write_char ('\n');
    7028              : 
    7029        10133 :   mio_lparen ();
    7030        10133 :   write_generic (gfc_current_ns->sym_root);
    7031        10133 :   mio_rparen ();
    7032        10133 :   write_char ('\n');
    7033        10133 :   write_char ('\n');
    7034              : 
    7035        10133 :   mio_lparen ();
    7036        10133 :   write_blank_common ();
    7037        10133 :   write_common (gfc_current_ns->common_root);
    7038        10133 :   mio_rparen ();
    7039        10133 :   write_char ('\n');
    7040        10133 :   write_char ('\n');
    7041              : 
    7042        10133 :   mio_lparen ();
    7043        10133 :   write_equiv ();
    7044        10133 :   mio_rparen ();
    7045        10133 :   write_char ('\n');
    7046        10133 :   write_char ('\n');
    7047              : 
    7048        10133 :   mio_lparen ();
    7049        10133 :   write_omp_udrs (gfc_current_ns->omp_udr_root);
    7050        10133 :   mio_rparen ();
    7051        10133 :   write_char ('\n');
    7052        10133 :   write_char ('\n');
    7053              : 
    7054              :   /* Condition can be removed if version is bumped.  Note that
    7055              :      write_symbol0 starts with an integer.  Keep in sync with read_module;
    7056              :      The 'UDM' tag can be only removed when changing COMPAT_MOD_VERSIONS.  */
    7057        10133 :   STATIC_ASSERT (MOD_VERSION_NUMERIC == 16);
    7058        10133 :   if (gfc_current_ns->omp_udm_root)
    7059              :     {
    7060            9 :       mio_lparen ();
    7061            9 :       write_atom (ATOM_NAME, "UDM");  /* Marker. */
    7062            9 :       write_omp_udms (gfc_current_ns->omp_udm_root);
    7063            9 :       mio_rparen ();
    7064            9 :       write_char ('\n');
    7065            9 :       write_char ('\n');
    7066              :     }
    7067              : 
    7068              :   /* Write symbol information.  First we traverse all symbols in the
    7069              :      primary namespace, writing those that need to be written.
    7070              :      Sometimes writing one symbol will cause another to need to be
    7071              :      written.  A list of these symbols ends up on the write stack, and
    7072              :      we end by popping the bottom of the stack and writing the symbol
    7073              :      until the stack is empty.  */
    7074              : 
    7075        10133 :   mio_lparen ();
    7076              : 
    7077        10133 :   write_symbol0 (gfc_current_ns->sym_root);
    7078        35941 :   while (write_symbol1 (pi_root))
    7079              :     /* Nothing.  */;
    7080              : 
    7081        10133 :   mio_rparen ();
    7082              : 
    7083        10133 :   write_char ('\n');
    7084        10133 :   write_char ('\n');
    7085              : 
    7086        10133 :   mio_lparen ();
    7087        10133 :   gfc_traverse_symtree (gfc_current_ns->sym_root, write_symtree);
    7088        10133 :   mio_rparen ();
    7089        10133 : }
    7090              : 
    7091              : 
    7092              : /* Read a CRC32 sum from the gzip trailer of a module file.  Returns
    7093              :    true on success, false on failure.  */
    7094              : 
    7095              : static bool
    7096        20266 : read_crc32_from_module_file (const char* filename, uLong* crc)
    7097              : {
    7098        20266 :   FILE *file;
    7099        20266 :   char buf[4];
    7100        20266 :   unsigned int val;
    7101              : 
    7102              :   /* Open the file in binary mode.  */
    7103        20266 :   if ((file = fopen (filename, "rb")) == NULL)
    7104              :     return false;
    7105              : 
    7106              :   /* The gzip crc32 value is found in the [END-8, END-4] bytes of the
    7107              :      file. See RFC 1952.  */
    7108        10352 :   if (fseek (file, -8, SEEK_END) != 0)
    7109              :     {
    7110            0 :       fclose (file);
    7111            0 :       return false;
    7112              :     }
    7113              : 
    7114              :   /* Read the CRC32.  */
    7115        10352 :   if (fread (buf, 1, 4, file) != 4)
    7116              :     {
    7117            0 :       fclose (file);
    7118            0 :       return false;
    7119              :     }
    7120              : 
    7121              :   /* Close the file.  */
    7122        10352 :   fclose (file);
    7123              : 
    7124        10352 :   val = (buf[0] & 0xFF) + ((buf[1] & 0xFF) << 8) + ((buf[2] & 0xFF) << 16)
    7125        10352 :     + ((buf[3] & 0xFF) << 24);
    7126        10352 :   *crc = val;
    7127              : 
    7128              :   /* For debugging, the CRC value printed in hexadecimal should match
    7129              :      the CRC printed by "zcat -l -v filename".
    7130              :      printf("CRC of file %s is %x\n", filename, val); */
    7131              : 
    7132        10352 :   return true;
    7133              : }
    7134              : 
    7135              : 
    7136              : /* Given module, dump it to disk.  If there was an error while
    7137              :    processing the module, dump_flag will be set to zero and we delete
    7138              :    the module file, even if it was already there.  */
    7139              : 
    7140              : static void
    7141        10622 : dump_module (const char *name, int dump_flag)
    7142              : {
    7143        10622 :   int n;
    7144        10622 :   char *filename, *filename_tmp;
    7145        10622 :   uLong crc, crc_old;
    7146              : 
    7147        10622 :   module_name = gfc_get_string ("%s", name);
    7148              : 
    7149        10622 :   if (dump_smod)
    7150              :     {
    7151          563 :       name = submodule_name;
    7152          563 :       n = strlen (name) + strlen (SUBMODULE_EXTENSION) + 1;
    7153              :     }
    7154              :   else
    7155        10059 :     n = strlen (name) + strlen (MODULE_EXTENSION) + 1;
    7156              : 
    7157        10622 :   if (gfc_option.module_dir != NULL)
    7158              :     {
    7159            0 :       n += strlen (gfc_option.module_dir);
    7160            0 :       filename = (char *) alloca (n);
    7161            0 :       strcpy (filename, gfc_option.module_dir);
    7162            0 :       strcat (filename, name);
    7163              :     }
    7164              :   else
    7165              :     {
    7166        10622 :       filename = (char *) alloca (n);
    7167        10622 :       strcpy (filename, name);
    7168              :     }
    7169              : 
    7170        10622 :   if (dump_smod)
    7171          563 :     strcat (filename, SUBMODULE_EXTENSION);
    7172              :   else
    7173        10059 :   strcat (filename, MODULE_EXTENSION);
    7174              : 
    7175              :   /* Name of the temporary file used to write the module.  */
    7176        10622 :   filename_tmp = (char *) alloca (n + 1);
    7177        10622 :   strcpy (filename_tmp, filename);
    7178        10622 :   strcat (filename_tmp, "0");
    7179              : 
    7180              :   /* There was an error while processing the module.  We delete the
    7181              :      module file, even if it was already there.  */
    7182        10622 :   if (!dump_flag)
    7183              :     {
    7184          489 :       remove (filename);
    7185          489 :       return;
    7186              :     }
    7187              : 
    7188        10133 :   if (gfc_cpp_makedep ())
    7189            0 :     gfc_cpp_add_target (filename);
    7190              : 
    7191              :   /* Write the module to the temporary file.  */
    7192        10133 :   module_fp = gzopen (filename_tmp, "w");
    7193        10133 :   if (module_fp == NULL)
    7194            0 :     gfc_fatal_error ("Cannot open module file %qs for writing at %C: %s",
    7195            0 :                      filename_tmp, xstrerror (errno));
    7196              : 
    7197              :   /* Use lbasename to ensure module files are reproducible regardless
    7198              :      of the build path (see the reproducible builds project).  */
    7199        10133 :   gzprintf (module_fp, "GFORTRAN module version '%s' created from %s\n",
    7200              :             MOD_VERSION, lbasename (gfc_source_file));
    7201              : 
    7202              :   /* Write the module itself.  */
    7203        10133 :   iomode = IO_OUTPUT;
    7204              : 
    7205        10133 :   init_pi_tree ();
    7206              : 
    7207        10133 :   write_module ();
    7208              : 
    7209        10133 :   free_pi_tree (pi_root);
    7210        10133 :   pi_root = NULL;
    7211              : 
    7212        10133 :   write_char ('\n');
    7213              : 
    7214        10133 :   if (gzclose (module_fp))
    7215            0 :     gfc_fatal_error ("Error writing module file %qs for writing: %s",
    7216            0 :                      filename_tmp, xstrerror (errno));
    7217              : 
    7218              :   /* Read the CRC32 from the gzip trailers of the module files and
    7219              :      compare.  */
    7220        10133 :   if (!read_crc32_from_module_file (filename_tmp, &crc)
    7221        10133 :       || !read_crc32_from_module_file (filename, &crc_old)
    7222        10352 :       || crc_old != crc)
    7223              :     {
    7224              :       /* Module file have changed, replace the old one.  */
    7225         9920 :       if (remove (filename) && errno != ENOENT)
    7226            0 :         gfc_fatal_error ("Cannot delete module file %qs: %s", filename,
    7227              :                          xstrerror (errno));
    7228         9920 :       if (rename (filename_tmp, filename))
    7229            0 :         gfc_fatal_error ("Cannot rename module file %qs to %qs: %s",
    7230            0 :                          filename_tmp, filename, xstrerror (errno));
    7231              :     }
    7232              :   else
    7233              :     {
    7234          213 :       if (remove (filename_tmp))
    7235            0 :         gfc_fatal_error ("Cannot delete temporary module file %qs: %s",
    7236            0 :                          filename_tmp, xstrerror (errno));
    7237              :     }
    7238              : }
    7239              : 
    7240              : 
    7241              : /* Suppress the output of a .smod file by module, if no module
    7242              :    procedures have been seen.  */
    7243              : static bool no_module_procedures;
    7244              : 
    7245              : static void
    7246       158224 : check_for_module_procedures (gfc_symbol *sym)
    7247              : {
    7248       158224 :   if (sym && sym->attr.module_procedure)
    7249         1162 :     no_module_procedures = false;
    7250       158224 : }
    7251              : 
    7252              : 
    7253              : void
    7254        10323 : gfc_dump_module (const char *name, int dump_flag)
    7255              : {
    7256        10323 :   if (gfc_state_stack->state == COMP_SUBMODULE)
    7257              :     dump_smod = true;
    7258              :   else
    7259        10059 :     dump_smod =false;
    7260              : 
    7261        10323 :   no_module_procedures = true;
    7262        10323 :   gfc_traverse_ns (gfc_current_ns, check_for_module_procedures);
    7263              : 
    7264        10323 :   dump_module (name, dump_flag);
    7265              : 
    7266        10323 :   if (no_module_procedures || dump_smod)
    7267              :     return;
    7268              : 
    7269              :   /* Write a submodule file from a module.  The 'dump_smod' flag switches
    7270              :      off the check for PRIVATE entities.  */
    7271          299 :   dump_smod = true;
    7272          299 :   submodule_name = module_name;
    7273          299 :   dump_module (name, dump_flag);
    7274          299 :   dump_smod = false;
    7275              : }
    7276              : 
    7277              : static void
    7278        27023 : create_intrinsic_function (const char *name, int id,
    7279              :                            const char *modname, intmod_id module,
    7280              :                            bool subroutine, gfc_symbol *result_type)
    7281              : {
    7282        27023 :   gfc_intrinsic_sym *isym;
    7283        27023 :   gfc_symtree *tmp_symtree;
    7284        27023 :   gfc_symbol *sym;
    7285              : 
    7286        27023 :   tmp_symtree = gfc_find_symtree (gfc_current_ns->sym_root, name);
    7287        27023 :   if (tmp_symtree)
    7288              :     {
    7289           48 :       if (tmp_symtree->n.sym && tmp_symtree->n.sym->module
    7290           48 :           && strcmp (modname, tmp_symtree->n.sym->module) == 0)
    7291           48 :         return;
    7292            0 :       gfc_error ("Symbol %qs at %C already declared", name);
    7293            0 :       return;
    7294              :     }
    7295              : 
    7296        26975 :   gfc_get_sym_tree (name, gfc_current_ns, &tmp_symtree, false);
    7297        26975 :   sym = tmp_symtree->n.sym;
    7298              : 
    7299        26975 :   if (subroutine)
    7300              :     {
    7301         9798 :       gfc_isym_id isym_id = gfc_isym_id_by_intmod (module, id);
    7302         9798 :       isym = gfc_intrinsic_subroutine_by_id (isym_id);
    7303         9798 :       sym->attr.subroutine = 1;
    7304              :     }
    7305              :   else
    7306              :     {
    7307        17177 :       gfc_isym_id isym_id = gfc_isym_id_by_intmod (module, id);
    7308        17177 :       isym = gfc_intrinsic_function_by_id (isym_id);
    7309              : 
    7310        17177 :       sym->attr.function = 1;
    7311        17177 :       if (result_type)
    7312              :         {
    7313         6688 :           sym->ts.type = BT_DERIVED;
    7314         6688 :           sym->ts.u.derived = result_type;
    7315         6688 :           sym->ts.is_c_interop = 1;
    7316         6688 :           isym->ts.f90_type = BT_VOID;
    7317         6688 :           isym->ts.type = BT_DERIVED;
    7318         6688 :           isym->ts.f90_type = BT_VOID;
    7319         6688 :           isym->ts.u.derived = result_type;
    7320         6688 :           isym->ts.is_c_interop = 1;
    7321              :         }
    7322              :     }
    7323        26975 :   gcc_assert (isym);
    7324              : 
    7325        26975 :   sym->attr.flavor = FL_PROCEDURE;
    7326        26975 :   sym->attr.intrinsic = 1;
    7327              : 
    7328        26975 :   sym->module = gfc_get_string ("%s", modname);
    7329        26975 :   sym->attr.use_assoc = 1;
    7330        26975 :   sym->from_intmod = module;
    7331        26975 :   sym->intmod_sym_id = id;
    7332              : }
    7333              : 
    7334              : 
    7335              : /* Import the intrinsic ISO_C_BINDING module, generating symbols in
    7336              :    the current namespace for all named constants, pointer types, and
    7337              :    procedures in the module unless the only clause was used or a rename
    7338              :    list was provided.  */
    7339              : 
    7340              : static void
    7341         9934 : import_iso_c_binding_module (void)
    7342              : {
    7343         9934 :   gfc_symbol *mod_sym = NULL, *return_type;
    7344         9934 :   gfc_symtree *mod_symtree = NULL, *tmp_symtree;
    7345         9934 :   gfc_symtree *c_ptr = NULL, *c_funptr = NULL;
    7346         9934 :   const char *iso_c_module_name = "__iso_c_binding";
    7347         9934 :   gfc_use_rename *u;
    7348         9934 :   int i;
    7349         9934 :   bool want_c_ptr = false, want_c_funptr = false;
    7350              : 
    7351              :   /* Look only in the current namespace.  */
    7352         9934 :   mod_symtree = gfc_find_symtree (gfc_current_ns->sym_root, iso_c_module_name);
    7353              : 
    7354         9934 :   if (mod_symtree == NULL)
    7355              :     {
    7356              :       /* symtree doesn't already exist in current namespace.  */
    7357         9859 :       gfc_get_sym_tree (iso_c_module_name, gfc_current_ns, &mod_symtree,
    7358              :                         false);
    7359              : 
    7360         9859 :       if (mod_symtree != NULL)
    7361         9859 :         mod_sym = mod_symtree->n.sym;
    7362              :       else
    7363            0 :         gfc_internal_error ("import_iso_c_binding_module(): Unable to "
    7364              :                             "create symbol for %s", iso_c_module_name);
    7365              : 
    7366         9859 :       mod_sym->attr.flavor = FL_MODULE;
    7367         9859 :       mod_sym->attr.intrinsic = 1;
    7368         9859 :       mod_sym->module = gfc_get_string ("%s", iso_c_module_name);
    7369         9859 :       mod_sym->from_intmod = INTMOD_ISO_C_BINDING;
    7370              :     }
    7371              : 
    7372              :   /* Check whether C_PTR or C_FUNPTR are in the include list, if so, load it;
    7373              :      check also whether C_NULL_(FUN)PTR or C_(FUN)LOC are requested, which
    7374              :      need C_(FUN)PTR.  */
    7375        20130 :   for (u = gfc_rename_list; u; u = u->next)
    7376              :     {
    7377        10196 :       if (strcmp (c_interop_kinds_table[ISOCBINDING_NULL_PTR].name,
    7378        10196 :                   u->use_name) == 0)
    7379              :         want_c_ptr = true;
    7380        10135 :       else if (strcmp (c_interop_kinds_table[ISOCBINDING_LOC].name,
    7381              :                        u->use_name) == 0)
    7382              :         want_c_ptr = true;
    7383        10005 :       else if (strcmp (c_interop_kinds_table[ISOCBINDING_NULL_FUNPTR].name,
    7384              :                        u->use_name) == 0)
    7385              :         want_c_funptr = true;
    7386         9996 :       else if (strcmp (c_interop_kinds_table[ISOCBINDING_FUNLOC].name,
    7387              :                        u->use_name) == 0)
    7388              :         want_c_funptr = true;
    7389         9960 :       else if (strcmp (c_interop_kinds_table[ISOCBINDING_PTR].name,
    7390              :                        u->use_name) == 0)
    7391              :         {
    7392         2268 :           c_ptr = generate_isocbinding_symbol (iso_c_module_name,
    7393              :                                                (iso_c_binding_symbol)
    7394              :                                                         ISOCBINDING_PTR,
    7395         2268 :                                                u->local_name[0] ? u->local_name
    7396              :                                                                 : u->use_name,
    7397              :                                                NULL, false);
    7398              :         }
    7399         7692 :       else if (strcmp (c_interop_kinds_table[ISOCBINDING_FUNPTR].name,
    7400              :                        u->use_name) == 0)
    7401              :         {
    7402          107 :           c_funptr
    7403          107 :              = generate_isocbinding_symbol (iso_c_module_name,
    7404              :                                             (iso_c_binding_symbol)
    7405              :                                                         ISOCBINDING_FUNPTR,
    7406          107 :                                              u->local_name[0] ? u->local_name
    7407              :                                                               : u->use_name,
    7408              :                                              NULL, false);
    7409              :         }
    7410              :     }
    7411              : 
    7412         9934 :   if ((want_c_ptr || !only_flag) && !c_ptr)
    7413         3304 :     c_ptr = generate_isocbinding_symbol (iso_c_module_name,
    7414              :                                          (iso_c_binding_symbol)
    7415              :                                                         ISOCBINDING_PTR,
    7416              :                                          NULL, NULL, only_flag);
    7417         9934 :   if ((want_c_funptr || !only_flag) && !c_funptr)
    7418         3268 :     c_funptr = generate_isocbinding_symbol (iso_c_module_name,
    7419              :                                             (iso_c_binding_symbol)
    7420              :                                                         ISOCBINDING_FUNPTR,
    7421              :                                             NULL, NULL, only_flag);
    7422              : 
    7423              :   /* Generate the symbols for the named constants representing
    7424              :      the kinds for intrinsic data types.  */
    7425       754984 :   for (i = 0; i < ISOCBINDING_NUMBER; i++)
    7426              :     {
    7427       745050 :       bool found = false;
    7428      1509750 :       for (u = gfc_rename_list; u; u = u->next)
    7429       764700 :         if (strcmp (c_interop_kinds_table[i].name, u->use_name) == 0)
    7430              :           {
    7431        10194 :             bool not_in_std;
    7432        10194 :             const char *name;
    7433        10194 :             u->found = 1;
    7434        10194 :             found = true;
    7435              : 
    7436        10194 :             switch (i)
    7437              :               {
    7438              : #define NAMED_FUNCTION(a,b,c,d) \
    7439              :                 case a: \
    7440              :                   not_in_std = (gfc_option.allow_std & d) == 0; \
    7441              :                   name = b; \
    7442              :                   break;
    7443              : #define NAMED_SUBROUTINE(a,b,c,d) \
    7444              :                 case a: \
    7445              :                   not_in_std = (gfc_option.allow_std & d) == 0; \
    7446              :                   name = b; \
    7447              :                   break;
    7448              : #define NAMED_INTCST(a,b,c,d) \
    7449              :                 case a: \
    7450              :                   not_in_std = (gfc_option.allow_std & d) == 0; \
    7451              :                   name = b; \
    7452              :                   break;
    7453              : #define NAMED_UINTCST(a,b,c,d) \
    7454              :                 case a: \
    7455              :                   not_in_std = (gfc_option.allow_std & d) == 0; \
    7456              :                   name = b; \
    7457              :                   break;
    7458              : #define NAMED_REALCST(a,b,c,d)                  \
    7459              :                 case a: \
    7460              :                   not_in_std = (gfc_option.allow_std & d) == 0; \
    7461              :                   name = b; \
    7462              :                   break;
    7463              : #define NAMED_CMPXCST(a,b,c,d) \
    7464              :                 case a: \
    7465              :                   not_in_std = (gfc_option.allow_std & d) == 0; \
    7466              :                   name = b; \
    7467              :                   break;
    7468              : #include "iso-c-binding.def"
    7469              :                 default:
    7470              :                   not_in_std = false;
    7471              :                   name = "";
    7472              :               }
    7473              : 
    7474         7403 :             if (not_in_std)
    7475              :               {
    7476            6 :                 gfc_error ("The symbol %qs, referenced at %L, is not "
    7477              :                            "in the selected standard", name, &u->where);
    7478            6 :                 continue;
    7479              :               }
    7480              : 
    7481        10188 :             switch (i)
    7482              :               {
    7483              : #define NAMED_FUNCTION(a,b,c,d) \
    7484              :                 case a: \
    7485              :                   if (a == ISOCBINDING_LOC) \
    7486              :                     return_type = c_ptr->n.sym; \
    7487              :                   else if (a == ISOCBINDING_FUNLOC) \
    7488              :                     return_type = c_funptr->n.sym; \
    7489              :                   else \
    7490              :                     return_type = NULL; \
    7491              :                   create_intrinsic_function (u->local_name[0] \
    7492              :                                              ? u->local_name : u->use_name, \
    7493              :                                              a, iso_c_module_name, \
    7494              :                                              INTMOD_ISO_C_BINDING, false, \
    7495              :                                              return_type); \
    7496              :                   break;
    7497              : #define NAMED_SUBROUTINE(a,b,c,d) \
    7498              :                 case a: \
    7499              :                   create_intrinsic_function (u->local_name[0] ? u->local_name \
    7500              :                                                               : u->use_name, \
    7501              :                                              a, iso_c_module_name, \
    7502              :                                              INTMOD_ISO_C_BINDING, true, NULL); \
    7503              :                   break;
    7504              : #include "iso-c-binding.def"
    7505              : 
    7506              :                 case ISOCBINDING_PTR:
    7507              :                 case ISOCBINDING_FUNPTR:
    7508              :                   /* Already handled above.  */
    7509              :                   break;
    7510         7440 :                 default:
    7511         7440 :                   if (i == ISOCBINDING_NULL_PTR)
    7512              :                     tmp_symtree = c_ptr;
    7513         7379 :                   else if (i == ISOCBINDING_NULL_FUNPTR)
    7514              :                     tmp_symtree = c_funptr;
    7515              :                   else
    7516         7370 :                     tmp_symtree = NULL;
    7517         7440 :                   generate_isocbinding_symbol (iso_c_module_name,
    7518              :                                                (iso_c_binding_symbol) i,
    7519         7440 :                                                u->local_name[0]
    7520              :                                                ? u->local_name : u->use_name,
    7521              :                                                tmp_symtree, false);
    7522              :               }
    7523              :           }
    7524              : 
    7525       745050 :       if (!found && !only_flag)
    7526              :         {
    7527              :           /* Skip, if the symbol is not in the enabled standard.  */
    7528       244984 :           switch (i)
    7529              :             {
    7530              : #define NAMED_FUNCTION(a,b,c,d) \
    7531              :               case a: \
    7532              :                 if ((gfc_option.allow_std & d) == 0) \
    7533              :                   continue; \
    7534              :                 break;
    7535              : #define NAMED_SUBROUTINE(a,b,c,d) \
    7536              :               case a: \
    7537              :                 if ((gfc_option.allow_std & d) == 0) \
    7538              :                   continue; \
    7539              :                 break;
    7540              : #define NAMED_INTCST(a,b,c,d) \
    7541              :               case a: \
    7542              :                 if ((gfc_option.allow_std & d) == 0) \
    7543              :                   continue; \
    7544              :                 break;
    7545              : #define NAMED_UINTCST(a,b,c,d) \
    7546              :               case a: \
    7547              :                 if ((gfc_option.allow_std & d) == 0) \
    7548              :                   continue; \
    7549              :                 break;
    7550              : #define NAMED_REALCST(a,b,c,d)                  \
    7551              :               case a: \
    7552              :                 if ((gfc_option.allow_std & d) == 0) \
    7553              :                   continue; \
    7554              :                 break;
    7555              : #define NAMED_CMPXCST(a,b,c,d) \
    7556              :               case a: \
    7557              :                 if ((gfc_option.allow_std & d) == 0) \
    7558              :                   continue; \
    7559              :                 break;
    7560              : #include "iso-c-binding.def"
    7561       175989 :               default:
    7562       175989 :                 ; /* Not GFC_STD_* versioned.  */
    7563              :             }
    7564              : 
    7565       175989 :           switch (i)
    7566              :             {
    7567              : #define NAMED_FUNCTION(a,b,c,d) \
    7568              :               case a: \
    7569              :                 if (a == ISOCBINDING_LOC) \
    7570              :                   return_type = c_ptr->n.sym; \
    7571              :                 else if (a == ISOCBINDING_FUNLOC) \
    7572              :                   return_type = c_funptr->n.sym; \
    7573              :                 else \
    7574              :                   return_type = NULL; \
    7575              :                 create_intrinsic_function (b, a, iso_c_module_name, \
    7576              :                                            INTMOD_ISO_C_BINDING, false, \
    7577              :                                            return_type); \
    7578              :                 break;
    7579              : #define NAMED_SUBROUTINE(a,b,c,d) \
    7580              :               case a: \
    7581              :                 create_intrinsic_function (b, a, iso_c_module_name, \
    7582              :                                            INTMOD_ISO_C_BINDING, true, NULL); \
    7583              :                   break;
    7584              : #include "iso-c-binding.def"
    7585              : 
    7586              :               case ISOCBINDING_PTR:
    7587              :               case ISOCBINDING_FUNPTR:
    7588              :                 /* Already handled above.  */
    7589              :                 break;
    7590       143453 :               default:
    7591       143453 :                 if (i == ISOCBINDING_NULL_PTR)
    7592              :                   tmp_symtree = c_ptr;
    7593       140186 :                 else if (i == ISOCBINDING_NULL_FUNPTR)
    7594              :                   tmp_symtree = c_funptr;
    7595              :                 else
    7596       136919 :                   tmp_symtree = NULL;
    7597       143453 :                 generate_isocbinding_symbol (iso_c_module_name,
    7598              :                                              (iso_c_binding_symbol) i, NULL,
    7599              :                                              tmp_symtree, false);
    7600              :             }
    7601              :         }
    7602              :    }
    7603              : 
    7604        20130 :    for (u = gfc_rename_list; u; u = u->next)
    7605              :      {
    7606        10196 :       if (u->found)
    7607        10194 :         continue;
    7608              : 
    7609            2 :       gfc_error ("Symbol %qs referenced at %L not found in intrinsic "
    7610            2 :                  "module ISO_C_BINDING", u->use_name, &u->where);
    7611              :      }
    7612         9934 : }
    7613              : 
    7614              : 
    7615              : /* Add an integer named constant from a given module.  */
    7616              : 
    7617              : static void
    7618        10047 : create_int_parameter (const char *name, int value, const char *modname,
    7619              :                       intmod_id module, int id)
    7620              : {
    7621        10047 :   gfc_symtree *tmp_symtree;
    7622        10047 :   gfc_symbol *sym;
    7623              : 
    7624        10047 :   tmp_symtree = gfc_find_symtree (gfc_current_ns->sym_root, name);
    7625        10047 :   if (tmp_symtree != NULL)
    7626              :     {
    7627            0 :       if (strcmp (modname, tmp_symtree->n.sym->module) == 0)
    7628            0 :         return;
    7629              :       else
    7630            0 :         gfc_error ("Symbol %qs already declared", name);
    7631              :     }
    7632              : 
    7633        10047 :   gfc_get_sym_tree (name, gfc_current_ns, &tmp_symtree, false);
    7634        10047 :   sym = tmp_symtree->n.sym;
    7635              : 
    7636        10047 :   sym->module = gfc_get_string ("%s", modname);
    7637        10047 :   sym->attr.flavor = FL_PARAMETER;
    7638        10047 :   sym->ts.type = BT_INTEGER;
    7639        10047 :   sym->ts.kind = gfc_default_integer_kind;
    7640        10047 :   sym->value = gfc_get_int_expr (gfc_default_integer_kind, NULL, value);
    7641        10047 :   sym->attr.use_assoc = 1;
    7642        10047 :   sym->from_intmod = module;
    7643        10047 :   sym->intmod_sym_id = id;
    7644              : }
    7645              : 
    7646              : 
    7647              : /* Value is already contained by the array constructor, but not
    7648              :    yet the shape.  */
    7649              : 
    7650              : static void
    7651         1314 : create_int_parameter_array (const char *name, int size, gfc_expr *value,
    7652              :                             const char *modname, intmod_id module, int id)
    7653              : {
    7654         1314 :   gfc_symtree *tmp_symtree;
    7655         1314 :   gfc_symbol *sym;
    7656              : 
    7657         1314 :   tmp_symtree = gfc_find_symtree (gfc_current_ns->sym_root, name);
    7658         1314 :   if (tmp_symtree != NULL)
    7659              :     {
    7660            1 :       if (tmp_symtree->n.sym->module &&
    7661            0 :           strcmp (modname, tmp_symtree->n.sym->module) == 0)
    7662            0 :         return;
    7663              :       else
    7664            1 :         gfc_error ("Symbol %qs already declared at %L conflicts with "
    7665              :                    "symbol in %qs at %C", name,
    7666              :                    &tmp_symtree->n.sym->declared_at, modname);
    7667              :     }
    7668              : 
    7669         1314 :   gfc_get_sym_tree (name, gfc_current_ns, &tmp_symtree, false);
    7670         1314 :   sym = tmp_symtree->n.sym;
    7671              : 
    7672         1314 :   sym->module = gfc_get_string ("%s", modname);
    7673         1314 :   sym->attr.flavor = FL_PARAMETER;
    7674         1314 :   sym->ts.type = BT_INTEGER;
    7675         1314 :   sym->ts.kind = gfc_default_integer_kind;
    7676         1314 :   sym->attr.use_assoc = 1;
    7677         1314 :   sym->from_intmod = module;
    7678         1314 :   sym->intmod_sym_id = id;
    7679         1314 :   sym->attr.dimension = 1;
    7680         1314 :   sym->as = gfc_get_array_spec ();
    7681         1314 :   sym->as->rank = 1;
    7682         1314 :   sym->as->type = AS_EXPLICIT;
    7683         1314 :   sym->as->lower[0] = gfc_get_int_expr (gfc_default_integer_kind, NULL, 1);
    7684         1314 :   sym->as->upper[0] = gfc_get_int_expr (gfc_default_integer_kind, NULL, size);
    7685              : 
    7686         1314 :   sym->value = value;
    7687         1314 :   sym->value->shape = gfc_get_shape (1);
    7688         1314 :   mpz_init_set_ui (sym->value->shape[0], size);
    7689              : }
    7690              : 
    7691              : 
    7692              : /* Add an derived type for a given module.  */
    7693              : 
    7694              : static void
    7695         1030 : create_derived_type (const char *name, const char *modname,
    7696              :                       intmod_id module, int id)
    7697              : {
    7698         1030 :   gfc_symtree *tmp_symtree;
    7699         1030 :   gfc_symbol *sym, *dt_sym;
    7700         1030 :   gfc_interface *intr, *head;
    7701              : 
    7702         1030 :   tmp_symtree = gfc_find_symtree (gfc_current_ns->sym_root, name);
    7703         1030 :   if (tmp_symtree != NULL)
    7704              :     {
    7705            0 :       if (strcmp (modname, tmp_symtree->n.sym->module) == 0)
    7706            0 :         return;
    7707              :       else
    7708            0 :         gfc_error ("Symbol %qs already declared", name);
    7709              :     }
    7710              : 
    7711         1030 :   gfc_get_sym_tree (name, gfc_current_ns, &tmp_symtree, false);
    7712         1030 :   sym = tmp_symtree->n.sym;
    7713         1030 :   sym->module = gfc_get_string ("%s", modname);
    7714         1030 :   sym->from_intmod = module;
    7715         1030 :   sym->intmod_sym_id = id;
    7716         1030 :   sym->attr.flavor = FL_PROCEDURE;
    7717         1030 :   sym->attr.function = 1;
    7718         1030 :   sym->attr.generic = 1;
    7719              : 
    7720         1030 :   gfc_get_sym_tree (gfc_dt_upper_string (sym->name),
    7721              :                     gfc_current_ns, &tmp_symtree, false);
    7722         1030 :   dt_sym = tmp_symtree->n.sym;
    7723         1030 :   dt_sym->name = gfc_get_string ("%s", sym->name);
    7724         1030 :   dt_sym->attr.flavor = FL_DERIVED;
    7725         1030 :   dt_sym->attr.private_comp = 1;
    7726         1030 :   dt_sym->attr.zero_comp = 1;
    7727         1030 :   dt_sym->attr.use_assoc = 1;
    7728         1030 :   dt_sym->module = gfc_get_string ("%s", modname);
    7729         1030 :   dt_sym->from_intmod = module;
    7730         1030 :   dt_sym->intmod_sym_id = id;
    7731              : 
    7732         1030 :   head = sym->generic;
    7733         1030 :   intr = gfc_get_interface ();
    7734         1030 :   intr->sym = dt_sym;
    7735         1030 :   intr->where = gfc_current_locus;
    7736         1030 :   intr->next = head;
    7737         1030 :   sym->generic = intr;
    7738         1030 :   sym->attr.if_source = IFSRC_DECL;
    7739              : }
    7740              : 
    7741              : 
    7742              : /* Read the contents of the module file into a temporary buffer.  */
    7743              : 
    7744              : static void
    7745        13914 : read_module_to_tmpbuf ()
    7746              : {
    7747              :   /* We don't know the uncompressed size, so enlarge the buffer as
    7748              :      needed.  */
    7749        13914 :   int cursz = 4096;
    7750        13914 :   int rsize = cursz;
    7751        13914 :   int len = 0;
    7752              : 
    7753        13914 :   module_content = XNEWVEC (char, cursz);
    7754              : 
    7755        58454 :   while (1)
    7756              :     {
    7757        36184 :       int nread = gzread (module_fp, module_content + len, rsize);
    7758        36184 :       len += nread;
    7759        36184 :       if (nread < rsize)
    7760              :         break;
    7761        22270 :       cursz *= 2;
    7762        22270 :       module_content = XRESIZEVEC (char, module_content, cursz);
    7763        22270 :       rsize = cursz - len;
    7764        22270 :     }
    7765              : 
    7766        13914 :   module_content = XRESIZEVEC (char, module_content, len + 1);
    7767        13914 :   module_content[len] = '\0';
    7768              : 
    7769        13914 :   module_pos = 0;
    7770        13914 : }
    7771              : 
    7772              : 
    7773              : /* USE the ISO_FORTRAN_ENV intrinsic module.  */
    7774              : 
    7775              : static void
    7776          638 : use_iso_fortran_env_module (void)
    7777              : {
    7778          638 :   static char mod[] = "iso_fortran_env";
    7779          638 :   gfc_use_rename *u;
    7780          638 :   gfc_symbol *mod_sym;
    7781          638 :   gfc_symtree *mod_symtree;
    7782          638 :   gfc_expr *expr;
    7783          638 :   int i, j;
    7784              : 
    7785          638 :   intmod_sym symbol[] = {
    7786              : #define NAMED_INTCST(a,b,c,d) { a, b, 0, d },
    7787              : #define NAMED_UINTCST(a,b,c,d) { a, b, 0, d },
    7788              : #define NAMED_KINDARRAY(a,b,c,d) { a, b, 0, d },
    7789              : #define NAMED_DERIVED_TYPE(a,b,c,d) { a, b, 0, d },
    7790              : #define NAMED_FUNCTION(a,b,c,d) { a, b, c, d },
    7791              : #define NAMED_SUBROUTINE(a,b,c,d) { a, b, c, d },
    7792              : #include "iso-fortran-env.def"
    7793              :     { ISOFORTRANENV_INVALID, NULL, -1234, 0 } };
    7794              : 
    7795              :   /* We could have used c in the NAMED_{,U}INTCST macros
    7796              :      instead of 0, but then current g++ expands the initialization
    7797              :      as clearing the whole object followed by explicit stores of
    7798              :      all the non-zero elements (over 150), while by using 0s for
    7799              :      the non-constant initializers and initializing them afterwards
    7800              :      g++ will often copy everything from .rodata and then only override
    7801              :      over 30 non-constant ones.  */
    7802          638 :   i = 0;
    7803              : #define NAMED_INTCST(a,b,c,d) symbol[i++].value = c;
    7804              : #define NAMED_UINTCST(a,b,c,d) symbol[i++].value = c;
    7805              : #define NAMED_KINDARRAY(a,b,c,d) i++;
    7806              : #define NAMED_DERIVED_TYPE(a,b,c,d) i++;
    7807              : #define NAMED_FUNCTION(a,b,c,d) i++;
    7808              : #define NAMED_SUBROUTINE(a,b,c,d) i++;
    7809              : #include "iso-fortran-env.def"
    7810          638 :   gcc_checking_assert (i == (int) ARRAY_SIZE (symbol) - 1);
    7811              : 
    7812              :   /* Generate the symbol for the module itself.  */
    7813          638 :   mod_symtree = gfc_find_symtree (gfc_current_ns->sym_root, mod);
    7814          638 :   if (mod_symtree == NULL)
    7815              :     {
    7816          637 :       gfc_get_sym_tree (mod, gfc_current_ns, &mod_symtree, false);
    7817          637 :       gcc_assert (mod_symtree);
    7818          637 :       mod_sym = mod_symtree->n.sym;
    7819              : 
    7820          637 :       mod_sym->attr.flavor = FL_MODULE;
    7821          637 :       mod_sym->attr.intrinsic = 1;
    7822          637 :       mod_sym->module = gfc_get_string ("%s", mod);
    7823          637 :       mod_sym->from_intmod = INTMOD_ISO_FORTRAN_ENV;
    7824              :     }
    7825              :   else
    7826            1 :     if (!mod_symtree->n.sym->attr.intrinsic)
    7827            1 :       gfc_error ("Use of intrinsic module %qs at %C conflicts with "
    7828              :                  "non-intrinsic module name used previously", mod);
    7829              : 
    7830              :   /* Generate the symbols for the module integer named constants.  */
    7831              : 
    7832        28710 :   for (i = 0; symbol[i].name; i++)
    7833              :     {
    7834        28072 :       bool found = false;
    7835        52316 :       for (u = gfc_rename_list; u; u = u->next)
    7836              :         {
    7837        24244 :           if (strcmp (symbol[i].name, u->use_name) == 0)
    7838              :             {
    7839          551 :               found = true;
    7840          551 :               u->found = 1;
    7841              : 
    7842          551 :               if (!gfc_notify_std (symbol[i].standard, "The symbol %qs, "
    7843              :                                    "referenced at %L, is not in the selected "
    7844              :                                    "standard", symbol[i].name, &u->where))
    7845           11 :                 continue;
    7846              : 
    7847          540 :               if ((flag_default_integer || flag_default_real_8)
    7848            2 :                   && symbol[i].id == ISOFORTRANENV_NUMERIC_STORAGE_SIZE)
    7849            0 :                 gfc_warning_now (0, "Use of the NUMERIC_STORAGE_SIZE named "
    7850              :                                  "constant from intrinsic module "
    7851              :                                  "ISO_FORTRAN_ENV at %L is incompatible with "
    7852              :                                  "option %qs", &u->where,
    7853              :                                  flag_default_integer
    7854              :                                    ? "-fdefault-integer-8"
    7855              :                                    : "-fdefault-real-8");
    7856          540 :               switch (symbol[i].id)
    7857              :                 {
    7858              : #define NAMED_INTCST(a,b,c,d) \
    7859              :                 case a:
    7860              : #include "iso-fortran-env.def"
    7861          335 :                   create_int_parameter (u->local_name[0] ? u->local_name
    7862              :                                                          : u->use_name,
    7863              :                                         symbol[i].value, mod,
    7864              :                                         INTMOD_ISO_FORTRAN_ENV, symbol[i].id);
    7865          335 :                   break;
    7866              : 
    7867              : #define NAMED_UINTCST(a,b,c,d) \
    7868              :                 case a:
    7869              : #include "iso-fortran-env.def"
    7870           30 :                   create_int_parameter (u->local_name[0] ? u->local_name
    7871              :                                                          : u->use_name,
    7872              :                                         symbol[i].value, mod,
    7873              :                                         INTMOD_ISO_FORTRAN_ENV, symbol[i].id);
    7874           30 :                   break;
    7875              : 
    7876              : #define NAMED_KINDARRAY(a,b,KINDS,d) \
    7877              :                 case a:\
    7878              :                   expr = gfc_get_array_expr (BT_INTEGER, \
    7879              :                                              gfc_default_integer_kind,\
    7880              :                                              NULL); \
    7881              :                   for (j = 0; KINDS[j].kind != 0; j++) \
    7882              :                     gfc_constructor_append_expr (&expr->value.constructor, \
    7883              :                         gfc_get_int_expr (gfc_default_integer_kind, NULL, \
    7884              :                                           KINDS[j].kind), NULL); \
    7885              :                   create_int_parameter_array (u->local_name[0] ? u->local_name \
    7886              :                                                          : u->use_name, \
    7887              :                                               j, expr, mod, \
    7888              :                                               INTMOD_ISO_FORTRAN_ENV, \
    7889              :                                               symbol[i].id); \
    7890              :                   break;
    7891              : #include "iso-fortran-env.def"
    7892              : 
    7893              : #define NAMED_DERIVED_TYPE(a,b,TYPE,STD) \
    7894              :                 case a:
    7895              : #include "iso-fortran-env.def"
    7896           94 :                   create_derived_type (u->local_name[0] ? u->local_name
    7897              :                                                         : u->use_name,
    7898              :                                        mod, INTMOD_ISO_FORTRAN_ENV,
    7899              :                                        symbol[i].id);
    7900           94 :                   break;
    7901              : 
    7902              : #define NAMED_FUNCTION(a,b,c,d) \
    7903              :                 case a:
    7904              : #include "iso-fortran-env.def"
    7905           15 :                   create_intrinsic_function (u->local_name[0] ? u->local_name
    7906              :                                                               : u->use_name,
    7907              :                                              symbol[i].id, mod,
    7908              :                                              INTMOD_ISO_FORTRAN_ENV, false,
    7909              :                                              NULL);
    7910           15 :                   break;
    7911              : 
    7912            0 :                 default:
    7913            0 :                   gcc_unreachable ();
    7914              :                 }
    7915              :             }
    7916              :         }
    7917              : 
    7918        28072 :       if (!found && !only_flag)
    7919              :         {
    7920        13845 :           if ((gfc_option.allow_std & symbol[i].standard) == 0)
    7921         1356 :             continue;
    7922              : 
    7923        12489 :           if ((flag_default_integer || flag_default_real_8)
    7924            0 :               && symbol[i].id == ISOFORTRANENV_NUMERIC_STORAGE_SIZE)
    7925            0 :             gfc_warning_now (0,
    7926              :                              "Use of the NUMERIC_STORAGE_SIZE named constant "
    7927              :                              "from intrinsic module ISO_FORTRAN_ENV at %C is "
    7928              :                              "incompatible with option %s",
    7929              :                              flag_default_integer
    7930              :                                 ? "-fdefault-integer-8" : "-fdefault-real-8");
    7931              : 
    7932        12489 :           switch (symbol[i].id)
    7933              :             {
    7934              : #define NAMED_INTCST(a,b,c,d) \
    7935              :             case a:
    7936              : #include "iso-fortran-env.def"
    7937         9678 :               create_int_parameter (symbol[i].name, symbol[i].value, mod,
    7938              :                                     INTMOD_ISO_FORTRAN_ENV, symbol[i].id);
    7939         9678 :               break;
    7940              : 
    7941              : #define NAMED_UINTCST(a,b,c,d)                  \
    7942              :             case a:
    7943              : #include "iso-fortran-env.def"
    7944            4 :               create_int_parameter (symbol[i].name, symbol[i].value, mod,
    7945              :                                     INTMOD_ISO_FORTRAN_ENV, symbol[i].id);
    7946            4 :               break;
    7947              : 
    7948              : #define NAMED_KINDARRAY(a,b,KINDS,d) \
    7949              :             case a:\
    7950              :               expr = gfc_get_array_expr (BT_INTEGER, gfc_default_integer_kind, \
    7951              :                                          NULL); \
    7952              :               for (j = 0; KINDS[j].kind != 0; j++) \
    7953              :                 gfc_constructor_append_expr (&expr->value.constructor, \
    7954              :                       gfc_get_int_expr (gfc_default_integer_kind, NULL, \
    7955              :                                         KINDS[j].kind), NULL); \
    7956              :             create_int_parameter_array (symbol[i].name, j, expr, mod, \
    7957              :                                         INTMOD_ISO_FORTRAN_ENV, symbol[i].id);\
    7958              :             break;
    7959              : #include "iso-fortran-env.def"
    7960              : 
    7961              : #define NAMED_DERIVED_TYPE(a,b,TYPE,STD) \
    7962              :           case a:
    7963              : #include "iso-fortran-env.def"
    7964          936 :             create_derived_type (symbol[i].name, mod, INTMOD_ISO_FORTRAN_ENV,
    7965              :                                  symbol[i].id);
    7966          936 :             break;
    7967              : 
    7968              : #define NAMED_FUNCTION(a,b,c,d) \
    7969              :           case a:
    7970              : #include "iso-fortran-env.def"
    7971          623 :             create_intrinsic_function (symbol[i].name, symbol[i].id, mod,
    7972              :                                        INTMOD_ISO_FORTRAN_ENV, false, NULL);
    7973          623 :             break;
    7974              : 
    7975            0 :           default:
    7976            0 :             gcc_unreachable ();
    7977              :           }
    7978              :         }
    7979              :     }
    7980              : 
    7981         1189 :   for (u = gfc_rename_list; u; u = u->next)
    7982              :     {
    7983          551 :       if (u->found)
    7984          551 :         continue;
    7985              : 
    7986            0 :       gfc_error ("Symbol %qs referenced at %L not found in intrinsic "
    7987            0 :                      "module ISO_FORTRAN_ENV", u->use_name, &u->where);
    7988              :     }
    7989          638 : }
    7990              : 
    7991              : 
    7992              : /* Process a USE directive.  */
    7993              : 
    7994              : static void
    7995        24491 : gfc_use_module (gfc_use_list *module)
    7996              : {
    7997        24491 :   char *filename;
    7998        24491 :   gfc_state_data *p;
    7999        24491 :   int c, line, start;
    8000        24491 :   gfc_symtree *mod_symtree;
    8001        24491 :   gfc_use_list *use_stmt;
    8002        24491 :   locus old_locus = gfc_current_locus;
    8003              : 
    8004        24491 :   gfc_current_locus = module->where;
    8005        24491 :   module_name = module->module_name;
    8006        24491 :   gfc_rename_list = module->rename;
    8007        24491 :   only_flag = module->only_flag;
    8008        24491 :   current_intmod = INTMOD_NONE;
    8009              : 
    8010        24491 :   if (!only_flag && gfc_state_stack->state != COMP_SUBMODULE)
    8011        15368 :     gfc_warning_now (OPT_Wuse_without_only,
    8012              :                      "USE statement at %C has no ONLY qualifier");
    8013              : 
    8014        24491 :   if (gfc_state_stack->state == COMP_MODULE
    8015        21890 :       || module->submodule_name == NULL)
    8016              :     {
    8017        24226 :       filename = XALLOCAVEC (char, strlen (module_name)
    8018              :                                    + strlen (MODULE_EXTENSION) + 1);
    8019        24226 :       strcpy (filename, module_name);
    8020        24226 :       strcat (filename, MODULE_EXTENSION);
    8021              :     }
    8022              :   else
    8023              :     {
    8024          265 :       filename = XALLOCAVEC (char, strlen (module->submodule_name)
    8025              :                                    + strlen (SUBMODULE_EXTENSION) + 1);
    8026          265 :       strcpy (filename, module->submodule_name);
    8027          265 :       strcat (filename, SUBMODULE_EXTENSION);
    8028              :     }
    8029              : 
    8030              :   /* First, try to find an non-intrinsic module, unless the USE statement
    8031              :      specified that the module is intrinsic.  */
    8032        24491 :   module_fp = NULL;
    8033        24491 :   if (!module->intrinsic)
    8034        20564 :     module_fp = gzopen_included_file (filename, true, true);
    8035              : 
    8036              :   /* Then, see if it's an intrinsic one, unless the USE statement
    8037              :      specified that the module is non-intrinsic.  */
    8038        24491 :   if (module_fp == NULL && !module->non_intrinsic)
    8039              :     {
    8040        11811 :       if (strcmp (module_name, "iso_fortran_env") == 0
    8041        11811 :           && gfc_notify_std (GFC_STD_F2003, "ISO_FORTRAN_ENV "
    8042              :                              "intrinsic module at %C"))
    8043              :        {
    8044          638 :          use_iso_fortran_env_module ();
    8045          638 :          free_rename (module->rename);
    8046          638 :          module->rename = NULL;
    8047          638 :          gfc_current_locus = old_locus;
    8048          638 :          module->intrinsic = true;
    8049        10572 :          return;
    8050              :        }
    8051              : 
    8052        11173 :       if (strcmp (module_name, "iso_c_binding") == 0
    8053        11173 :           && gfc_notify_std (GFC_STD_F2003, "ISO_C_BINDING module at %C"))
    8054              :         {
    8055         9934 :           import_iso_c_binding_module();
    8056         9934 :           free_rename (module->rename);
    8057         9934 :           module->rename = NULL;
    8058         9934 :           gfc_current_locus = old_locus;
    8059         9934 :           module->intrinsic = true;
    8060         9934 :           return;
    8061              :         }
    8062              : 
    8063         1239 :       module_fp = gzopen_intrinsic_module (filename);
    8064              : 
    8065         1239 :       if (module_fp == NULL && module->intrinsic)
    8066            0 :         gfc_fatal_error ("Cannot find an intrinsic module named %qs at %C",
    8067              :                          module_name);
    8068              : 
    8069              :       /* Check for the IEEE modules, so we can mark their symbols
    8070              :          accordingly when we read them.  */
    8071         1239 :       if (strcmp (module_name, "ieee_features") == 0
    8072         1239 :           && gfc_notify_std (GFC_STD_F2003, "IEEE_FEATURES module at %C"))
    8073              :         {
    8074           52 :           current_intmod = INTMOD_IEEE_FEATURES;
    8075              :         }
    8076         1187 :       else if (strcmp (module_name, "ieee_exceptions") == 0
    8077         1187 :                && gfc_notify_std (GFC_STD_F2003,
    8078              :                                   "IEEE_EXCEPTIONS module at %C"))
    8079              :         {
    8080           60 :           current_intmod = INTMOD_IEEE_EXCEPTIONS;
    8081              :         }
    8082         1127 :       else if (strcmp (module_name, "ieee_arithmetic") == 0
    8083         1127 :                && gfc_notify_std (GFC_STD_F2003,
    8084              :                                   "IEEE_ARITHMETIC module at %C"))
    8085              :         {
    8086          405 :           current_intmod = INTMOD_IEEE_ARITHMETIC;
    8087              :         }
    8088              :     }
    8089              : 
    8090        13919 :   if (module_fp == NULL)
    8091              :     {
    8092            5 :       if (gfc_state_stack->state != COMP_SUBMODULE
    8093            4 :           && module->submodule_name == NULL)
    8094            4 :         gfc_fatal_error ("Cannot open module file %qs for reading at %C: %s",
    8095            4 :                          filename, xstrerror (errno));
    8096              :       else
    8097            1 :         gfc_fatal_error ("Module file %qs has not been generated, either "
    8098              :                          "because the module does not contain a MODULE "
    8099              :                          "PROCEDURE or there is an error in the module.",
    8100              :                          filename);
    8101              :     }
    8102              : 
    8103              :   /* Check that we haven't already USEd an intrinsic module with the
    8104              :      same name.  */
    8105              : 
    8106        13914 :   mod_symtree = gfc_find_symtree (gfc_current_ns->sym_root, module_name);
    8107        13914 :   if (mod_symtree && mod_symtree->n.sym->attr.intrinsic)
    8108            1 :     gfc_error ("Use of non-intrinsic module %qs at %C conflicts with "
    8109              :                "intrinsic module name used previously", module_name);
    8110              : 
    8111        13914 :   iomode = IO_INPUT;
    8112        13914 :   module_line = 1;
    8113        13914 :   module_column = 1;
    8114        13914 :   start = 0;
    8115              : 
    8116        13914 :   read_module_to_tmpbuf ();
    8117        13914 :   gzclose (module_fp);
    8118              : 
    8119              :   /* Skip the first line of the module, after checking that this is
    8120              :      a gfortran module file.  */
    8121        13914 :   line = 0;
    8122       514088 :   while (line < 1)
    8123              :     {
    8124       486260 :       c = module_char ();
    8125       486260 :       if (c == EOF)
    8126            0 :         bad_module ("Unexpected end of module");
    8127       486260 :       if (start++ < 3)
    8128        41742 :         parse_name (c);
    8129       486260 :       if ((start == 1 && strcmp (atom_name, "GFORTRAN") != 0)
    8130       486260 :           || (start == 2 && strcmp (atom_name, " module") != 0))
    8131            0 :         gfc_fatal_error ("File %qs opened at %C is not a GNU Fortran"
    8132              :                          " module file", module_fullpath);
    8133       486260 :       if (start == 3)
    8134              :         {
    8135        13914 :           bool fatal = false;
    8136        13914 :           if (strcmp (atom_name, " version") != 0
    8137        13914 :               || module_char () != ' '
    8138        27828 :               || parse_atom () != ATOM_STRING)
    8139              :             fatal = true;
    8140        13914 :           else if (strcmp (atom_string, MOD_VERSION))
    8141              :             {
    8142              :               static const char *compat_mod_versions[] = COMPAT_MOD_VERSIONS;
    8143            0 :               fatal = true;
    8144            0 :               for (unsigned i = 0; i < ARRAY_SIZE (compat_mod_versions); ++i)
    8145            0 :                 if (!strcmp (atom_string, compat_mod_versions[i]))
    8146              :                   {
    8147              :                     fatal = false;
    8148              :                     break;
    8149              :                   }
    8150              :             }
    8151            0 :           if (fatal)
    8152            0 :             gfc_fatal_error ("Cannot read module file %qs opened at %C,"
    8153              :                              " because it was created by a different"
    8154              :                              " version of GNU Fortran", module_fullpath);
    8155              : 
    8156        13914 :           free (atom_string);
    8157              :         }
    8158              : 
    8159       486260 :       if (c == '\n')
    8160        13914 :         line++;
    8161              :     }
    8162              : 
    8163              :   /* Make sure we're not reading the same module that we may be building.  */
    8164        46839 :   for (p = gfc_state_stack; p; p = p->previous)
    8165        32925 :     if ((p->state == COMP_MODULE || p->state == COMP_SUBMODULE)
    8166         2385 :          && strcmp (p->sym->name, module_name) == 0)
    8167              :       {
    8168            0 :         if (p->state == COMP_SUBMODULE)
    8169            0 :           gfc_fatal_error ("Cannot USE a submodule that is currently built");
    8170              :         else
    8171            0 :           gfc_fatal_error ("Cannot USE a module that is currently built");
    8172              :       }
    8173              : 
    8174        13914 :   init_pi_tree ();
    8175        13914 :   init_true_name_tree ();
    8176              : 
    8177        13914 :   read_module ();
    8178              : 
    8179        13914 :   free_true_name (true_name_root);
    8180        13914 :   true_name_root = NULL;
    8181              : 
    8182        13914 :   free_pi_tree (pi_root);
    8183        13914 :   pi_root = NULL;
    8184              : 
    8185        13914 :   XDELETEVEC (module_content);
    8186        13914 :   module_content = NULL;
    8187              : 
    8188        13914 :   use_stmt = gfc_get_use_list ();
    8189        13914 :   *use_stmt = *module;
    8190        13914 :   use_stmt->next = gfc_current_ns->use_stmts;
    8191        13914 :   gfc_current_ns->use_stmts = use_stmt;
    8192              : 
    8193        13914 :   gfc_current_locus = old_locus;
    8194              : }
    8195              : 
    8196              : 
    8197              : /* Remove duplicated intrinsic operators from the rename list.  */
    8198              : 
    8199              : static void
    8200        24491 : rename_list_remove_duplicate (gfc_use_rename *list)
    8201              : {
    8202        24491 :   gfc_use_rename *seek, *last;
    8203              : 
    8204        38348 :   for (; list; list = list->next)
    8205        13857 :     if (list->op != INTRINSIC_USER && list->op != INTRINSIC_NONE)
    8206              :       {
    8207          113 :         last = list;
    8208          459 :         for (seek = list->next; seek; seek = last->next)
    8209              :           {
    8210          346 :             if (list->op == seek->op)
    8211              :               {
    8212            2 :                 last->next = seek->next;
    8213            2 :                 free (seek);
    8214              :               }
    8215              :             else
    8216              :               last = seek;
    8217              :           }
    8218              :       }
    8219        24491 : }
    8220              : 
    8221              : 
    8222              : /* Process all USE directives.  */
    8223              : 
    8224              : void
    8225        21315 : gfc_use_modules (void)
    8226              : {
    8227        21315 :   gfc_use_list *next, *seek, *last;
    8228              : 
    8229        45806 :   for (next = module_list; next; next = next->next)
    8230              :     {
    8231        24491 :       bool non_intrinsic = next->non_intrinsic;
    8232        24491 :       bool intrinsic = next->intrinsic;
    8233        24491 :       bool neither = !non_intrinsic && !intrinsic;
    8234              : 
    8235        28491 :       for (seek = next->next; seek; seek = seek->next)
    8236              :         {
    8237         4000 :           if (next->module_name != seek->module_name)
    8238         3801 :             continue;
    8239              : 
    8240          199 :           if (seek->non_intrinsic)
    8241              :             non_intrinsic = true;
    8242          198 :           else if (seek->intrinsic)
    8243              :             intrinsic = true;
    8244              :           else
    8245          158 :             neither = true;
    8246              :         }
    8247              : 
    8248        24491 :       if (intrinsic && neither && !non_intrinsic)
    8249              :         {
    8250            1 :           char *filename;
    8251            1 :           FILE *fp;
    8252              : 
    8253            1 :           filename = XALLOCAVEC (char,
    8254              :                                  strlen (next->module_name)
    8255              :                                  + strlen (MODULE_EXTENSION) + 1);
    8256            1 :           strcpy (filename, next->module_name);
    8257            1 :           strcat (filename, MODULE_EXTENSION);
    8258            1 :           fp = gfc_open_included_file (filename, true, true);
    8259            1 :           if (fp != NULL)
    8260              :             {
    8261            0 :               non_intrinsic = true;
    8262            0 :               fclose (fp);
    8263              :             }
    8264              :         }
    8265              : 
    8266        24491 :       last = next;
    8267        28491 :       for (seek = next->next; seek; seek = last->next)
    8268              :         {
    8269         4000 :           if (next->module_name != seek->module_name)
    8270              :             {
    8271         3801 :               last = seek;
    8272         3801 :               continue;
    8273              :             }
    8274              : 
    8275          199 :           if ((!next->intrinsic && !seek->intrinsic)
    8276           41 :               || (next->intrinsic && seek->intrinsic)
    8277            3 :               || !non_intrinsic)
    8278              :             {
    8279          197 :               if (!seek->only_flag)
    8280           18 :                 next->only_flag = false;
    8281          197 :               if (seek->rename)
    8282              :                 {
    8283              :                   gfc_use_rename *r = seek->rename;
    8284          406 :                   while (r->next)
    8285              :                     r = r->next;
    8286          192 :                   r->next = next->rename;
    8287          192 :                   next->rename = seek->rename;
    8288              :                 }
    8289          197 :               last->next = seek->next;
    8290          197 :               free (seek);
    8291          197 :             }
    8292              :           else
    8293              :             last = seek;
    8294              :         }
    8295              :     }
    8296              : 
    8297        45801 :   for (; module_list; module_list = next)
    8298              :     {
    8299        24491 :       next = module_list->next;
    8300        24491 :       rename_list_remove_duplicate (module_list->rename);
    8301        24491 :       gfc_use_module (module_list);
    8302        24486 :       free (module_list);
    8303              :     }
    8304        21310 :   module_list = NULL;
    8305        21310 :   old_module_list_tail = &module_list;
    8306        21310 :   gfc_rename_list = NULL;
    8307        21310 : }
    8308              : 
    8309              : 
    8310              : void
    8311      9774193 : gfc_free_use_stmts (gfc_use_list *use_stmts)
    8312              : {
    8313      9774193 :   gfc_use_list *next;
    8314      9788111 :   for (; use_stmts; use_stmts = next)
    8315              :     {
    8316              :       gfc_use_rename *next_rename;
    8317              : 
    8318        17028 :       for (; use_stmts->rename; use_stmts->rename = next_rename)
    8319              :         {
    8320         3110 :           next_rename = use_stmts->rename->next;
    8321         3110 :           free (use_stmts->rename);
    8322              :         }
    8323        13918 :       next = use_stmts->next;
    8324        13918 :       free (use_stmts);
    8325              :     }
    8326      9774193 : }
    8327              : 
    8328              : 
    8329              : /* Remember the end of the MODULE_LIST list, so that the list can be restored
    8330              :    to its previous state if the current statement is erroneous.  */
    8331              : 
    8332              : void
    8333      1475061 : gfc_save_module_list ()
    8334              : {
    8335      1475061 :   gfc_use_list **tail = &module_list;
    8336      1505664 :   while (*tail != NULL)
    8337        30603 :     tail = &(*tail)->next;
    8338      1475061 :   old_module_list_tail = tail;
    8339      1475061 : }
    8340              : 
    8341              : 
    8342              : /* Restore the MODULE_LIST list to its previous value and free the use
    8343              :    statements that are no longer part of the list.  */
    8344              : 
    8345              : void
    8346      9226998 : gfc_restore_old_module_list ()
    8347              : {
    8348      9226998 :   gfc_free_use_stmts (*old_module_list_tail);
    8349      9226998 :   *old_module_list_tail = NULL;
    8350      9226998 : }
    8351              : 
    8352              : 
    8353              : void
    8354        82638 : gfc_module_init_2 (void)
    8355              : {
    8356        82638 :   last_atom = ATOM_LPAREN;
    8357        82638 :   gfc_rename_list = NULL;
    8358        82638 :   module_list = NULL;
    8359        82638 : }
    8360              : 
    8361              : 
    8362              : void
    8363        83000 : gfc_module_done_2 (void)
    8364              : {
    8365        83000 :   free_rename (gfc_rename_list);
    8366        83000 :   gfc_rename_list = NULL;
    8367        83000 : }
        

Generated by: LCOV version 2.4-beta

LCOV profile is generated on x86_64 machine using following configure options: configure --disable-bootstrap --enable-coverage=opt --enable-languages=c,c++,fortran,go,jit,lto,rust,m2 --enable-host-shared. GCC test suite is run with the built compiler.