Re: [PATCH v2] cgcc: accept any file type with '-x c'

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Nov 22, 2018 at 03:43:50PM +0100, Antonio Ospite wrote:
> On Thu, 22 Nov 2018 14:13:44 +0100
> Luc Van Oostenryck <luc.vanoostenryck@xxxxxxxxx> wrote:
> 
> > Currently cgcc only processes file given as stdin or if their
>                                 ^^^^
>                                 files? -> their :)
> 
> > name end with '.c'. Other files are explicitly ignored.
> > 
> > This generally corresponds to what is wanted but GCC also accept
> > files with any extension if their type is given via the option
> > '-x <language>'. Some projects use this mechanism, for example
> > to use the C pre-processor on some files containing no code.
> > This fails when cgcc is used as wrapper around sparse + GCC.
> > 
> > Fix this by teaching sparse about the '-x c' option.
> >
> 
> Maybe mention the change about "-o", but this is all just nitpicking.
> 
> > Reported-by: Antonio Ospite <ao2@xxxxxx>
> > Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@xxxxxxxxx>
> > ---
> >  cgcc | 15 +++++++++++++++
> >  1 file changed, 15 insertions(+)
> > 
> > diff --git a/cgcc b/cgcc
> > index 7611dc9ff..c62645e5e 100755
> > --- a/cgcc
> > +++ b/cgcc
> > @@ -25,6 +25,15 @@ while (@ARGV) {
> >      # Ditto for stdin.
> >      $do_check = 1 if $_ eq '-';
> >  
> > +    # accept any file type when '-x c' is given as option.
> > +    if ($_ eq '-x') {
> > +	my $lang = shift(@ARGV);
> > +	die ("$0: missing argument for -x") if !$lang;
> > +	die ("$0: invalid argument for -x") if $lang ne 'c';
> > +	$do_check = 1;
> > +	next;
> > +    }
> > +
> >      $m32 = 1 if /^-m32$/;
> >      $m64 = 1 if /^-m64$/;
> >      $gendeps = 1 if /^-M$/;
> > @@ -52,6 +61,12 @@ while (@ARGV) {
> >          next;
> >      }
> >  
> > +    if (/^-o$/) {
> > +	$_ = shift @ARGV;
> > +	die ("$0: missing argument for -o") if !$_;
> 
> Shouldn't '-o' and its arg still need to be appended to $cc and $check?
> Otherwise they will be lost.

Yes, they should, and ideally the '-x c' should also.
 
> diff --git a/cgcc b/cgcc
> index c62645e..e588f4a 100755
> --- a/cgcc
> +++ b/cgcc
> @@ -64,6 +64,9 @@ while (@ARGV) {
>      if (/^-o$/) {
>         $_ = shift @ARGV;
>         die ("$0: missing argument for -o") if !$_;
> +       my $this_arg = ' -o ' . &quote_arg ($_);
> +       $cc .= $this_arg;
> +       $check .= $this_arg;
>         next;
>      }
> 
> Handling '-o -something' as invalid argument won't be needed as gcc
> seems to accept filenames looking like options.

Yes, they're as valid as any other filenames.

> However gcc interprets '-o -' as "output to stdout" while sparse
> apparently does not. but this is material for a different patch.

Yes (and undocumented in GCC manual).

I'll send another version tomorrow.
Thanks for the review.

-- Luc



[Index of Archives]     [Newbies FAQ]     [LKML]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Trinity Fuzzer Tool]

  Powered by Linux