ada/4945: Rewriting '-gant' as '-gnat' is failing

Matthew Woodcraft mjw@chiark.greenend.org.uk
Thu Nov 15 12:43:00 GMT 2001


>Number:         4945
>Category:       ada
>Synopsis:       Rewriting '-gant' as '-gnat' is failing
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sun Nov 25 10:06:00 PST 2001
>Closed-Date:
>Last-Modified:
>Originator:     Matthew Woodcraft
>Release:        3.1 20011124 (experimental)
>Organization:
>Environment:
System: Linux golux 2.2.18 #1 Wed Jan 3 21:42:52 GMT 2001 i686 unknown
Architecture: i686
host: i686-pc-linux-gnu
build: i686-pc-linux-gnu
target: i686-pc-linux-gnu
configured with: /home/mjw/src/gcc/gcc-cvs/configure --prefix=/home/mjw/src/gcc/install --enable-languages=c,ada --enable-checking=no
>Description:
The Ada front end detects -gnat<...> switches which have been mistyped
as -gant<...> . This support is apparently broken in the current
sources:

% touch hello.adb      
% gnatmake -gnaty hello
gcc -c -gnaty hello.adb
hello.adb:3:02: (style) bad indentation
gnatbind -x hello.ali
gnatlink hello.ali

% touch hello.adb      
% gnatmake -ganty hello
gcc -c -ganty hello.adb
gnat1: warning: `-gnat' misspelled as `-gant'
gnatbind -x hello.ali
gnatlink -ganty hello.ali
gnat1: warning: `-gnat' misspelled as `-gant'

A warning is issued, but the switch is ignored. In previous versions
of Gnat, the warning was issued and switch was processed as if it had
been typed correctly. I presume that this is still the intended
behaviour, as otherwise the warning ought to be an error.

>How-To-Repeat:
>Fix:

I think this needs to be handled in switch.adb. The following change
works for me:

*** switch.adb	2001/10/02 14:52:00	1.1
--- switch.adb	2001/11/25 17:11:26
***************
*** 86,92 ****
            (Switch_Chars (Ptr + 1) = 'I'
               or else
            (Switch_Chars'Length >= 5
!                          and then Switch_Chars (Ptr + 1 .. Ptr + 4) = "gnat"));
     end Is_Front_End_Switch;
  
     ---------------
--- 86,95 ----
            (Switch_Chars (Ptr + 1) = 'I'
               or else
            (Switch_Chars'Length >= 5
!                          and then
!                            (Switch_Chars (Ptr + 1 .. Ptr + 4) = "gnat"
!                               or else
!                             Switch_Chars (Ptr + 1 .. Ptr + 4) = "gant")));
     end Is_Front_End_Switch;
  
     ---------------
***************
*** 462,472 ****
           Ptr := Ptr + 1;
        end if;
  
!       --  A little check, "gnat" at the start of a switch is not allowed
!       --  except for the compiler (where it was already removed)
  
        Switch_Starts_With_Gnat :=
!          Ptr + 3 <= Max and then Switch_Chars (Ptr .. Ptr + 3) = "gnat";
  
        if Switch_Starts_With_Gnat then
           Ptr := Ptr + 4;
--- 465,478 ----
           Ptr := Ptr + 1;
        end if;
  
!       --  A little check, "gnat" at the start of a switch is allowed
!       --  for the compiler
  
        Switch_Starts_With_Gnat :=
!          Ptr + 3 <= Max
!            and then (Switch_Chars (Ptr .. Ptr + 3) = "gnat"
!                       or else
!                      Switch_Chars (Ptr .. Ptr + 3) = "gant");
  
        if Switch_Starts_With_Gnat then
           Ptr := Ptr + 4;
***************
*** 1142,1148 ****
        end if;
  
        --  A little check, "gnat" at the start of a switch is not allowed
!       --  except for the compiler (where it was already removed)
  
        if Switch_Chars'Length >= Ptr + 3
          and then Switch_Chars (Ptr .. Ptr + 3) = "gnat"
--- 1148,1154 ----
        end if;
  
        --  A little check, "gnat" at the start of a switch is not allowed
!       --  except for the compiler
  
        if Switch_Chars'Length >= Ptr + 3
          and then Switch_Chars (Ptr .. Ptr + 3) = "gnat"



The code which generates the warning, in misc.c, also seems to be
wrong:

static int
gnat_decode_option (argc, argv)
     int argc ATTRIBUTE_UNUSED;
     char **argv;
{
  char *p = argv[0];
  int i;

  if (!strncmp (p, "-I", 2))
    {
      /* Pass the -I switches as-is. */
      gnat_argv[gnat_argc] = p;
      gnat_argc ++;
      return 1;
    }

  else if (!strncmp (p, "-gant", 5))
    {
      char *q = (char *) xmalloc (strlen (p) + 1);

      warning ("`-gnat' misspelled as `-gant'");
      strcpy (q, p);
      q[2] = 'n', q[3] = 'a';
      p = q;
      return 1;
    }

  else if (!strncmp (p, "-gnat", 5))
    {
      /* Recopy the switches without the 'gnat' prefix */

      gnat_argv[gnat_argc] =  (char *) xmalloc (strlen (p) - 3);
      gnat_argv[gnat_argc][0] = '-';
      strcpy (gnat_argv[gnat_argc] + 1, p + 5);
      gnat_argc ++;
      if (p[5] == 'O')
	for (i = 1; i < save_argc - 1; i++) 
	  if (!strncmp (save_argv[i], "-gnatO", 6))
	    if (save_argv[++i][0] != '-')
	      {
		/* Preserve output filename as GCC doesn't save it for GNAT. */
		gnat_argv[gnat_argc] = save_argv[i];
		gnat_argc++;
		break;
	      }

      return 1;
    }

  /* Ignore -W flags since people may want to use the same flags for all
     languages.  */
  else if (p[0] == '-' && p[1] == 'W' && p[2] != 0)
    return 1;

  return 0;
}

The check for "-gant" surely can't be behaving as intended - it
rewrites the option and then throws away the pointer to the memory it
just allocated.

I think most of the code in this function is now unnecessary, as
Scan_Compiler_Arguments reads the arguments directly from save_argv,
and doesn't use gnat_argv at all. The right thing is probably for
gnat_decode_option to return 1 for a front-end option it recognises
and do nothing else. The warning could be handled in
Scan_Front_End_Switches instead.

>Release-Note:
>Audit-Trail:
>Unformatted:



More information about the Gcc-bugs mailing list