public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* Re: preprocessor/7988: POSIX broken in gcc
@ 2002-10-04 11:56 Neil Booth
  0 siblings, 0 replies; 4+ messages in thread
From: Neil Booth @ 2002-10-04 11:56 UTC (permalink / raw)
  To: nobody; +Cc: gcc-prs

The following reply was made to PR target/7988; it has been noted by GNATS.

From: Neil Booth <neil@daikokuya.co.uk>
To: gcc-gnats@gcc.gnu.org
Cc:  
Subject: Re: preprocessor/7988: POSIX broken in gcc
Date: Fri, 4 Oct 2002 19:47:19 +0100

 ----- Forwarded message from cs720 Administrator <cs720@cisunix.unh.edu> -----
 
 Subject: Re: preprocessor/7988: POSIX broken in gcc
 From: cs720 Administrator <cs720@cisunix.unh.edu>
 To: Neil Booth <neil@daikokuya.co.uk>
 Date: Fri, 4 Oct 2002 11:00:26 -0400 (EDT)
 
 
 Neil:
 
 I have some further information that should help to narrow
 the search for the cause of this bug.
 The problem seems to appear only when the stat() function
 is called with its second parameter, of type struct stat,
 allocated locally, on the stack, as in the first attachment
 above.  If it is allocated globally, as in the second attachment,
 or is allocated dynamically, using malloc(), as in the third
 attachment, everything works fine.
 
 I hope this extra information helps locate the bug.
 If nothing else, it may help to to categorize it better.
 To me it now looks like it may be a code generator problem.
 
 Thanks,
 Bob Russell
 
 
 On Fri, 20 Sep 2002, Neil Booth wrote:
 
 > cs720 Administrator wrote:-
 >
 > > Neil:
 > >
 > > I wasn't sure how to categorize it --
 > > _POSIX_C_SOURCE is a preprocessor symbol and it
 > > is used to select header files, define other symbols
 > > and structures, etc.  Defining it selects one set
 > > of headers, etc. while not defining it selects
 > > another set.  Perhaps the error is in the
 > > organization of the header files themselves,
 > > and the use of _POSIX_C_SOURCE within those header files.
 > > I doubt it is in the preprocessor itself, but
 > > what other category would be better?
 >
 > Um, I'll re-assign it to target.
 >
 > Neil.
 >
 
 /*	ftype.c	- program to demonstrate POSIX stat() and file-type macros */
 
 #define _POSIX_C_SOURCE	199506L
 
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
 #include <sys/stat.h>
 
 int main( int argc, char *argv[] )
 	{
 	int				i;
 	char			*ptr;
 	struct stat		statbuf;
 
 	if( argc < 2 )
 		{
 		fprintf(stderr, "Usage: ftype file1 [file2 ...]\n");
 		exit(EXIT_FAILURE);
 		}
 
 	for( i = 1;  i < argc;  i++ )
 		{
 		if( stat(argv[i], &statbuf) < 0 )
 			perror(argv[i]);
 		else
 			{
 				if( S_ISREG(statbuf.st_mode) )	ptr ="regular file";
 			else if( S_ISDIR(statbuf.st_mode) )	ptr ="directory";
 			else if( S_ISCHR(statbuf.st_mode) )	ptr ="character special file";
 			else if( S_ISBLK(statbuf.st_mode) )	ptr ="block special file";
 			else if( S_ISFIFO(statbuf.st_mode))	ptr ="FIFO file";
 			else								ptr ="UNKNOWN FILE TYPE";
 			printf("%s: %s\n", argv[i], ptr);
 			}
 		}
 
 	return EXIT_SUCCESS;
 	}
 
 /*	ftype.c	- program to demonstrate POSIX stat() and file-type macros */
 
 #define _POSIX_C_SOURCE	199506L
 
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
 #include <sys/stat.h>
 
 struct stat		statbuf;
 
 int main( int argc, char *argv[] )
 	{
 	int				i;
 	char			*ptr;
 
 	if( argc < 2 )
 		{
 		fprintf(stderr, "Usage: ftype file1 [file2 ...]\n");
 		exit(EXIT_FAILURE);
 		}
 
 	for( i = 1;  i < argc;  i++ )
 		{
 		if( stat(argv[i], &statbuf) < 0 )
 			perror(argv[i]);
 		else
 			{
 				if( S_ISREG(statbuf.st_mode) )	ptr ="regular file";
 			else if( S_ISDIR(statbuf.st_mode) )	ptr ="directory";
 			else if( S_ISCHR(statbuf.st_mode) )	ptr ="character special file";
 			else if( S_ISBLK(statbuf.st_mode) )	ptr ="block special file";
 			else if( S_ISFIFO(statbuf.st_mode))	ptr ="FIFO file";
 			else								ptr ="UNKNOWN FILE TYPE";
 			printf("%s: %s\n", argv[i], ptr);
 			}
 		}
 
 	return EXIT_SUCCESS;
 	}
 
 /*	ftype.c	- program to demonstrate POSIX stat() and file-type macros */
 
 #define _POSIX_C_SOURCE	199506L
 
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
 #include <sys/stat.h>
 
 int main( int argc, char *argv[] )
 	{
 	int				i;
 	char			*ptr;
 	struct stat		*statbuf;
 
 	if( argc < 2 )
 		{
 		fprintf(stderr, "Usage: ftype file1 [file2 ...]\n");
 		exit(EXIT_FAILURE);
 		}
 
 	if( (statbuf = malloc(sizeof(struct stat))) == NULL )
 		{
 		fprintf(stderr, "No space for stat buffer\n");
 		exit(EXIT_FAILURE);
 		}
 
 	for( i = 1;  i < argc;  i++ )
 		{
 		if( stat(argv[i], statbuf) < 0 )
 			perror(argv[i]);
 		else
 			{
 				if( S_ISREG(statbuf->st_mode) )	ptr ="regular file";
 			else if(S_ISDIR(statbuf->st_mode) )	ptr ="directory";
 			else if(S_ISCHR(statbuf->st_mode) )	ptr ="character special file";
 			else if(S_ISBLK(statbuf->st_mode) )	ptr ="block special file";
 			else if(S_ISFIFO(statbuf->st_mode))	ptr ="FIFO file";
 			else								ptr ="UNKNOWN FILE TYPE";
 			printf("%s: %s\n", argv[i], ptr);
 			}
 		}
 
 	return EXIT_SUCCESS;
 	}
 
 
 ----- End forwarded message -----


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

* Re: preprocessor/7988: POSIX broken in gcc
@ 2002-09-20 12:06 cs720 Administrator
  0 siblings, 0 replies; 4+ messages in thread
From: cs720 Administrator @ 2002-09-20 12:06 UTC (permalink / raw)
  To: nobody; +Cc: gcc-prs

The following reply was made to PR target/7988; it has been noted by GNATS.

From: cs720 Administrator <cs720@cisunix.unh.edu>
To: Neil Booth <neil@daikokuya.co.uk>
Cc: cs720@unh.edu, <gcc-gnats@gcc.gnu.org>, <rdr@unh.edu>, <pas@unh.edu>
Subject: Re: preprocessor/7988: POSIX broken in gcc
Date: Fri, 20 Sep 2002 15:00:20 -0400 (EDT)

 Neil:
 
 I wasn't sure how to categorize it --
 _POSIX_C_SOURCE is a preprocessor symbol and it
 is used to select header files, define other symbols
 and structures, etc.  Defining it selects one set
 of headers, etc. while not defining it selects
 another set.  Perhaps the error is in the
 organization of the header files themselves,
 and the use of _POSIX_C_SOURCE within those header files.
 I doubt it is in the preprocessor itself, but
 what other category would be better?
 
 Thanks,
 Bob Russell
 
 
 On Fri, 20 Sep 2002, Neil Booth wrote:
 
 > cs720@unh.edu wrote:-
 >
 > > >Number:         7988
 > > >Category:       preprocessor
 > > >Synopsis:       Programs defining _POSIX_C_SOURCE compile but won't run
 >
 > So this has nothing to do with the preprocessor then?
 >
 > Neil.
 >
 


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

* Re: preprocessor/7988: POSIX broken in gcc
@ 2002-09-20 10:26 Neil Booth
  0 siblings, 0 replies; 4+ messages in thread
From: Neil Booth @ 2002-09-20 10:26 UTC (permalink / raw)
  To: nobody; +Cc: gcc-prs

The following reply was made to PR preprocessor/7988; it has been noted by GNATS.

From: Neil Booth <neil@daikokuya.co.uk>
To: cs720@unh.edu
Cc: gcc-gnats@gcc.gnu.org, rdr@unh.edu, pas@unh.edu
Subject: Re: preprocessor/7988: POSIX broken in gcc
Date: Fri, 20 Sep 2002 18:17:06 +0100

 cs720@unh.edu wrote:-
 
 > >Number:         7988
 > >Category:       preprocessor
 > >Synopsis:       Programs defining _POSIX_C_SOURCE compile but won't run
 
 So this has nothing to do with the preprocessor then?
 
 Neil.


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

* preprocessor/7988: POSIX broken in gcc
@ 2002-09-20  8:06 cs720
  0 siblings, 0 replies; 4+ messages in thread
From: cs720 @ 2002-09-20  8:06 UTC (permalink / raw)
  To: gcc-gnats; +Cc: rdr, pas


>Number:         7988
>Category:       preprocessor
>Synopsis:       Programs defining _POSIX_C_SOURCE compile but won't run
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          wrong-code
>Submitter-Id:   net
>Arrival-Date:   Fri Sep 20 08:06:01 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator:     cs720 Administrator
>Release:        3.2
>Organization:
University of New Hampshire
>Environment:
System: OSF1 hypatia.unh.edu V5.1 1885 alpha
Machine: alpha
	
host: alphaev56-dec-osf5.1
build: alphaev56-dec-osf5.1
target: alphaev56-dec-osf5.1
configured with: ../gcc-3.2/configure 
>Description:
	Many of my programs contain the line
	#define _POSIX_C_SOURCE 199506L
	before all #include lines.
	These used to work (over 1 year ago).
	Now they compile but give Segmentation faults or wrong answers when run.

>How-To-Repeat:
	Attached below is a sample program called ftype.c
	If I compile it with "gcc ftype.c"
	and then run it with "a.out /dev/tty"
	it gives me a segmentation fault.
	If I compile it with "gcc -O ftype.c"
	and then run it with "a.out /dev/tty"
	it produces the output "/dev/tty: UNKNOWN FILE TYPE"
	which is the wrong answer.
	If I delete the line defining _POSIX_C_SOURCE
	and compile it with "gcc ftype.c" or "gcc -O ftype.c"
	and then run it with "a.out /dev/tty"
	it procudes the output "/dev/ttyp: character special file"
	which is the correct answer.
/***********************************************************************/
/*	ftype.c	- program to demonstrate POSIX stat() and file-type macros */

#define _POSIX_C_SOURCE	199506L

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/stat.h>

int main( int argc, char *argv[] )
	{
	int				i;
	char			*ptr;
	struct stat		statbuf;

	if( argc < 2 )
		{
		fprintf(stderr, "Usage: ftype file1 [file2 ...]\n");
		exit(EXIT_FAILURE);
		}

	for( i = 1;  i < argc;  i++ )
		{
		if( stat(argv[i], &statbuf) < 0 )
			perror(argv[i]);
		else
			{
				if( S_ISREG(statbuf.st_mode) )	ptr ="regular file";
			else if( S_ISDIR(statbuf.st_mode) )	ptr ="directory";
			else if( S_ISCHR(statbuf.st_mode) )	ptr ="character special file";
			else if( S_ISBLK(statbuf.st_mode) )	ptr ="block special file";
			else if( S_ISFIFO(statbuf.st_mode))	ptr ="FIFO file";
			else								ptr ="UNKNOWN FILE TYPE";
			printf("%s: %s\n", argv[i], ptr);
			}
		}

	return EXIT_SUCCESS;
	}
/***********************************************************************/

>Fix:
	Just delete the line defining _POSIX_C_SOURCE.
	However, this worked in previous versions of gcc on OSF systems,
	and continues to work in current versions of gcc on Linux and
	Solaris systems.

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


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

end of thread, other threads:[~2002-10-04 18:56 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-10-04 11:56 preprocessor/7988: POSIX broken in gcc Neil Booth
  -- strict thread matches above, loose matches on Subject: below --
2002-09-20 12:06 cs720 Administrator
2002-09-20 10:26 Neil Booth
2002-09-20  8:06 cs720

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).