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

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

 



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.

So the question is: does it make sense to run sparse on files which
are only preprocessed? Or can -E be treated in the same way as -M is
handled?

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.

Thank you,
   Antonio

-- 
Antonio Ospite
https://ao2.it
https://twitter.com/ao2it

A: Because it messes up the order in which people normally read text.
   See http://en.wikipedia.org/wiki/Posting_style
Q: Why is top-posting such a bad thing?



[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