LCOV - code coverage report
Current view: top level - gcc/rust - rustspec.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 82.8 % 64 53
Test Date: 2024-03-23 14:05:01 Functions: 100.0 % 2 2
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: - 0 0

             Branch data     Line data    Source code
       1                 :             : /* rustspec.c -- Specific flags and argument handling of the gcc Rust front end.
       2                 :             :    Copyright (C) 2009-2024 Free Software Foundation, Inc.
       3                 :             : 
       4                 :             : This file is part of GCC.
       5                 :             : 
       6                 :             : GCC is free software; you can redistribute it and/or modify it under
       7                 :             : the terms of the GNU General Public License as published by the Free
       8                 :             : Software Foundation; either version 3, or (at your option) any later
       9                 :             : version.
      10                 :             : 
      11                 :             : GCC is distributed in the hope that it will be useful, but WITHOUT ANY
      12                 :             : WARRANTY; without even the implied warranty of MERCHANTABILITY or
      13                 :             : FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
      14                 :             : for more details.
      15                 :             : 
      16                 :             : You should have received a copy of the GNU General Public License
      17                 :             : along with GCC; see the file COPYING3.  If not see
      18                 :             : <http://www.gnu.org/licenses/>.  */
      19                 :             : 
      20                 :             : #include "config.h"
      21                 :             : #include "system.h"
      22                 :             : #include "coretypes.h"
      23                 :             : #include "tm.h"
      24                 :             : #include "opts.h"
      25                 :             : 
      26                 :             : // satisfy intellisense
      27                 :             : #include "options.h"
      28                 :             : 
      29                 :             : /* This bit is set if we saw a `-xfoo' language specification.  */
      30                 :             : #define LANGSPEC (1 << 1)
      31                 :             : /* This bit is set if they did `-lc'.  */
      32                 :             : #define WITHLIBC (1 << 2)
      33                 :             : /* Skip this option.  */
      34                 :             : #define SKIPOPT (1 << 3)
      35                 :             : 
      36                 :             : void
      37                 :        4275 : lang_specific_driver (struct cl_decoded_option **in_decoded_options,
      38                 :             :                       unsigned int *in_decoded_options_count,
      39                 :             :                       int *in_added_libraries)
      40                 :             : {
      41                 :        4275 :   unsigned int i, j;
      42                 :             : 
      43                 :             :   /* The new argument list will be contained in this.  */
      44                 :        4275 :   struct cl_decoded_option *new_decoded_options;
      45                 :             : 
      46                 :             :   /* "-lc" if it appears on the command line.  */
      47                 :        4275 :   const struct cl_decoded_option *saw_libc = 0;
      48                 :             : 
      49                 :             :   /* An array used to flag each argument that needs a bit set for
      50                 :             :      LANGSPEC or WITHLIBC.  */
      51                 :        4275 :   int *args;
      52                 :             : 
      53                 :             :   /* True if we saw -static.  */
      54                 :        4275 :   int static_link = 0;
      55                 :             : 
      56                 :             :   /* True if we should add -shared-libgcc to the command-line.  */
      57                 :        4275 :   int shared_libgcc = 1;
      58                 :             : 
      59                 :             :   /* The total number of arguments with the new stuff.  */
      60                 :        4275 :   unsigned int argc;
      61                 :             : 
      62                 :             :   /* The argument list.  */
      63                 :        4275 :   struct cl_decoded_option *decoded_options;
      64                 :             : 
      65                 :             :   /* The number of libraries added in.  */
      66                 :        4275 :   int added_libraries;
      67                 :             : 
      68                 :             :   /* The total number of arguments with the new stuff.  */
      69                 :        4275 :   int num_args = 1;
      70                 :             : 
      71                 :             :   /* Whether the -o option was used.  */
      72                 :        4275 :   bool saw_opt_o = false;
      73                 :             : 
      74                 :             :   /* The first input file with an extension of .rs.  */
      75                 :        4275 :   const char *first_rust_file = NULL;
      76                 :             : 
      77                 :        4275 :   argc = *in_decoded_options_count;
      78                 :        4275 :   decoded_options = *in_decoded_options;
      79                 :        4275 :   added_libraries = *in_added_libraries;
      80                 :             : 
      81                 :        4275 :   args = XCNEWVEC (int, argc);
      82                 :             : 
      83                 :       65896 :   for (i = 1; i < argc; i++)
      84                 :             :     {
      85                 :       61621 :       const char *arg = decoded_options[i].arg;
      86                 :             : 
      87                 :       61621 :       switch (decoded_options[i].opt_index)
      88                 :             :         {
      89                 :        1143 :         case OPT_l:
      90                 :        1143 :           if (strcmp (arg, "c") == 0)
      91                 :           0 :             args[i] |= WITHLIBC;
      92                 :             :           break;
      93                 :             : 
      94                 :             :         case OPT_o:
      95                 :       61621 :           saw_opt_o = true;
      96                 :             :           break;
      97                 :             : 
      98                 :           0 :         case OPT_static:
      99                 :           0 :           static_link = 1;
     100                 :           0 :           break;
     101                 :             : 
     102                 :           0 :         case OPT_static_libgcc:
     103                 :           0 :           shared_libgcc = 0;
     104                 :           0 :           break;
     105                 :             : 
     106                 :        4275 :         case OPT_SPECIAL_input_file:
     107                 :        4275 :           if (first_rust_file == NULL)
     108                 :             :             {
     109                 :        4275 :               int len;
     110                 :             : 
     111                 :        4275 :               len = strlen (arg);
     112                 :        4275 :               if (len > 3 && strcmp (arg + len - 3, ".rs") == 0)
     113                 :        3696 :                 first_rust_file = arg;
     114                 :             :             }
     115                 :             :           else
     116                 :             :             {
     117                 :             :               // FIXME: ARTHUR: Do we want to error here? If there's already one
     118                 :             :               // file?
     119                 :             :               // How do we error here? Do we want to instead just handle that in
     120                 :             :               // the session manager?
     121                 :             :             }
     122                 :             : 
     123                 :             :           break;
     124                 :             :         }
     125                 :             :     }
     126                 :             : 
     127                 :             :     /* There's no point adding -shared-libgcc if we don't have a shared
     128                 :             :        libgcc.  */
     129                 :             : #ifndef ENABLE_SHARED_LIBGCC
     130                 :             :   shared_libgcc = 0;
     131                 :             : #endif
     132                 :             : 
     133                 :             :   /* Make sure to have room for the trailing NULL argument.  */
     134                 :        4275 :   num_args = argc + shared_libgcc * 5 + 10;
     135                 :        4275 :   new_decoded_options = XNEWVEC (struct cl_decoded_option, num_args);
     136                 :             : 
     137                 :        4275 :   i = 0;
     138                 :        4275 :   j = 0;
     139                 :             : 
     140                 :             :   /* Copy the 0th argument, i.e., the name of the program itself.  */
     141                 :        4275 :   new_decoded_options[j++] = decoded_options[i++];
     142                 :             : 
     143                 :             :   /* NOTE: We start at 1 now, not 0.  */
     144                 :       65896 :   while (i < argc)
     145                 :             :     {
     146                 :       61621 :       new_decoded_options[j] = decoded_options[i];
     147                 :             : 
     148                 :       61621 :       if (!saw_libc && (args[i] & WITHLIBC))
     149                 :             :         {
     150                 :           0 :           --j;
     151                 :           0 :           saw_libc = &decoded_options[i];
     152                 :             :         }
     153                 :             : 
     154                 :       61621 :       if ((args[i] & SKIPOPT) != 0)
     155                 :           0 :         --j;
     156                 :             : 
     157                 :       61621 :       i++;
     158                 :       61621 :       j++;
     159                 :             :     }
     160                 :             : 
     161                 :             :   /* If we didn't see a -o option, add one.  This is because we need
     162                 :             :      the driver to pass all .rs files to crab1.  Without a -o option the
     163                 :             :      driver will invoke crab1 separately for each input file.  FIXME:
     164                 :             :      This should probably use some other interface to force the driver
     165                 :             :      to set combine_inputs.  */
     166                 :        4275 :   if (!saw_opt_o)
     167                 :             :     {
     168                 :         183 :       generate_option (OPT_o, "a.out", 1, CL_DRIVER, &new_decoded_options[j]);
     169                 :         183 :       j++;
     170                 :             :     }
     171                 :             : 
     172                 :        4275 :   if (saw_libc)
     173                 :           0 :     new_decoded_options[j++] = *saw_libc;
     174                 :        4275 :   if (shared_libgcc && !static_link)
     175                 :        4275 :     generate_option (OPT_shared_libgcc, NULL, 1, CL_DRIVER,
     176                 :        4275 :                      &new_decoded_options[j++]);
     177                 :             : 
     178                 :        4275 :   *in_decoded_options_count = j;
     179                 :        4275 :   *in_decoded_options = new_decoded_options;
     180                 :        4275 :   *in_added_libraries = added_libraries;
     181                 :        4275 : }
     182                 :             : 
     183                 :             : /* Called before linking.  Returns 0 on success and -1 on failure.  */
     184                 :             : int
     185                 :        3876 : lang_specific_pre_link (void) /* Not used for Rust.  */
     186                 :             : {
     187                 :        3876 :   return 0;
     188                 :             : }
     189                 :             : 
     190                 :             : /* Number of extra output files that lang_specific_pre_link may generate.  */
     191                 :             : int lang_specific_extra_outfiles = 0; /* Not used for Rust.  */
        

Generated by: LCOV version 2.0-1

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.