🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.gcc.bug
Article #1229

Inefficiency in once-only include files in cpp

#1229
From: Kevin Dalley
Date: Tue, 29 Sep 1992 02:12
116 lines
3553 bytes
I'm using the version of gcc that has been distributed for use with
Interviews, gcc.xtar.Z, though this problem probably appears in the
standard release gcc-2.2.2.  I configured gcc with "./configure
mips-sgi-irix4".  It's running on an SGI 4D/35 running Irix 4.0.1.


cpp in gcc-2.2.2 is supposed to efficiently handle multiple includes of header
files that are wrapped with conditionals like this:

     #ifndef __FILE_FOO_SEEN__
     #define __FILE_FOO_SEEN__
     
     THE ENTIRE FILE
     
     #endif /* __FILE_FOO_SEEN__ */

as long the "#ifndef" is at the beginning.  The preprocessor
successfully skips over many types of white space and comments, but
some white space is not skipped over.  I apoligize for the form feeds,
but it's part of the bug, so here goes.  I hope it's readable.

Here two files, ethel.c and
fred.h that show the inefficiency with the cpp.

ethel.c:
#include "fred.h"
#include "fred.h"

**************************************************
fred.h:

#ifndef FRED_H__
#define FRED_H__
#endif /* FRED_H__ */
**************************************************

where ^L is a form-feed.
fred.h should only be included once, but in fact it is included twice.
I ran cpp as "cpp -v ethel.c" and received the following output:
GNU CPP version 2.2.2 [AL 1.1, MM 24] Silicon Graphics Mips
# 1 "ethel.c"
# 1 "fred.h" 1




# 1 "ethel.c" 2

# 1 "fred.h" 1




# 2 "ethel.c" 2

**************************************************
If I remove the '^L' from fred.h I receive this output:
GNU CPP version 2.2.2 [AL 1.1, MM 24] Silicon Graphics Mips
# 1 "ethel.c"
# 1 "fred.h" 1




# 1 "ethel.c" 2


**************************************************
which seems more reasonable and in line with the once-only include philosophy.
I tentatively identify the problem as being in do_xifdef in cccp.c in
the following section of code:

  /* Detect a #ifndef at start of file (not counting comments).  */
  if (ip->fname != 0 && keyword->type == T_IFNDEF) {
    U_CHAR *p = ip->buf;
    while (p != directive_start) {
      char c = *p++;
      switch (c) {
      case ' ':
      case '\t':
      case '\n':
	break;
      case '/':
	if (p != ip->bufp && *p == '*') {
	  /* Skip this comment.  */
	  int junk;
	  U_CHAR *save_bufp = ip->bufp;
	  ip->bufp = p + 1;
	  p = skip_to_end_of_comment (ip, &junk, 1);
	  ip->bufp = save_bufp;
	}
	break;
      default:
	goto fail;
      }
    }
    /* If we get here, this conditional is the beginning of the file.  */
    start_of_file = 1;
  fail: ;
  }
**************************************************

The only forms of white space that are skipped are ' ', '\t', and
'\n'.  As soon as it hits the form feed, it goes to default, which
goes to fail.  It may make more sense to put a SKIP_ALL_WHITE_SPACE
(or something similar) in here somewhere, since any form of white
space should be able to precede the "#ifndef".





--
Kevin Dalley
Toshiba America MRI, Inc.
kevin@tamri.com
Technical Details
Message-ID: <KEVIN.92Sep28191215@polkacide.tamri.com>
Path: arc1-ca.pugleaf.net!sparky!uunet!convex!darwin.sura.net!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!tamri.com!kevin

Show Full Headers
Complete Article Headers
Newsgroups: gnu.gcc.bug
Path: arc1-ca.pugleaf.net!sparky!uunet!convex!darwin.sura.net!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!tamri.com!kevin
From: kevin@tamri.com (Kevin Dalley)
Subject: Inefficiency in once-only include files in cpp
Message-ID: <KEVIN.92Sep28191215@polkacide.tamri.com>
Sender: gnulists@ai.mit.edu
Reply-To: kevin@tamri.com
Organization: TOSHIBA America MRI, South San Francisco, CA
Distribution: gnu
Date: Tue, 29 Sep 1992 02:12:17 GMT
Approved: bug-gcc@prep.ai.mit.edu
Lines: 119