OSDN Git Service

* cpplib.c (do_include_common): Revert to correct line number
authorneil <neil@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 25 Jun 2002 06:00:30 +0000 (06:00 +0000)
committerneil <neil@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 25 Jun 2002 06:00:30 +0000 (06:00 +0000)
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.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@54978 138bc75d-0d04-0410-961f-82ee72b054a4

39 files changed:
gcc/ChangeLog
gcc/cpplib.c
gcc/cpptrad.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/cpp/mi7.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/cpp/mi7a.h [new file with mode: 0644]
gcc/testsuite/gcc.dg/cpp/mi7b.h [new file with mode: 0644]
gcc/testsuite/gcc.dg/cpp/trad/builtins.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/cpp/trad/builtins.h [new file with mode: 0644]
gcc/testsuite/gcc.dg/cpp/trad/cmdlne-C.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/cpp/trad/cmdlne-C2.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/cpp/trad/maccom1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/cpp/trad/maccom2.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/cpp/trad/maccom3.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/cpp/trad/maccom4.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/cpp/trad/maccom6.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/cpp/trad/mi1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/cpp/trad/mi1c.h [new file with mode: 0644]
gcc/testsuite/gcc.dg/cpp/trad/mi1nd.h [new file with mode: 0644]
gcc/testsuite/gcc.dg/cpp/trad/mi1ndp.h [new file with mode: 0644]
gcc/testsuite/gcc.dg/cpp/trad/mi1x.h [new file with mode: 0644]
gcc/testsuite/gcc.dg/cpp/trad/mi2.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/cpp/trad/mi2a.h [new file with mode: 0644]
gcc/testsuite/gcc.dg/cpp/trad/mi2b.h [new file with mode: 0644]
gcc/testsuite/gcc.dg/cpp/trad/mi2c.h [new file with mode: 0644]
gcc/testsuite/gcc.dg/cpp/trad/mi3.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/cpp/trad/mi3.def [new file with mode: 0644]
gcc/testsuite/gcc.dg/cpp/trad/mi3.h [new file with mode: 0644]
gcc/testsuite/gcc.dg/cpp/trad/mi4.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/cpp/trad/mi5.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/cpp/trad/mi6.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/cpp/trad/mi6a.h [new file with mode: 0644]
gcc/testsuite/gcc.dg/cpp/trad/mi6b.h [new file with mode: 0644]
gcc/testsuite/gcc.dg/cpp/trad/mi6c.h [new file with mode: 0644]
gcc/testsuite/gcc.dg/cpp/trad/mi6d.h [new file with mode: 0644]
gcc/testsuite/gcc.dg/cpp/trad/mi6e.h [new file with mode: 0644]
gcc/testsuite/gcc.dg/cpp/trad/mi7.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/cpp/trad/mi7a.h [new file with mode: 0644]
gcc/testsuite/gcc.dg/cpp/trad/mi7b.h [new file with mode: 0644]

index d21dd25..b54947b 100644 (file)
@@ -1,3 +1,11 @@
+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@.
index 59e2fe6..18e44ba 100644 (file)
@@ -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);
        }
     }
index 7ae8819..9bcb915 100644 (file)
@@ -698,8 +698,12 @@ scan_out_logical_line (pfile, macro)
              out = pfile->out.cur;
 
              if (is_vspace (*cur))
-               /* Null directive ignored.  */
-               out = pfile->out.base;
+               {
+                 /* 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;
 
index 32c9098..6988b9c 100644 (file)
@@ -1,3 +1,23 @@
+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,
diff --git a/gcc/testsuite/gcc.dg/cpp/mi7.c b/gcc/testsuite/gcc.dg/cpp/mi7.c
new file mode 100644 (file)
index 0000000..e54d270
--- /dev/null
@@ -0,0 +1,19 @@
+/* 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"
diff --git a/gcc/testsuite/gcc.dg/cpp/mi7a.h b/gcc/testsuite/gcc.dg/cpp/mi7a.h
new file mode 100644 (file)
index 0000000..0c701d7
--- /dev/null
@@ -0,0 +1,4 @@
+:
+#ifndef GUARD1
+#define GUARD1
+#endif
diff --git a/gcc/testsuite/gcc.dg/cpp/mi7b.h b/gcc/testsuite/gcc.dg/cpp/mi7b.h
new file mode 100644 (file)
index 0000000..1747e54
--- /dev/null
@@ -0,0 +1,4 @@
+#ifndef GUARD2
+#define GUARD2
+#endif
+:
diff --git a/gcc/testsuite/gcc.dg/cpp/trad/builtins.c b/gcc/testsuite/gcc.dg/cpp/trad/builtins.c
new file mode 100644 (file)
index 0000000..df27189
--- /dev/null
@@ -0,0 +1,52 @@
+/* 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;
+}
diff --git a/gcc/testsuite/gcc.dg/cpp/trad/builtins.h b/gcc/testsuite/gcc.dg/cpp/trad/builtins.h
new file mode 100644 (file)
index 0000000..9f2b9a0
--- /dev/null
@@ -0,0 +1 @@
+int level = __INCLUDE_LEVEL__;
diff --git a/gcc/testsuite/gcc.dg/cpp/trad/cmdlne-C.c b/gcc/testsuite/gcc.dg/cpp/trad/cmdlne-C.c
new file mode 100644 (file)
index 0000000..ff67ddb
--- /dev/null
@@ -0,0 +1,37 @@
+/* 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
diff --git a/gcc/testsuite/gcc.dg/cpp/trad/cmdlne-C2.c b/gcc/testsuite/gcc.dg/cpp/trad/cmdlne-C2.c
new file mode 100644 (file)
index 0000000..6836e9e
--- /dev/null
@@ -0,0 +1,15 @@
+/* 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"        } }
+*/
+
diff --git a/gcc/testsuite/gcc.dg/cpp/trad/maccom1.c b/gcc/testsuite/gcc.dg/cpp/trad/maccom1.c
new file mode 100644 (file)
index 0000000..da9c4a1
--- /dev/null
@@ -0,0 +1,17 @@
+/* { 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" } }
+*/
diff --git a/gcc/testsuite/gcc.dg/cpp/trad/maccom2.c b/gcc/testsuite/gcc.dg/cpp/trad/maccom2.c
new file mode 100644 (file)
index 0000000..331c9fc
--- /dev/null
@@ -0,0 +1,18 @@
+/* { 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" } }
+*/
diff --git a/gcc/testsuite/gcc.dg/cpp/trad/maccom3.c b/gcc/testsuite/gcc.dg/cpp/trad/maccom3.c
new file mode 100644 (file)
index 0000000..b3dd3ac
--- /dev/null
@@ -0,0 +1,17 @@
+/* { 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" } }
+*/
diff --git a/gcc/testsuite/gcc.dg/cpp/trad/maccom4.c b/gcc/testsuite/gcc.dg/cpp/trad/maccom4.c
new file mode 100644 (file)
index 0000000..e962d28
--- /dev/null
@@ -0,0 +1,19 @@
+/* { 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"     } }
+*/
diff --git a/gcc/testsuite/gcc.dg/cpp/trad/maccom6.c b/gcc/testsuite/gcc.dg/cpp/trad/maccom6.c
new file mode 100644 (file)
index 0000000..13f0fc5
--- /dev/null
@@ -0,0 +1,24 @@
+/* { 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"  } }
+*/
diff --git a/gcc/testsuite/gcc.dg/cpp/trad/mi1.c b/gcc/testsuite/gcc.dg/cpp/trad/mi1.c
new file mode 100644 (file)
index 0000000..deb9929
--- /dev/null
@@ -0,0 +1,36 @@
+/* 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;
+}
diff --git a/gcc/testsuite/gcc.dg/cpp/trad/mi1c.h b/gcc/testsuite/gcc.dg/cpp/trad/mi1c.h
new file mode 100644 (file)
index 0000000..2956286
--- /dev/null
@@ -0,0 +1,12 @@
+/* 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!  */
diff --git a/gcc/testsuite/gcc.dg/cpp/trad/mi1nd.h b/gcc/testsuite/gcc.dg/cpp/trad/mi1nd.h
new file mode 100644 (file)
index 0000000..c14c1a3
--- /dev/null
@@ -0,0 +1,8 @@
+/* Redundant include check with #if !defined.  */
+
+#if !defined CPP_MIND_H
+#define CPP_MIND_H
+
+int c;
+
+#endif
diff --git a/gcc/testsuite/gcc.dg/cpp/trad/mi1ndp.h b/gcc/testsuite/gcc.dg/cpp/trad/mi1ndp.h
new file mode 100644 (file)
index 0000000..b84202c
--- /dev/null
@@ -0,0 +1,7 @@
+#if !defined ( CPP_MINDP_H)
+#define CPP_MINDP_H
+
+/* Redundant include check with #if !defined and parentheses.  */
+int d;
+
+#endif
diff --git a/gcc/testsuite/gcc.dg/cpp/trad/mi1x.h b/gcc/testsuite/gcc.dg/cpp/trad/mi1x.h
new file mode 100644 (file)
index 0000000..a317cf8
--- /dev/null
@@ -0,0 +1,9 @@
+/* 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
diff --git a/gcc/testsuite/gcc.dg/cpp/trad/mi2.c b/gcc/testsuite/gcc.dg/cpp/trad/mi2.c
new file mode 100644 (file)
index 0000000..916d5a9
--- /dev/null
@@ -0,0 +1,12 @@
+/* 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;
+}
diff --git a/gcc/testsuite/gcc.dg/cpp/trad/mi2a.h b/gcc/testsuite/gcc.dg/cpp/trad/mi2a.h
new file mode 100644 (file)
index 0000000..e3f53b6
--- /dev/null
@@ -0,0 +1,5 @@
+/* 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"
diff --git a/gcc/testsuite/gcc.dg/cpp/trad/mi2b.h b/gcc/testsuite/gcc.dg/cpp/trad/mi2b.h
new file mode 100644 (file)
index 0000000..1d9a8b9
--- /dev/null
@@ -0,0 +1,6 @@
+/* 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"
diff --git a/gcc/testsuite/gcc.dg/cpp/trad/mi2c.h b/gcc/testsuite/gcc.dg/cpp/trad/mi2c.h
new file mode 100644 (file)
index 0000000..521792b
--- /dev/null
@@ -0,0 +1,15 @@
+/* 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
diff --git a/gcc/testsuite/gcc.dg/cpp/trad/mi3.c b/gcc/testsuite/gcc.dg/cpp/trad/mi3.c
new file mode 100644 (file)
index 0000000..f33fd78
--- /dev/null
@@ -0,0 +1,20 @@
+/* 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;
+}
diff --git a/gcc/testsuite/gcc.dg/cpp/trad/mi3.def b/gcc/testsuite/gcc.dg/cpp/trad/mi3.def
new file mode 100644 (file)
index 0000000..375d9c7
--- /dev/null
@@ -0,0 +1,10 @@
+/* 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;
diff --git a/gcc/testsuite/gcc.dg/cpp/trad/mi3.h b/gcc/testsuite/gcc.dg/cpp/trad/mi3.h
new file mode 100644 (file)
index 0000000..8774fcf
--- /dev/null
@@ -0,0 +1,7 @@
+/* Another test case for over-eager multiple include optimization. */
+
+#ifndef GUARD
+#define GUARD
+#elif 1                                /* #elif kills optimisation  */
+int c;
+#endif
diff --git a/gcc/testsuite/gcc.dg/cpp/trad/mi4.c b/gcc/testsuite/gcc.dg/cpp/trad/mi4.c
new file mode 100644 (file)
index 0000000..c886cc2
--- /dev/null
@@ -0,0 +1,10 @@
+/* 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"
diff --git a/gcc/testsuite/gcc.dg/cpp/trad/mi5.c b/gcc/testsuite/gcc.dg/cpp/trad/mi5.c
new file mode 100644 (file)
index 0000000..fe3c8d2
--- /dev/null
@@ -0,0 +1,13 @@
+/* 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"
diff --git a/gcc/testsuite/gcc.dg/cpp/trad/mi6.c b/gcc/testsuite/gcc.dg/cpp/trad/mi6.c
new file mode 100644 (file)
index 0000000..aa1c8ed
--- /dev/null
@@ -0,0 +1,59 @@
+/* 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;
+}
diff --git a/gcc/testsuite/gcc.dg/cpp/trad/mi6a.h b/gcc/testsuite/gcc.dg/cpp/trad/mi6a.h
new file mode 100644 (file)
index 0000000..68a2fce
--- /dev/null
@@ -0,0 +1,5 @@
+#if NOT_DEFINED
+ #ifdef VAR
+   VAR++;
+ #endif
+#endif
diff --git a/gcc/testsuite/gcc.dg/cpp/trad/mi6b.h b/gcc/testsuite/gcc.dg/cpp/trad/mi6b.h
new file mode 100644 (file)
index 0000000..d2fe8be
--- /dev/null
@@ -0,0 +1,5 @@
+#if NOT defined (guard)
+ #ifdef VAR
+   VAR++;
+ #endif
+#endif
diff --git a/gcc/testsuite/gcc.dg/cpp/trad/mi6c.h b/gcc/testsuite/gcc.dg/cpp/trad/mi6c.h
new file mode 100644 (file)
index 0000000..d19cb54
--- /dev/null
@@ -0,0 +1,5 @@
+#if !DEFINED
+ #ifdef VAR
+   VAR++;
+ #endif
+#endif
diff --git a/gcc/testsuite/gcc.dg/cpp/trad/mi6d.h b/gcc/testsuite/gcc.dg/cpp/trad/mi6d.h
new file mode 100644 (file)
index 0000000..a1eabba
--- /dev/null
@@ -0,0 +1,5 @@
+#if EMPTYL !defined (guard)
+ #ifdef VAR
+   VAR++;
+ #endif
+#endif
diff --git a/gcc/testsuite/gcc.dg/cpp/trad/mi6e.h b/gcc/testsuite/gcc.dg/cpp/trad/mi6e.h
new file mode 100644 (file)
index 0000000..26ba715
--- /dev/null
@@ -0,0 +1,5 @@
+#if !defined (guard) EMPTYR
+ #ifdef VAR
+   VAR++;
+ #endif
+#endif
diff --git a/gcc/testsuite/gcc.dg/cpp/trad/mi7.c b/gcc/testsuite/gcc.dg/cpp/trad/mi7.c
new file mode 100644 (file)
index 0000000..8a079d9
--- /dev/null
@@ -0,0 +1,19 @@
+/* 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"
diff --git a/gcc/testsuite/gcc.dg/cpp/trad/mi7a.h b/gcc/testsuite/gcc.dg/cpp/trad/mi7a.h
new file mode 100644 (file)
index 0000000..0c701d7
--- /dev/null
@@ -0,0 +1,4 @@
+:
+#ifndef GUARD1
+#define GUARD1
+#endif
diff --git a/gcc/testsuite/gcc.dg/cpp/trad/mi7b.h b/gcc/testsuite/gcc.dg/cpp/trad/mi7b.h
new file mode 100644 (file)
index 0000000..1747e54
--- /dev/null
@@ -0,0 +1,4 @@
+#ifndef GUARD2
+#define GUARD2
+#endif
+: