From patchwork Fri Sep 28 15:59:01 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joseph Myers X-Patchwork-Id: 187825 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 4CA1E2C00B9 for ; Sat, 29 Sep 2012 01:59:31 +1000 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1349452772; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:Received:Date:From:To:CC:Subject:In-Reply-To:Message-ID: References:MIME-Version:Content-Type:Mailing-List:Precedence: List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender: Delivered-To; bh=yfVQ4BzoBgqOSEEBrJdM5U6R+vA=; b=E6yLSDpF3tHbN50 YrGTwT/1vn+flWX0CCXlQeSwgKgNk9lrPmu/1cNU7v8B7W/PSxdt3j/beCm6wGhJ YXVoKnqxl5B8iEmLaI3c/p50MKydmZBzRuCvR0A9+vsDYLlozhJEy2dC4X/MAIi0 Onst2uLMVM+o427PJTks+672pSqc= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Received:Received:Received:Date:From:To:CC:Subject:In-Reply-To:Message-ID:References:MIME-Version:Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=EHI1AnUjnOU+ywBtTeOYUHeqMJ2sgQvWE61Yn0XmE04UhZ21sVPN74E9F5AipE /G9b9FHlFdPRToK3EogMgW8WzMUIwTc+qTkbo1eYz8fQX1pzTEaAo6AaRE1G4w5f 34QisgH3IqxP1g4mWtILkgevk7eowHeb0K+AqEaTi8wi0=; Received: (qmail 4783 invoked by alias); 28 Sep 2012 15:59:26 -0000 Received: (qmail 4763 invoked by uid 22791); 28 Sep 2012 15:59:21 -0000 X-SWARE-Spam-Status: No, hits=-4.7 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, KHOP_THREADED, RCVD_IN_HOSTKARMA_W, RCVD_IN_HOSTKARMA_WL, TW_CX, TW_DL, TW_EG X-Spam-Check-By: sourceware.org Received: from relay1.mentorg.com (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 28 Sep 2012 15:59:07 +0000 Received: from svr-orw-fem-01.mgc.mentorg.com ([147.34.98.93]) by relay1.mentorg.com with esmtp id 1THcy2-0006V6-H3 from joseph_myers@mentor.com ; Fri, 28 Sep 2012 08:59:06 -0700 Received: from SVR-IES-FEM-02.mgc.mentorg.com ([137.202.0.106]) by svr-orw-fem-01.mgc.mentorg.com over TLS secured channel with Microsoft SMTPSVC(6.0.3790.4675); Fri, 28 Sep 2012 08:59:06 -0700 Received: from digraph.polyomino.org.uk (137.202.0.76) by SVR-IES-FEM-02.mgc.mentorg.com (137.202.0.106) with Microsoft SMTP Server id 14.1.289.1; Fri, 28 Sep 2012 16:59:02 +0100 Received: from jsm28 (helo=localhost) by digraph.polyomino.org.uk with local-esmtp (Exim 4.76) (envelope-from ) id 1THcxx-0002Hl-Kh; Fri, 28 Sep 2012 15:59:01 +0000 Date: Fri, 28 Sep 2012 15:59:01 +0000 From: "Joseph S. Myers" To: Ian Lance Taylor CC: Subject: Re: Defining C99 predefined macros for whole translation unit In-Reply-To: Message-ID: References: MIME-Version: 1.0 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org On Fri, 24 Apr 2009, Ian Lance Taylor wrote: > This patch to gcc is OK if the patch to glibc is OK. Now that the corresponding glibc patch is in glibc 2.16, I've updated the GCC patch (original submission ) for current sources and retested it. Although the original version was approved conditional on the glibc patch, some fairly substantial changes were needed for changes to hook handling in the past three years, so I'm resubmitting (the non-C parts of) this patch rather than just committing it. (The C parts also have fairly substantial changes relating to PCH, which seems to have got rather more fragile and difficult to keep working in the past three years; the PCH-related bits of this patch may well not be particularly ideal, but they were what I found that actually works for the PCH tests for both old and new glibc headers.) Bootstrapped with no regressions on x86_64-unknown-linux-gnu (older glibc). Also tested with cross to arm-none-linux-gnueabi (current glibc). OK to commit? gcc: 2012-09-28 Joseph Myers * 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: 2012-09-28 Joseph Myers * 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: 2012-09-28 Joseph Myers * 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: 2012-09-28 Joseph Myers * 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. Index: gcc/doc/tm.texi =================================================================== --- gcc/doc/tm.texi (revision 191711) +++ gcc/doc/tm.texi (working copy) @@ -10646,6 +10646,12 @@ convention when processing system header files, bu 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: gcc/doc/tm.texi.in =================================================================== --- gcc/doc/tm.texi.in (revision 191711) +++ gcc/doc/tm.texi.in (working copy) @@ -10504,6 +10504,8 @@ convention when processing system header files, bu 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: gcc/hooks.c =================================================================== --- gcc/hooks.c (revision 191711) +++ gcc/hooks.c (working copy) @@ -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 @@ -333,6 +333,13 @@ hook_tree_tree_tree_tree_3rd_identity (tree a ATTR 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: gcc/hooks.h =================================================================== --- gcc/hooks.h (revision 191711) +++ gcc/hooks.h (working copy) @@ -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 @@ -94,6 +94,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: gcc/c-family/c-opts.c =================================================================== --- gcc/c-family/c-opts.c (revision 191711) +++ gcc/c-family/c-opts.c (working copy) @@ -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); @@ -1432,6 +1435,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++]; @@ -1467,7 +1483,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: gcc/c-family/c-common.h =================================================================== --- gcc/c-family/c-common.h (revision 191711) +++ gcc/c-family/c-common.h (working copy) @@ -1018,6 +1018,7 @@ extern tree c_build_bind_expr (location_t, tree, t /* 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: gcc/c-family/c-target.def =================================================================== --- gcc/c-family/c-target.def (revision 191711) +++ gcc/c-family/c-target.def (working copy) @@ -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: gcc/c-family/c-pch.c =================================================================== --- gcc/c-family/c-pch.c (revision 191711) +++ gcc/c-family/c-pch.c (working copy) @@ -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,9 +140,33 @@ 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 will produce a PCH file. */ Index: gcc/testsuite/gcc.dg/cpp/cmdlne-dU-5.c =================================================================== --- gcc/testsuite/gcc.dg/cpp/cmdlne-dU-5.c (revision 191711) +++ gcc/testsuite/gcc.dg/cpp/cmdlne-dU-5.c (working copy) @@ -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: gcc/testsuite/gcc.dg/cpp/cmdlne-dU-10.c =================================================================== --- gcc/testsuite/gcc.dg/cpp/cmdlne-dU-10.c (revision 191711) +++ gcc/testsuite/gcc.dg/cpp/cmdlne-dU-10.c (working copy) @@ -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: gcc/testsuite/gcc.dg/cpp/cmdlne-dU-18.c =================================================================== --- gcc/testsuite/gcc.dg/cpp/cmdlne-dU-18.c (revision 191711) +++ gcc/testsuite/gcc.dg/cpp/cmdlne-dU-18.c (working copy) @@ -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: gcc/testsuite/gcc.dg/cpp/cmdlne-dU-6.c =================================================================== --- gcc/testsuite/gcc.dg/cpp/cmdlne-dU-6.c (revision 191711) +++ gcc/testsuite/gcc.dg/cpp/cmdlne-dU-6.c (working copy) @@ -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: gcc/testsuite/gcc.dg/cpp/cmdlne-dU-11.c =================================================================== --- gcc/testsuite/gcc.dg/cpp/cmdlne-dU-11.c (revision 191711) +++ gcc/testsuite/gcc.dg/cpp/cmdlne-dU-11.c (working copy) @@ -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: gcc/testsuite/gcc.dg/cpp/mi5.c =================================================================== --- gcc/testsuite/gcc.dg/cpp/mi5.c (revision 191711) +++ gcc/testsuite/gcc.dg/cpp/mi5.c (working copy) @@ -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: gcc/testsuite/gcc.dg/cpp/cmdlne-dU-19.c =================================================================== --- gcc/testsuite/gcc.dg/cpp/cmdlne-dU-19.c (revision 191711) +++ gcc/testsuite/gcc.dg/cpp/cmdlne-dU-19.c (working copy) @@ -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: gcc/testsuite/gcc.dg/cpp/cmdlne-dU-20.c =================================================================== --- gcc/testsuite/gcc.dg/cpp/cmdlne-dU-20.c (revision 191711) +++ gcc/testsuite/gcc.dg/cpp/cmdlne-dU-20.c (working copy) @@ -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: gcc/testsuite/gcc.dg/cpp/cmdlne-dU-7.c =================================================================== --- gcc/testsuite/gcc.dg/cpp/cmdlne-dU-7.c (revision 191711) +++ gcc/testsuite/gcc.dg/cpp/cmdlne-dU-7.c (working copy) @@ -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: gcc/testsuite/gcc.dg/cpp/cmdlne-dU-12.c =================================================================== --- gcc/testsuite/gcc.dg/cpp/cmdlne-dU-12.c (revision 191711) +++ gcc/testsuite/gcc.dg/cpp/cmdlne-dU-12.c (working copy) @@ -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: gcc/testsuite/gcc.dg/cpp/multiline.c =================================================================== --- gcc/testsuite/gcc.dg/cpp/multiline.c (revision 191711) +++ gcc/testsuite/gcc.dg/cpp/multiline.c (working copy) @@ -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: gcc/testsuite/gcc.dg/cpp/cmdlne-dU-21.c =================================================================== --- gcc/testsuite/gcc.dg/cpp/cmdlne-dU-21.c (revision 191711) +++ gcc/testsuite/gcc.dg/cpp/cmdlne-dU-21.c (working copy) @@ -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: gcc/testsuite/gcc.dg/cpp/cmdlne-dU-8.c =================================================================== --- gcc/testsuite/gcc.dg/cpp/cmdlne-dU-8.c (revision 191711) +++ gcc/testsuite/gcc.dg/cpp/cmdlne-dU-8.c (working copy) @@ -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: gcc/testsuite/gcc.dg/cpp/cmdlne-dU-13.c =================================================================== --- gcc/testsuite/gcc.dg/cpp/cmdlne-dU-13.c (revision 191711) +++ gcc/testsuite/gcc.dg/cpp/cmdlne-dU-13.c (working copy) @@ -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: gcc/testsuite/gcc.dg/cpp/cmdlne-dU-22.c =================================================================== --- gcc/testsuite/gcc.dg/cpp/cmdlne-dU-22.c (revision 191711) +++ gcc/testsuite/gcc.dg/cpp/cmdlne-dU-22.c (working copy) @@ -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: gcc/testsuite/gcc.dg/cpp/cmdlne-dU-1.c =================================================================== --- gcc/testsuite/gcc.dg/cpp/cmdlne-dU-1.c (revision 191711) +++ gcc/testsuite/gcc.dg/cpp/cmdlne-dU-1.c (working copy) @@ -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: gcc/testsuite/gcc.dg/cpp/cmdlne-dU-9.c =================================================================== --- gcc/testsuite/gcc.dg/cpp/cmdlne-dU-9.c (revision 191711) +++ gcc/testsuite/gcc.dg/cpp/cmdlne-dU-9.c (working copy) @@ -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: gcc/testsuite/gcc.dg/cpp/cmdlne-dU-14.c =================================================================== --- gcc/testsuite/gcc.dg/cpp/cmdlne-dU-14.c (revision 191711) +++ gcc/testsuite/gcc.dg/cpp/cmdlne-dU-14.c (working copy) @@ -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: gcc/testsuite/gcc.dg/cpp/cmdlne-dU-2.c =================================================================== --- gcc/testsuite/gcc.dg/cpp/cmdlne-dU-2.c (revision 191711) +++ gcc/testsuite/gcc.dg/cpp/cmdlne-dU-2.c (working copy) @@ -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: gcc/testsuite/gcc.dg/cpp/cmdlne-dU-15.c =================================================================== --- gcc/testsuite/gcc.dg/cpp/cmdlne-dU-15.c (revision 191711) +++ gcc/testsuite/gcc.dg/cpp/cmdlne-dU-15.c (working copy) @@ -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: gcc/testsuite/gcc.dg/cpp/cmdlne-dU-3.c =================================================================== --- gcc/testsuite/gcc.dg/cpp/cmdlne-dU-3.c (revision 191711) +++ gcc/testsuite/gcc.dg/cpp/cmdlne-dU-3.c (working copy) @@ -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: gcc/testsuite/gcc.dg/cpp/cmdlne-dU-16.c =================================================================== --- gcc/testsuite/gcc.dg/cpp/cmdlne-dU-16.c (revision 191711) +++ gcc/testsuite/gcc.dg/cpp/cmdlne-dU-16.c (working copy) @@ -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: gcc/testsuite/gcc.dg/cpp/cmdlne-dU-4.c =================================================================== --- gcc/testsuite/gcc.dg/cpp/cmdlne-dU-4.c (revision 191711) +++ gcc/testsuite/gcc.dg/cpp/cmdlne-dU-4.c (working copy) @@ -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: gcc/testsuite/gcc.dg/cpp/cmdlne-dU-17.c =================================================================== --- gcc/testsuite/gcc.dg/cpp/cmdlne-dU-17.c (revision 191711) +++ gcc/testsuite/gcc.dg/cpp/cmdlne-dU-17.c (working copy) @@ -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: gcc/testsuite/gcc.dg/c99-predef-1.c =================================================================== --- gcc/testsuite/gcc.dg/c99-predef-1.c (revision 0) +++ gcc/testsuite/gcc.dg/c99-predef-1.c (revision 0) @@ -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 + +#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: gcc/config.gcc =================================================================== --- gcc/config.gcc (revision 191711) +++ gcc/config.gcc (working copy) @@ -667,6 +667,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" @@ -2468,16 +2472,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*) Index: gcc/config/t-glibc =================================================================== --- gcc/config/t-glibc (revision 0) +++ gcc/config/t-glibc (revision 0) @@ -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 +# . + +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: gcc/config/glibc-c.c =================================================================== --- gcc/config/glibc-c.c (revision 0) +++ gcc/config/glibc-c.c (revision 0) @@ -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 +. */ + +#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; Index: libcpp/files.c =================================================================== --- libcpp/files.c (revision 191711) +++ libcpp/files.c (working copy) @@ -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, /* 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_file * 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_file * 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; } @@ -949,7 +966,10 @@ _cpp_stack_include (cpp_reader *pfile, const char 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 @@ -959,7 +979,8 @@ _cpp_stack_include (cpp_reader *pfile, const char 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); @@ -1242,7 +1263,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 @@ -1360,7 +1381,7 @@ _cpp_compare_file_date (cpp_reader *pfile, const c 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; @@ -1381,6 +1402,15 @@ cpp_push_include (cpp_reader *pfile, const char *f 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: libcpp/include/cpplib.h =================================================================== --- libcpp/include/cpplib.h (revision 191711) +++ libcpp/include/cpplib.h (working copy) @@ -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: libcpp/init.c =================================================================== --- libcpp/init.c (revision 191711) +++ libcpp/init.c (working copy) @@ -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 } 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: libcpp/internal.h =================================================================== --- libcpp/internal.h (revision 191711) +++ libcpp/internal.h (working copy) @@ -117,7 +117,7 @@ extern unsigned char *_cpp_unaligned_alloc (cpp_re #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 *);