Commit 0c6db544 by Neil Booth Committed by Neil Booth

cpplib.c (do_include_common): Revert to correct line number if -traditional.

	* cpplib.c (do_include_common): Revert to correct line number
	if -traditional.
	* cpptrad.c (scan_out_logical_line): Treat null directive as
	white space.  Invlidate MI optimization for non-whitespace
	text outside a directive.
testsuite:
	* gcc.dg/cpp/mi7.c, gcc.dg/cpp/mi7a.h, gcc.dg/cpp/mi7b.h,
	gcc.dg/cpp/trad/builtins.c, gcc.dg/cpp/trad/builtins.h,
	gcc.dg/cpp/trad/cmdlne-C.c, gcc.dg/cpp/trad/cmdlne-C2.c,
	gcc.dg/cpp/trad/maccom1.c, gcc.dg/cpp/trad/maccom2.c,
	gcc.dg/cpp/trad/maccom3.c, gcc.dg/cpp/trad/maccom4.c,
	gcc.dg/cpp/trad/maccom6.c, gcc.dg/cpp/trad/mi1.c,
	gcc.dg/cpp/trad/mi1c.h, gcc.dg/cpp/trad/mi1nd.h,
	gcc.dg/cpp/trad/mi1ndp.h, gcc.dg/cpp/trad/mi1x.h,
	gcc.dg/cpp/trad/mi2.c, gcc.dg/cpp/trad/mi2a.h,
	gcc.dg/cpp/trad/mi2b.h, gcc.dg/cpp/trad/mi2c.h
	gcc.dg/cpp/trad/mi3.c, gcc.dg/cpp/trad/mi3.def,
	gcc.dg/cpp/trad/mi3.h, gcc.dg/cpp/trad/mi4.c,
	gcc.dg/cpp/trad/mi5.c, gcc.dg/cpp/trad/mi6.c,
	gcc.dg/cpp/trad/mi6a.h, gcc.dg/cpp/trad/mi6b.h,
	gcc.dg/cpp/trad/mi6c.h, gcc.dg/cpp/trad/mi6d.h,
	gcc.dg/cpp/trad/mi6e.h, gcc.dg/cpp/trad/mi7.c,
	gcc.dg/cpp/trad/mi7a.h, gcc.dg/cpp/trad/mi7b.h: New tests.

From-SVN: r54978
parent d74bba04
2002-06-25 Neil Booth <neil@daikokuya.co.uk>
* cpplib.c (do_include_common): Revert to correct line number
if -traditional.
* cpptrad.c (scan_out_logical_line): Treat null directive as
white space. Invlidate MI optimization for non-whitespace
text outside a directive.
2002-06-24 Kaveh R. Ghazi <ghazi@caip.rutgers.edu>
* Makefile.in (SHELL): Set to @SHELL@.
......
......@@ -705,6 +705,9 @@ do_include_common (pfile, type)
(*pfile->cb.include) (pfile, pfile->directive_line,
pfile->directive->name, header);
/* Revert to the correct line if traditional. */
if (CPP_OPTION (pfile, traditional))
pfile->line = pfile->saved_line;
_cpp_execute_include (pfile, header, type);
}
}
......
......@@ -698,8 +698,12 @@ scan_out_logical_line (pfile, macro)
out = pfile->out.cur;
if (is_vspace (*cur))
/* Null directive ignored. */
{
/* Null directive. Ignore it and don't invalidate
the MI optimization. */
out = pfile->out.base;
continue;
}
else
{
bool do_it = false;
......@@ -733,6 +737,10 @@ scan_out_logical_line (pfile, macro)
break;
}
/* Non-whitespace disables MI optimization. */
if (!pfile->state.in_directive)
pfile->mi_valid = false;
if (lex_state == ls_none)
continue;
......
2002-06-25 Neil Booth <neil@daikokuya.co.uk>
* gcc.dg/cpp/mi7.c, gcc.dg/cpp/mi7a.h, gcc.dg/cpp/mi7b.h,
gcc.dg/cpp/trad/builtins.c, gcc.dg/cpp/trad/builtins.h,
gcc.dg/cpp/trad/cmdlne-C.c, gcc.dg/cpp/trad/cmdlne-C2.c,
gcc.dg/cpp/trad/maccom1.c, gcc.dg/cpp/trad/maccom2.c,
gcc.dg/cpp/trad/maccom3.c, gcc.dg/cpp/trad/maccom4.c,
gcc.dg/cpp/trad/maccom6.c, gcc.dg/cpp/trad/mi1.c,
gcc.dg/cpp/trad/mi1c.h, gcc.dg/cpp/trad/mi1nd.h,
gcc.dg/cpp/trad/mi1ndp.h, gcc.dg/cpp/trad/mi1x.h,
gcc.dg/cpp/trad/mi2.c, gcc.dg/cpp/trad/mi2a.h,
gcc.dg/cpp/trad/mi2b.h, gcc.dg/cpp/trad/mi2c.h
gcc.dg/cpp/trad/mi3.c, gcc.dg/cpp/trad/mi3.def,
gcc.dg/cpp/trad/mi3.h, gcc.dg/cpp/trad/mi4.c,
gcc.dg/cpp/trad/mi5.c, gcc.dg/cpp/trad/mi6.c,
gcc.dg/cpp/trad/mi6a.h, gcc.dg/cpp/trad/mi6b.h,
gcc.dg/cpp/trad/mi6c.h, gcc.dg/cpp/trad/mi6d.h,
gcc.dg/cpp/trad/mi6e.h, gcc.dg/cpp/trad/mi7.c,
gcc.dg/cpp/trad/mi7a.h, gcc.dg/cpp/trad/mi7b.h: New tests.
2002-06-24 Neil Booth <neil@daikokuya.co.uk>
* gcc.dg/cpp/trad/argcout.c, gcc.dg/cpp/trad/assembler.S,
......
/* Test "ignore redundant include" facility.
-H is used because cpp might confuse the issue by optimizing out
#line markers. This test only passes if the headers is read
twice.
The disgusting regexp in the dg-error line, when stuck into
dg.exp's compiler-output regexp, matches the correct -H output and
only the correct -H output. It has to be all on one line because
otherwise it will not be interpreted all in one unit. */
/* { dg-do preprocess }
{ dg-options "-H" }
{ dg-error "mi7a\.h\n\[^\n\]*mi7a\.h\n\[^\n\]*mi7b\.h\n\[^\n\]*mi7b\.h" "redundant include check" { target *-*-* } 0 } */
#include "mi7a.h"
#include "mi7a.h"
#include "mi7b.h"
#include "mi7b.h"
:
#ifndef GUARD1
#define GUARD1
#endif
#ifndef GUARD2
#define GUARD2
#endif
:
/* Test that builtin-macros are OK. */
/* { dg-do run } */
#include "builtins.h"
void abort (void);
char *strstr (const char *, const char *);
int strcmp (const char *, const char *);
#define LINE __LINE__
#if __LINE__ != 13
# error __LINE__ part 1 /* { dg-bogus "__LINE__" } */
#endif
#if \
__LINE__ != 18
# error __LINE__ part 2 /* { dg-bogus "__LINE__" } */
#endif
#if LINE != 22
# error __LINE__ part 3 /* { dg-bogus "__LINE__" } */
#endif
#if __INCLUDE_LEVEL != 0
# error __INCLUDE_LEVEL__ /* { dg-bogus "__INCLUDE_LEVEL__" } */
#endif
#if !defined (__TIME__)
# error __TIME__ /* { dg-bogus "__TIME__" } */
#endif
#if !defined (__DATE__)
# error __DATE__ /* { dg-bogus "__DATE__" } */
#endif
int main ()
{
/* level is defined in builtins.h. */
if (level != 1)
abort ();
if (!strstr (__FILE__, "builtins.c"))
abort ();
if (!strcmp (__BASE_FILE__, "builtins.c"))
abort ();
return 0;
}
int level = __INCLUDE_LEVEL__;
/* Copyright (C) 2000 Free Software Foundation, Inc. */
/* { dg-do preprocess } */
/* { dg-options "-C -traditional-cpp" } */
/* Test -C doesn't fail with #define. #define is the tricky case,
being the only directive that remembers its comments.
-C treats comments as tokens in their own right, so e.g. comment at
the beginning of a directive turns it into a non-directive. */
#define simple no comments
#define/**/obj_like/**/(some)/**/thing/**/
#define fun_like(/**/x/**/,/**/y/**/)/**/
/**/#define not_a_macro
#if !defined simple || !defined obj_like || !defined fun_like
#error Missed some macros with -C
#endif
#ifdef not_a_macro
#error not_a_macro is!
#endif
/* Check obj_like doesn't expect arguments, and fun_like does. */
obj_like
fun_like (foo, bar)
/* Check OK to redefine fun_like without comments in the params. */
#define fun_like(x, y)/**/
/* Check comments in macros in directives are OK. */
#define ZERO 0 /* A trailing comment. */
#if ZERO
#endif
/* Copyright (C) 2002 Free Software Foundation, Inc. */
/* { dg-do preprocess } */
/* { dg-options "-C -traditional-cpp" } */
/* Test that comments are actually written out
Neil Booth, 24 Jun 2002. */
/*
{ dg-final { if ![file exists cmdlne-C2.i] { return } } }
{ dg-final { if { [grep cmdlne-C2.i "dg-final"] != "" } { return } } }
{ dg-final { fail "cmdlne-C2.i: C comments output with -C" } }
*/
/* { dg-do preprocess } */
/* { dg-options "-CC -traditional-cpp" } */
/* This tests to make sure that comments are ignored between # and the
directive name when the -CC option is used.
Jason R. Thorpe, 6 Apr 2002 */
#/**/define def passed
def
/*
{ dg-final { if ![file exists maccom1.i] { return } } }
{ dg-final { if { [grep maccom1.i "^passed"] != "" } { return } } }
{ dg-final { fail "maccom1.c: comment between # and directive name with -CC" } }
*/
/* { dg-do preprocess } */
/* { dg-options "-CC -traditional-cpp" } */
/* This tests to make sure that comments between the #define directive
and the macro identifier are ignored (i.e. treated like whitespace)
when the -CC option is used.
Jason R. Thorpe, 6 Apr 2002 */
#define/**/def passed
def
/*
{ dg-final { if ![file exists maccom2.i] { return } } }
{ dg-final { if { [grep maccom2.i "^passed"] != "" } { return } } }
{ dg-final { fail "maccom2.c: comment between #define and identifier with -CC" } }
*/
/* { dg-do preprocess } */
/* { dg-options "-CC -traditional-cpp" } */
/* This tests to make sure that comments in the definition of a macro
parameter list are ignored when the -CC option is used.
Jason R. Thorpe, 6 Apr 2002 */
#define def(x /**/, y) passed
def(x,y)
/*
{ dg-final { if ![file exists maccom3.i] { return } } }
{ dg-final { if { [grep maccom3.i "^passed"] != "" } { return } } }
{ dg-final { fail "maccom3.c: comment in macro parameter list with -CC" } }
*/
/* { dg-do preprocess } */
/* { dg-options "-CC -traditional-cpp" } */
/* This tests to make sure the comment is saved in the macro and copied
to the output file when the macro is expanded when the -CC option is
used.
Jason R. Thorpe, 6 Apr 2002 */
#define def /* passed */
def
/*
/* The + in the regexp prevents it from matching itself. */
{ dg-final { if ![file exists maccom4.i] { return } } }
{ dg-final { if { [grep maccom4.i "p+assed"] != "" } { return } } }
{ dg-final { fail "maccom4.c: comment in macro expansion with -CC" } }
*/
/* { dg-do preprocess } */
/* { dg-options "-CC -traditional-cpp" } */
/* This tests to make sure that expressions function properly
when used with macros containing comments and the -CC option
is being used.
Jason R. Thorpe, 6 Apr 2002 */
#define ONE 1 /* one */
#define TWO 2 /* two */
#define THREE 3 /* three */
#if (ONE + TWO) != THREE
failed
#else
passed
#endif
/*
{ dg-final { if ![file exists maccom6.i] { return } } }
{ dg-final { if { [grep maccom6.i "^passed"] != "" } { return } } }
{ dg-final { fail "maccom6.c: comments in macro expressions with -CC" } }
*/
/* Test "ignore redundant include" facility.
We must test with C comments, and null directives, outside
the guard conditional; also, we test guarding with #ifndef and #if
!defined. -H is used because cpp might confuse the issue by
optimizing out #line markers. This test only passes if each of the
headers is read exactly once.
The disgusting regexp in the dg-error line, when stuck into
dg.exp's compiler-output regexp, matches the correct -H output and
only the correct -H output. It has to be all on one line because
otherwise it will not be interpreted all in one unit. */
/* { dg-do compile }
{ dg-options "-H -traditional-cpp" }
{ dg-error "mi1c\.h\n\[^\n\]*mi1nd\.h\n\[^\n\]*mi1ndp\.h\n\[^\n\]*mi1x\.h" "redundant include check" { target *-*-* } 0 } */
#include "mi1c.h"
#include "mi1c.h"
#include "mi1c.h"
#include "mi1nd.h"
#include "mi1nd.h"
#include "mi1ndp.h"
#include "mi1ndp.h"
#define MIX_H
#include "mi1x.h"
#include "mi1x.h"
int
main (void)
{
return a + c + d;
}
/* Redundant header include test with C comments at top. */
# /* And a null directive at the top. */
#ifndef CPP_MIC_H
#define CPP_MIC_H
int a;
#endif
# /* And at the end, too! */
/* And at the end too! */
/* Redundant include check with #if !defined. */
#if !defined CPP_MIND_H
#define CPP_MIND_H
int c;
#endif
#if !defined ( CPP_MINDP_H)
#define CPP_MINDP_H
/* Redundant include check with #if !defined and parentheses. */
int d;
#endif
/* This header is never to have its contents visible, but it should
still receive the optimization. */
#ifndef MIX_H
#define MIX_H
#define main wibble
#endif
/* Test for overly eager multiple include optimization.
Problem distilled from glibc 2.0.7's time.h, sys/time.h, timebits.h.
Problem noted by Tom Tromey <tromey@cygnus.com>. */
/* { dg-do compile } */
#include "mi2a.h"
#include "mi2b.h"
int main (void)
{
return x;
}
/* Test for overly eager multiple include optimization.
Problem distilled from glibc 2.0.7's time.h, sys/time.h, timebits.h.
Problem noted by Tom Tromey <tromey@cygnus.com>. */
#include "mi2c.h"
/* Test for overly eager multiple include optimization.
Problem distilled from glibc 2.0.7's time.h, sys/time.h, timebits.h.
Problem noted by Tom Tromey <tromey@cygnus.com>. */
#define need_x
#include "mi2c.h"
/* Test for overly eager multiple include optimization.
Problem distilled from glibc 2.0.7's time.h, sys/time.h, timebits.h.
Problem noted by Tom Tromey <tromey@cygnus.com>. */
#ifdef need_x
#undef need_x
#ifndef have_x
#define have_x
extern int x;
#endif
#endif
#ifndef t_h
#define t_h
extern int y;
#endif
/* Another test case for over-eager multiple include optimization.
This one distilled from glibc's setlocale.c and categories.def. */
/* { dg-do compile } */
#define X a
#include "mi3.def"
#undef X
#define X b
#include "mi3.def"
#undef X
#include "mi3.h"
#include "mi3.h" /* The second include declares variable c. */
int
main(void)
{
return a + b + c;
}
/* Another test case for over-eager multiple include optimization.
This one distilled from glibc's setlocale.c and categories.def.
The #ifdef block doesn't cover the entire file, so it must not be
taken for a reinclude guard. */
#ifndef NO_POSTLOAD
#define NO_POSTLOAD NULL
#endif
int X;
/* Another test case for over-eager multiple include optimization. */
#ifndef GUARD
#define GUARD
#elif 1 /* #elif kills optimisation */
int c;
#endif
/* Copyright (C) 2000 Free Software Foundation, Inc. */
/* { dg-do preprocess } */
/* Undefining a macro guard and re-including the file used to confuse
file caching in cppfiles.c, and attempt to open a bad fd. */
#include "mi1c.h"
#undef CPP_MIC_H
#include "mi1c.h"
/* Test "ignore redundant include" facility, with -C on.
The disgusting regexp in the dg-error line, when stuck into
dg.exp's compiler-output regexp, matches the correct -H output and
only the correct -H output. It has to be all on one line because
otherwise it will not be interpreted all in one unit. */
/* { dg-do preprocess }
{ dg-options "-H -C -traditional-cpp" }
{ dg-error "mi1c\.h" "redundant include check with -C" { target *-*-* } 0 } */
#include "mi1c.h"
#include "mi1c.h"
/* Another test case for over-eager multiple include optimization,
where the leading "#if !defined" expression is obtained partially,
or wholly, from macros. Neil Booth, 30 Sep 2001. */
/* { dg-do compile } */
/* { dg-options "" } */
/* Each include file should not be subject to MI optimisation, since
macro definitions can change. Each header increments the variable
VAR if it is defined.
The first set of inclusions gets the headers into CPP's cache, but
does nothing since VAR is not defined. The second set should each
increment VAR, since none of the initial set should have been
flagged as optimizable. */
#define EMPTYL
#define EMPTYR
#define NOT !
#define DEFINED defined (guard)
#define NOT_DEFINED ! defined (guard)
#include "mi6a.h"
#include "mi6b.h"
#include "mi6c.h"
#include "mi6d.h"
#include "mi6e.h"
/* Define the macro guard, and redefine the macros to something that
forces compilation of the conditional blocks. */
#define guard
#undef EMPTYL
#define EMPTYL 1 ||
#undef EMPTYR
#define EMPTYR || 1
#undef NOT
#define NOT
#undef DEFINED
#define DEFINED 0
#undef NOT_DEFINED
#define NOT_DEFINED 1
#define VAR five
int
main(void)
{
unsigned int five = 0;
#include "mi6a.h"
#include "mi6b.h"
#include "mi6c.h"
#include "mi6d.h"
#include "mi6e.h"
if (five != 5)
abort ();
return 0;
}
#if NOT_DEFINED
#ifdef VAR
VAR++;
#endif
#endif
#if NOT defined (guard)
#ifdef VAR
VAR++;
#endif
#endif
#if !DEFINED
#ifdef VAR
VAR++;
#endif
#endif
#if EMPTYL !defined (guard)
#ifdef VAR
VAR++;
#endif
#endif
#if !defined (guard) EMPTYR
#ifdef VAR
VAR++;
#endif
#endif
/* Test "ignore redundant include" facility.
-H is used because cpp might confuse the issue by optimizing out
#line markers. This test only passes if the headers is read
twice.
The disgusting regexp in the dg-error line, when stuck into
dg.exp's compiler-output regexp, matches the correct -H output and
only the correct -H output. It has to be all on one line because
otherwise it will not be interpreted all in one unit. */
/* { dg-do preprocess }
{ dg-options "-H -traditional-cpp" }
{ dg-error "mi7a\.h\n\[^\n\]*mi7a\.h\n\[^\n\]*mi7b\.h\n\[^\n\]*mi7b\.h" "redundant include check" { target *-*-* } 0 } */
#include "mi7a.h"
#include "mi7a.h"
#include "mi7b.h"
#include "mi7b.h"
:
#ifndef GUARD1
#define GUARD1
#endif
#ifndef GUARD2
#define GUARD2
#endif
:
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment