public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* stray warning from gcc's cpp
@ 2014-03-19 10:32 Andriy Gapon
  2014-03-28 15:19 ` Andriy Gapon
  0 siblings, 1 reply; 3+ messages in thread
From: Andriy Gapon @ 2014-03-19 10:32 UTC (permalink / raw)
  To: gcc-patches


I observe the following minor annoyance on FreeBSD systems where cpp is GCC's
cpp.  If a DTrace script has the following shebang line:
#!/usr/sbin/dtrace -Cs
then the following warning is produced when the script is run:
cc1: warning:  is shorter than expected

Some details.  dtrace(1) first forks. Then a child seeks on a file descriptor
associated with the script file, so that the shebang line is skipped (because
otherwise it would confuse cpp).  Then the child makes the file descriptor its
standard input and then it execs cpp.  cpp performs fstat(2) on its standard
input descriptor and determines that it points to a regular file.  Then it
verifies that a number of bytes it reads from the file is the same as a size of
the file.  The check makes sense if the file is opened by cpp itself, but it
does not always make sense for the stdin as described above.

The following patch seems to fix the issue, but perhaps there is a better /
smarter alternative.

--- a/libcpp/files.c
+++ b/libcpp/files.c
@@ -601,7 +601,8 @@ read_file_guts (cpp_reader *pfile, _cpp_file *file)
       return false;
     }

-  if (regular && total != size && STAT_SIZE_RELIABLE (file->st))
+  if (regular && total != size && file->fd != 0
+      && STAT_SIZE_RELIABLE (file->st))
     cpp_error (pfile, CPP_DL_WARNING,
 	       "%s is shorter than expected", file->path);


-- 
Andriy Gapon

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: stray warning from gcc's cpp
  2014-03-19 10:32 stray warning from gcc's cpp Andriy Gapon
@ 2014-03-28 15:19 ` Andriy Gapon
  2016-09-01 16:24   ` Gerald Pfeifer
  0 siblings, 1 reply; 3+ messages in thread
From: Andriy Gapon @ 2014-03-28 15:19 UTC (permalink / raw)
  To: gcc-patches

on 19/03/2014 12:03 Andriy Gapon said the following:
> 
> I observe the following minor annoyance on FreeBSD systems where cpp is GCC's
> cpp.  If a DTrace script has the following shebang line:
> #!/usr/sbin/dtrace -Cs
> then the following warning is produced when the script is run:
> cc1: warning:  is shorter than expected
> 
> Some details.  dtrace(1) first forks. Then a child seeks on a file descriptor
> associated with the script file, so that the shebang line is skipped (because
> otherwise it would confuse cpp).  Then the child makes the file descriptor its
> standard input and then it execs cpp.  cpp performs fstat(2) on its standard
> input descriptor and determines that it points to a regular file.  Then it
> verifies that a number of bytes it reads from the file is the same as a size of
> the file.  The check makes sense if the file is opened by cpp itself, but it
> does not always make sense for the stdin as described above.
> 
> The following patch seems to fix the issue, but perhaps there is a better /
> smarter alternative.

A patch that implements a different approach has been committed in FreeBSD:
https://github.com/freebsd/freebsd/commit/6ceec4444ddbc
Please consider.  Thanks!

> --- a/libcpp/files.c
> +++ b/libcpp/files.c
> @@ -601,7 +601,8 @@ read_file_guts (cpp_reader *pfile, _cpp_file *file)
>        return false;
>      }
> 
> -  if (regular && total != size && STAT_SIZE_RELIABLE (file->st))
> +  if (regular && total != size && file->fd != 0
> +      && STAT_SIZE_RELIABLE (file->st))
>      cpp_error (pfile, CPP_DL_WARNING,
>  	       "%s is shorter than expected", file->path);
> 
> 


-- 
Andriy Gapon

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: stray warning from gcc's cpp
  2014-03-28 15:19 ` Andriy Gapon
@ 2016-09-01 16:24   ` Gerald Pfeifer
  0 siblings, 0 replies; 3+ messages in thread
From: Gerald Pfeifer @ 2016-09-01 16:24 UTC (permalink / raw)
  To: gcc-patches, David Malcolm; +Cc: Andriy Gapon

Hi David,

I found this older report (including patches for two approaches
even!) that it seems did not see any response despite the nice
analysis (and the patch).

Mind having a look?

Gerald

PS: If you prefer, I can put this into Bugzilla, too.

On Fri, 28 Mar 2014, Andriy Gapon wrote:
> on 19/03/2014 12:03 Andriy Gapon said the following:
>> 
>> I observe the following minor annoyance on FreeBSD systems where cpp is GCC's
>> cpp.  If a DTrace script has the following shebang line:
>> #!/usr/sbin/dtrace -Cs
>> then the following warning is produced when the script is run:
>> cc1: warning:  is shorter than expected
>> 
>> Some details.  dtrace(1) first forks. Then a child seeks on a file 
>> descriptor associated with the script file, so that the shebang line is 
>> skipped (because otherwise it would confuse cpp).  Then the child makes 
>> the file descriptor its standard input and then it execs cpp.  cpp 
>> performs fstat(2) on its standard input descriptor and determines that 
>> it points to a regular file.  Then it verifies that a number of bytes 
>> it reads from the file is the same as a size of the file.  The check 
>> makes sense if the file is opened by cpp itself, but it does not always 
>> make sense for the stdin as described above.
>> 
>> The following patch seems to fix the issue, but perhaps there is a 
>> better / smarter alternative.
> A patch that implements a different approach has been committed in FreeBSD:
> https://github.com/freebsd/freebsd/commit/6ceec4444ddbc
> Please consider.  Thanks!
> 
>> --- a/libcpp/files.c
>> +++ b/libcpp/files.c
>> @@ -601,7 +601,8 @@ read_file_guts (cpp_reader *pfile, _cpp_file *file)
>>        return false;
>>      }
>> 
>> -  if (regular && total != size && STAT_SIZE_RELIABLE (file->st))
>> +  if (regular && total != size && file->fd != 0
>> +      && STAT_SIZE_RELIABLE (file->st))
>>      cpp_error (pfile, CPP_DL_WARNING,
>>  	       "%s is shorter than expected", file->path);

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2016-09-01 16:24 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-03-19 10:32 stray warning from gcc's cpp Andriy Gapon
2014-03-28 15:19 ` Andriy Gapon
2016-09-01 16:24   ` Gerald Pfeifer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).