]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gcc:
authorJoseph Myers <joseph@codesourcery.com>
Tue, 23 Oct 2012 14:55:55 +0000 (15:55 +0100)
committerJoseph Myers <jsm28@gcc.gnu.org>
Tue, 23 Oct 2012 14:55:55 +0000 (15:55 +0100)
* config.gcc (*-*-linux* | frv-*-*linux* | *-*-kfreebsd*-gnu |
*-*-knetbsd*-gnu | *-*-gnu* | *-*-kopensolaris*-gnu): Use
glibc-c.o in c_target_objs and cxx_target_objs.  Use t-glibc in
tmake_file.  Set target_has_targetcm.
(tilegx-*-linux*, tilepro-*-linux*): Append to c_target_objs and
cxx_target_objs rather than overriding previous value.
* config/glibc-c.c, config/t-glibc: New.
* doc/tm.texi.in (TARGET_C_PREINCLUDE): New @hook.
* doc/tm.texi: Regenerate.
* hooks.c (hook_constcharptr_void_null): New.
* hooks.h (hook_constcharptr_void_null): Declare.

gcc/c-family:
* c-common.h (pch_cpp_save_state): Declare.
* c-target.def (c_preinclude): New hook.
* c-opts.c (done_preinclude): New.
(push_command_line_include): Handle default preincluded header.
(cb_file_change): Call pch_cpp_save_state when calling
push_command_line_include.
* c-pch.c (pch_ready_to_save_cpp_state, pch_cpp_state_saved)
(pch_cpp_save_state): New.
(pch_init): Call pch_cpp_save_state conditionally, instead of
calling cpp_save_state.

gcc/testsuite:
* gcc.dg/c99-predef-1.c: New test.
* gcc.dg/cpp/cmdlne-dU-1.c, gcc.dg/cpp/cmdlne-dU-2.c,
gcc.dg/cpp/cmdlne-dU-3.c, gcc.dg/cpp/cmdlne-dU-4.c,
gcc.dg/cpp/cmdlne-dU-5.c, gcc.dg/cpp/cmdlne-dU-6.c,
gcc.dg/cpp/cmdlne-dU-7.c, gcc.dg/cpp/cmdlne-dU-8.c,
gcc.dg/cpp/cmdlne-dU-9.c, gcc.dg/cpp/cmdlne-dU-10.c,
gcc.dg/cpp/cmdlne-dU-11.c, gcc.dg/cpp/cmdlne-dU-12.c,
gcc.dg/cpp/cmdlne-dU-13.c, gcc.dg/cpp/cmdlne-dU-14.c,
gcc.dg/cpp/cmdlne-dU-15.c, gcc.dg/cpp/cmdlne-dU-16.c,
gcc.dg/cpp/cmdlne-dU-17.c, gcc.dg/cpp/cmdlne-dU-18.c,
gcc.dg/cpp/cmdlne-dU-19.c, gcc.dg/cpp/cmdlne-dU-20.c,
gcc.dg/cpp/cmdlne-dU-21.c, gcc.dg/cpp/cmdlne-dU-22.c,
gcc.dg/cpp/mi5.c, gcc.dg/cpp/multiline.c: Add -nostdinc to
dg-options.

libcpp:
* files.c (struct _cpp_file): Add implicit_preinclude.
(pch_open_file): Allow a previously opened implicitly included
file.
(_cpp_find_file): Add implicit_preinclude argument.  Free file and
do not call open_file_failed if implicit_preinclude.  Store
implicit_preinclude value.
(_cpp_stack_include, _cpp_fake_include, _cpp_compare_file_date):
Update calls to _cpp_find_file.
(_cpp_stack_include): Handle IT_DEFAULT.
(cpp_push_default_include): New.
* include/cpplib.h (cpp_push_default_include): Declare.
* init.c (cpp_read_main_file): Update call to _cpp_find_file.
* internal.h (enum include_type): Add IT_DEFAULT.
(_cpp_find_file): Update prototype.

From-SVN: r192715

44 files changed:
gcc/ChangeLog
gcc/c-family/ChangeLog
gcc/c-family/c-common.h
gcc/c-family/c-opts.c
gcc/c-family/c-pch.c
gcc/c-family/c-target.def
gcc/config.gcc
gcc/config/glibc-c.c [new file with mode: 0644]
gcc/config/t-glibc [new file with mode: 0644]
gcc/doc/tm.texi
gcc/doc/tm.texi.in
gcc/hooks.c
gcc/hooks.h
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/c99-predef-1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/cpp/cmdlne-dU-1.c
gcc/testsuite/gcc.dg/cpp/cmdlne-dU-10.c
gcc/testsuite/gcc.dg/cpp/cmdlne-dU-11.c
gcc/testsuite/gcc.dg/cpp/cmdlne-dU-12.c
gcc/testsuite/gcc.dg/cpp/cmdlne-dU-13.c
gcc/testsuite/gcc.dg/cpp/cmdlne-dU-14.c
gcc/testsuite/gcc.dg/cpp/cmdlne-dU-15.c
gcc/testsuite/gcc.dg/cpp/cmdlne-dU-16.c
gcc/testsuite/gcc.dg/cpp/cmdlne-dU-17.c
gcc/testsuite/gcc.dg/cpp/cmdlne-dU-18.c
gcc/testsuite/gcc.dg/cpp/cmdlne-dU-19.c
gcc/testsuite/gcc.dg/cpp/cmdlne-dU-2.c
gcc/testsuite/gcc.dg/cpp/cmdlne-dU-20.c
gcc/testsuite/gcc.dg/cpp/cmdlne-dU-21.c
gcc/testsuite/gcc.dg/cpp/cmdlne-dU-22.c
gcc/testsuite/gcc.dg/cpp/cmdlne-dU-3.c
gcc/testsuite/gcc.dg/cpp/cmdlne-dU-4.c
gcc/testsuite/gcc.dg/cpp/cmdlne-dU-5.c
gcc/testsuite/gcc.dg/cpp/cmdlne-dU-6.c
gcc/testsuite/gcc.dg/cpp/cmdlne-dU-7.c
gcc/testsuite/gcc.dg/cpp/cmdlne-dU-8.c
gcc/testsuite/gcc.dg/cpp/cmdlne-dU-9.c
gcc/testsuite/gcc.dg/cpp/mi5.c
gcc/testsuite/gcc.dg/cpp/multiline.c
libcpp/ChangeLog
libcpp/files.c
libcpp/include/cpplib.h
libcpp/init.c
libcpp/internal.h

index 8b530790bd8939f76a652095eba92410716e0f91..3394051215b3b2783c157741a3f759f257000f1d 100644 (file)
@@ -1,3 +1,17 @@
+2012-10-23  Joseph Myers  <joseph@codesourcery.com>
+
+       * config.gcc (*-*-linux* | frv-*-*linux* | *-*-kfreebsd*-gnu |
+       *-*-knetbsd*-gnu | *-*-gnu* | *-*-kopensolaris*-gnu): Use
+       glibc-c.o in c_target_objs and cxx_target_objs.  Use t-glibc in
+       tmake_file.  Set target_has_targetcm.
+       (tilegx-*-linux*, tilepro-*-linux*): Append to c_target_objs and
+       cxx_target_objs rather than overriding previous value.
+       * config/glibc-c.c, config/t-glibc: New.
+       * doc/tm.texi.in (TARGET_C_PREINCLUDE): New @hook.
+       * doc/tm.texi: Regenerate.
+       * hooks.c (hook_constcharptr_void_null): New.
+       * hooks.h (hook_constcharptr_void_null): Declare.
+
 2012-10-23  Eric Botcazou  <ebotcazou@adacore.com>
 
        * config/mips/linux-common.h (STACK_CHECK_STATIC_BUILTIN): Define.
index 3fb6a30ee7f61dc1aab6073ae8243115c8b69afd..cf43137f4442c797f571a571d671c83f5f83eba4 100644 (file)
@@ -1,3 +1,16 @@
+2012-10-23  Joseph Myers  <joseph@codesourcery.com>
+
+       * c-common.h (pch_cpp_save_state): Declare.
+       * c-target.def (c_preinclude): New hook.
+       * c-opts.c (done_preinclude): New.
+       (push_command_line_include): Handle default preincluded header.
+       (cb_file_change): Call pch_cpp_save_state when calling
+       push_command_line_include.
+       * c-pch.c (pch_ready_to_save_cpp_state, pch_cpp_state_saved)
+       (pch_cpp_save_state): New.
+       (pch_init): Call pch_cpp_save_state conditionally, instead of
+       calling cpp_save_state.
+
 2012-10-20  Manuel López-Ibáñez  <manu@gcc.gnu.org>
 
        PR c/53063
index 94449a5f3f35d134b045b4a72f8aad4157e40664..c78804d36e2930113c813e0cfbd168afea54fa1d 100644 (file)
@@ -1021,6 +1021,7 @@ extern tree c_build_bind_expr (location_t, tree, tree);
 
 /* In c-pch.c  */
 extern void pch_init (void);
+extern void pch_cpp_save_state (void);
 extern int c_common_valid_pch (cpp_reader *pfile, const char *name, int fd);
 extern void c_common_read_pch (cpp_reader *pfile, const char *name, int fd,
                               const char *orig);
index b1746d0079a3d489249bf1bd575becccc12d0f17..b420d2a2cc14a5d920a196ecb8896124f52f6d21 100644 (file)
@@ -108,6 +108,9 @@ static size_t deferred_count;
 /* Number of deferred options scanned for -include.  */
 static size_t include_cursor;
 
+/* Whether any standard preincluded header has been preincluded.  */
+static bool done_preinclude;
+
 static void handle_OPT_d (const char *);
 static void set_std_cxx98 (int);
 static void set_std_cxx11 (int);
@@ -1353,6 +1356,19 @@ c_finish_options (void)
 static void
 push_command_line_include (void)
 {
+  if (!done_preinclude)
+    {
+      done_preinclude = true;
+      if (flag_hosted && std_inc && !cpp_opts->preprocessed)
+       {
+         const char *preinc = targetcm.c_preinclude ();
+         if (preinc && cpp_push_default_include (parse_in, preinc))
+           return;
+       }
+    }
+
+  pch_cpp_save_state ();
+
   while (include_cursor < deferred_count)
     {
       struct deferred_opt *opt = &deferred_opts[include_cursor++];
@@ -1388,7 +1404,10 @@ cb_file_change (cpp_reader * ARG_UNUSED (pfile),
     fe_file_change (new_map);
 
   if (new_map == 0 || (new_map->reason == LC_LEAVE && MAIN_FILE_P (new_map)))
-    push_command_line_include ();
+    {
+      pch_cpp_save_state ();
+      push_command_line_include ();
+    }
 }
 
 void
index b239ed4f3434a9c9c1bb864cefd630ef55b444fd..f945f05b7e7de8b17d83db79870a480445772372 100644 (file)
@@ -93,6 +93,10 @@ get_ident (void)
   return result;
 }
 
+/* Whether preprocessor state should be saved by pch_init.  */
+
+static bool pch_ready_to_save_cpp_state = false;
+
 /* Prepare to write a PCH file, if one is being written.  This is
    called at the start of compilation.  */
 
@@ -136,7 +140,31 @@ pch_init (void)
   /* Let the debugging format deal with the PCHness.  */
   (*debug_hooks->handle_pch) (0);
 
-  cpp_save_state (parse_in, f);
+  if (pch_ready_to_save_cpp_state)
+    pch_cpp_save_state ();
+}
+
+/* Whether preprocessor state has been saved in a PCH file.  */
+
+static bool pch_cpp_state_saved = false;
+
+/* Save preprocessor state in a PCH file, after implicitly included
+   headers have been read.  If the PCH file has not yet been opened,
+   record that state should be saved when it is opened.  */
+
+void
+pch_cpp_save_state (void)
+{
+  if (!pch_cpp_state_saved)
+    {
+      if (pch_outfile)
+       {
+         cpp_save_state (parse_in, pch_outfile);
+         pch_cpp_state_saved = true;
+       }
+      else
+       pch_ready_to_save_cpp_state = true;
+    }
 }
 
 /* Write the PCH file.  This is called at the end of a compilation which
index c5ebdf14ac4445d26b7bca5220ea6415e3c09d10..c2025ab76b76970f0255ed773e4dc66b40bfeb24 100644 (file)
@@ -1,6 +1,6 @@
 /* Target hook definitions for C-family front ends.
    Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
-   2011
+   2011, 2012
    Free Software Foundation, Inc.
 
    This program is free software; you can redistribute it and/or modify it
@@ -89,5 +89,20 @@ DEFHOOK
   @var{format_arg} is one recognized as a valid string reference type.",
  void, (tree format_arg, tree args_list),
  NULL)
+
+DEFHOOK
+(c_preinclude,
+ "Define this hook to return the name of a header file to be included at\
+ the start of all compilations, as if it had been included with\
+ @code{#include <@var{file}>}.  If this hook returns @code{NULL}, or is\
+ not defined, or the header is not found, or if the user specifies\
+ @option{-ffreestanding} or @option{-nostdinc}, no header is included.\n\
+\n\
+ This hook can be used together with a header provided by the system C\
+ library to implement ISO C requirements for certain macros to be\
+ predefined that describe properties of the whole implementation rather\
+ than just the compiler.",
+ const char *, (void),
+ hook_constcharptr_void_null)
  
 HOOK_VECTOR_END (C90_EMPTY_HACK)
index 38041e637553d248c67ce03a481d03b07ddfd98e..fbbf38943a9d998fcf0688c2097b7310b5dd214a 100644 (file)
@@ -666,6 +666,10 @@ case ${target} in
       tm_defines="$tm_defines ANDROID_DEFAULT=0"
       ;;
   esac
+  c_target_objs="${c_target_objs} glibc-c.o"
+  cxx_target_objs="${cxx_target_objs} glibc-c.o"
+  tmake_file="${tmake_file} t-glibc"
+  target_has_targetcm=yes
   ;;
 *-*-netbsd*)
   tmake_file="t-slibgcc"
@@ -2472,16 +2476,16 @@ tilegx-*-linux*)
        tm_file="elfos.h gnu-user.h linux.h glibc-stdint.h tilegx/linux.h ${tm_file}"
         tmake_file="${tmake_file} tilegx/t-tilegx"
        extra_objs="mul-tables.o"
-       c_target_objs="tilegx-c.o"
-       cxx_target_objs="tilegx-c.o"
+       c_target_objs="${c_target_objs} tilegx-c.o"
+       cxx_target_objs="${cxx_target_objs} tilegx-c.o"
        extra_headers="feedback.h"
        ;;
 tilepro-*-linux*)
        tm_file="elfos.h gnu-user.h linux.h glibc-stdint.h tilepro/linux.h ${tm_file}"
         tmake_file="${tmake_file} tilepro/t-tilepro"
        extra_objs="mul-tables.o"
-       c_target_objs="tilepro-c.o"
-       cxx_target_objs="tilepro-c.o"
+       c_target_objs="${c_target_objs} tilepro-c.o"
+       cxx_target_objs="${cxx_target_objs} tilepro-c.o"
        extra_headers="feedback.h"
        ;;
 v850-*-rtems*)
diff --git a/gcc/config/glibc-c.c b/gcc/config/glibc-c.c
new file mode 100644 (file)
index 0000000..e350c6e
--- /dev/null
@@ -0,0 +1,38 @@
+/* C-family target hooks initializer for targets possibly using glibc.
+   Copyright (C) 2012
+   Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 3, or (at your option) any later
+version.
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with GCC; see the file COPYING3.  If not see
+<http://www.gnu.org/licenses/>.  */
+
+#include "config.h"
+#include "system.h"
+#include "coretypes.h"
+#include "c-family/c-target.h"
+#include "c-family/c-target-def.h"
+
+/* Implement TARGET_C_PREINCLUDE for glibc targets.  */
+
+static const char *
+glibc_c_preinclude (void)
+{
+  return "stdc-predef.h";
+}
+
+#undef TARGET_C_PREINCLUDE
+#define TARGET_C_PREINCLUDE glibc_c_preinclude
+
+struct gcc_targetcm targetcm = TARGETCM_INITIALIZER;
diff --git a/gcc/config/t-glibc b/gcc/config/t-glibc
new file mode 100644 (file)
index 0000000..c4dcc51
--- /dev/null
@@ -0,0 +1,23 @@
+# Copyright (C) 2012
+# Free Software Foundation, Inc.
+#
+# This file is part of GCC.
+#
+# GCC is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# GCC is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GCC; see the file COPYING3.  If not see
+# <http://www.gnu.org/licenses/>.
+
+glibc-c.o: config/glibc-c.c $(CONFIG_H) $(SYSTEM_H) coretypes.h \
+  $(C_TARGET_H) $(C_TARGET_DEF_H)
+       $(COMPILER) -c $(ALL_COMPILERFLAGS) $(ALL_CPPFLAGS) \
+         $< $(OUTPUT_OPTION)
index b36c764a3b5ae7e04c925562d02ec15538270ea0..72ea14cd28ed1a13ba893d86a275318c0057df4c 100644 (file)
@@ -10647,6 +10647,12 @@ convention when processing system header files, but when processing user
 files @code{__STDC__} will always expand to 1.
 @end defmac
 
+@deftypefn {C Target Hook} {const char *} TARGET_C_PREINCLUDE (void)
+Define this hook to return the name of a header file to be included at the start of all compilations, as if it had been included with @code{#include <@var{file}>}.  If this hook returns @code{NULL}, or is not defined, or the header is not found, or if the user specifies @option{-ffreestanding} or @option{-nostdinc}, no header is included.
+
+ This hook can be used together with a header provided by the system C library to implement ISO C requirements for certain macros to be predefined that describe properties of the whole implementation rather than just the compiler.
+@end deftypefn
+
 @defmac NO_IMPLICIT_EXTERN_C
 Define this macro if the system header files support C++ as well as C@.
 This macro inhibits the usual method of using system header files in
index 4858d97e27fffdbad0db2826895d46760655772d..ce31aae4b72ceb5454c2420c6712b18e34c51eae 100644 (file)
@@ -10505,6 +10505,8 @@ convention when processing system header files, but when processing user
 files @code{__STDC__} will always expand to 1.
 @end defmac
 
+@hook TARGET_C_PREINCLUDE
+
 @defmac NO_IMPLICIT_EXTERN_C
 Define this macro if the system header files support C++ as well as C@.
 This macro inhibits the usual method of using system header files in
index b26252203f7ffe34d391c6c91911fde1e6afb0df..cbb6e86f7d2488762a31c9bfd9455345c6187f1a 100644 (file)
@@ -1,5 +1,5 @@
 /* General-purpose hooks.
-   Copyright (C) 2002, 2003, 2004, 2005, 2007, 2008, 2009, 2010, 2011
+   Copyright (C) 2002, 2003, 2004, 2005, 2007, 2008, 2009, 2010, 2011, 2012
    Free Software Foundation, Inc.
 
    This program is free software; you can redistribute it and/or modify it
@@ -341,6 +341,13 @@ hook_tree_tree_tree_tree_3rd_identity (tree a ATTRIBUTE_UNUSED,
   return c;
 }
 
+/* Generic hook that takes no arguments and returns a NULL string.  */
+const char *
+hook_constcharptr_void_null (void)
+{
+  return NULL;
+}
+
 /* Generic hook that takes a tree and returns a NULL string.  */
 const char *
 hook_constcharptr_const_tree_null (const_tree t ATTRIBUTE_UNUSED)
index 71b391a1b49e665c5d41a64653e4c391d4bcd262..5c77f927502ff085cc0bc9bb3168d5dd7d757d6b 100644 (file)
@@ -1,5 +1,5 @@
 /* General-purpose hooks.
-   Copyright (C) 2002, 2003, 2004, 2005, 2007, 2008, 2009, 2010, 2011
+   Copyright (C) 2002, 2003, 2004, 2005, 2007, 2008, 2009, 2010, 2011, 2012
    Free Software Foundation, Inc.
 
    This program is free software; you can redistribute it and/or modify it
@@ -95,6 +95,7 @@ extern rtx hook_rtx_rtx_identity (rtx);
 extern rtx hook_rtx_rtx_null (rtx);
 extern rtx hook_rtx_tree_int_null (tree, int);
 
+extern const char *hook_constcharptr_void_null (void);
 extern const char *hook_constcharptr_const_tree_null (const_tree);
 extern const char *hook_constcharptr_const_rtx_null (const_rtx);
 extern const char *hook_constcharptr_const_tree_const_tree_null (const_tree, const_tree);
index 7c7ce7c0c4ae2247dd2f68265e6457e5e5156c7c..f305e7b07e566925693f6cd971188c41b401453c 100644 (file)
@@ -1,3 +1,20 @@
+2012-10-23  Joseph Myers  <joseph@codesourcery.com>
+
+       * gcc.dg/c99-predef-1.c: New test.
+       * gcc.dg/cpp/cmdlne-dU-1.c, gcc.dg/cpp/cmdlne-dU-2.c,
+       gcc.dg/cpp/cmdlne-dU-3.c, gcc.dg/cpp/cmdlne-dU-4.c,
+       gcc.dg/cpp/cmdlne-dU-5.c, gcc.dg/cpp/cmdlne-dU-6.c,
+       gcc.dg/cpp/cmdlne-dU-7.c, gcc.dg/cpp/cmdlne-dU-8.c,
+       gcc.dg/cpp/cmdlne-dU-9.c, gcc.dg/cpp/cmdlne-dU-10.c,
+       gcc.dg/cpp/cmdlne-dU-11.c, gcc.dg/cpp/cmdlne-dU-12.c,
+       gcc.dg/cpp/cmdlne-dU-13.c, gcc.dg/cpp/cmdlne-dU-14.c,
+       gcc.dg/cpp/cmdlne-dU-15.c, gcc.dg/cpp/cmdlne-dU-16.c,
+       gcc.dg/cpp/cmdlne-dU-17.c, gcc.dg/cpp/cmdlne-dU-18.c,
+       gcc.dg/cpp/cmdlne-dU-19.c, gcc.dg/cpp/cmdlne-dU-20.c,
+       gcc.dg/cpp/cmdlne-dU-21.c, gcc.dg/cpp/cmdlne-dU-22.c,
+       gcc.dg/cpp/mi5.c, gcc.dg/cpp/multiline.c: Add -nostdinc to
+       dg-options.
+
 2012-10-23  Marc Glisse  <marc.glisse@inria.fr>
 
        * gcc.dg/tree-ssa/foldconst-6.c: New testcase.
diff --git a/gcc/testsuite/gcc.dg/c99-predef-1.c b/gcc/testsuite/gcc.dg/c99-predef-1.c
new file mode 100644 (file)
index 0000000..b907764
--- /dev/null
@@ -0,0 +1,63 @@
+/* Verify that predefined macros for properties of the compiler and
+   library together are the same before and after system headers are
+   included.  This is broken with older glibc versions.  */
+/* { dg-do compile } */
+/* { dg-options "-std=iso9899:1999 -pedantic-errors" } */
+
+#ifdef __STDC_IEC_559__
+#define IEC_559_DEFINED_BEFORE 1
+#else
+#define IEC_559_DEFINED_BEFORE 0
+#endif
+
+#ifdef __STDC_IEC_559_COMPLEX__
+#define IEC_559_COMPLEX_DEFINED_BEFORE 1
+#else
+#define IEC_559_COMPLEX_DEFINED_BEFORE 0
+#endif
+
+#ifdef __STDC_ISO_10646__
+#define ISO_10646_DEFINED_BEFORE 1
+#else
+#define ISO_10646_DEFINED_BEFORE 0
+#endif
+
+#include <stdio.h>
+
+#ifdef __STDC_IEC_559__
+#define IEC_559_DEFINED_AFTER 1
+#else
+#define IEC_559_DEFINED_AFTER 0
+#endif
+
+#ifdef __STDC_IEC_559_COMPLEX__
+#define IEC_559_COMPLEX_DEFINED_AFTER 1
+#else
+#define IEC_559_COMPLEX_DEFINED_AFTER 0
+#endif
+
+#ifdef __STDC_ISO_10646__
+#define ISO_10646_DEFINED_AFTER 1
+#else
+#define ISO_10646_DEFINED_AFTER 0
+#endif
+
+#if defined(__GLIBC__) && (__GLIBC__ < 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ < 16))
+#define BROKEN
+#endif
+
+#ifndef BROKEN
+
+#if IEC_559_DEFINED_BEFORE != IEC_559_DEFINED_AFTER
+#error "__STDC_IEC_559__ definition inconsistency"
+#endif
+
+#if IEC_559_COMPLEX_DEFINED_BEFORE != IEC_559_COMPLEX_DEFINED_AFTER
+#error "__STDC_IEC_559_COMPLEX__ definition inconsistency"
+#endif
+
+#if ISO_10646_DEFINED_BEFORE != ISO_10646_DEFINED_AFTER
+#error "__STDC_ISO_10646__ definition inconsistency"
+#endif
+
+#endif
index ce3f5b72128abfa8206f269a9709dc483cabb262..129e48bf8e643a06c7042f816d1ed1e58dd923bb 100644 (file)
@@ -1,5 +1,5 @@
 /* { dg-do preprocess } */
-/* { dg-options "-P -dU" } */
+/* { dg-options "-nostdinc -P -dU" } */
 /* { dg-final { scan-file cmdlne-dU-1.i "^\n*#undef A\n*$" } } */
 #ifdef A
 #endif
index dd1474ad0ebaa33862eeffb8544adae62b08b293..31398a7625b13bfba4bf473deb80ac65a75d1a3d 100644 (file)
@@ -1,7 +1,7 @@
 /* { dg-do preprocess } */
-/* { dg-options "-P -dU" } */
+/* { dg-options "-nostdinc -P -dU" } */
 /* { dg-final { scan-file cmdlne-dU-10.i "^\n*C\n+#define B C\n+#define A B\n*$" } } */
 /* This file deliberately has no final newline.  */
 #define A B
 #define B C
-A
\ No newline at end of file
+A
index c9cc593463179288ae3d4e280209224661419346..1c0128bb431820f556eb787550c0a8bc4fdcf8b4 100644 (file)
@@ -1,5 +1,5 @@
 /* { dg-do preprocess } */
-/* { dg-options "-P -dU" } */
+/* { dg-options "-nostdinc -P -dU" } */
 /* { dg-final { scan-file cmdlne-dU-11.i "^\n*\n*$" } } */
 #define A B
 #if 0
index bf765fbf0eb836e39f219f77d05e4a25a338b0b4..54620a57ee2ffae1dd73fd27bf2c77682216b37f 100644 (file)
@@ -1,5 +1,5 @@
 /* { dg-do preprocess } */
-/* { dg-options "-P -dU" } */
+/* { dg-options "-nostdinc -P -dU" } */
 /* { dg-final { scan-file cmdlne-dU-12.i "^\n*#define A 1\n*$" } } */
 #define A 1
 #if A
index 3ab08d5d59c6236500cf628c106402766f7eed8e..45ce532b20616834f337976a68708c266313ea5b 100644 (file)
@@ -1,5 +1,5 @@
 /* { dg-do preprocess } */
-/* { dg-options "-P -dU" } */
+/* { dg-options "-nostdinc -P -dU" } */
 /* { dg-final { scan-file cmdlne-dU-13.i "^\n*#undef A\n*$" } } */
 #ifdef A
 #endif
index 5d36f1acb098a9049bfb9152be93a6cf7076b88d..4fe96a4d7708b51d449f9d53c007550945f4609d 100644 (file)
@@ -1,5 +1,5 @@
 /* { dg-do preprocess } */
-/* { dg-options "-P -dU" } */
+/* { dg-options "-nostdinc -P -dU" } */
 /* { dg-final { scan-file cmdlne-dU-14.i "^\n*B\n+#define A B\n+B\n*$" } } */
 #define A B
 A
index a6a9618267850ddcd50779c718941129762c3da1..2df0b62f9bec07ebfeaa75dd59783ce1d8a6e0e5 100644 (file)
@@ -1,5 +1,5 @@
 /* { dg-do preprocess } */
-/* { dg-options "-P -dU" } */
+/* { dg-options "-nostdinc -P -dU" } */
 /* { dg-final { scan-file cmdlne-dU-15.i "^\n*\n*$" } } */
 #if A
 #endif
index 463c0b9e707068cd481c44285204315505439694..41a9a9110bfc2c29acda7cd2502886737b8e951a 100644 (file)
@@ -1,6 +1,6 @@
 /* { dg-do preprocess } */
-/* { dg-options "-P -dU" } */
-/* { dg-options "-P -dU -std=c89" { target *-*-solaris2.* } } */
+/* { dg-options "-nostdinc -P -dU" } */
+/* { dg-options "-nostdinc -P -dU -std=c89" { target *-*-solaris2.* } } */
 /* { dg-final { scan-file cmdlne-dU-16.i "^\n*#define __STDC__ 1\n*$" } } */
 #ifdef __STDC__
 #endif
index 2ae9d273a9bde0d09401e3c32f3a8021a5990399..fd608e1d4d68a04ce71d379756f5f1e02f613d3f 100644 (file)
@@ -1,5 +1,5 @@
 /* { dg-do preprocess } */
-/* { dg-options "-P -dU" } */
-/* { dg-options "-P -dU -std=c89" { target *-*-solaris2.* } } */
+/* { dg-options "-nostdinc -P -dU" } */
+/* { dg-options "-nostdinc -P -dU -std=c89" { target *-*-solaris2.* } } */
 /* { dg-final { scan-file cmdlne-dU-17.i "^\n*1\n+#define __STDC__ 1\n*$" } } */
 __STDC__
index 0b2c54307ee94c686e7136e11b2e13b8ab1384c5..97104845d08488f7fc719b6d3113f7784a21f751 100644 (file)
@@ -1,5 +1,5 @@
 /* { dg-do preprocess } */
-/* { dg-options "-P -dU" } */
+/* { dg-options "-nostdinc -P -dU" } */
 /* { dg-final { scan-file cmdlne-dU-18.i "^\n*x 1 y\n+#define A 1\n*$" } } */
 #define A 1
 x A y
index 50edfc2b959e16580993eadf5bb124b386887b53..c6c3af3562c9e6236fda97672d405a52c6f9e9b3 100644 (file)
@@ -1,5 +1,5 @@
 /* { dg-do preprocess } */
-/* { dg-options "-P -dU" } */
+/* { dg-options "-nostdinc -P -dU" } */
 /* { dg-final { scan-file cmdlne-dU-19.i "^\n*B\n+#define A B\n+#undef A\n*$" } } */
 #define A B
 A
index e4754630405ad063e7977b54463981ac61cb2cd2..dffdd2ba90954ffc1c3ba3258fecfaafd2ec1c14 100644 (file)
@@ -1,5 +1,5 @@
 /* { dg-do preprocess } */
-/* { dg-options "-P -dU" } */
+/* { dg-options "-nostdinc -P -dU" } */
 /* { dg-final { scan-file cmdlne-dU-2.i "^\n*#define A *\n*$" } } */
 #define A
 #ifdef A
index 4845b51e77bed9e477d57b8fb295ebdb7a5a3e45..065b807ef61c5c96b5e5fb070ac04749ac9832c5 100644 (file)
@@ -1,5 +1,5 @@
 /* { dg-do preprocess } */
-/* { dg-options "-P -dU" } */
+/* { dg-options "-nostdinc -P -dU" } */
 /* { dg-final { scan-file cmdlne-dU-20.i "^\n*A B\n*$" } } */
 #define A(x) x
 A B
index c17a0435ed76cc683f61496706eea69cd8c6c523..1fefe542cbdd1e845b3bd9399fb8c796be2771c3 100644 (file)
@@ -1,5 +1,5 @@
 /* { dg-do preprocess } */
-/* { dg-options "-P -dU" } */
+/* { dg-options "-nostdinc -P -dU" } */
 /* { dg-final { scan-file cmdlne-dU-21.i "^\n*hello There\n+#define ASTRING There\n+#define MACROARGS\\(A\\) A\n+#undef BSTRING\n*$" } } */
 #define ASTRING There
 #define MACROARGS(A) A
index 383a29f85e825b41926255281cb3d412ef40d1a7..fe100ceb023e79baa88bd821b501618566ce0077 100644 (file)
@@ -1,5 +1,5 @@
 /* { dg-do preprocess } */
-/* { dg-options "-P -dU" } */
+/* { dg-options "-nostdinc -P -dU" } */
 /* { dg-final { scan-file cmdlne-dU-22.i "^\n*#undef AAA\n+AAA is undefined\n+#undef BBB\n+BBB is undefined\n+#undef CCC\n+CCC is undefined\n*$" } } */
 #ifndef AAA
 AAA is undefined
index 26c6ec1de26fecf7cb08e126a44a9e946b9d8d12..a26fc9881de61e55f191f57254168ee5c1b6d7fe 100644 (file)
@@ -1,5 +1,5 @@
 /* { dg-do preprocess } */
-/* { dg-options "-P -dU" } */
+/* { dg-options "-nostdinc -P -dU" } */
 /* { dg-final { scan-file cmdlne-dU-3.i "^\n*#define A B\n*$" } } */
 #define A B
 #ifndef A
index 9c57ffe7c74dcb502e204e6433d63ebe5e464480..aa3d853a09ae114501f43b9a4e5f3ef6c960a369 100644 (file)
@@ -1,5 +1,5 @@
 /* { dg-do preprocess } */
-/* { dg-options "-P -dU" } */
+/* { dg-options "-nostdinc -P -dU" } */
 /* { dg-final { scan-file cmdlne-dU-4.i "^\n*#undef A\n*$" } } */
 #if defined(A)
 #endif
index 01880b77b5f74073f4faccce16f05cf7cb889ce4..bfae850de30cddb691871ba46e700a619a43e509 100644 (file)
@@ -1,5 +1,5 @@
 /* { dg-do preprocess } */
-/* { dg-options "-P -dU" } */
+/* { dg-options "-nostdinc -P -dU" } */
 /* { dg-final { scan-file cmdlne-dU-5.i "^\n*#undef A\n*$" } } */
 #ifdef A
 #ifdef B
index edf6b4445184a1fb1bcf7d1ecf9d2489119fed4d..e2c801df30770e8076e900cfc88532953fb11e4a 100644 (file)
@@ -1,5 +1,5 @@
 /* { dg-do preprocess } */
-/* { dg-options "-P -dU" } */
+/* { dg-options "-nostdinc -P -dU" } */
 /* { dg-final { scan-file cmdlne-dU-6.i "^\n*#undef A\n+#define A *\n*$" } } */
 #ifdef A
 #endif
index 43a66341d0c34b628674997f344dba999fdadb43..030917844839ce64d4d36336631bff2b1728dc44 100644 (file)
@@ -1,5 +1,5 @@
 /* { dg-do preprocess } */
-/* { dg-options "-P -dU" } */
+/* { dg-options "-nostdinc -P -dU" } */
 /* { dg-final { scan-file cmdlne-dU-7.i "^\n*B\n+#define A B\n+C\n+#define A C\n*$" } } */
 #define A B
 A
index d5984a31494d40bfc2d06c8255ba2de01d0b197b..da97fabed5b5e28fa3119993b18091d8ee42d212 100644 (file)
@@ -1,5 +1,5 @@
 /* { dg-do preprocess } */
-/* { dg-options "-P -dU" } */
+/* { dg-options "-nostdinc -P -dU" } */
 /* { dg-final { scan-file cmdlne-dU-8.i "^\n*B D\n+#define A\\(x\\) B x\n+#define C D\n*$" } } */
 #define A(x) B x
 #define C D
index ac8b92114ac15e5247b6415a227ce9005dcedc4a..bd0f0edfeccef464f06dbc557ddcc86de78b6f43 100644 (file)
@@ -1,5 +1,5 @@
 /* { dg-do preprocess } */
-/* { dg-options "-P -dU" } */
+/* { dg-options "-nostdinc -P -dU" } */
 /* { dg-final { scan-file cmdlne-dU-9.i "^\n*C\n+#define B C\n+#define A B\n*$" } } */
 #define A B
 #define B C
index 327c47621916a70d434065942a3de50cf183973e..09f4f5c0d465c0c19cf323d927af4ce779e65805 100644 (file)
@@ -6,7 +6,7 @@
    otherwise it will not be interpreted all in one unit.  */
 
 /* { dg-do preprocess }
-   { dg-options "-H -C" }
+   { dg-options "-nostdinc -H -C" }
    { dg-message "mi1c\.h" "redundant include check with -C" { target *-*-* } 0 } */
 
 #include "mi1c.h"
index 38798bdfaafa3d236d3a222327dcdf02161a3820..970cf2faa0ca17f13fc99694c88183af44d84748 100644 (file)
@@ -1,6 +1,6 @@
 /* Copyright (C) 2000, 2003 Free Software Foundation, Inc.  */
 /* { dg-do preprocess } */
-/* { dg-options "-C" } */
+/* { dg-options "-nostdinc -C" } */
 /* Test that multi-line tokens are recognized by cpp0 as being
    multiline .  Source: Neil Booth, 17 Dec 2000.  */
 /* Line 1
index fdc151c9aa68558b906f15b466001b3ef61a4e94..9b833522836df5512b4e6b75890476c48cdd9b5e 100644 (file)
@@ -1,3 +1,20 @@
+2012-10-23  Joseph Myers  <joseph@codesourcery.com>
+
+       * files.c (struct _cpp_file): Add implicit_preinclude.
+       (pch_open_file): Allow a previously opened implicitly included
+       file.
+       (_cpp_find_file): Add implicit_preinclude argument.  Free file and
+       do not call open_file_failed if implicit_preinclude.  Store
+       implicit_preinclude value.
+       (_cpp_stack_include, _cpp_fake_include, _cpp_compare_file_date):
+       Update calls to _cpp_find_file.
+       (_cpp_stack_include): Handle IT_DEFAULT.
+       (cpp_push_default_include): New.
+       * include/cpplib.h (cpp_push_default_include): Declare.
+       * init.c (cpp_read_main_file): Update call to _cpp_find_file.
+       * internal.h (enum include_type): Add IT_DEFAULT.
+       (_cpp_find_file): Update prototype.
+
 2012-10-15  Tobias Burnus  <burnus@net-b.de>
 
        * files.c (read_file_guts, _cpp_save_file_entries): Free memory
index 6fc24e2af44908f561954c492a58b6a6625b956b..ecaa27414e1e3c2003fbe9dc4a1ee9c5d46e347c 100644 (file)
@@ -110,6 +110,9 @@ struct _cpp_file
 
   /* If BUFFER above contains the true contents of the file.  */
   bool buffer_valid;
+
+  /* If this file is implicitly preincluded.  */
+  bool implicit_preinclude;
 };
 
 /* A singly-linked list for all searches for a given file name, with
@@ -291,7 +294,8 @@ pch_open_file (cpp_reader *pfile, _cpp_file *file, bool *invalid_pch)
   /* If the file is not included as first include from either the toplevel
      file or the command-line it is not a valid use of PCH.  */
   if (pfile->all_files
-      && pfile->all_files->next_file)
+      && pfile->all_files->next_file
+      && !pfile->all_files->next_file->implicit_preinclude)
     return false;
 
   flen = strlen (path);
@@ -480,9 +484,14 @@ _cpp_find_failed (_cpp_file *file)
    descriptor.  FD can be -1 if the file was found in the cache and
    had previously been closed.  To open it again pass the return value
    to open_file().
+
+   If IMPLICIT_PREINCLUDE then it is OK for the file to be missing.
+   If present, it is OK for a precompiled header to be included after
+   it.
 */
 _cpp_file *
-_cpp_find_file (cpp_reader *pfile, const char *fname, cpp_dir *start_dir, bool fake, int angle_brackets)
+_cpp_find_file (cpp_reader *pfile, const char *fname, cpp_dir *start_dir,
+               bool fake, int angle_brackets, bool implicit_preinclude)
 {
   struct file_hash_entry *entry, **hash_slot;
   _cpp_file *file;
@@ -506,6 +515,7 @@ _cpp_find_file (cpp_reader *pfile, const char *fname, cpp_dir *start_dir, bool f
     return entry->u.file;
 
   file = make_cpp_file (pfile, start_dir, fname);
+  file->implicit_preinclude = implicit_preinclude;
 
   /* Try each path in the include chain.  */
   for (; !fake ;)
@@ -535,7 +545,14 @@ _cpp_find_file (cpp_reader *pfile, const char *fname, cpp_dir *start_dir, bool f
                cpp_error (pfile, CPP_DL_ERROR,
                           "use -Winvalid-pch for more information");
            }
-         open_file_failed (pfile, file, angle_brackets);
+         if (implicit_preinclude)
+           {
+             free ((char *) file->name);
+             free (file);
+             return NULL;
+           }
+         else
+           open_file_failed (pfile, file, angle_brackets);
          break;
        }
 
@@ -950,7 +967,10 @@ _cpp_stack_include (cpp_reader *pfile, const char *fname, int angle_brackets,
   if (!dir)
     return false;
 
-  file = _cpp_find_file (pfile, fname, dir, false, angle_brackets);
+  file = _cpp_find_file (pfile, fname, dir, false, angle_brackets,
+                        type == IT_DEFAULT);
+  if (type == IT_DEFAULT && file == NULL)
+    return false;
 
   /* Compensate for the increment in linemap_add that occurs in
      _cpp_stack_file.  In the case of a normal #include, we're
@@ -960,7 +980,8 @@ _cpp_stack_include (cpp_reader *pfile, const char *fname, int angle_brackets,
      This does not apply if we found a PCH file (in which case
      linemap_add is not called) or we were included from the
      command-line.  */
-  if (file->pchname == NULL && file->err_no == 0 && type != IT_CMDLINE)
+  if (file->pchname == NULL && file->err_no == 0
+      && type != IT_CMDLINE && type != IT_DEFAULT)
     pfile->line_table->highest_location--;
 
   return _cpp_stack_file (pfile, file, type == IT_IMPORT);
@@ -1243,7 +1264,7 @@ cpp_clear_file_cache (cpp_reader *pfile)
 void
 _cpp_fake_include (cpp_reader *pfile, const char *fname)
 {
-  _cpp_find_file (pfile, fname, pfile->buffer->file->dir, true, 0);
+  _cpp_find_file (pfile, fname, pfile->buffer->file->dir, true, 0, false);
 }
 
 /* Not everyone who wants to set system-header-ness on a buffer can
@@ -1361,7 +1382,7 @@ _cpp_compare_file_date (cpp_reader *pfile, const char *fname,
   if (!dir)
     return -1;
 
-  file = _cpp_find_file (pfile, fname, dir, false, angle_brackets);
+  file = _cpp_find_file (pfile, fname, dir, false, angle_brackets, false);
   if (file->err_no)
     return -1;
 
@@ -1382,6 +1403,15 @@ cpp_push_include (cpp_reader *pfile, const char *fname)
   return _cpp_stack_include (pfile, fname, false, IT_CMDLINE);
 }
 
+/* Pushes the given file, implicitly included at the start of a
+   compilation, onto the buffer stack but without any errors if the
+   file is not found.  Returns nonzero if successful.  */
+bool
+cpp_push_default_include (cpp_reader *pfile, const char *fname)
+{
+  return _cpp_stack_include (pfile, fname, true, IT_DEFAULT);
+}
+
 /* Do appropriate cleanup when a file INC's buffer is popped off the
    input stack.  */
 void
index 2ec7eaaae2f95b8a8379134421e67c5a7bf2de45..a58454e9839be0fa81b73c8aec9090dd11017fe7 100644 (file)
@@ -1,6 +1,6 @@
 /* Definitions for CPP library.
    Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
-   2004, 2005, 2007, 2008, 2009, 2010, 2011
+   2004, 2005, 2007, 2008, 2009, 2010, 2011, 2012
    Free Software Foundation, Inc.
    Written by Per Bothner, 1994-95.
 
@@ -1010,6 +1010,7 @@ extern bool cpp_included (cpp_reader *, const char *);
 extern bool cpp_included_before (cpp_reader *, const char *, source_location);
 extern void cpp_make_system_header (cpp_reader *, int, int);
 extern bool cpp_push_include (cpp_reader *, const char *);
+extern bool cpp_push_default_include (cpp_reader *, const char *);
 extern void cpp_change_file (cpp_reader *, enum lc_reason, const char *);
 extern const char *cpp_get_path (struct _cpp_file *);
 extern cpp_dir *cpp_get_dir (struct _cpp_file *);
index 040ab34eb90dcc8dab6518f80d5d6d44c27da944..81b66df57e50d918bc66466a984437421a35fcf5 100644 (file)
@@ -1,7 +1,7 @@
 /* CPP Library.
    Copyright (C) 1986, 1987, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
    1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008,
-   2009, 2010, 2011 Free Software Foundation, Inc.
+   2009, 2010, 2011, 2012 Free Software Foundation, Inc.
    Contributed by Per Bothner, 1994-95.
    Based on CCCP program by Paul Rubin, June 1986
    Adapted to ANSI C, Richard Stallman, Jan 1987
@@ -593,7 +593,7 @@ cpp_read_main_file (cpp_reader *pfile, const char *fname)
     }
 
   pfile->main_file
-    = _cpp_find_file (pfile, fname, &pfile->no_search_path, false, 0);
+    = _cpp_find_file (pfile, fname, &pfile->no_search_path, false, 0, false);
   if (_cpp_find_failed (pfile->main_file))
     return NULL;
 
index 79dd54f06cfa83e7c66dbda36129634ff0bdaa19..312b8b5cb0ec648412d54b44e29199565c6f139f 100644 (file)
@@ -117,7 +117,7 @@ extern unsigned char *_cpp_unaligned_alloc (cpp_reader *, size_t);
 #define BUFF_LIMIT(BUFF) ((BUFF)->limit)
 
 /* #include types.  */
-enum include_type {IT_INCLUDE, IT_INCLUDE_NEXT, IT_IMPORT, IT_CMDLINE};
+enum include_type {IT_INCLUDE, IT_INCLUDE_NEXT, IT_IMPORT, IT_CMDLINE, IT_DEFAULT};
 
 union utoken
 {
@@ -625,7 +625,7 @@ extern void _cpp_destroy_hashtable (cpp_reader *);
 /* In files.c */
 typedef struct _cpp_file _cpp_file;
 extern _cpp_file *_cpp_find_file (cpp_reader *, const char *, cpp_dir *,
-                                 bool, int);
+                                 bool, int, bool);
 extern bool _cpp_find_failed (_cpp_file *);
 extern void _cpp_mark_file_once_only (cpp_reader *, struct _cpp_file *);
 extern void _cpp_fake_include (cpp_reader *, const char *);