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

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

 



On Wed, Nov 21, 2018 at 11:44:06PM +0100, Antonio Ospite wrote:
> On Wed, 21 Nov 2018 22:27:16 +0100
> Luc Van Oostenryck <luc.vanoostenryck@xxxxxxxxx> wrote:
> 
> > Currently cgcc only process file given as stdin or if their
> > name end with '.c'. Other files are explicitly ignored.
> > 
> > This generally correspond 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.
> > 
> > Reported-by: Antonio Ospite <ao2@xxxxxx>
> > Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@xxxxxxxxx>
> > ---
> >  cgcc | 8 ++++++++
> >  1 file changed, 8 insertions(+)
> > 
> > diff --git a/cgcc b/cgcc
> > index 7611dc9ff..188197369 100755
> > --- a/cgcc
> > +++ b/cgcc
> > @@ -25,6 +25,14 @@ while (@ARGV) {
> >      # Ditto for stdin.
> >      $do_check = 1 if $_ eq '-';
> >  
> > +    # accept any file type input language is specified with '-x c'
> > +    if ($_ eq '-x') {
> > +	my $lang = shift(@ARGV);
> > +	die ("$0: missing argument for -x") if !$lang;
> > +	$do_check = 1 if $lang eq 'c';
> > +	next;
> > +    }
> > +
> 
> Hi Luc,
> 
> this improves things a bit, but there is another issue with -E.
> 
> If "-o file" is passed and only $do_check is enabled sparse will
> ignore the -o option and the preprocessed output will go to the stdout
> and not in the specified file, as would be expected by a normal gcc
> invocation.

Yes, I know. Sparse always ignored the '-o option' but I added a patch
for it yesterday.

> So the question is: does it make sense to run sparse on files which
> are only preprocessed?

It really does make sense. The biggest reason is because you want
to have coherent results between the output of '-E' and sparse's
pre-processing at checking time (for example, if the code contains
#ifdef __CHECKER__).

I can also imagine cases where it make less sense, for example
because '-E' need to produce an output and sparse (when simply
used as a checker) doesn't, like in your case here.

> Or can -E be treated in the same way as -M is
> handled?

The -M is handled so because sparse doesn't have the support for it
so its delegated to $(CC).

> I really don't know as I don't work a lot with sparse, I am just a
> casual user.
> 
> I was thinking about something like:
> 
> diff --git a/cgcc b/cgcc
> index 7611dc9..3a00819 100755
> --- a/cgcc
> +++ b/cgcc
> @@ -9,6 +9,7 @@ my $m32 = 0;
>  my $m64 = 0;
>  my $has_specs = 0;
>  my $gendeps = 0;
> +my $preprocess = 0;
>  my $do_check = 0;
>  my $do_compile = 1;
>  my $gcc_base_dir;
> @@ -28,6 +29,7 @@ while (@ARGV) {
>      $m32 = 1 if /^-m32$/;
>      $m64 = 1 if /^-m64$/;
>      $gendeps = 1 if /^-M$/;
> +    $preprocess = 1 if /^-E$/;
> 
>      if (/^-target=(.*)$/) {
>         $check .= &add_specs ($1);
> @@ -52,9 +54,6 @@ while (@ARGV) {
>          next;
>      }
> 
> -    # If someone adds "-E", don't pre-process twice.
> -    $do_compile = 0 if $_ eq '-E';
> -
>      $verbose = 1 if $_ eq '-v';
> 
>      my $this_arg = ' ' . &quote_arg ($_);
> @@ -62,7 +61,7 @@ while (@ARGV) {
>      $check .= $this_arg;
>  }
> 
> -if ($gendeps) {
> +if ($gendeps || $preprocess) {
>      $do_compile = 1;
>      $do_check = 0;
>  }
> 
> 
> If this is acceptable I can send a proper patch.

If fact, I like it because it uses a more 'positive logic'
but it would change the current behaviour. So, if the patch
with '-o' works for you, I would prefer to leave it as is
for now.

Thanks,
-- 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