2003-01-10 10:22:34 +08:00
|
|
|
/* Part of CPP library. (Precompiled header reading/writing.)
|
2024-01-03 19:19:35 +08:00
|
|
|
Copyright (C) 2000-2024 Free Software Foundation, Inc.
|
2003-01-10 10:22:34 +08:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it
|
|
|
|
under the terms of the GNU General Public License as published by the
|
2009-04-09 23:00:19 +08:00
|
|
|
Free Software Foundation; either version 3, or (at your option) any
|
2003-01-10 10:22:34 +08:00
|
|
|
later version.
|
|
|
|
|
|
|
|
This program 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
|
2009-04-09 23:00:19 +08:00
|
|
|
along with this program; see the file COPYING3. If not see
|
|
|
|
<http://www.gnu.org/licenses/>. */
|
2003-01-10 10:22:34 +08:00
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "system.h"
|
|
|
|
#include "cpplib.h"
|
2004-05-24 18:50:45 +08:00
|
|
|
#include "internal.h"
|
2003-01-10 10:22:34 +08:00
|
|
|
#include "hashtab.h"
|
|
|
|
#include "mkdeps.h"
|
|
|
|
|
* cpplib.h, cpphash.h, cppcharset.c, cpperror.c, cppexp.c
* cppfiles.c, cpphash.c, cppinit.c, cpplex.c, cpplib.c
* cppmacro.c, cpppch.c, cpptrad.c, cppspec.c: Convert to
ISO C: new-style function declarations, no need for PARAMS,
no special punctuation on indirect function calls, use string
constant concatenation where convenient.
From-SVN: r68070
2003-06-17 14:17:44 +08:00
|
|
|
static int write_macdef (cpp_reader *, cpp_hashnode *, void *);
|
|
|
|
static int save_idents (cpp_reader *, cpp_hashnode *, void *);
|
|
|
|
static hashval_t hashmem (const void *, size_t);
|
|
|
|
static hashval_t cpp_string_hash (const void *);
|
|
|
|
static int cpp_string_eq (const void *, const void *);
|
|
|
|
static int count_defs (cpp_reader *, cpp_hashnode *, void *);
|
|
|
|
static int comp_hashnodes (const void *, const void *);
|
|
|
|
static int collect_ht_nodes (cpp_reader *, cpp_hashnode *, void *);
|
|
|
|
static int write_defs (cpp_reader *, cpp_hashnode *, void *);
|
|
|
|
static int save_macros (cpp_reader *, cpp_hashnode *, void *);
|
2009-11-12 02:37:19 +08:00
|
|
|
static int _cpp_save_pushed_macros (cpp_reader *, FILE *);
|
|
|
|
static int _cpp_restore_pushed_macros (cpp_reader *, FILE *);
|
2003-01-10 10:22:34 +08:00
|
|
|
|
|
|
|
/* This structure represents a macro definition on disk. */
|
2007-06-01 10:12:37 +08:00
|
|
|
struct macrodef_struct
|
2003-01-10 10:22:34 +08:00
|
|
|
{
|
|
|
|
unsigned int definition_length;
|
|
|
|
unsigned short name_length;
|
|
|
|
unsigned short flags;
|
|
|
|
};
|
|
|
|
|
2007-06-01 10:12:37 +08:00
|
|
|
/* This is how we write out a macro definition.
|
2003-01-10 10:22:34 +08:00
|
|
|
Suitable for being called by cpp_forall_identifiers. */
|
|
|
|
|
|
|
|
static int
|
* cpplib.h, cpphash.h, cppcharset.c, cpperror.c, cppexp.c
* cppfiles.c, cpphash.c, cppinit.c, cpplex.c, cpplib.c
* cppmacro.c, cpppch.c, cpptrad.c, cppspec.c: Convert to
ISO C: new-style function declarations, no need for PARAMS,
no special punctuation on indirect function calls, use string
constant concatenation where convenient.
From-SVN: r68070
2003-06-17 14:17:44 +08:00
|
|
|
write_macdef (cpp_reader *pfile, cpp_hashnode *hn, void *file_p)
|
2003-01-10 10:22:34 +08:00
|
|
|
{
|
|
|
|
FILE *f = (FILE *) file_p;
|
[CPP PATCH] node type
https://gcc.gnu.org/ml/gcc-patches/2018-08/msg01164.html
* include/cpplib.h (NODE_BUILTIN, NODE_MACRO_ARG): Delete.
Renumber others.
(enum node_type): Replace NT_MACRO with NT_USER_MACRO,
NT_BUILTIN_MACRO, NT_MACRO_ARG. Delete NT_ASSERTION.
(NTV_MACRO, NTV_ANSWER, NTV_BUILTIN, NTV_ARGUMENT, NTV_NONE):
Delete.
(CPP_HASHNODE_VALUE_IDX): Delete.
(union _cpp_hashnode_value): GTY tag from enum node_type directly.
(struct cpp_hashnode): Adjust GTY desc for value field.
(cpp_user_macro_p, cpp_builtin_macro_p, cpp_macro_p): Adjust.
* directives.c (undefine_macros): Clear value.anwers, adjust flag
clearing.
(_cpp_test_assertion): No need to check NT_ASSERTION.
(do_assert, do_unassert): Likewise.
* init.c (cpp_init_special_builtins): Set type not flags.
* macro.c (struct macro_arg_saved_data): Add type field.
(cpp_get_token_1): Check type not NT_VOID.
(_cpp_free_definition): Adjust flag clearing. Nullify
value.answers.
(_cpp_save_parameter, _cpp_unsave_parameters): Save and restore
type.
(lex_expansion_token): Check type not flags.
(_cpp_create_definition): Set type to NT_USER_MACRO.
(_cpp_notify_macro_use): Adjust type checking.
* pch.c (write_macdef, count_defs, write_defs, cpp_valid_state)
(save_macros): Adjust node type/flag handling.
* traditional.c (_cpp_scan_out_logical_line): Check type not flags.
From-SVN: r263667
2018-08-21 00:32:29 +08:00
|
|
|
bool is_void = false;
|
2003-01-10 10:22:34 +08:00
|
|
|
switch (hn->type)
|
|
|
|
{
|
|
|
|
case NT_VOID:
|
|
|
|
if (! (hn->flags & NODE_POISONED))
|
|
|
|
return 1;
|
[CPP PATCH] node type
https://gcc.gnu.org/ml/gcc-patches/2018-08/msg01164.html
* include/cpplib.h (NODE_BUILTIN, NODE_MACRO_ARG): Delete.
Renumber others.
(enum node_type): Replace NT_MACRO with NT_USER_MACRO,
NT_BUILTIN_MACRO, NT_MACRO_ARG. Delete NT_ASSERTION.
(NTV_MACRO, NTV_ANSWER, NTV_BUILTIN, NTV_ARGUMENT, NTV_NONE):
Delete.
(CPP_HASHNODE_VALUE_IDX): Delete.
(union _cpp_hashnode_value): GTY tag from enum node_type directly.
(struct cpp_hashnode): Adjust GTY desc for value field.
(cpp_user_macro_p, cpp_builtin_macro_p, cpp_macro_p): Adjust.
* directives.c (undefine_macros): Clear value.anwers, adjust flag
clearing.
(_cpp_test_assertion): No need to check NT_ASSERTION.
(do_assert, do_unassert): Likewise.
* init.c (cpp_init_special_builtins): Set type not flags.
* macro.c (struct macro_arg_saved_data): Add type field.
(cpp_get_token_1): Check type not NT_VOID.
(_cpp_free_definition): Adjust flag clearing. Nullify
value.answers.
(_cpp_save_parameter, _cpp_unsave_parameters): Save and restore
type.
(lex_expansion_token): Check type not flags.
(_cpp_create_definition): Set type to NT_USER_MACRO.
(_cpp_notify_macro_use): Adjust type checking.
* pch.c (write_macdef, count_defs, write_defs, cpp_valid_state)
(save_macros): Adjust node type/flag handling.
* traditional.c (_cpp_scan_out_logical_line): Check type not flags.
From-SVN: r263667
2018-08-21 00:32:29 +08:00
|
|
|
is_void = true;
|
|
|
|
goto poisoned;
|
2007-06-01 10:12:37 +08:00
|
|
|
|
[CPP PATCH] node type
https://gcc.gnu.org/ml/gcc-patches/2018-08/msg01164.html
* include/cpplib.h (NODE_BUILTIN, NODE_MACRO_ARG): Delete.
Renumber others.
(enum node_type): Replace NT_MACRO with NT_USER_MACRO,
NT_BUILTIN_MACRO, NT_MACRO_ARG. Delete NT_ASSERTION.
(NTV_MACRO, NTV_ANSWER, NTV_BUILTIN, NTV_ARGUMENT, NTV_NONE):
Delete.
(CPP_HASHNODE_VALUE_IDX): Delete.
(union _cpp_hashnode_value): GTY tag from enum node_type directly.
(struct cpp_hashnode): Adjust GTY desc for value field.
(cpp_user_macro_p, cpp_builtin_macro_p, cpp_macro_p): Adjust.
* directives.c (undefine_macros): Clear value.anwers, adjust flag
clearing.
(_cpp_test_assertion): No need to check NT_ASSERTION.
(do_assert, do_unassert): Likewise.
* init.c (cpp_init_special_builtins): Set type not flags.
* macro.c (struct macro_arg_saved_data): Add type field.
(cpp_get_token_1): Check type not NT_VOID.
(_cpp_free_definition): Adjust flag clearing. Nullify
value.answers.
(_cpp_save_parameter, _cpp_unsave_parameters): Save and restore
type.
(lex_expansion_token): Check type not flags.
(_cpp_create_definition): Set type to NT_USER_MACRO.
(_cpp_notify_macro_use): Adjust type checking.
* pch.c (write_macdef, count_defs, write_defs, cpp_valid_state)
(save_macros): Adjust node type/flag handling.
* traditional.c (_cpp_scan_out_logical_line): Check type not flags.
From-SVN: r263667
2018-08-21 00:32:29 +08:00
|
|
|
case NT_BUILTIN_MACRO:
|
2003-01-10 10:22:34 +08:00
|
|
|
return 1;
|
2007-06-01 10:12:37 +08:00
|
|
|
|
[CPP PATCH] node type
https://gcc.gnu.org/ml/gcc-patches/2018-08/msg01164.html
* include/cpplib.h (NODE_BUILTIN, NODE_MACRO_ARG): Delete.
Renumber others.
(enum node_type): Replace NT_MACRO with NT_USER_MACRO,
NT_BUILTIN_MACRO, NT_MACRO_ARG. Delete NT_ASSERTION.
(NTV_MACRO, NTV_ANSWER, NTV_BUILTIN, NTV_ARGUMENT, NTV_NONE):
Delete.
(CPP_HASHNODE_VALUE_IDX): Delete.
(union _cpp_hashnode_value): GTY tag from enum node_type directly.
(struct cpp_hashnode): Adjust GTY desc for value field.
(cpp_user_macro_p, cpp_builtin_macro_p, cpp_macro_p): Adjust.
* directives.c (undefine_macros): Clear value.anwers, adjust flag
clearing.
(_cpp_test_assertion): No need to check NT_ASSERTION.
(do_assert, do_unassert): Likewise.
* init.c (cpp_init_special_builtins): Set type not flags.
* macro.c (struct macro_arg_saved_data): Add type field.
(cpp_get_token_1): Check type not NT_VOID.
(_cpp_free_definition): Adjust flag clearing. Nullify
value.answers.
(_cpp_save_parameter, _cpp_unsave_parameters): Save and restore
type.
(lex_expansion_token): Check type not flags.
(_cpp_create_definition): Set type to NT_USER_MACRO.
(_cpp_notify_macro_use): Adjust type checking.
* pch.c (write_macdef, count_defs, write_defs, cpp_valid_state)
(save_macros): Adjust node type/flag handling.
* traditional.c (_cpp_scan_out_logical_line): Check type not flags.
From-SVN: r263667
2018-08-21 00:32:29 +08:00
|
|
|
case NT_USER_MACRO:
|
|
|
|
if (hn->value.macro->kind != cmk_assert)
|
|
|
|
{
|
|
|
|
poisoned:
|
|
|
|
struct macrodef_struct s;
|
|
|
|
const unsigned char *defn;
|
|
|
|
|
|
|
|
s.name_length = NODE_LEN (hn);
|
|
|
|
s.flags = hn->flags & NODE_POISONED;
|
|
|
|
|
|
|
|
if (is_void)
|
|
|
|
{
|
|
|
|
defn = NODE_NAME (hn);
|
|
|
|
s.definition_length = s.name_length;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
defn = cpp_macro_definition (pfile, hn);
|
|
|
|
s.definition_length = ustrlen (defn);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fwrite (&s, sizeof (s), 1, f) != 1
|
|
|
|
|| fwrite (defn, 1, s.definition_length, f) != s.definition_length)
|
|
|
|
{
|
|
|
|
cpp_errno (pfile, CPP_DL_ERROR,
|
|
|
|
"while writing precompiled header");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2003-01-10 10:22:34 +08:00
|
|
|
return 1;
|
|
|
|
|
|
|
|
default:
|
|
|
|
abort ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* This structure records the names of the defined macros.
|
|
|
|
It's also used as a callback structure for size_initial_idents
|
|
|
|
and save_idents. */
|
|
|
|
|
|
|
|
struct cpp_savedstate
|
|
|
|
{
|
|
|
|
/* A hash table of the defined identifiers. */
|
|
|
|
htab_t definedhash;
|
|
|
|
/* The size of the definitions of those identifiers (the size of
|
|
|
|
'definedstrs'). */
|
|
|
|
size_t hashsize;
|
2003-04-01 04:02:40 +08:00
|
|
|
/* Number of definitions */
|
|
|
|
size_t n_defs;
|
2003-06-23 23:27:37 +08:00
|
|
|
/* Array of definitions. In cpp_write_pch_deps it is used for sorting. */
|
2003-04-01 04:02:40 +08:00
|
|
|
cpp_hashnode **defs;
|
2003-01-10 10:22:34 +08:00
|
|
|
/* Space for the next definition. Definitions are null-terminated
|
|
|
|
strings. */
|
|
|
|
unsigned char *definedstrs;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Save this identifier into the state: put it in the hash table,
|
|
|
|
put the definition in 'definedstrs'. */
|
|
|
|
|
|
|
|
static int
|
* cpplib.h, cpphash.h, cppcharset.c, cpperror.c, cppexp.c
* cppfiles.c, cpphash.c, cppinit.c, cpplex.c, cpplib.c
* cppmacro.c, cpppch.c, cpptrad.c, cppspec.c: Convert to
ISO C: new-style function declarations, no need for PARAMS,
no special punctuation on indirect function calls, use string
constant concatenation where convenient.
From-SVN: r68070
2003-06-17 14:17:44 +08:00
|
|
|
save_idents (cpp_reader *pfile ATTRIBUTE_UNUSED, cpp_hashnode *hn, void *ss_p)
|
2003-01-10 10:22:34 +08:00
|
|
|
{
|
|
|
|
struct cpp_savedstate *const ss = (struct cpp_savedstate *)ss_p;
|
2007-06-01 10:12:37 +08:00
|
|
|
|
2003-01-10 10:22:34 +08:00
|
|
|
if (hn->type != NT_VOID)
|
|
|
|
{
|
|
|
|
struct cpp_string news;
|
|
|
|
void **slot;
|
|
|
|
|
|
|
|
news.len = NODE_LEN (hn);
|
|
|
|
news.text= NODE_NAME (hn);
|
|
|
|
slot = htab_find_slot (ss->definedhash, &news, INSERT);
|
|
|
|
if (*slot == NULL)
|
|
|
|
{
|
|
|
|
struct cpp_string *sp;
|
|
|
|
unsigned char *text;
|
2007-06-01 10:12:37 +08:00
|
|
|
|
2005-05-28 23:52:48 +08:00
|
|
|
sp = XNEW (struct cpp_string);
|
2003-01-10 10:22:34 +08:00
|
|
|
*slot = sp;
|
|
|
|
|
|
|
|
sp->len = NODE_LEN (hn);
|
2005-05-28 23:52:48 +08:00
|
|
|
sp->text = text = XNEWVEC (unsigned char, NODE_LEN (hn));
|
2003-01-10 10:22:34 +08:00
|
|
|
memcpy (text, NODE_NAME (hn), NODE_LEN (hn));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Hash some memory in a generic way. */
|
|
|
|
|
|
|
|
static hashval_t
|
* cpplib.h, cpphash.h, cppcharset.c, cpperror.c, cppexp.c
* cppfiles.c, cpphash.c, cppinit.c, cpplex.c, cpplib.c
* cppmacro.c, cpppch.c, cpptrad.c, cppspec.c: Convert to
ISO C: new-style function declarations, no need for PARAMS,
no special punctuation on indirect function calls, use string
constant concatenation where convenient.
From-SVN: r68070
2003-06-17 14:17:44 +08:00
|
|
|
hashmem (const void *p_p, size_t sz)
|
2003-01-10 10:22:34 +08:00
|
|
|
{
|
|
|
|
const unsigned char *p = (const unsigned char *)p_p;
|
|
|
|
size_t i;
|
|
|
|
hashval_t h;
|
2007-06-01 10:12:37 +08:00
|
|
|
|
2003-01-10 10:22:34 +08:00
|
|
|
h = 0;
|
|
|
|
for (i = 0; i < sz; i++)
|
|
|
|
h = h * 67 - (*p++ - 113);
|
|
|
|
return h;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Hash a cpp string for the hashtable machinery. */
|
|
|
|
|
|
|
|
static hashval_t
|
* cpplib.h, cpphash.h, cppcharset.c, cpperror.c, cppexp.c
* cppfiles.c, cpphash.c, cppinit.c, cpplex.c, cpplib.c
* cppmacro.c, cpppch.c, cpptrad.c, cppspec.c: Convert to
ISO C: new-style function declarations, no need for PARAMS,
no special punctuation on indirect function calls, use string
constant concatenation where convenient.
From-SVN: r68070
2003-06-17 14:17:44 +08:00
|
|
|
cpp_string_hash (const void *a_p)
|
2003-01-10 10:22:34 +08:00
|
|
|
{
|
|
|
|
const struct cpp_string *a = (const struct cpp_string *) a_p;
|
|
|
|
return hashmem (a->text, a->len);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Compare two cpp strings for the hashtable machinery. */
|
|
|
|
|
|
|
|
static int
|
* cpplib.h, cpphash.h, cppcharset.c, cpperror.c, cppexp.c
* cppfiles.c, cpphash.c, cppinit.c, cpplex.c, cpplib.c
* cppmacro.c, cpppch.c, cpptrad.c, cppspec.c: Convert to
ISO C: new-style function declarations, no need for PARAMS,
no special punctuation on indirect function calls, use string
constant concatenation where convenient.
From-SVN: r68070
2003-06-17 14:17:44 +08:00
|
|
|
cpp_string_eq (const void *a_p, const void *b_p)
|
2003-01-10 10:22:34 +08:00
|
|
|
{
|
|
|
|
const struct cpp_string *a = (const struct cpp_string *) a_p;
|
|
|
|
const struct cpp_string *b = (const struct cpp_string *) b_p;
|
|
|
|
return (a->len == b->len
|
|
|
|
&& memcmp (a->text, b->text, a->len) == 0);
|
|
|
|
}
|
|
|
|
|
2013-03-02 05:06:04 +08:00
|
|
|
/* Free memory associated with cpp_string. */
|
|
|
|
|
|
|
|
static void
|
|
|
|
cpp_string_free (void *a_p)
|
|
|
|
{
|
|
|
|
struct cpp_string *a = (struct cpp_string *) a_p;
|
|
|
|
free ((void *) a->text);
|
|
|
|
free (a);
|
|
|
|
}
|
|
|
|
|
2003-01-10 10:22:34 +08:00
|
|
|
/* Save the current definitions of the cpp_reader for dependency
|
|
|
|
checking purposes. When writing a precompiled header, this should
|
|
|
|
be called at the same point in the compilation as cpp_valid_state
|
|
|
|
would be called when reading the precompiled header back in. */
|
|
|
|
|
|
|
|
int
|
* cpplib.h, cpphash.h, cppcharset.c, cpperror.c, cppexp.c
* cppfiles.c, cpphash.c, cppinit.c, cpplex.c, cpplib.c
* cppmacro.c, cpppch.c, cpptrad.c, cppspec.c: Convert to
ISO C: new-style function declarations, no need for PARAMS,
no special punctuation on indirect function calls, use string
constant concatenation where convenient.
From-SVN: r68070
2003-06-17 14:17:44 +08:00
|
|
|
cpp_save_state (cpp_reader *r, FILE *f)
|
2003-01-10 10:22:34 +08:00
|
|
|
{
|
|
|
|
/* Save the list of non-void identifiers for the dependency checking. */
|
2005-05-28 23:52:48 +08:00
|
|
|
r->savedstate = XNEW (struct cpp_savedstate);
|
2007-06-01 10:12:37 +08:00
|
|
|
r->savedstate->definedhash = htab_create (100, cpp_string_hash,
|
2013-03-02 05:06:04 +08:00
|
|
|
cpp_string_eq, cpp_string_free);
|
2003-01-10 10:22:34 +08:00
|
|
|
cpp_forall_identifiers (r, save_idents, r->savedstate);
|
2007-06-01 10:12:37 +08:00
|
|
|
|
2003-01-10 10:22:34 +08:00
|
|
|
/* Write out the list of defined identifiers. */
|
|
|
|
cpp_forall_identifiers (r, write_macdef, f);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Calculate the 'hashsize' field of the saved state. */
|
|
|
|
|
|
|
|
static int
|
* cpplib.h, cpphash.h, cppcharset.c, cpperror.c, cppexp.c
* cppfiles.c, cpphash.c, cppinit.c, cpplex.c, cpplib.c
* cppmacro.c, cpppch.c, cpptrad.c, cppspec.c: Convert to
ISO C: new-style function declarations, no need for PARAMS,
no special punctuation on indirect function calls, use string
constant concatenation where convenient.
From-SVN: r68070
2003-06-17 14:17:44 +08:00
|
|
|
count_defs (cpp_reader *pfile ATTRIBUTE_UNUSED, cpp_hashnode *hn, void *ss_p)
|
2003-01-10 10:22:34 +08:00
|
|
|
{
|
|
|
|
struct cpp_savedstate *const ss = (struct cpp_savedstate *)ss_p;
|
2007-06-01 10:12:37 +08:00
|
|
|
|
2003-01-10 10:22:34 +08:00
|
|
|
switch (hn->type)
|
|
|
|
{
|
[CPP PATCH] node type
https://gcc.gnu.org/ml/gcc-patches/2018-08/msg01164.html
* include/cpplib.h (NODE_BUILTIN, NODE_MACRO_ARG): Delete.
Renumber others.
(enum node_type): Replace NT_MACRO with NT_USER_MACRO,
NT_BUILTIN_MACRO, NT_MACRO_ARG. Delete NT_ASSERTION.
(NTV_MACRO, NTV_ANSWER, NTV_BUILTIN, NTV_ARGUMENT, NTV_NONE):
Delete.
(CPP_HASHNODE_VALUE_IDX): Delete.
(union _cpp_hashnode_value): GTY tag from enum node_type directly.
(struct cpp_hashnode): Adjust GTY desc for value field.
(cpp_user_macro_p, cpp_builtin_macro_p, cpp_macro_p): Adjust.
* directives.c (undefine_macros): Clear value.anwers, adjust flag
clearing.
(_cpp_test_assertion): No need to check NT_ASSERTION.
(do_assert, do_unassert): Likewise.
* init.c (cpp_init_special_builtins): Set type not flags.
* macro.c (struct macro_arg_saved_data): Add type field.
(cpp_get_token_1): Check type not NT_VOID.
(_cpp_free_definition): Adjust flag clearing. Nullify
value.answers.
(_cpp_save_parameter, _cpp_unsave_parameters): Save and restore
type.
(lex_expansion_token): Check type not flags.
(_cpp_create_definition): Set type to NT_USER_MACRO.
(_cpp_notify_macro_use): Adjust type checking.
* pch.c (write_macdef, count_defs, write_defs, cpp_valid_state)
(save_macros): Adjust node type/flag handling.
* traditional.c (_cpp_scan_out_logical_line): Check type not flags.
From-SVN: r263667
2018-08-21 00:32:29 +08:00
|
|
|
case NT_BUILTIN_MACRO:
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
case NT_USER_MACRO:
|
|
|
|
if (hn->value.macro->kind == cmk_assert)
|
2003-01-10 10:22:34 +08:00
|
|
|
return 1;
|
2007-06-01 10:12:37 +08:00
|
|
|
|
2016-08-12 18:30:47 +08:00
|
|
|
/* fall through. */
|
2003-01-10 10:22:34 +08:00
|
|
|
|
|
|
|
case NT_VOID:
|
|
|
|
{
|
|
|
|
struct cpp_string news;
|
|
|
|
void **slot;
|
2007-06-01 10:12:37 +08:00
|
|
|
|
2003-01-10 10:22:34 +08:00
|
|
|
news.len = NODE_LEN (hn);
|
|
|
|
news.text = NODE_NAME (hn);
|
2005-05-28 23:52:48 +08:00
|
|
|
slot = (void **) htab_find (ss->definedhash, &news);
|
2003-01-10 10:22:34 +08:00
|
|
|
if (slot == NULL)
|
2003-04-01 04:02:40 +08:00
|
|
|
{
|
|
|
|
ss->hashsize += NODE_LEN (hn) + 1;
|
|
|
|
ss->n_defs += 1;
|
|
|
|
}
|
2003-01-10 10:22:34 +08:00
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
default:
|
|
|
|
abort ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-06-23 23:27:37 +08:00
|
|
|
/* Collect the identifiers into the state's string table. */
|
2003-01-10 10:22:34 +08:00
|
|
|
static int
|
* cpplib.h, cpphash.h, cppcharset.c, cpperror.c, cppexp.c
* cppfiles.c, cpphash.c, cppinit.c, cpplex.c, cpplib.c
* cppmacro.c, cpppch.c, cpptrad.c, cppspec.c: Convert to
ISO C: new-style function declarations, no need for PARAMS,
no special punctuation on indirect function calls, use string
constant concatenation where convenient.
From-SVN: r68070
2003-06-17 14:17:44 +08:00
|
|
|
write_defs (cpp_reader *pfile ATTRIBUTE_UNUSED, cpp_hashnode *hn, void *ss_p)
|
2003-01-10 10:22:34 +08:00
|
|
|
{
|
|
|
|
struct cpp_savedstate *const ss = (struct cpp_savedstate *)ss_p;
|
2007-06-01 10:12:37 +08:00
|
|
|
|
2003-01-10 10:22:34 +08:00
|
|
|
switch (hn->type)
|
|
|
|
{
|
[CPP PATCH] node type
https://gcc.gnu.org/ml/gcc-patches/2018-08/msg01164.html
* include/cpplib.h (NODE_BUILTIN, NODE_MACRO_ARG): Delete.
Renumber others.
(enum node_type): Replace NT_MACRO with NT_USER_MACRO,
NT_BUILTIN_MACRO, NT_MACRO_ARG. Delete NT_ASSERTION.
(NTV_MACRO, NTV_ANSWER, NTV_BUILTIN, NTV_ARGUMENT, NTV_NONE):
Delete.
(CPP_HASHNODE_VALUE_IDX): Delete.
(union _cpp_hashnode_value): GTY tag from enum node_type directly.
(struct cpp_hashnode): Adjust GTY desc for value field.
(cpp_user_macro_p, cpp_builtin_macro_p, cpp_macro_p): Adjust.
* directives.c (undefine_macros): Clear value.anwers, adjust flag
clearing.
(_cpp_test_assertion): No need to check NT_ASSERTION.
(do_assert, do_unassert): Likewise.
* init.c (cpp_init_special_builtins): Set type not flags.
* macro.c (struct macro_arg_saved_data): Add type field.
(cpp_get_token_1): Check type not NT_VOID.
(_cpp_free_definition): Adjust flag clearing. Nullify
value.answers.
(_cpp_save_parameter, _cpp_unsave_parameters): Save and restore
type.
(lex_expansion_token): Check type not flags.
(_cpp_create_definition): Set type to NT_USER_MACRO.
(_cpp_notify_macro_use): Adjust type checking.
* pch.c (write_macdef, count_defs, write_defs, cpp_valid_state)
(save_macros): Adjust node type/flag handling.
* traditional.c (_cpp_scan_out_logical_line): Check type not flags.
From-SVN: r263667
2018-08-21 00:32:29 +08:00
|
|
|
case NT_BUILTIN_MACRO:
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
case NT_USER_MACRO:
|
|
|
|
if (hn->value.macro->kind == cmk_assert)
|
2003-01-10 10:22:34 +08:00
|
|
|
return 1;
|
2007-06-01 10:12:37 +08:00
|
|
|
|
2016-08-12 18:30:47 +08:00
|
|
|
/* fall through. */
|
2003-01-10 10:22:34 +08:00
|
|
|
|
|
|
|
case NT_VOID:
|
|
|
|
{
|
|
|
|
struct cpp_string news;
|
|
|
|
void **slot;
|
2007-06-01 10:12:37 +08:00
|
|
|
|
2003-01-10 10:22:34 +08:00
|
|
|
news.len = NODE_LEN (hn);
|
|
|
|
news.text = NODE_NAME (hn);
|
2005-05-28 23:52:48 +08:00
|
|
|
slot = (void **) htab_find (ss->definedhash, &news);
|
2003-01-10 10:22:34 +08:00
|
|
|
if (slot == NULL)
|
|
|
|
{
|
2003-04-01 04:02:40 +08:00
|
|
|
ss->defs[ss->n_defs] = hn;
|
|
|
|
ss->n_defs += 1;
|
2003-01-10 10:22:34 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
default:
|
|
|
|
abort ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-04-01 04:02:40 +08:00
|
|
|
/* Comparison function for qsort. The arguments point to pointers of
|
|
|
|
type ht_hashnode *. */
|
|
|
|
static int
|
* cpplib.h, cpphash.h, cppcharset.c, cpperror.c, cppexp.c
* cppfiles.c, cpphash.c, cppinit.c, cpplex.c, cpplib.c
* cppmacro.c, cpppch.c, cpptrad.c, cppspec.c: Convert to
ISO C: new-style function declarations, no need for PARAMS,
no special punctuation on indirect function calls, use string
constant concatenation where convenient.
From-SVN: r68070
2003-06-17 14:17:44 +08:00
|
|
|
comp_hashnodes (const void *px, const void *py)
|
2003-04-01 04:02:40 +08:00
|
|
|
{
|
|
|
|
cpp_hashnode *x = *(cpp_hashnode **) px;
|
|
|
|
cpp_hashnode *y = *(cpp_hashnode **) py;
|
|
|
|
return ustrcmp (NODE_NAME (x), NODE_NAME (y));
|
|
|
|
}
|
|
|
|
|
2003-01-10 10:22:34 +08:00
|
|
|
/* Write out the remainder of the dependency information. This should be
|
|
|
|
called after the PCH is ready to be saved. */
|
|
|
|
|
|
|
|
int
|
* cpplib.h, cpphash.h, cppcharset.c, cpperror.c, cppexp.c
* cppfiles.c, cpphash.c, cppinit.c, cpplex.c, cpplib.c
* cppmacro.c, cpppch.c, cpptrad.c, cppspec.c: Convert to
ISO C: new-style function declarations, no need for PARAMS,
no special punctuation on indirect function calls, use string
constant concatenation where convenient.
From-SVN: r68070
2003-06-17 14:17:44 +08:00
|
|
|
cpp_write_pch_deps (cpp_reader *r, FILE *f)
|
2003-01-10 10:22:34 +08:00
|
|
|
{
|
|
|
|
struct macrodef_struct z;
|
|
|
|
struct cpp_savedstate *const ss = r->savedstate;
|
|
|
|
unsigned char *definedstrs;
|
2003-04-01 04:02:40 +08:00
|
|
|
size_t i;
|
2007-06-01 10:12:37 +08:00
|
|
|
|
2003-04-01 04:02:40 +08:00
|
|
|
/* Collect the list of identifiers which have been seen and
|
2003-01-10 10:22:34 +08:00
|
|
|
weren't defined to anything previously. */
|
2003-04-01 04:02:40 +08:00
|
|
|
ss->hashsize = 0;
|
|
|
|
ss->n_defs = 0;
|
2003-01-10 10:22:34 +08:00
|
|
|
cpp_forall_identifiers (r, count_defs, ss);
|
2003-04-01 04:02:40 +08:00
|
|
|
|
2005-05-28 23:52:48 +08:00
|
|
|
ss->defs = XNEWVEC (cpp_hashnode *, ss->n_defs);
|
2003-04-01 04:02:40 +08:00
|
|
|
ss->n_defs = 0;
|
2003-01-10 10:22:34 +08:00
|
|
|
cpp_forall_identifiers (r, write_defs, ss);
|
2003-04-01 04:02:40 +08:00
|
|
|
|
2003-06-23 23:27:37 +08:00
|
|
|
/* Sort the list, copy it into a buffer, and write it out. */
|
2003-04-01 04:02:40 +08:00
|
|
|
qsort (ss->defs, ss->n_defs, sizeof (cpp_hashnode *), &comp_hashnodes);
|
2005-05-28 23:52:48 +08:00
|
|
|
definedstrs = ss->definedstrs = XNEWVEC (unsigned char, ss->hashsize);
|
2003-04-01 04:02:40 +08:00
|
|
|
for (i = 0; i < ss->n_defs; ++i)
|
|
|
|
{
|
|
|
|
size_t len = NODE_LEN (ss->defs[i]);
|
|
|
|
memcpy (definedstrs, NODE_NAME (ss->defs[i]), len + 1);
|
|
|
|
definedstrs += len + 1;
|
|
|
|
}
|
|
|
|
|
2003-01-10 10:22:34 +08:00
|
|
|
memset (&z, 0, sizeof (z));
|
|
|
|
z.definition_length = ss->hashsize;
|
|
|
|
if (fwrite (&z, sizeof (z), 1, f) != 1
|
2003-04-01 04:02:40 +08:00
|
|
|
|| fwrite (ss->definedstrs, ss->hashsize, 1, f) != 1)
|
2003-01-10 10:22:34 +08:00
|
|
|
{
|
re PR preprocessor/12847 (xxx.c:1:20: xxxx.h: No such file or directory)
PR preprocessor/12847
* cppfiles.c, cppexp.c, cpperror.c, cpplib.h, cpplib.c, cpplex.c,
cppinit.c, cpptrad.c, cppmacro.c, fix-header.c, cpppch.c, c-pch.c,
c-incpath.c, cppcharset.c (DL_WARNING, DL_WARNING_SYSHDR, DL_PEDWARN,
DL_ERROR, DL_ICE, DL_EXTRACT, DL_WARNING_P): Prefix macro names with
"CPP_".
From-SVN: r73183
2003-11-02 06:56:54 +08:00
|
|
|
cpp_errno (r, CPP_DL_ERROR, "while writing precompiled header");
|
2003-01-10 10:22:34 +08:00
|
|
|
return -1;
|
|
|
|
}
|
2003-04-01 04:02:40 +08:00
|
|
|
free (ss->definedstrs);
|
2013-03-02 05:06:04 +08:00
|
|
|
free (ss->defs);
|
|
|
|
htab_delete (ss->definedhash);
|
2003-01-10 10:22:34 +08:00
|
|
|
|
|
|
|
/* Free the saved state. */
|
|
|
|
free (ss);
|
|
|
|
r->savedstate = NULL;
|
2007-05-25 04:55:36 +08:00
|
|
|
|
|
|
|
/* Save the next value of __COUNTER__. */
|
|
|
|
if (fwrite (&r->counter, sizeof (r->counter), 1, f) != 1)
|
|
|
|
{
|
|
|
|
cpp_errno (r, CPP_DL_ERROR, "while writing precompiled header");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2003-01-10 10:22:34 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Write out the definitions of the preprocessor, in a form suitable for
|
|
|
|
cpp_read_state. */
|
|
|
|
|
|
|
|
int
|
* cpplib.h, cpphash.h, cppcharset.c, cpperror.c, cppexp.c
* cppfiles.c, cpphash.c, cppinit.c, cpplex.c, cpplib.c
* cppmacro.c, cpppch.c, cpptrad.c, cppspec.c: Convert to
ISO C: new-style function declarations, no need for PARAMS,
no special punctuation on indirect function calls, use string
constant concatenation where convenient.
From-SVN: r68070
2003-06-17 14:17:44 +08:00
|
|
|
cpp_write_pch_state (cpp_reader *r, FILE *f)
|
2003-01-10 10:22:34 +08:00
|
|
|
{
|
|
|
|
if (!r->deps)
|
|
|
|
r->deps = deps_init ();
|
|
|
|
|
|
|
|
if (deps_save (r->deps, f) != 0)
|
|
|
|
{
|
re PR preprocessor/12847 (xxx.c:1:20: xxxx.h: No such file or directory)
PR preprocessor/12847
* cppfiles.c, cppexp.c, cpperror.c, cpplib.h, cpplib.c, cpplex.c,
cppinit.c, cpptrad.c, cppmacro.c, fix-header.c, cpppch.c, c-pch.c,
c-incpath.c, cppcharset.c (DL_WARNING, DL_WARNING_SYSHDR, DL_PEDWARN,
DL_ERROR, DL_ICE, DL_EXTRACT, DL_WARNING_P): Prefix macro names with
"CPP_".
From-SVN: r73183
2003-11-02 06:56:54 +08:00
|
|
|
cpp_errno (r, CPP_DL_ERROR, "while writing precompiled header");
|
2003-01-10 10:22:34 +08:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2004-01-17 08:37:47 +08:00
|
|
|
if (! _cpp_save_file_entries (r, f))
|
|
|
|
{
|
|
|
|
cpp_errno (r, CPP_DL_ERROR, "while writing precompiled header");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2007-05-25 04:55:36 +08:00
|
|
|
/* Save the next __COUNTER__ value. When we include a precompiled header,
|
|
|
|
we need to start at the offset we would have if the header had been
|
|
|
|
included normally. */
|
|
|
|
if (fwrite (&r->counter, sizeof (r->counter), 1, f) != 1)
|
|
|
|
{
|
|
|
|
cpp_errno (r, CPP_DL_ERROR, "while writing precompiled header");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2009-11-12 02:37:19 +08:00
|
|
|
/* Write saved macros. */
|
|
|
|
if (! _cpp_save_pushed_macros (r, f))
|
|
|
|
{
|
|
|
|
cpp_errno (r, CPP_DL_ERROR, "while writing precompiled header");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2003-01-10 10:22:34 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-11-12 02:37:19 +08:00
|
|
|
static int
|
|
|
|
_cpp_restore_pushed_macros (cpp_reader *r, FILE *f)
|
|
|
|
{
|
|
|
|
size_t count_saved = 0;
|
|
|
|
size_t i;
|
|
|
|
struct def_pragma_macro *p;
|
|
|
|
size_t nlen;
|
|
|
|
uchar *defn;
|
|
|
|
size_t defnlen;
|
|
|
|
|
|
|
|
if (fread (&count_saved, sizeof (count_saved), 1, f) != 1)
|
|
|
|
return 0;
|
|
|
|
if (! count_saved)
|
|
|
|
return 1;
|
|
|
|
for (i = 0; i < count_saved; i++)
|
|
|
|
{
|
|
|
|
if (fread (&nlen, sizeof (nlen), 1, f) != 1)
|
|
|
|
return 0;
|
|
|
|
p = XNEW (struct def_pragma_macro);
|
2010-09-30 02:18:38 +08:00
|
|
|
memset (p, 0, sizeof (struct def_pragma_macro));
|
2009-11-12 02:37:19 +08:00
|
|
|
p->name = XNEWVAR (char, nlen + 1);
|
|
|
|
p->name[nlen] = 0;
|
|
|
|
if (fread (p->name, nlen, 1, f) != 1)
|
|
|
|
return 0;
|
|
|
|
if (fread (&defnlen, sizeof (defnlen), 1, f) != 1)
|
|
|
|
return 0;
|
2010-09-30 02:18:38 +08:00
|
|
|
if (defnlen == 0)
|
|
|
|
p->is_undef = 1;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
defn = XNEWVEC (uchar, defnlen + 1);
|
|
|
|
defn[defnlen] = 0;
|
|
|
|
|
|
|
|
if (fread (defn, defnlen, 1, f) != 1)
|
|
|
|
return 0;
|
2009-11-12 02:37:19 +08:00
|
|
|
|
2010-09-30 02:18:38 +08:00
|
|
|
p->definition = defn;
|
2018-11-14 04:05:03 +08:00
|
|
|
if (fread (&(p->line), sizeof (location_t), 1, f) != 1)
|
2010-09-30 02:18:38 +08:00
|
|
|
return 0;
|
|
|
|
defnlen = 0;
|
|
|
|
if (fread (&defnlen, sizeof (defnlen), 1, f) != 1)
|
|
|
|
return 0;
|
|
|
|
p->syshdr = ((defnlen & 1) != 0 ? 1 : 0);
|
|
|
|
p->used = ((defnlen & 2) != 0 ? 1 : 0);
|
|
|
|
}
|
2009-11-12 02:37:19 +08:00
|
|
|
|
|
|
|
p->next = r->pushed_macros;
|
|
|
|
r->pushed_macros = p;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
_cpp_save_pushed_macros (cpp_reader *r, FILE *f)
|
|
|
|
{
|
|
|
|
size_t count_saved = 0;
|
|
|
|
size_t i;
|
|
|
|
struct def_pragma_macro *p,**pp;
|
|
|
|
size_t defnlen;
|
|
|
|
|
|
|
|
/* Get count. */
|
|
|
|
p = r->pushed_macros;
|
|
|
|
while (p != NULL)
|
|
|
|
{
|
|
|
|
count_saved++;
|
|
|
|
p = p->next;
|
|
|
|
}
|
|
|
|
if (fwrite (&count_saved, sizeof (count_saved), 1, f) != 1)
|
|
|
|
return 0;
|
|
|
|
if (!count_saved)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
pp = (struct def_pragma_macro **) alloca (sizeof (struct def_pragma_macro *)
|
|
|
|
* count_saved);
|
|
|
|
/* Store them in reverse order. */
|
|
|
|
p = r->pushed_macros;
|
|
|
|
i = count_saved;
|
|
|
|
while (p != NULL)
|
|
|
|
{
|
|
|
|
--i;
|
|
|
|
pp[i] = p;
|
|
|
|
p = p->next;
|
|
|
|
}
|
|
|
|
for (i = 0; i < count_saved; i++)
|
|
|
|
{
|
|
|
|
defnlen = strlen (pp[i]->name);
|
|
|
|
if (fwrite (&defnlen, sizeof (size_t), 1, f) != 1
|
|
|
|
|| fwrite (pp[i]->name, defnlen, 1, f) != 1)
|
|
|
|
return 0;
|
2010-09-30 02:18:38 +08:00
|
|
|
if (pp[i]->is_undef)
|
|
|
|
{
|
|
|
|
defnlen = 0;
|
|
|
|
if (fwrite (&defnlen, sizeof (size_t), 1, f) != 1)
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
defnlen = ustrlen (pp[i]->definition);
|
|
|
|
if (fwrite (&defnlen, sizeof (size_t), 1, f) != 1
|
|
|
|
|| fwrite (pp[i]->definition, defnlen, 1, f) != 1)
|
|
|
|
return 0;
|
2018-11-14 04:05:03 +08:00
|
|
|
if (fwrite (&(pp[i]->line), sizeof (location_t), 1, f) != 1)
|
2010-09-30 02:18:38 +08:00
|
|
|
return 0;
|
|
|
|
defnlen = 0;
|
|
|
|
defnlen |= (pp[i]->syshdr != 0 ? 1 : 0);
|
|
|
|
defnlen |= (pp[i]->used != 0 ? 2 : 0);
|
|
|
|
if (fwrite (&defnlen, sizeof (defnlen), 1, f) != 1)
|
|
|
|
return 0;
|
|
|
|
}
|
2009-11-12 02:37:19 +08:00
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2003-04-01 04:02:40 +08:00
|
|
|
|
|
|
|
/* Data structure to transform hash table nodes into a sorted list */
|
|
|
|
|
|
|
|
struct ht_node_list
|
|
|
|
{
|
|
|
|
/* Array of nodes */
|
|
|
|
cpp_hashnode **defs;
|
|
|
|
/* Number of nodes in the array */
|
|
|
|
size_t n_defs;
|
|
|
|
/* Size of the allocated array */
|
|
|
|
size_t asize;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Callback for collecting identifiers from hash table */
|
|
|
|
|
|
|
|
static int
|
* cpplib.h, cpphash.h, cppcharset.c, cpperror.c, cppexp.c
* cppfiles.c, cpphash.c, cppinit.c, cpplex.c, cpplib.c
* cppmacro.c, cpppch.c, cpptrad.c, cppspec.c: Convert to
ISO C: new-style function declarations, no need for PARAMS,
no special punctuation on indirect function calls, use string
constant concatenation where convenient.
From-SVN: r68070
2003-06-17 14:17:44 +08:00
|
|
|
collect_ht_nodes (cpp_reader *pfile ATTRIBUTE_UNUSED, cpp_hashnode *hn,
|
|
|
|
void *nl_p)
|
2003-04-01 04:02:40 +08:00
|
|
|
{
|
|
|
|
struct ht_node_list *const nl = (struct ht_node_list *)nl_p;
|
|
|
|
|
|
|
|
if (hn->type != NT_VOID || hn->flags & NODE_POISONED)
|
|
|
|
{
|
|
|
|
if (nl->n_defs == nl->asize)
|
|
|
|
{
|
|
|
|
nl->asize *= 2;
|
2005-05-28 23:52:48 +08:00
|
|
|
nl->defs = XRESIZEVEC (cpp_hashnode *, nl->defs, nl->asize);
|
2003-04-01 04:02:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
nl->defs[nl->n_defs] = hn;
|
|
|
|
++nl->n_defs;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-01-10 10:22:34 +08:00
|
|
|
/* Return nonzero if FD is a precompiled header which is consistent
|
|
|
|
with the preprocessor's current definitions. It will be consistent
|
|
|
|
when:
|
|
|
|
|
2007-06-01 10:12:37 +08:00
|
|
|
- anything that was defined just before the PCH was generated
|
2003-01-10 10:22:34 +08:00
|
|
|
is defined the same way now; and
|
|
|
|
- anything that was not defined then, but is defined now, was not
|
|
|
|
used by the PCH.
|
|
|
|
|
|
|
|
NAME is used to print warnings if `warn_invalid_pch' is set in the
|
|
|
|
reader's flags.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int
|
* cpplib.h, cpphash.h, cppcharset.c, cpperror.c, cppexp.c
* cppfiles.c, cpphash.c, cppinit.c, cpplex.c, cpplib.c
* cppmacro.c, cpppch.c, cpptrad.c, cppspec.c: Convert to
ISO C: new-style function declarations, no need for PARAMS,
no special punctuation on indirect function calls, use string
constant concatenation where convenient.
From-SVN: r68070
2003-06-17 14:17:44 +08:00
|
|
|
cpp_valid_state (cpp_reader *r, const char *name, int fd)
|
2003-01-10 10:22:34 +08:00
|
|
|
{
|
|
|
|
struct macrodef_struct m;
|
|
|
|
size_t namebufsz = 256;
|
2005-05-28 23:52:48 +08:00
|
|
|
unsigned char *namebuf = XNEWVEC (unsigned char, namebufsz);
|
2003-01-10 10:22:34 +08:00
|
|
|
unsigned char *undeftab = NULL;
|
2003-04-18 07:10:17 +08:00
|
|
|
struct ht_node_list nl = { 0, 0, 0 };
|
2003-04-01 04:02:40 +08:00
|
|
|
unsigned char *first, *last;
|
2003-01-10 10:22:34 +08:00
|
|
|
unsigned int i;
|
2007-05-25 04:55:36 +08:00
|
|
|
unsigned int counter;
|
2007-06-01 10:12:37 +08:00
|
|
|
|
2003-01-10 10:22:34 +08:00
|
|
|
/* Read in the list of identifiers that must be defined
|
|
|
|
Check that they are defined in the same way. */
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
cpp_hashnode *h;
|
|
|
|
const unsigned char *newdefn;
|
2007-06-01 10:12:37 +08:00
|
|
|
|
2003-01-10 10:22:34 +08:00
|
|
|
if (read (fd, &m, sizeof (m)) != sizeof (m))
|
|
|
|
goto error;
|
2007-06-01 10:12:37 +08:00
|
|
|
|
2003-01-10 10:22:34 +08:00
|
|
|
if (m.name_length == 0)
|
|
|
|
break;
|
|
|
|
|
2004-06-22 14:51:56 +08:00
|
|
|
/* If this file is already preprocessed, there won't be any
|
|
|
|
macros defined, and that's OK. */
|
|
|
|
if (CPP_OPTION (r, preprocessed))
|
|
|
|
{
|
|
|
|
if (lseek (fd, m.definition_length, SEEK_CUR) == -1)
|
|
|
|
goto error;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2003-01-10 10:22:34 +08:00
|
|
|
if (m.definition_length > namebufsz)
|
|
|
|
{
|
|
|
|
free (namebuf);
|
|
|
|
namebufsz = m.definition_length + 256;
|
2005-05-28 23:52:48 +08:00
|
|
|
namebuf = XNEWVEC (unsigned char, namebufsz);
|
2003-01-10 10:22:34 +08:00
|
|
|
}
|
2004-06-22 14:51:56 +08:00
|
|
|
|
2007-06-01 10:12:37 +08:00
|
|
|
if ((size_t)read (fd, namebuf, m.definition_length)
|
2003-01-10 10:22:34 +08:00
|
|
|
!= m.definition_length)
|
|
|
|
goto error;
|
2007-06-01 10:12:37 +08:00
|
|
|
|
2003-01-10 10:22:34 +08:00
|
|
|
h = cpp_lookup (r, namebuf, m.name_length);
|
|
|
|
if (m.flags & NODE_POISONED
|
|
|
|
|| h->flags & NODE_POISONED)
|
|
|
|
{
|
2008-12-11 01:31:07 +08:00
|
|
|
if (CPP_OPTION (r, warn_invalid_pch))
|
diagnostic.h (diagnostic_override_option_index): New macro to set a diagnostic's option_index.
* diagnostic.h (diagnostic_override_option_index): New macro to
set a diagnostic's option_index.
* c-tree.h (c_cpp_error): Add warning reason argument.
* opts.c (_warning_as_error_callback): New.
(register_warning_as_error_callback): Store callback for
warnings enabled via enable_warning_as_error.
(enable_warning_as_error): Call callback, minor code tidy.
* opts.h (register_warning_as_error_callback): Declare.
* c-opts.c (warning_as_error_callback): New, set cpp_opts flag in
response to -Werror=.
(c_common_init_options): Register warning_as_error_callback in opts.c.
* common.opt: Add -Wno-cpp option.
* c-common.c (struct reason_option_codes_t): Map cpp warning
reason codes to gcc option indexes.
* (c_option_controlling_cpp_error): New function, lookup the gcc
option index for a cpp warning reason code.
* (c_cpp_error): Add warning reason argument, call
c_option_controlling_cpp_error for diagnostic_override_option_index.
* doc/invoke.texi: Document -Wno-cpp.
* cpp.c (cb_cpp_error): Add warning reason argument, set a value
for diagnostic_override_option_index if CPP_W_WARNING_DIRECTIVE.
* directives.c (do_diagnostic): Add warning reason argument,
call appropriate error reporting function for code.
(directive_diagnostics): Call specific warning functions with
warning reason where appropriate.
(do_error, do_warning, do_pragma_dependency): Add warning reason
argument to do_diagnostic calls.
* macro.c (_cpp_warn_if_unused_macro, enter_macro_context,
_cpp_create_definition): Call specific warning functions with
warning reason where appropriate.
* Makefile.in: Add new diagnostic functions to gettext translations.
* include/cpplib.h (struct cpp_callbacks): Add warning reason code
to error callback.
(CPP_DL_WARNING, CPP_DL_WARNING_SYSHDR, CPP_DL_PEDWARN, CPP_DL_ERROR,
CPP_DL_ICE, CPP_DL_NOTE, CPP_DL_FATAL): Replace macros with enums.
(CPP_W_NONE, CPP_W_DEPRECATED, CPP_W_COMMENTS,
CPP_W_MISSING_INCLUDE_DIRS, CPP_W_TRIGRAPHS, CPP_W_MULTICHAR,
CPP_W_TRADITIONAL, CPP_W_LONG_LONG, CPP_W_ENDIF_LABELS,
CPP_W_NUM_SIGN_CHANGE, CPP_W_VARIADIC_MACROS,
CPP_W_BUILTIN_MACRO_REDEFINED, CPP_W_DOLLARS, CPP_W_UNDEF,
CPP_W_UNUSED_MACROS, CPP_W_CXX_OPERATOR_NAMES, CPP_W_NORMALIZE,
CPP_W_INVALID_PCH, CPP_W_WARNING_DIRECTIVE): New enums for cpp
warning reason codes.
(cpp_warning, cpp_pedwarning, cpp_warning_syshdr,
cpp_warning_with_line, cpp_pedwarning_with_line,
cpp_warning_with_line_syshdr): New specific error reporting functions.
* pch.c (cpp_valid_state): Call specific warning functions with
warning reason where appropriate.
* errors.c (cpp_diagnostic, cpp_diagnostic_with_line): New central
diagnostic handlers.
(cpp_warning, cpp_pedwarning, cpp_warning_syshdr,
cpp_warning_with_line, cpp_pedwarning_with_line,
cpp_warning_with_line_syshdr): New specific error reporting functions.
* expr.c (cpp_classify_number, eval_token, num_unary_op): Call
specific warning functions with warning reason where appropriate.
* lex.c (_cpp_process_line_notes, _cpp_skip_block_comment,
warn_about_normalization, lex_identifier_intern, lex_identifier,
_cpp_lex_direct): Ditto.
* charset.c (_cpp_valid_ucn, convert_hex, convert_escape,
narrow_str_to_charconst): Ditto.
* gcc.dg/cpp/warn-undef-2.c: New.
* gcc.dg/cpp/warn-traditional-2.c: New.
* gcc.dg/cpp/warn-comments-2.c: New.
* gcc.dg/cpp/warning-directive-1.c: New.
* gcc.dg/cpp/warn-long-long.c: New.
* gcc.dg/cpp/warn-traditional.c: New.
* gcc.dg/cpp/warn-variadic-2.c: New.
* gcc.dg/cpp/warn-undef.c: New.
* gcc.dg/cpp/warn-normalized-1.c: New.
* gcc.dg/cpp/warning-directive-2.c: New.
* gcc.dg/cpp/warn-long-long-2.c: New.
* gcc.dg/cpp/warn-variadic.c: New.
* gcc.dg/cpp/warn-normalized-2.c: New.
* gcc.dg/cpp/warning-directive-3.c: New.
* gcc.dg/cpp/warn-deprecated-2.c: New.
* gcc.dg/cpp/warn-trigraphs-1.c: New.
* gcc.dg/cpp/warn-multichar-2.c: New.
* gcc.dg/cpp/warn-normalized-3.c: New.
* gcc.dg/cpp/warning-directive-4.c: New.
* gcc.dg/cpp/warn-unused-macros.c: New.
* gcc.dg/cpp/warn-trigraphs-2.c: New.
* gcc.dg/cpp/warn-cxx-compat-2.c: New.
* gcc.dg/cpp/warn-cxx-compat.c: New.
* gcc.dg/cpp/warn-redefined.c: New.
* gcc.dg/cpp/warn-trigraphs-3.c: New.
* gcc.dg/cpp/warn-unused-macros-2.c: New.
* gcc.dg/cpp/warn-deprecated.c: New.
* gcc.dg/cpp/warn-trigraphs-4.c: New.
* gcc.dg/cpp/warn-redefined-2.c: New.
* gcc.dg/cpp/warn-comments.c: New.
* gcc.dg/cpp/warn-multichar.c: New.
* g++.dg/cpp/warning-directive-1.C: New.
* g++.dg/cpp/warning-directive-2.C: New.
* g++.dg/cpp/warning-directive-3.C: New.
* g++.dg/cpp/warning-directive-4.C: New.
* gfortran.dg/warning-directive-1.F90: New.
* gfortran.dg/warning-directive-3.F90: New.
* gfortran.dg/warning-directive-2.F90: New.
* gfortran.dg/warning-directive-4.F90: New.
From-SVN: r158079
2010-04-08 01:18:10 +08:00
|
|
|
cpp_warning_syshdr (r, CPP_W_INVALID_PCH,
|
libcpp, genmatch: Use gcc_diag instead of printf for libcpp diagnostics
When working on #embed support, or -Wheader-guard or other recent libcpp
changes, I've been annoyed by the libcpp diagnostics being visually
different from normal gcc diagnostics, especially in the area of quoting
stuff in the diagnostic messages.
Normall GCC diagnostics is gcc_diag/gcc_tdiag, one can use
%</%>, %qs etc. in there, while libcpp diagnostics was marked as printf
and in libcpp we've been very creative with quoting stuff, either
no quotes at all, or "something" quoting, or 'something' quoting, or
`something' quoting (but in none of the cases it used colors consistently
with the rest of the compiler).
Now, libcpp diagnostics is always emitted using a callback,
pfile->cb.diagnostic. On the gcc/ side, this callback is initialized with
genmatch.cc: cb->diagnostic = diagnostic_cb;
c-family/c-opts.cc: cb->diagnostic = c_cpp_diagnostic;
fortran/cpp.cc: cb->diagnostic = cb_cpp_diagnostic;
where the latter two just use diagnostic_report_diagnostic, so actually
support all the gcc_diag stuff, only the genmatch.cc case didn't.
So, the following patch changes genmatch.cc to use pp_format* instead
of vfprintf so that it supports the gcc_diag formatting (pretty-print.o
unfortunately has various dependencies, so had to link genmatch with
libcommon.a libbacktrace.a and tweak Makefile.in so that there are no
circular dependencies) and marks the libcpp diagnostic routines as
gcc_diag rather than printf. That change resulted in hundreds of
-Wformat-diag new warnings (most of them useful and resulting IMHO in
better diagnostics), so the rest of the patch is changing the format
strings to make -Wformat-diag happy and adjusting the testsuite for
the differences in how is the diagnostic reformatted.
Dunno if some out of GCC tree projects use libcpp, that case would
make it harder because one couldn't use vfprintf in the diagnostic
callback anymore, but there is always David's libdiagnostic which could
be used for that purpose IMHO.
2024-10-12 Jakub Jelinek <jakub@redhat.com>
libcpp/
* include/cpplib.h (ATTRIBUTE_CPP_PPDIAG): Define.
(struct cpp_callbacks): Use ATTRIBUTE_CPP_PPDIAG instead of
ATTRIBUTE_FPTR_PRINTF on diagnostic callback.
(cpp_error, cpp_warning, cpp_pedwarning, cpp_warning_syshdr): Use
ATTRIBUTE_CPP_PPDIAG (3, 4) instead of ATTRIBUTE_PRINTF_3.
(cpp_warning_at, cpp_pedwarning_at): Use ATTRIBUTE_CPP_PPDIAG (4, 5)
instead of ATTRIBUTE_PRINTF_4.
(cpp_error_with_line, cpp_warning_with_line, cpp_pedwarning_with_line,
cpp_warning_with_line_syshdr): Use ATTRIBUTE_CPP_PPDIAG (5, 6)
instead of ATTRIBUTE_PRINTF_5.
(cpp_error_at): Use ATTRIBUTE_CPP_PPDIAG (4, 5) instead of
ATTRIBUTE_PRINTF_4.
* Makefile.in (po/$(PACKAGE).pot): Use --language=GCC-source rather
than --language=c.
* errors.cc (cpp_diagnostic_at, cpp_diagnostic,
cpp_diagnostic_with_line): Use ATTRIBUTE_CPP_PPDIAG instead of
-ATTRIBUTE_FPTR_PRINTF.
* charset.cc (cpp_host_to_exec_charset, _cpp_valid_ucn, convert_hex,
convert_oct, convert_escape): Fix up -Wformat-diag warnings.
(cpp_interpret_string_ranges, count_source_chars): Use
ATTRIBUTE_CPP_PPDIAG instead of ATTRIBUTE_FPTR_PRINTF.
(narrow_str_to_charconst): Fix up -Wformat-diag warnings.
* directives.cc (check_eol_1, directive_diagnostics, lex_macro_node,
do_undef, glue_header_name, parse_include, do_include_common,
do_include_next, _cpp_parse_embed_params, do_embed, read_flag,
do_line, do_linemarker, register_pragma_1, do_pragma_once,
do_pragma_push_macro, do_pragma_pop_macro, do_pragma_poison,
do_pragma_system_header, do_pragma_warning_or_error, _cpp_do__Pragma,
do_else, do_elif, do_endif, parse_answer, do_assert,
cpp_define_unused): Likewise.
* expr.cc (cpp_classify_number, parse_defined, eval_token,
_cpp_parse_expr, reduce, check_promotion): Likewise.
* files.cc (_cpp_find_file, finish_base64_embed,
_cpp_pop_file_buffer): Likewise.
* init.cc (sanity_checks): Likewise.
* lex.cc (_cpp_process_line_notes, maybe_warn_bidi_on_char,
_cpp_warn_invalid_utf8, _cpp_skip_block_comment,
warn_about_normalization, forms_identifier_p, maybe_va_opt_error,
identifier_diagnostics_on_lex, cpp_maybe_module_directive): Likewise.
* macro.cc (class vaopt_state, builtin_has_include_1,
builtin_has_include, builtin_has_embed, _cpp_warn_if_unused_macro,
_cpp_builtin_macro_text, builtin_macro, stringify_arg,
_cpp_arguments_ok, collect_args, enter_macro_context,
_cpp_save_parameter, parse_params, create_iso_definition,
_cpp_create_definition, check_trad_stringification): Likewise.
* pch.cc (cpp_valid_state): Likewise.
* traditional.cc (_cpp_scan_out_logical_line, recursive_macro):
Likewise.
gcc/
* Makefile.in (generated_files): Remove {gimple,generic}-match*.
(generated_match_files): New variable. Add a dependency of
$(filter-out $(OBJS-libcommon),$(ALL_HOST_OBJS)) files on those.
(build/genmatch$(build_exeext)): Depend on and link against
libcommon.a and $(LIBBACKTRACE).
* genmatch.cc: Include pretty-print.h and input.h.
(ggc_internal_cleared_alloc, ggc_free): Remove.
(fatal): New function.
(line_table): Remove.
(linemap_client_expand_location_to_spelling_point): Remove.
(diagnostic_cb): Use gcc_diag rather than printf format. Use
pp_format_verbatim on a temporary pretty_printer instead of
vfprintf.
(fatal_at, warning_at): Use gcc_diag rather than printf format.
(output_line_directive): Rename location_hash to loc_hash.
(parser::eat_ident, parser::parse_operation, parser::parse_expr,
parser::parse_pattern, parser::finish_match_operand): Fix up
-Wformat-diag warnings.
gcc/c-family/
* c-lex.cc (c_common_has_attribute,
c_common_lex_availability_macro): Fix up -Wformat-diag warnings.
gcc/testsuite/
* c-c++-common/cpp/counter-2.c: Adjust expected diagnostics for
libcpp diagnostic formatting changes.
* c-c++-common/cpp/embed-3.c: Likewise.
* c-c++-common/cpp/embed-4.c: Likewise.
* c-c++-common/cpp/embed-16.c: Likewise.
* c-c++-common/cpp/embed-18.c: Likewise.
* c-c++-common/cpp/eof-2.c: Likewise.
* c-c++-common/cpp/eof-3.c: Likewise.
* c-c++-common/cpp/fmax-include-depth.c: Likewise.
* c-c++-common/cpp/has-builtin.c: Likewise.
* c-c++-common/cpp/line-2.c: Likewise.
* c-c++-common/cpp/line-3.c: Likewise.
* c-c++-common/cpp/macro-arg-count-1.c: Likewise.
* c-c++-common/cpp/macro-arg-count-2.c: Likewise.
* c-c++-common/cpp/macro-ranges.c: Likewise.
* c-c++-common/cpp/named-universal-char-escape-4.c: Likewise.
* c-c++-common/cpp/named-universal-char-escape-5.c: Likewise.
* c-c++-common/cpp/pr88974.c: Likewise.
* c-c++-common/cpp/va-opt-error.c: Likewise.
* c-c++-common/cpp/va-opt-pedantic.c: Likewise.
* c-c++-common/cpp/Wheader-guard-2.c: Likewise.
* c-c++-common/cpp/Wheader-guard-3.c: Likewise.
* c-c++-common/cpp/Winvalid-utf8-1.c: Likewise.
* c-c++-common/cpp/Winvalid-utf8-2.c: Likewise.
* c-c++-common/cpp/Winvalid-utf8-3.c: Likewise.
* c-c++-common/diagnostic-format-sarif-file-bad-utf8-pr109098-1.c:
Likewise.
* c-c++-common/diagnostic-format-sarif-file-bad-utf8-pr109098-3.c:
Likewise.
* c-c++-common/pr68833-3.c: Likewise.
* c-c++-common/raw-string-directive-1.c: Likewise.
* gcc.dg/analyzer/named-constants-Wunused-macros.c: Likewise.
* gcc.dg/binary-constants-4.c: Likewise.
* gcc.dg/builtin-redefine.c: Likewise.
* gcc.dg/cpp/19951025-1.c: Likewise.
* gcc.dg/cpp/c11-warning-1.c: Likewise.
* gcc.dg/cpp/c11-warning-2.c: Likewise.
* gcc.dg/cpp/c11-warning-3.c: Likewise.
* gcc.dg/cpp/c23-elifdef-2.c: Likewise.
* gcc.dg/cpp/c23-warning-2.c: Likewise.
* gcc.dg/cpp/embed-2.c: Likewise.
* gcc.dg/cpp/embed-3.c: Likewise.
* gcc.dg/cpp/embed-4.c: Likewise.
* gcc.dg/cpp/expr.c: Likewise.
* gcc.dg/cpp/gnu11-elifdef-2.c: Likewise.
* gcc.dg/cpp/gnu11-elifdef-3.c: Likewise.
* gcc.dg/cpp/gnu11-elifdef-4.c: Likewise.
* gcc.dg/cpp/gnu11-warning-1.c: Likewise.
* gcc.dg/cpp/gnu11-warning-2.c: Likewise.
* gcc.dg/cpp/gnu11-warning-3.c: Likewise.
* gcc.dg/cpp/gnu23-warning-2.c: Likewise.
* gcc.dg/cpp/include6.c: Likewise.
* gcc.dg/cpp/pr35322.c: Likewise.
* gcc.dg/cpp/tr-warn6.c: Likewise.
* gcc.dg/cpp/undef2.c: Likewise.
* gcc.dg/cpp/warn-comments.c: Likewise.
* gcc.dg/cpp/warn-comments-2.c: Likewise.
* gcc.dg/cpp/warn-comments-3.c: Likewise.
* gcc.dg/cpp/warn-cxx-compat.c: Likewise.
* gcc.dg/cpp/warn-cxx-compat-2.c: Likewise.
* gcc.dg/cpp/warn-deprecated.c: Likewise.
* gcc.dg/cpp/warn-deprecated-2.c: Likewise.
* gcc.dg/cpp/warn-long-long.c: Likewise.
* gcc.dg/cpp/warn-long-long-2.c: Likewise.
* gcc.dg/cpp/warn-normalized-1.c: Likewise.
* gcc.dg/cpp/warn-normalized-2.c: Likewise.
* gcc.dg/cpp/warn-normalized-3.c: Likewise.
* gcc.dg/cpp/warn-normalized-4-bytes.c: Likewise.
* gcc.dg/cpp/warn-normalized-4-unicode.c: Likewise.
* gcc.dg/cpp/warn-redefined.c: Likewise.
* gcc.dg/cpp/warn-redefined-2.c: Likewise.
* gcc.dg/cpp/warn-traditional.c: Likewise.
* gcc.dg/cpp/warn-traditional-2.c: Likewise.
* gcc.dg/cpp/warn-trigraphs-1.c: Likewise.
* gcc.dg/cpp/warn-trigraphs-2.c: Likewise.
* gcc.dg/cpp/warn-trigraphs-3.c: Likewise.
* gcc.dg/cpp/warn-trigraphs-4.c: Likewise.
* gcc.dg/cpp/warn-undef.c: Likewise.
* gcc.dg/cpp/warn-undef-2.c: Likewise.
* gcc.dg/cpp/warn-unused-macros.c: Likewise.
* gcc.dg/cpp/warn-unused-macros-2.c: Likewise.
* gcc.dg/pch/counter-2.c: Likewise.
* g++.dg/cpp0x/udlit-error1.C: Likewise.
* g++.dg/cpp23/named-universal-char-escape1.C: Likewise.
* g++.dg/cpp23/named-universal-char-escape2.C: Likewise.
* g++.dg/cpp23/Winvalid-utf8-1.C: Likewise.
* g++.dg/cpp23/Winvalid-utf8-2.C: Likewise.
* g++.dg/cpp23/Winvalid-utf8-3.C: Likewise.
* g++.dg/cpp23/Winvalid-utf8-4.C: Likewise.
* g++.dg/cpp23/Winvalid-utf8-5.C: Likewise.
* g++.dg/cpp23/Winvalid-utf8-6.C: Likewise.
* g++.dg/cpp23/Winvalid-utf8-7.C: Likewise.
* g++.dg/cpp23/Winvalid-utf8-8.C: Likewise.
* g++.dg/cpp23/Winvalid-utf8-9.C: Likewise.
* g++.dg/cpp23/Winvalid-utf8-10.C: Likewise.
* g++.dg/cpp23/Winvalid-utf8-11.C: Likewise.
* g++.dg/cpp23/Winvalid-utf8-12.C: Likewise.
* g++.dg/cpp/elifdef-3.C: Likewise.
* g++.dg/cpp/elifdef-5.C: Likewise.
* g++.dg/cpp/elifdef-6.C: Likewise.
* g++.dg/cpp/elifdef-7.C: Likewise.
* g++.dg/cpp/embed-1.C: Likewise.
* g++.dg/cpp/embed-2.C: Likewise.
* g++.dg/cpp/pedantic-errors.C: Likewise.
* g++.dg/cpp/warning-1.C: Likewise.
* g++.dg/cpp/warning-2.C: Likewise.
* g++.dg/ext/bitint1.C: Likewise.
* g++.dg/ext/bitint2.C: Likewise.
2024-10-12 16:44:17 +08:00
|
|
|
"%s: not used because %<%.*s%> is poisoned",
|
diagnostic.h (diagnostic_override_option_index): New macro to set a diagnostic's option_index.
* diagnostic.h (diagnostic_override_option_index): New macro to
set a diagnostic's option_index.
* c-tree.h (c_cpp_error): Add warning reason argument.
* opts.c (_warning_as_error_callback): New.
(register_warning_as_error_callback): Store callback for
warnings enabled via enable_warning_as_error.
(enable_warning_as_error): Call callback, minor code tidy.
* opts.h (register_warning_as_error_callback): Declare.
* c-opts.c (warning_as_error_callback): New, set cpp_opts flag in
response to -Werror=.
(c_common_init_options): Register warning_as_error_callback in opts.c.
* common.opt: Add -Wno-cpp option.
* c-common.c (struct reason_option_codes_t): Map cpp warning
reason codes to gcc option indexes.
* (c_option_controlling_cpp_error): New function, lookup the gcc
option index for a cpp warning reason code.
* (c_cpp_error): Add warning reason argument, call
c_option_controlling_cpp_error for diagnostic_override_option_index.
* doc/invoke.texi: Document -Wno-cpp.
* cpp.c (cb_cpp_error): Add warning reason argument, set a value
for diagnostic_override_option_index if CPP_W_WARNING_DIRECTIVE.
* directives.c (do_diagnostic): Add warning reason argument,
call appropriate error reporting function for code.
(directive_diagnostics): Call specific warning functions with
warning reason where appropriate.
(do_error, do_warning, do_pragma_dependency): Add warning reason
argument to do_diagnostic calls.
* macro.c (_cpp_warn_if_unused_macro, enter_macro_context,
_cpp_create_definition): Call specific warning functions with
warning reason where appropriate.
* Makefile.in: Add new diagnostic functions to gettext translations.
* include/cpplib.h (struct cpp_callbacks): Add warning reason code
to error callback.
(CPP_DL_WARNING, CPP_DL_WARNING_SYSHDR, CPP_DL_PEDWARN, CPP_DL_ERROR,
CPP_DL_ICE, CPP_DL_NOTE, CPP_DL_FATAL): Replace macros with enums.
(CPP_W_NONE, CPP_W_DEPRECATED, CPP_W_COMMENTS,
CPP_W_MISSING_INCLUDE_DIRS, CPP_W_TRIGRAPHS, CPP_W_MULTICHAR,
CPP_W_TRADITIONAL, CPP_W_LONG_LONG, CPP_W_ENDIF_LABELS,
CPP_W_NUM_SIGN_CHANGE, CPP_W_VARIADIC_MACROS,
CPP_W_BUILTIN_MACRO_REDEFINED, CPP_W_DOLLARS, CPP_W_UNDEF,
CPP_W_UNUSED_MACROS, CPP_W_CXX_OPERATOR_NAMES, CPP_W_NORMALIZE,
CPP_W_INVALID_PCH, CPP_W_WARNING_DIRECTIVE): New enums for cpp
warning reason codes.
(cpp_warning, cpp_pedwarning, cpp_warning_syshdr,
cpp_warning_with_line, cpp_pedwarning_with_line,
cpp_warning_with_line_syshdr): New specific error reporting functions.
* pch.c (cpp_valid_state): Call specific warning functions with
warning reason where appropriate.
* errors.c (cpp_diagnostic, cpp_diagnostic_with_line): New central
diagnostic handlers.
(cpp_warning, cpp_pedwarning, cpp_warning_syshdr,
cpp_warning_with_line, cpp_pedwarning_with_line,
cpp_warning_with_line_syshdr): New specific error reporting functions.
* expr.c (cpp_classify_number, eval_token, num_unary_op): Call
specific warning functions with warning reason where appropriate.
* lex.c (_cpp_process_line_notes, _cpp_skip_block_comment,
warn_about_normalization, lex_identifier_intern, lex_identifier,
_cpp_lex_direct): Ditto.
* charset.c (_cpp_valid_ucn, convert_hex, convert_escape,
narrow_str_to_charconst): Ditto.
* gcc.dg/cpp/warn-undef-2.c: New.
* gcc.dg/cpp/warn-traditional-2.c: New.
* gcc.dg/cpp/warn-comments-2.c: New.
* gcc.dg/cpp/warning-directive-1.c: New.
* gcc.dg/cpp/warn-long-long.c: New.
* gcc.dg/cpp/warn-traditional.c: New.
* gcc.dg/cpp/warn-variadic-2.c: New.
* gcc.dg/cpp/warn-undef.c: New.
* gcc.dg/cpp/warn-normalized-1.c: New.
* gcc.dg/cpp/warning-directive-2.c: New.
* gcc.dg/cpp/warn-long-long-2.c: New.
* gcc.dg/cpp/warn-variadic.c: New.
* gcc.dg/cpp/warn-normalized-2.c: New.
* gcc.dg/cpp/warning-directive-3.c: New.
* gcc.dg/cpp/warn-deprecated-2.c: New.
* gcc.dg/cpp/warn-trigraphs-1.c: New.
* gcc.dg/cpp/warn-multichar-2.c: New.
* gcc.dg/cpp/warn-normalized-3.c: New.
* gcc.dg/cpp/warning-directive-4.c: New.
* gcc.dg/cpp/warn-unused-macros.c: New.
* gcc.dg/cpp/warn-trigraphs-2.c: New.
* gcc.dg/cpp/warn-cxx-compat-2.c: New.
* gcc.dg/cpp/warn-cxx-compat.c: New.
* gcc.dg/cpp/warn-redefined.c: New.
* gcc.dg/cpp/warn-trigraphs-3.c: New.
* gcc.dg/cpp/warn-unused-macros-2.c: New.
* gcc.dg/cpp/warn-deprecated.c: New.
* gcc.dg/cpp/warn-trigraphs-4.c: New.
* gcc.dg/cpp/warn-redefined-2.c: New.
* gcc.dg/cpp/warn-comments.c: New.
* gcc.dg/cpp/warn-multichar.c: New.
* g++.dg/cpp/warning-directive-1.C: New.
* g++.dg/cpp/warning-directive-2.C: New.
* g++.dg/cpp/warning-directive-3.C: New.
* g++.dg/cpp/warning-directive-4.C: New.
* gfortran.dg/warning-directive-1.F90: New.
* gfortran.dg/warning-directive-3.F90: New.
* gfortran.dg/warning-directive-2.F90: New.
* gfortran.dg/warning-directive-4.F90: New.
From-SVN: r158079
2010-04-08 01:18:10 +08:00
|
|
|
name, m.name_length, namebuf);
|
2008-12-11 01:31:07 +08:00
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
[CPP PATCH] node type
https://gcc.gnu.org/ml/gcc-patches/2018-08/msg01164.html
* include/cpplib.h (NODE_BUILTIN, NODE_MACRO_ARG): Delete.
Renumber others.
(enum node_type): Replace NT_MACRO with NT_USER_MACRO,
NT_BUILTIN_MACRO, NT_MACRO_ARG. Delete NT_ASSERTION.
(NTV_MACRO, NTV_ANSWER, NTV_BUILTIN, NTV_ARGUMENT, NTV_NONE):
Delete.
(CPP_HASHNODE_VALUE_IDX): Delete.
(union _cpp_hashnode_value): GTY tag from enum node_type directly.
(struct cpp_hashnode): Adjust GTY desc for value field.
(cpp_user_macro_p, cpp_builtin_macro_p, cpp_macro_p): Adjust.
* directives.c (undefine_macros): Clear value.anwers, adjust flag
clearing.
(_cpp_test_assertion): No need to check NT_ASSERTION.
(do_assert, do_unassert): Likewise.
* init.c (cpp_init_special_builtins): Set type not flags.
* macro.c (struct macro_arg_saved_data): Add type field.
(cpp_get_token_1): Check type not NT_VOID.
(_cpp_free_definition): Adjust flag clearing. Nullify
value.answers.
(_cpp_save_parameter, _cpp_unsave_parameters): Save and restore
type.
(lex_expansion_token): Check type not flags.
(_cpp_create_definition): Set type to NT_USER_MACRO.
(_cpp_notify_macro_use): Adjust type checking.
* pch.c (write_macdef, count_defs, write_defs, cpp_valid_state)
(save_macros): Adjust node type/flag handling.
* traditional.c (_cpp_scan_out_logical_line): Check type not flags.
From-SVN: r263667
2018-08-21 00:32:29 +08:00
|
|
|
if (h->type == NT_VOID)
|
2008-12-11 01:31:07 +08:00
|
|
|
{
|
|
|
|
/* It's ok if __GCC_HAVE_DWARF2_CFI_ASM becomes undefined,
|
|
|
|
as in, when the PCH file is created with -g and we're
|
|
|
|
attempting to use it without -g. Restoring the PCH file
|
|
|
|
is supposed to bring in this definition *and* enable the
|
|
|
|
generation of call frame information, so that precompiled
|
2017-04-04 06:30:56 +08:00
|
|
|
definitions that take this macro into account, to decide
|
2008-12-11 01:31:07 +08:00
|
|
|
what asm to emit, won't issue .cfi directives when the
|
|
|
|
compiler doesn't. */
|
|
|
|
if (!(h->flags & NODE_USED)
|
|
|
|
&& m.name_length == sizeof ("__GCC_HAVE_DWARF2_CFI_ASM") - 1
|
|
|
|
&& !memcmp (namebuf, "__GCC_HAVE_DWARF2_CFI_ASM", m.name_length))
|
|
|
|
continue;
|
|
|
|
|
2003-01-10 10:22:34 +08:00
|
|
|
if (CPP_OPTION (r, warn_invalid_pch))
|
diagnostic.h (diagnostic_override_option_index): New macro to set a diagnostic's option_index.
* diagnostic.h (diagnostic_override_option_index): New macro to
set a diagnostic's option_index.
* c-tree.h (c_cpp_error): Add warning reason argument.
* opts.c (_warning_as_error_callback): New.
(register_warning_as_error_callback): Store callback for
warnings enabled via enable_warning_as_error.
(enable_warning_as_error): Call callback, minor code tidy.
* opts.h (register_warning_as_error_callback): Declare.
* c-opts.c (warning_as_error_callback): New, set cpp_opts flag in
response to -Werror=.
(c_common_init_options): Register warning_as_error_callback in opts.c.
* common.opt: Add -Wno-cpp option.
* c-common.c (struct reason_option_codes_t): Map cpp warning
reason codes to gcc option indexes.
* (c_option_controlling_cpp_error): New function, lookup the gcc
option index for a cpp warning reason code.
* (c_cpp_error): Add warning reason argument, call
c_option_controlling_cpp_error for diagnostic_override_option_index.
* doc/invoke.texi: Document -Wno-cpp.
* cpp.c (cb_cpp_error): Add warning reason argument, set a value
for diagnostic_override_option_index if CPP_W_WARNING_DIRECTIVE.
* directives.c (do_diagnostic): Add warning reason argument,
call appropriate error reporting function for code.
(directive_diagnostics): Call specific warning functions with
warning reason where appropriate.
(do_error, do_warning, do_pragma_dependency): Add warning reason
argument to do_diagnostic calls.
* macro.c (_cpp_warn_if_unused_macro, enter_macro_context,
_cpp_create_definition): Call specific warning functions with
warning reason where appropriate.
* Makefile.in: Add new diagnostic functions to gettext translations.
* include/cpplib.h (struct cpp_callbacks): Add warning reason code
to error callback.
(CPP_DL_WARNING, CPP_DL_WARNING_SYSHDR, CPP_DL_PEDWARN, CPP_DL_ERROR,
CPP_DL_ICE, CPP_DL_NOTE, CPP_DL_FATAL): Replace macros with enums.
(CPP_W_NONE, CPP_W_DEPRECATED, CPP_W_COMMENTS,
CPP_W_MISSING_INCLUDE_DIRS, CPP_W_TRIGRAPHS, CPP_W_MULTICHAR,
CPP_W_TRADITIONAL, CPP_W_LONG_LONG, CPP_W_ENDIF_LABELS,
CPP_W_NUM_SIGN_CHANGE, CPP_W_VARIADIC_MACROS,
CPP_W_BUILTIN_MACRO_REDEFINED, CPP_W_DOLLARS, CPP_W_UNDEF,
CPP_W_UNUSED_MACROS, CPP_W_CXX_OPERATOR_NAMES, CPP_W_NORMALIZE,
CPP_W_INVALID_PCH, CPP_W_WARNING_DIRECTIVE): New enums for cpp
warning reason codes.
(cpp_warning, cpp_pedwarning, cpp_warning_syshdr,
cpp_warning_with_line, cpp_pedwarning_with_line,
cpp_warning_with_line_syshdr): New specific error reporting functions.
* pch.c (cpp_valid_state): Call specific warning functions with
warning reason where appropriate.
* errors.c (cpp_diagnostic, cpp_diagnostic_with_line): New central
diagnostic handlers.
(cpp_warning, cpp_pedwarning, cpp_warning_syshdr,
cpp_warning_with_line, cpp_pedwarning_with_line,
cpp_warning_with_line_syshdr): New specific error reporting functions.
* expr.c (cpp_classify_number, eval_token, num_unary_op): Call
specific warning functions with warning reason where appropriate.
* lex.c (_cpp_process_line_notes, _cpp_skip_block_comment,
warn_about_normalization, lex_identifier_intern, lex_identifier,
_cpp_lex_direct): Ditto.
* charset.c (_cpp_valid_ucn, convert_hex, convert_escape,
narrow_str_to_charconst): Ditto.
* gcc.dg/cpp/warn-undef-2.c: New.
* gcc.dg/cpp/warn-traditional-2.c: New.
* gcc.dg/cpp/warn-comments-2.c: New.
* gcc.dg/cpp/warning-directive-1.c: New.
* gcc.dg/cpp/warn-long-long.c: New.
* gcc.dg/cpp/warn-traditional.c: New.
* gcc.dg/cpp/warn-variadic-2.c: New.
* gcc.dg/cpp/warn-undef.c: New.
* gcc.dg/cpp/warn-normalized-1.c: New.
* gcc.dg/cpp/warning-directive-2.c: New.
* gcc.dg/cpp/warn-long-long-2.c: New.
* gcc.dg/cpp/warn-variadic.c: New.
* gcc.dg/cpp/warn-normalized-2.c: New.
* gcc.dg/cpp/warning-directive-3.c: New.
* gcc.dg/cpp/warn-deprecated-2.c: New.
* gcc.dg/cpp/warn-trigraphs-1.c: New.
* gcc.dg/cpp/warn-multichar-2.c: New.
* gcc.dg/cpp/warn-normalized-3.c: New.
* gcc.dg/cpp/warning-directive-4.c: New.
* gcc.dg/cpp/warn-unused-macros.c: New.
* gcc.dg/cpp/warn-trigraphs-2.c: New.
* gcc.dg/cpp/warn-cxx-compat-2.c: New.
* gcc.dg/cpp/warn-cxx-compat.c: New.
* gcc.dg/cpp/warn-redefined.c: New.
* gcc.dg/cpp/warn-trigraphs-3.c: New.
* gcc.dg/cpp/warn-unused-macros-2.c: New.
* gcc.dg/cpp/warn-deprecated.c: New.
* gcc.dg/cpp/warn-trigraphs-4.c: New.
* gcc.dg/cpp/warn-redefined-2.c: New.
* gcc.dg/cpp/warn-comments.c: New.
* gcc.dg/cpp/warn-multichar.c: New.
* g++.dg/cpp/warning-directive-1.C: New.
* g++.dg/cpp/warning-directive-2.C: New.
* g++.dg/cpp/warning-directive-3.C: New.
* g++.dg/cpp/warning-directive-4.C: New.
* gfortran.dg/warning-directive-1.F90: New.
* gfortran.dg/warning-directive-3.F90: New.
* gfortran.dg/warning-directive-2.F90: New.
* gfortran.dg/warning-directive-4.F90: New.
From-SVN: r158079
2010-04-08 01:18:10 +08:00
|
|
|
cpp_warning_syshdr (r, CPP_W_INVALID_PCH,
|
libcpp, genmatch: Use gcc_diag instead of printf for libcpp diagnostics
When working on #embed support, or -Wheader-guard or other recent libcpp
changes, I've been annoyed by the libcpp diagnostics being visually
different from normal gcc diagnostics, especially in the area of quoting
stuff in the diagnostic messages.
Normall GCC diagnostics is gcc_diag/gcc_tdiag, one can use
%</%>, %qs etc. in there, while libcpp diagnostics was marked as printf
and in libcpp we've been very creative with quoting stuff, either
no quotes at all, or "something" quoting, or 'something' quoting, or
`something' quoting (but in none of the cases it used colors consistently
with the rest of the compiler).
Now, libcpp diagnostics is always emitted using a callback,
pfile->cb.diagnostic. On the gcc/ side, this callback is initialized with
genmatch.cc: cb->diagnostic = diagnostic_cb;
c-family/c-opts.cc: cb->diagnostic = c_cpp_diagnostic;
fortran/cpp.cc: cb->diagnostic = cb_cpp_diagnostic;
where the latter two just use diagnostic_report_diagnostic, so actually
support all the gcc_diag stuff, only the genmatch.cc case didn't.
So, the following patch changes genmatch.cc to use pp_format* instead
of vfprintf so that it supports the gcc_diag formatting (pretty-print.o
unfortunately has various dependencies, so had to link genmatch with
libcommon.a libbacktrace.a and tweak Makefile.in so that there are no
circular dependencies) and marks the libcpp diagnostic routines as
gcc_diag rather than printf. That change resulted in hundreds of
-Wformat-diag new warnings (most of them useful and resulting IMHO in
better diagnostics), so the rest of the patch is changing the format
strings to make -Wformat-diag happy and adjusting the testsuite for
the differences in how is the diagnostic reformatted.
Dunno if some out of GCC tree projects use libcpp, that case would
make it harder because one couldn't use vfprintf in the diagnostic
callback anymore, but there is always David's libdiagnostic which could
be used for that purpose IMHO.
2024-10-12 Jakub Jelinek <jakub@redhat.com>
libcpp/
* include/cpplib.h (ATTRIBUTE_CPP_PPDIAG): Define.
(struct cpp_callbacks): Use ATTRIBUTE_CPP_PPDIAG instead of
ATTRIBUTE_FPTR_PRINTF on diagnostic callback.
(cpp_error, cpp_warning, cpp_pedwarning, cpp_warning_syshdr): Use
ATTRIBUTE_CPP_PPDIAG (3, 4) instead of ATTRIBUTE_PRINTF_3.
(cpp_warning_at, cpp_pedwarning_at): Use ATTRIBUTE_CPP_PPDIAG (4, 5)
instead of ATTRIBUTE_PRINTF_4.
(cpp_error_with_line, cpp_warning_with_line, cpp_pedwarning_with_line,
cpp_warning_with_line_syshdr): Use ATTRIBUTE_CPP_PPDIAG (5, 6)
instead of ATTRIBUTE_PRINTF_5.
(cpp_error_at): Use ATTRIBUTE_CPP_PPDIAG (4, 5) instead of
ATTRIBUTE_PRINTF_4.
* Makefile.in (po/$(PACKAGE).pot): Use --language=GCC-source rather
than --language=c.
* errors.cc (cpp_diagnostic_at, cpp_diagnostic,
cpp_diagnostic_with_line): Use ATTRIBUTE_CPP_PPDIAG instead of
-ATTRIBUTE_FPTR_PRINTF.
* charset.cc (cpp_host_to_exec_charset, _cpp_valid_ucn, convert_hex,
convert_oct, convert_escape): Fix up -Wformat-diag warnings.
(cpp_interpret_string_ranges, count_source_chars): Use
ATTRIBUTE_CPP_PPDIAG instead of ATTRIBUTE_FPTR_PRINTF.
(narrow_str_to_charconst): Fix up -Wformat-diag warnings.
* directives.cc (check_eol_1, directive_diagnostics, lex_macro_node,
do_undef, glue_header_name, parse_include, do_include_common,
do_include_next, _cpp_parse_embed_params, do_embed, read_flag,
do_line, do_linemarker, register_pragma_1, do_pragma_once,
do_pragma_push_macro, do_pragma_pop_macro, do_pragma_poison,
do_pragma_system_header, do_pragma_warning_or_error, _cpp_do__Pragma,
do_else, do_elif, do_endif, parse_answer, do_assert,
cpp_define_unused): Likewise.
* expr.cc (cpp_classify_number, parse_defined, eval_token,
_cpp_parse_expr, reduce, check_promotion): Likewise.
* files.cc (_cpp_find_file, finish_base64_embed,
_cpp_pop_file_buffer): Likewise.
* init.cc (sanity_checks): Likewise.
* lex.cc (_cpp_process_line_notes, maybe_warn_bidi_on_char,
_cpp_warn_invalid_utf8, _cpp_skip_block_comment,
warn_about_normalization, forms_identifier_p, maybe_va_opt_error,
identifier_diagnostics_on_lex, cpp_maybe_module_directive): Likewise.
* macro.cc (class vaopt_state, builtin_has_include_1,
builtin_has_include, builtin_has_embed, _cpp_warn_if_unused_macro,
_cpp_builtin_macro_text, builtin_macro, stringify_arg,
_cpp_arguments_ok, collect_args, enter_macro_context,
_cpp_save_parameter, parse_params, create_iso_definition,
_cpp_create_definition, check_trad_stringification): Likewise.
* pch.cc (cpp_valid_state): Likewise.
* traditional.cc (_cpp_scan_out_logical_line, recursive_macro):
Likewise.
gcc/
* Makefile.in (generated_files): Remove {gimple,generic}-match*.
(generated_match_files): New variable. Add a dependency of
$(filter-out $(OBJS-libcommon),$(ALL_HOST_OBJS)) files on those.
(build/genmatch$(build_exeext)): Depend on and link against
libcommon.a and $(LIBBACKTRACE).
* genmatch.cc: Include pretty-print.h and input.h.
(ggc_internal_cleared_alloc, ggc_free): Remove.
(fatal): New function.
(line_table): Remove.
(linemap_client_expand_location_to_spelling_point): Remove.
(diagnostic_cb): Use gcc_diag rather than printf format. Use
pp_format_verbatim on a temporary pretty_printer instead of
vfprintf.
(fatal_at, warning_at): Use gcc_diag rather than printf format.
(output_line_directive): Rename location_hash to loc_hash.
(parser::eat_ident, parser::parse_operation, parser::parse_expr,
parser::parse_pattern, parser::finish_match_operand): Fix up
-Wformat-diag warnings.
gcc/c-family/
* c-lex.cc (c_common_has_attribute,
c_common_lex_availability_macro): Fix up -Wformat-diag warnings.
gcc/testsuite/
* c-c++-common/cpp/counter-2.c: Adjust expected diagnostics for
libcpp diagnostic formatting changes.
* c-c++-common/cpp/embed-3.c: Likewise.
* c-c++-common/cpp/embed-4.c: Likewise.
* c-c++-common/cpp/embed-16.c: Likewise.
* c-c++-common/cpp/embed-18.c: Likewise.
* c-c++-common/cpp/eof-2.c: Likewise.
* c-c++-common/cpp/eof-3.c: Likewise.
* c-c++-common/cpp/fmax-include-depth.c: Likewise.
* c-c++-common/cpp/has-builtin.c: Likewise.
* c-c++-common/cpp/line-2.c: Likewise.
* c-c++-common/cpp/line-3.c: Likewise.
* c-c++-common/cpp/macro-arg-count-1.c: Likewise.
* c-c++-common/cpp/macro-arg-count-2.c: Likewise.
* c-c++-common/cpp/macro-ranges.c: Likewise.
* c-c++-common/cpp/named-universal-char-escape-4.c: Likewise.
* c-c++-common/cpp/named-universal-char-escape-5.c: Likewise.
* c-c++-common/cpp/pr88974.c: Likewise.
* c-c++-common/cpp/va-opt-error.c: Likewise.
* c-c++-common/cpp/va-opt-pedantic.c: Likewise.
* c-c++-common/cpp/Wheader-guard-2.c: Likewise.
* c-c++-common/cpp/Wheader-guard-3.c: Likewise.
* c-c++-common/cpp/Winvalid-utf8-1.c: Likewise.
* c-c++-common/cpp/Winvalid-utf8-2.c: Likewise.
* c-c++-common/cpp/Winvalid-utf8-3.c: Likewise.
* c-c++-common/diagnostic-format-sarif-file-bad-utf8-pr109098-1.c:
Likewise.
* c-c++-common/diagnostic-format-sarif-file-bad-utf8-pr109098-3.c:
Likewise.
* c-c++-common/pr68833-3.c: Likewise.
* c-c++-common/raw-string-directive-1.c: Likewise.
* gcc.dg/analyzer/named-constants-Wunused-macros.c: Likewise.
* gcc.dg/binary-constants-4.c: Likewise.
* gcc.dg/builtin-redefine.c: Likewise.
* gcc.dg/cpp/19951025-1.c: Likewise.
* gcc.dg/cpp/c11-warning-1.c: Likewise.
* gcc.dg/cpp/c11-warning-2.c: Likewise.
* gcc.dg/cpp/c11-warning-3.c: Likewise.
* gcc.dg/cpp/c23-elifdef-2.c: Likewise.
* gcc.dg/cpp/c23-warning-2.c: Likewise.
* gcc.dg/cpp/embed-2.c: Likewise.
* gcc.dg/cpp/embed-3.c: Likewise.
* gcc.dg/cpp/embed-4.c: Likewise.
* gcc.dg/cpp/expr.c: Likewise.
* gcc.dg/cpp/gnu11-elifdef-2.c: Likewise.
* gcc.dg/cpp/gnu11-elifdef-3.c: Likewise.
* gcc.dg/cpp/gnu11-elifdef-4.c: Likewise.
* gcc.dg/cpp/gnu11-warning-1.c: Likewise.
* gcc.dg/cpp/gnu11-warning-2.c: Likewise.
* gcc.dg/cpp/gnu11-warning-3.c: Likewise.
* gcc.dg/cpp/gnu23-warning-2.c: Likewise.
* gcc.dg/cpp/include6.c: Likewise.
* gcc.dg/cpp/pr35322.c: Likewise.
* gcc.dg/cpp/tr-warn6.c: Likewise.
* gcc.dg/cpp/undef2.c: Likewise.
* gcc.dg/cpp/warn-comments.c: Likewise.
* gcc.dg/cpp/warn-comments-2.c: Likewise.
* gcc.dg/cpp/warn-comments-3.c: Likewise.
* gcc.dg/cpp/warn-cxx-compat.c: Likewise.
* gcc.dg/cpp/warn-cxx-compat-2.c: Likewise.
* gcc.dg/cpp/warn-deprecated.c: Likewise.
* gcc.dg/cpp/warn-deprecated-2.c: Likewise.
* gcc.dg/cpp/warn-long-long.c: Likewise.
* gcc.dg/cpp/warn-long-long-2.c: Likewise.
* gcc.dg/cpp/warn-normalized-1.c: Likewise.
* gcc.dg/cpp/warn-normalized-2.c: Likewise.
* gcc.dg/cpp/warn-normalized-3.c: Likewise.
* gcc.dg/cpp/warn-normalized-4-bytes.c: Likewise.
* gcc.dg/cpp/warn-normalized-4-unicode.c: Likewise.
* gcc.dg/cpp/warn-redefined.c: Likewise.
* gcc.dg/cpp/warn-redefined-2.c: Likewise.
* gcc.dg/cpp/warn-traditional.c: Likewise.
* gcc.dg/cpp/warn-traditional-2.c: Likewise.
* gcc.dg/cpp/warn-trigraphs-1.c: Likewise.
* gcc.dg/cpp/warn-trigraphs-2.c: Likewise.
* gcc.dg/cpp/warn-trigraphs-3.c: Likewise.
* gcc.dg/cpp/warn-trigraphs-4.c: Likewise.
* gcc.dg/cpp/warn-undef.c: Likewise.
* gcc.dg/cpp/warn-undef-2.c: Likewise.
* gcc.dg/cpp/warn-unused-macros.c: Likewise.
* gcc.dg/cpp/warn-unused-macros-2.c: Likewise.
* gcc.dg/pch/counter-2.c: Likewise.
* g++.dg/cpp0x/udlit-error1.C: Likewise.
* g++.dg/cpp23/named-universal-char-escape1.C: Likewise.
* g++.dg/cpp23/named-universal-char-escape2.C: Likewise.
* g++.dg/cpp23/Winvalid-utf8-1.C: Likewise.
* g++.dg/cpp23/Winvalid-utf8-2.C: Likewise.
* g++.dg/cpp23/Winvalid-utf8-3.C: Likewise.
* g++.dg/cpp23/Winvalid-utf8-4.C: Likewise.
* g++.dg/cpp23/Winvalid-utf8-5.C: Likewise.
* g++.dg/cpp23/Winvalid-utf8-6.C: Likewise.
* g++.dg/cpp23/Winvalid-utf8-7.C: Likewise.
* g++.dg/cpp23/Winvalid-utf8-8.C: Likewise.
* g++.dg/cpp23/Winvalid-utf8-9.C: Likewise.
* g++.dg/cpp23/Winvalid-utf8-10.C: Likewise.
* g++.dg/cpp23/Winvalid-utf8-11.C: Likewise.
* g++.dg/cpp23/Winvalid-utf8-12.C: Likewise.
* g++.dg/cpp/elifdef-3.C: Likewise.
* g++.dg/cpp/elifdef-5.C: Likewise.
* g++.dg/cpp/elifdef-6.C: Likewise.
* g++.dg/cpp/elifdef-7.C: Likewise.
* g++.dg/cpp/embed-1.C: Likewise.
* g++.dg/cpp/embed-2.C: Likewise.
* g++.dg/cpp/pedantic-errors.C: Likewise.
* g++.dg/cpp/warning-1.C: Likewise.
* g++.dg/cpp/warning-2.C: Likewise.
* g++.dg/ext/bitint1.C: Likewise.
* g++.dg/ext/bitint2.C: Likewise.
2024-10-12 16:44:17 +08:00
|
|
|
"%s: not used because %<%.*s%> not defined",
|
diagnostic.h (diagnostic_override_option_index): New macro to set a diagnostic's option_index.
* diagnostic.h (diagnostic_override_option_index): New macro to
set a diagnostic's option_index.
* c-tree.h (c_cpp_error): Add warning reason argument.
* opts.c (_warning_as_error_callback): New.
(register_warning_as_error_callback): Store callback for
warnings enabled via enable_warning_as_error.
(enable_warning_as_error): Call callback, minor code tidy.
* opts.h (register_warning_as_error_callback): Declare.
* c-opts.c (warning_as_error_callback): New, set cpp_opts flag in
response to -Werror=.
(c_common_init_options): Register warning_as_error_callback in opts.c.
* common.opt: Add -Wno-cpp option.
* c-common.c (struct reason_option_codes_t): Map cpp warning
reason codes to gcc option indexes.
* (c_option_controlling_cpp_error): New function, lookup the gcc
option index for a cpp warning reason code.
* (c_cpp_error): Add warning reason argument, call
c_option_controlling_cpp_error for diagnostic_override_option_index.
* doc/invoke.texi: Document -Wno-cpp.
* cpp.c (cb_cpp_error): Add warning reason argument, set a value
for diagnostic_override_option_index if CPP_W_WARNING_DIRECTIVE.
* directives.c (do_diagnostic): Add warning reason argument,
call appropriate error reporting function for code.
(directive_diagnostics): Call specific warning functions with
warning reason where appropriate.
(do_error, do_warning, do_pragma_dependency): Add warning reason
argument to do_diagnostic calls.
* macro.c (_cpp_warn_if_unused_macro, enter_macro_context,
_cpp_create_definition): Call specific warning functions with
warning reason where appropriate.
* Makefile.in: Add new diagnostic functions to gettext translations.
* include/cpplib.h (struct cpp_callbacks): Add warning reason code
to error callback.
(CPP_DL_WARNING, CPP_DL_WARNING_SYSHDR, CPP_DL_PEDWARN, CPP_DL_ERROR,
CPP_DL_ICE, CPP_DL_NOTE, CPP_DL_FATAL): Replace macros with enums.
(CPP_W_NONE, CPP_W_DEPRECATED, CPP_W_COMMENTS,
CPP_W_MISSING_INCLUDE_DIRS, CPP_W_TRIGRAPHS, CPP_W_MULTICHAR,
CPP_W_TRADITIONAL, CPP_W_LONG_LONG, CPP_W_ENDIF_LABELS,
CPP_W_NUM_SIGN_CHANGE, CPP_W_VARIADIC_MACROS,
CPP_W_BUILTIN_MACRO_REDEFINED, CPP_W_DOLLARS, CPP_W_UNDEF,
CPP_W_UNUSED_MACROS, CPP_W_CXX_OPERATOR_NAMES, CPP_W_NORMALIZE,
CPP_W_INVALID_PCH, CPP_W_WARNING_DIRECTIVE): New enums for cpp
warning reason codes.
(cpp_warning, cpp_pedwarning, cpp_warning_syshdr,
cpp_warning_with_line, cpp_pedwarning_with_line,
cpp_warning_with_line_syshdr): New specific error reporting functions.
* pch.c (cpp_valid_state): Call specific warning functions with
warning reason where appropriate.
* errors.c (cpp_diagnostic, cpp_diagnostic_with_line): New central
diagnostic handlers.
(cpp_warning, cpp_pedwarning, cpp_warning_syshdr,
cpp_warning_with_line, cpp_pedwarning_with_line,
cpp_warning_with_line_syshdr): New specific error reporting functions.
* expr.c (cpp_classify_number, eval_token, num_unary_op): Call
specific warning functions with warning reason where appropriate.
* lex.c (_cpp_process_line_notes, _cpp_skip_block_comment,
warn_about_normalization, lex_identifier_intern, lex_identifier,
_cpp_lex_direct): Ditto.
* charset.c (_cpp_valid_ucn, convert_hex, convert_escape,
narrow_str_to_charconst): Ditto.
* gcc.dg/cpp/warn-undef-2.c: New.
* gcc.dg/cpp/warn-traditional-2.c: New.
* gcc.dg/cpp/warn-comments-2.c: New.
* gcc.dg/cpp/warning-directive-1.c: New.
* gcc.dg/cpp/warn-long-long.c: New.
* gcc.dg/cpp/warn-traditional.c: New.
* gcc.dg/cpp/warn-variadic-2.c: New.
* gcc.dg/cpp/warn-undef.c: New.
* gcc.dg/cpp/warn-normalized-1.c: New.
* gcc.dg/cpp/warning-directive-2.c: New.
* gcc.dg/cpp/warn-long-long-2.c: New.
* gcc.dg/cpp/warn-variadic.c: New.
* gcc.dg/cpp/warn-normalized-2.c: New.
* gcc.dg/cpp/warning-directive-3.c: New.
* gcc.dg/cpp/warn-deprecated-2.c: New.
* gcc.dg/cpp/warn-trigraphs-1.c: New.
* gcc.dg/cpp/warn-multichar-2.c: New.
* gcc.dg/cpp/warn-normalized-3.c: New.
* gcc.dg/cpp/warning-directive-4.c: New.
* gcc.dg/cpp/warn-unused-macros.c: New.
* gcc.dg/cpp/warn-trigraphs-2.c: New.
* gcc.dg/cpp/warn-cxx-compat-2.c: New.
* gcc.dg/cpp/warn-cxx-compat.c: New.
* gcc.dg/cpp/warn-redefined.c: New.
* gcc.dg/cpp/warn-trigraphs-3.c: New.
* gcc.dg/cpp/warn-unused-macros-2.c: New.
* gcc.dg/cpp/warn-deprecated.c: New.
* gcc.dg/cpp/warn-trigraphs-4.c: New.
* gcc.dg/cpp/warn-redefined-2.c: New.
* gcc.dg/cpp/warn-comments.c: New.
* gcc.dg/cpp/warn-multichar.c: New.
* g++.dg/cpp/warning-directive-1.C: New.
* g++.dg/cpp/warning-directive-2.C: New.
* g++.dg/cpp/warning-directive-3.C: New.
* g++.dg/cpp/warning-directive-4.C: New.
* gfortran.dg/warning-directive-1.F90: New.
* gfortran.dg/warning-directive-3.F90: New.
* gfortran.dg/warning-directive-2.F90: New.
* gfortran.dg/warning-directive-4.F90: New.
From-SVN: r158079
2010-04-08 01:18:10 +08:00
|
|
|
name, m.name_length, namebuf);
|
2003-01-10 10:22:34 +08:00
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
newdefn = cpp_macro_definition (r, h);
|
2007-06-01 10:12:37 +08:00
|
|
|
|
2003-01-10 10:22:34 +08:00
|
|
|
if (m.definition_length != ustrlen (newdefn)
|
|
|
|
|| memcmp (namebuf, newdefn, m.definition_length) != 0)
|
|
|
|
{
|
|
|
|
if (CPP_OPTION (r, warn_invalid_pch))
|
diagnostic.h (diagnostic_override_option_index): New macro to set a diagnostic's option_index.
* diagnostic.h (diagnostic_override_option_index): New macro to
set a diagnostic's option_index.
* c-tree.h (c_cpp_error): Add warning reason argument.
* opts.c (_warning_as_error_callback): New.
(register_warning_as_error_callback): Store callback for
warnings enabled via enable_warning_as_error.
(enable_warning_as_error): Call callback, minor code tidy.
* opts.h (register_warning_as_error_callback): Declare.
* c-opts.c (warning_as_error_callback): New, set cpp_opts flag in
response to -Werror=.
(c_common_init_options): Register warning_as_error_callback in opts.c.
* common.opt: Add -Wno-cpp option.
* c-common.c (struct reason_option_codes_t): Map cpp warning
reason codes to gcc option indexes.
* (c_option_controlling_cpp_error): New function, lookup the gcc
option index for a cpp warning reason code.
* (c_cpp_error): Add warning reason argument, call
c_option_controlling_cpp_error for diagnostic_override_option_index.
* doc/invoke.texi: Document -Wno-cpp.
* cpp.c (cb_cpp_error): Add warning reason argument, set a value
for diagnostic_override_option_index if CPP_W_WARNING_DIRECTIVE.
* directives.c (do_diagnostic): Add warning reason argument,
call appropriate error reporting function for code.
(directive_diagnostics): Call specific warning functions with
warning reason where appropriate.
(do_error, do_warning, do_pragma_dependency): Add warning reason
argument to do_diagnostic calls.
* macro.c (_cpp_warn_if_unused_macro, enter_macro_context,
_cpp_create_definition): Call specific warning functions with
warning reason where appropriate.
* Makefile.in: Add new diagnostic functions to gettext translations.
* include/cpplib.h (struct cpp_callbacks): Add warning reason code
to error callback.
(CPP_DL_WARNING, CPP_DL_WARNING_SYSHDR, CPP_DL_PEDWARN, CPP_DL_ERROR,
CPP_DL_ICE, CPP_DL_NOTE, CPP_DL_FATAL): Replace macros with enums.
(CPP_W_NONE, CPP_W_DEPRECATED, CPP_W_COMMENTS,
CPP_W_MISSING_INCLUDE_DIRS, CPP_W_TRIGRAPHS, CPP_W_MULTICHAR,
CPP_W_TRADITIONAL, CPP_W_LONG_LONG, CPP_W_ENDIF_LABELS,
CPP_W_NUM_SIGN_CHANGE, CPP_W_VARIADIC_MACROS,
CPP_W_BUILTIN_MACRO_REDEFINED, CPP_W_DOLLARS, CPP_W_UNDEF,
CPP_W_UNUSED_MACROS, CPP_W_CXX_OPERATOR_NAMES, CPP_W_NORMALIZE,
CPP_W_INVALID_PCH, CPP_W_WARNING_DIRECTIVE): New enums for cpp
warning reason codes.
(cpp_warning, cpp_pedwarning, cpp_warning_syshdr,
cpp_warning_with_line, cpp_pedwarning_with_line,
cpp_warning_with_line_syshdr): New specific error reporting functions.
* pch.c (cpp_valid_state): Call specific warning functions with
warning reason where appropriate.
* errors.c (cpp_diagnostic, cpp_diagnostic_with_line): New central
diagnostic handlers.
(cpp_warning, cpp_pedwarning, cpp_warning_syshdr,
cpp_warning_with_line, cpp_pedwarning_with_line,
cpp_warning_with_line_syshdr): New specific error reporting functions.
* expr.c (cpp_classify_number, eval_token, num_unary_op): Call
specific warning functions with warning reason where appropriate.
* lex.c (_cpp_process_line_notes, _cpp_skip_block_comment,
warn_about_normalization, lex_identifier_intern, lex_identifier,
_cpp_lex_direct): Ditto.
* charset.c (_cpp_valid_ucn, convert_hex, convert_escape,
narrow_str_to_charconst): Ditto.
* gcc.dg/cpp/warn-undef-2.c: New.
* gcc.dg/cpp/warn-traditional-2.c: New.
* gcc.dg/cpp/warn-comments-2.c: New.
* gcc.dg/cpp/warning-directive-1.c: New.
* gcc.dg/cpp/warn-long-long.c: New.
* gcc.dg/cpp/warn-traditional.c: New.
* gcc.dg/cpp/warn-variadic-2.c: New.
* gcc.dg/cpp/warn-undef.c: New.
* gcc.dg/cpp/warn-normalized-1.c: New.
* gcc.dg/cpp/warning-directive-2.c: New.
* gcc.dg/cpp/warn-long-long-2.c: New.
* gcc.dg/cpp/warn-variadic.c: New.
* gcc.dg/cpp/warn-normalized-2.c: New.
* gcc.dg/cpp/warning-directive-3.c: New.
* gcc.dg/cpp/warn-deprecated-2.c: New.
* gcc.dg/cpp/warn-trigraphs-1.c: New.
* gcc.dg/cpp/warn-multichar-2.c: New.
* gcc.dg/cpp/warn-normalized-3.c: New.
* gcc.dg/cpp/warning-directive-4.c: New.
* gcc.dg/cpp/warn-unused-macros.c: New.
* gcc.dg/cpp/warn-trigraphs-2.c: New.
* gcc.dg/cpp/warn-cxx-compat-2.c: New.
* gcc.dg/cpp/warn-cxx-compat.c: New.
* gcc.dg/cpp/warn-redefined.c: New.
* gcc.dg/cpp/warn-trigraphs-3.c: New.
* gcc.dg/cpp/warn-unused-macros-2.c: New.
* gcc.dg/cpp/warn-deprecated.c: New.
* gcc.dg/cpp/warn-trigraphs-4.c: New.
* gcc.dg/cpp/warn-redefined-2.c: New.
* gcc.dg/cpp/warn-comments.c: New.
* gcc.dg/cpp/warn-multichar.c: New.
* g++.dg/cpp/warning-directive-1.C: New.
* g++.dg/cpp/warning-directive-2.C: New.
* g++.dg/cpp/warning-directive-3.C: New.
* g++.dg/cpp/warning-directive-4.C: New.
* gfortran.dg/warning-directive-1.F90: New.
* gfortran.dg/warning-directive-3.F90: New.
* gfortran.dg/warning-directive-2.F90: New.
* gfortran.dg/warning-directive-4.F90: New.
From-SVN: r158079
2010-04-08 01:18:10 +08:00
|
|
|
cpp_warning_syshdr (r, CPP_W_INVALID_PCH,
|
libcpp, genmatch: Use gcc_diag instead of printf for libcpp diagnostics
When working on #embed support, or -Wheader-guard or other recent libcpp
changes, I've been annoyed by the libcpp diagnostics being visually
different from normal gcc diagnostics, especially in the area of quoting
stuff in the diagnostic messages.
Normall GCC diagnostics is gcc_diag/gcc_tdiag, one can use
%</%>, %qs etc. in there, while libcpp diagnostics was marked as printf
and in libcpp we've been very creative with quoting stuff, either
no quotes at all, or "something" quoting, or 'something' quoting, or
`something' quoting (but in none of the cases it used colors consistently
with the rest of the compiler).
Now, libcpp diagnostics is always emitted using a callback,
pfile->cb.diagnostic. On the gcc/ side, this callback is initialized with
genmatch.cc: cb->diagnostic = diagnostic_cb;
c-family/c-opts.cc: cb->diagnostic = c_cpp_diagnostic;
fortran/cpp.cc: cb->diagnostic = cb_cpp_diagnostic;
where the latter two just use diagnostic_report_diagnostic, so actually
support all the gcc_diag stuff, only the genmatch.cc case didn't.
So, the following patch changes genmatch.cc to use pp_format* instead
of vfprintf so that it supports the gcc_diag formatting (pretty-print.o
unfortunately has various dependencies, so had to link genmatch with
libcommon.a libbacktrace.a and tweak Makefile.in so that there are no
circular dependencies) and marks the libcpp diagnostic routines as
gcc_diag rather than printf. That change resulted in hundreds of
-Wformat-diag new warnings (most of them useful and resulting IMHO in
better diagnostics), so the rest of the patch is changing the format
strings to make -Wformat-diag happy and adjusting the testsuite for
the differences in how is the diagnostic reformatted.
Dunno if some out of GCC tree projects use libcpp, that case would
make it harder because one couldn't use vfprintf in the diagnostic
callback anymore, but there is always David's libdiagnostic which could
be used for that purpose IMHO.
2024-10-12 Jakub Jelinek <jakub@redhat.com>
libcpp/
* include/cpplib.h (ATTRIBUTE_CPP_PPDIAG): Define.
(struct cpp_callbacks): Use ATTRIBUTE_CPP_PPDIAG instead of
ATTRIBUTE_FPTR_PRINTF on diagnostic callback.
(cpp_error, cpp_warning, cpp_pedwarning, cpp_warning_syshdr): Use
ATTRIBUTE_CPP_PPDIAG (3, 4) instead of ATTRIBUTE_PRINTF_3.
(cpp_warning_at, cpp_pedwarning_at): Use ATTRIBUTE_CPP_PPDIAG (4, 5)
instead of ATTRIBUTE_PRINTF_4.
(cpp_error_with_line, cpp_warning_with_line, cpp_pedwarning_with_line,
cpp_warning_with_line_syshdr): Use ATTRIBUTE_CPP_PPDIAG (5, 6)
instead of ATTRIBUTE_PRINTF_5.
(cpp_error_at): Use ATTRIBUTE_CPP_PPDIAG (4, 5) instead of
ATTRIBUTE_PRINTF_4.
* Makefile.in (po/$(PACKAGE).pot): Use --language=GCC-source rather
than --language=c.
* errors.cc (cpp_diagnostic_at, cpp_diagnostic,
cpp_diagnostic_with_line): Use ATTRIBUTE_CPP_PPDIAG instead of
-ATTRIBUTE_FPTR_PRINTF.
* charset.cc (cpp_host_to_exec_charset, _cpp_valid_ucn, convert_hex,
convert_oct, convert_escape): Fix up -Wformat-diag warnings.
(cpp_interpret_string_ranges, count_source_chars): Use
ATTRIBUTE_CPP_PPDIAG instead of ATTRIBUTE_FPTR_PRINTF.
(narrow_str_to_charconst): Fix up -Wformat-diag warnings.
* directives.cc (check_eol_1, directive_diagnostics, lex_macro_node,
do_undef, glue_header_name, parse_include, do_include_common,
do_include_next, _cpp_parse_embed_params, do_embed, read_flag,
do_line, do_linemarker, register_pragma_1, do_pragma_once,
do_pragma_push_macro, do_pragma_pop_macro, do_pragma_poison,
do_pragma_system_header, do_pragma_warning_or_error, _cpp_do__Pragma,
do_else, do_elif, do_endif, parse_answer, do_assert,
cpp_define_unused): Likewise.
* expr.cc (cpp_classify_number, parse_defined, eval_token,
_cpp_parse_expr, reduce, check_promotion): Likewise.
* files.cc (_cpp_find_file, finish_base64_embed,
_cpp_pop_file_buffer): Likewise.
* init.cc (sanity_checks): Likewise.
* lex.cc (_cpp_process_line_notes, maybe_warn_bidi_on_char,
_cpp_warn_invalid_utf8, _cpp_skip_block_comment,
warn_about_normalization, forms_identifier_p, maybe_va_opt_error,
identifier_diagnostics_on_lex, cpp_maybe_module_directive): Likewise.
* macro.cc (class vaopt_state, builtin_has_include_1,
builtin_has_include, builtin_has_embed, _cpp_warn_if_unused_macro,
_cpp_builtin_macro_text, builtin_macro, stringify_arg,
_cpp_arguments_ok, collect_args, enter_macro_context,
_cpp_save_parameter, parse_params, create_iso_definition,
_cpp_create_definition, check_trad_stringification): Likewise.
* pch.cc (cpp_valid_state): Likewise.
* traditional.cc (_cpp_scan_out_logical_line, recursive_macro):
Likewise.
gcc/
* Makefile.in (generated_files): Remove {gimple,generic}-match*.
(generated_match_files): New variable. Add a dependency of
$(filter-out $(OBJS-libcommon),$(ALL_HOST_OBJS)) files on those.
(build/genmatch$(build_exeext)): Depend on and link against
libcommon.a and $(LIBBACKTRACE).
* genmatch.cc: Include pretty-print.h and input.h.
(ggc_internal_cleared_alloc, ggc_free): Remove.
(fatal): New function.
(line_table): Remove.
(linemap_client_expand_location_to_spelling_point): Remove.
(diagnostic_cb): Use gcc_diag rather than printf format. Use
pp_format_verbatim on a temporary pretty_printer instead of
vfprintf.
(fatal_at, warning_at): Use gcc_diag rather than printf format.
(output_line_directive): Rename location_hash to loc_hash.
(parser::eat_ident, parser::parse_operation, parser::parse_expr,
parser::parse_pattern, parser::finish_match_operand): Fix up
-Wformat-diag warnings.
gcc/c-family/
* c-lex.cc (c_common_has_attribute,
c_common_lex_availability_macro): Fix up -Wformat-diag warnings.
gcc/testsuite/
* c-c++-common/cpp/counter-2.c: Adjust expected diagnostics for
libcpp diagnostic formatting changes.
* c-c++-common/cpp/embed-3.c: Likewise.
* c-c++-common/cpp/embed-4.c: Likewise.
* c-c++-common/cpp/embed-16.c: Likewise.
* c-c++-common/cpp/embed-18.c: Likewise.
* c-c++-common/cpp/eof-2.c: Likewise.
* c-c++-common/cpp/eof-3.c: Likewise.
* c-c++-common/cpp/fmax-include-depth.c: Likewise.
* c-c++-common/cpp/has-builtin.c: Likewise.
* c-c++-common/cpp/line-2.c: Likewise.
* c-c++-common/cpp/line-3.c: Likewise.
* c-c++-common/cpp/macro-arg-count-1.c: Likewise.
* c-c++-common/cpp/macro-arg-count-2.c: Likewise.
* c-c++-common/cpp/macro-ranges.c: Likewise.
* c-c++-common/cpp/named-universal-char-escape-4.c: Likewise.
* c-c++-common/cpp/named-universal-char-escape-5.c: Likewise.
* c-c++-common/cpp/pr88974.c: Likewise.
* c-c++-common/cpp/va-opt-error.c: Likewise.
* c-c++-common/cpp/va-opt-pedantic.c: Likewise.
* c-c++-common/cpp/Wheader-guard-2.c: Likewise.
* c-c++-common/cpp/Wheader-guard-3.c: Likewise.
* c-c++-common/cpp/Winvalid-utf8-1.c: Likewise.
* c-c++-common/cpp/Winvalid-utf8-2.c: Likewise.
* c-c++-common/cpp/Winvalid-utf8-3.c: Likewise.
* c-c++-common/diagnostic-format-sarif-file-bad-utf8-pr109098-1.c:
Likewise.
* c-c++-common/diagnostic-format-sarif-file-bad-utf8-pr109098-3.c:
Likewise.
* c-c++-common/pr68833-3.c: Likewise.
* c-c++-common/raw-string-directive-1.c: Likewise.
* gcc.dg/analyzer/named-constants-Wunused-macros.c: Likewise.
* gcc.dg/binary-constants-4.c: Likewise.
* gcc.dg/builtin-redefine.c: Likewise.
* gcc.dg/cpp/19951025-1.c: Likewise.
* gcc.dg/cpp/c11-warning-1.c: Likewise.
* gcc.dg/cpp/c11-warning-2.c: Likewise.
* gcc.dg/cpp/c11-warning-3.c: Likewise.
* gcc.dg/cpp/c23-elifdef-2.c: Likewise.
* gcc.dg/cpp/c23-warning-2.c: Likewise.
* gcc.dg/cpp/embed-2.c: Likewise.
* gcc.dg/cpp/embed-3.c: Likewise.
* gcc.dg/cpp/embed-4.c: Likewise.
* gcc.dg/cpp/expr.c: Likewise.
* gcc.dg/cpp/gnu11-elifdef-2.c: Likewise.
* gcc.dg/cpp/gnu11-elifdef-3.c: Likewise.
* gcc.dg/cpp/gnu11-elifdef-4.c: Likewise.
* gcc.dg/cpp/gnu11-warning-1.c: Likewise.
* gcc.dg/cpp/gnu11-warning-2.c: Likewise.
* gcc.dg/cpp/gnu11-warning-3.c: Likewise.
* gcc.dg/cpp/gnu23-warning-2.c: Likewise.
* gcc.dg/cpp/include6.c: Likewise.
* gcc.dg/cpp/pr35322.c: Likewise.
* gcc.dg/cpp/tr-warn6.c: Likewise.
* gcc.dg/cpp/undef2.c: Likewise.
* gcc.dg/cpp/warn-comments.c: Likewise.
* gcc.dg/cpp/warn-comments-2.c: Likewise.
* gcc.dg/cpp/warn-comments-3.c: Likewise.
* gcc.dg/cpp/warn-cxx-compat.c: Likewise.
* gcc.dg/cpp/warn-cxx-compat-2.c: Likewise.
* gcc.dg/cpp/warn-deprecated.c: Likewise.
* gcc.dg/cpp/warn-deprecated-2.c: Likewise.
* gcc.dg/cpp/warn-long-long.c: Likewise.
* gcc.dg/cpp/warn-long-long-2.c: Likewise.
* gcc.dg/cpp/warn-normalized-1.c: Likewise.
* gcc.dg/cpp/warn-normalized-2.c: Likewise.
* gcc.dg/cpp/warn-normalized-3.c: Likewise.
* gcc.dg/cpp/warn-normalized-4-bytes.c: Likewise.
* gcc.dg/cpp/warn-normalized-4-unicode.c: Likewise.
* gcc.dg/cpp/warn-redefined.c: Likewise.
* gcc.dg/cpp/warn-redefined-2.c: Likewise.
* gcc.dg/cpp/warn-traditional.c: Likewise.
* gcc.dg/cpp/warn-traditional-2.c: Likewise.
* gcc.dg/cpp/warn-trigraphs-1.c: Likewise.
* gcc.dg/cpp/warn-trigraphs-2.c: Likewise.
* gcc.dg/cpp/warn-trigraphs-3.c: Likewise.
* gcc.dg/cpp/warn-trigraphs-4.c: Likewise.
* gcc.dg/cpp/warn-undef.c: Likewise.
* gcc.dg/cpp/warn-undef-2.c: Likewise.
* gcc.dg/cpp/warn-unused-macros.c: Likewise.
* gcc.dg/cpp/warn-unused-macros-2.c: Likewise.
* gcc.dg/pch/counter-2.c: Likewise.
* g++.dg/cpp0x/udlit-error1.C: Likewise.
* g++.dg/cpp23/named-universal-char-escape1.C: Likewise.
* g++.dg/cpp23/named-universal-char-escape2.C: Likewise.
* g++.dg/cpp23/Winvalid-utf8-1.C: Likewise.
* g++.dg/cpp23/Winvalid-utf8-2.C: Likewise.
* g++.dg/cpp23/Winvalid-utf8-3.C: Likewise.
* g++.dg/cpp23/Winvalid-utf8-4.C: Likewise.
* g++.dg/cpp23/Winvalid-utf8-5.C: Likewise.
* g++.dg/cpp23/Winvalid-utf8-6.C: Likewise.
* g++.dg/cpp23/Winvalid-utf8-7.C: Likewise.
* g++.dg/cpp23/Winvalid-utf8-8.C: Likewise.
* g++.dg/cpp23/Winvalid-utf8-9.C: Likewise.
* g++.dg/cpp23/Winvalid-utf8-10.C: Likewise.
* g++.dg/cpp23/Winvalid-utf8-11.C: Likewise.
* g++.dg/cpp23/Winvalid-utf8-12.C: Likewise.
* g++.dg/cpp/elifdef-3.C: Likewise.
* g++.dg/cpp/elifdef-5.C: Likewise.
* g++.dg/cpp/elifdef-6.C: Likewise.
* g++.dg/cpp/elifdef-7.C: Likewise.
* g++.dg/cpp/embed-1.C: Likewise.
* g++.dg/cpp/embed-2.C: Likewise.
* g++.dg/cpp/pedantic-errors.C: Likewise.
* g++.dg/cpp/warning-1.C: Likewise.
* g++.dg/cpp/warning-2.C: Likewise.
* g++.dg/ext/bitint1.C: Likewise.
* g++.dg/ext/bitint2.C: Likewise.
2024-10-12 16:44:17 +08:00
|
|
|
"%s: not used because %<%.*s%> defined as "
|
|
|
|
"%<%s%> not %<%.*s%>",
|
|
|
|
name, m.name_length, namebuf,
|
|
|
|
newdefn + m.name_length,
|
|
|
|
m.definition_length - m.name_length,
|
|
|
|
namebuf + m.name_length);
|
2003-01-10 10:22:34 +08:00
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
free (namebuf);
|
|
|
|
namebuf = NULL;
|
|
|
|
|
|
|
|
/* Read in the list of identifiers that must not be defined.
|
|
|
|
Check that they really aren't. */
|
2005-05-28 23:52:48 +08:00
|
|
|
undeftab = XNEWVEC (unsigned char, m.definition_length);
|
2003-01-10 10:22:34 +08:00
|
|
|
if ((size_t) read (fd, undeftab, m.definition_length) != m.definition_length)
|
|
|
|
goto error;
|
2003-04-01 04:02:40 +08:00
|
|
|
|
|
|
|
/* Collect identifiers from the current hash table. */
|
|
|
|
nl.n_defs = 0;
|
|
|
|
nl.asize = 10;
|
2005-05-28 23:52:48 +08:00
|
|
|
nl.defs = XNEWVEC (cpp_hashnode *, nl.asize);
|
2003-04-01 04:02:40 +08:00
|
|
|
cpp_forall_identifiers (r, &collect_ht_nodes, &nl);
|
|
|
|
qsort (nl.defs, nl.n_defs, sizeof (cpp_hashnode *), &comp_hashnodes);
|
2007-06-01 10:12:37 +08:00
|
|
|
|
2003-04-01 04:02:40 +08:00
|
|
|
/* Loop through nl.defs and undeftab, both of which are sorted lists.
|
2003-06-23 23:27:37 +08:00
|
|
|
There should be no matches. */
|
2003-04-01 04:02:40 +08:00
|
|
|
first = undeftab;
|
|
|
|
last = undeftab + m.definition_length;
|
|
|
|
i = 0;
|
2007-06-01 10:12:37 +08:00
|
|
|
|
2003-04-01 04:02:40 +08:00
|
|
|
while (first < last && i < nl.n_defs)
|
2003-01-10 10:22:34 +08:00
|
|
|
{
|
2003-04-01 04:02:40 +08:00
|
|
|
int cmp = ustrcmp (first, NODE_NAME (nl.defs[i]));
|
2007-06-01 10:12:37 +08:00
|
|
|
|
2003-04-01 04:02:40 +08:00
|
|
|
if (cmp < 0)
|
|
|
|
first += ustrlen (first) + 1;
|
|
|
|
else if (cmp > 0)
|
|
|
|
++i;
|
|
|
|
else
|
2003-08-20 12:04:47 +08:00
|
|
|
{
|
|
|
|
if (CPP_OPTION (r, warn_invalid_pch))
|
diagnostic.h (diagnostic_override_option_index): New macro to set a diagnostic's option_index.
* diagnostic.h (diagnostic_override_option_index): New macro to
set a diagnostic's option_index.
* c-tree.h (c_cpp_error): Add warning reason argument.
* opts.c (_warning_as_error_callback): New.
(register_warning_as_error_callback): Store callback for
warnings enabled via enable_warning_as_error.
(enable_warning_as_error): Call callback, minor code tidy.
* opts.h (register_warning_as_error_callback): Declare.
* c-opts.c (warning_as_error_callback): New, set cpp_opts flag in
response to -Werror=.
(c_common_init_options): Register warning_as_error_callback in opts.c.
* common.opt: Add -Wno-cpp option.
* c-common.c (struct reason_option_codes_t): Map cpp warning
reason codes to gcc option indexes.
* (c_option_controlling_cpp_error): New function, lookup the gcc
option index for a cpp warning reason code.
* (c_cpp_error): Add warning reason argument, call
c_option_controlling_cpp_error for diagnostic_override_option_index.
* doc/invoke.texi: Document -Wno-cpp.
* cpp.c (cb_cpp_error): Add warning reason argument, set a value
for diagnostic_override_option_index if CPP_W_WARNING_DIRECTIVE.
* directives.c (do_diagnostic): Add warning reason argument,
call appropriate error reporting function for code.
(directive_diagnostics): Call specific warning functions with
warning reason where appropriate.
(do_error, do_warning, do_pragma_dependency): Add warning reason
argument to do_diagnostic calls.
* macro.c (_cpp_warn_if_unused_macro, enter_macro_context,
_cpp_create_definition): Call specific warning functions with
warning reason where appropriate.
* Makefile.in: Add new diagnostic functions to gettext translations.
* include/cpplib.h (struct cpp_callbacks): Add warning reason code
to error callback.
(CPP_DL_WARNING, CPP_DL_WARNING_SYSHDR, CPP_DL_PEDWARN, CPP_DL_ERROR,
CPP_DL_ICE, CPP_DL_NOTE, CPP_DL_FATAL): Replace macros with enums.
(CPP_W_NONE, CPP_W_DEPRECATED, CPP_W_COMMENTS,
CPP_W_MISSING_INCLUDE_DIRS, CPP_W_TRIGRAPHS, CPP_W_MULTICHAR,
CPP_W_TRADITIONAL, CPP_W_LONG_LONG, CPP_W_ENDIF_LABELS,
CPP_W_NUM_SIGN_CHANGE, CPP_W_VARIADIC_MACROS,
CPP_W_BUILTIN_MACRO_REDEFINED, CPP_W_DOLLARS, CPP_W_UNDEF,
CPP_W_UNUSED_MACROS, CPP_W_CXX_OPERATOR_NAMES, CPP_W_NORMALIZE,
CPP_W_INVALID_PCH, CPP_W_WARNING_DIRECTIVE): New enums for cpp
warning reason codes.
(cpp_warning, cpp_pedwarning, cpp_warning_syshdr,
cpp_warning_with_line, cpp_pedwarning_with_line,
cpp_warning_with_line_syshdr): New specific error reporting functions.
* pch.c (cpp_valid_state): Call specific warning functions with
warning reason where appropriate.
* errors.c (cpp_diagnostic, cpp_diagnostic_with_line): New central
diagnostic handlers.
(cpp_warning, cpp_pedwarning, cpp_warning_syshdr,
cpp_warning_with_line, cpp_pedwarning_with_line,
cpp_warning_with_line_syshdr): New specific error reporting functions.
* expr.c (cpp_classify_number, eval_token, num_unary_op): Call
specific warning functions with warning reason where appropriate.
* lex.c (_cpp_process_line_notes, _cpp_skip_block_comment,
warn_about_normalization, lex_identifier_intern, lex_identifier,
_cpp_lex_direct): Ditto.
* charset.c (_cpp_valid_ucn, convert_hex, convert_escape,
narrow_str_to_charconst): Ditto.
* gcc.dg/cpp/warn-undef-2.c: New.
* gcc.dg/cpp/warn-traditional-2.c: New.
* gcc.dg/cpp/warn-comments-2.c: New.
* gcc.dg/cpp/warning-directive-1.c: New.
* gcc.dg/cpp/warn-long-long.c: New.
* gcc.dg/cpp/warn-traditional.c: New.
* gcc.dg/cpp/warn-variadic-2.c: New.
* gcc.dg/cpp/warn-undef.c: New.
* gcc.dg/cpp/warn-normalized-1.c: New.
* gcc.dg/cpp/warning-directive-2.c: New.
* gcc.dg/cpp/warn-long-long-2.c: New.
* gcc.dg/cpp/warn-variadic.c: New.
* gcc.dg/cpp/warn-normalized-2.c: New.
* gcc.dg/cpp/warning-directive-3.c: New.
* gcc.dg/cpp/warn-deprecated-2.c: New.
* gcc.dg/cpp/warn-trigraphs-1.c: New.
* gcc.dg/cpp/warn-multichar-2.c: New.
* gcc.dg/cpp/warn-normalized-3.c: New.
* gcc.dg/cpp/warning-directive-4.c: New.
* gcc.dg/cpp/warn-unused-macros.c: New.
* gcc.dg/cpp/warn-trigraphs-2.c: New.
* gcc.dg/cpp/warn-cxx-compat-2.c: New.
* gcc.dg/cpp/warn-cxx-compat.c: New.
* gcc.dg/cpp/warn-redefined.c: New.
* gcc.dg/cpp/warn-trigraphs-3.c: New.
* gcc.dg/cpp/warn-unused-macros-2.c: New.
* gcc.dg/cpp/warn-deprecated.c: New.
* gcc.dg/cpp/warn-trigraphs-4.c: New.
* gcc.dg/cpp/warn-redefined-2.c: New.
* gcc.dg/cpp/warn-comments.c: New.
* gcc.dg/cpp/warn-multichar.c: New.
* g++.dg/cpp/warning-directive-1.C: New.
* g++.dg/cpp/warning-directive-2.C: New.
* g++.dg/cpp/warning-directive-3.C: New.
* g++.dg/cpp/warning-directive-4.C: New.
* gfortran.dg/warning-directive-1.F90: New.
* gfortran.dg/warning-directive-3.F90: New.
* gfortran.dg/warning-directive-2.F90: New.
* gfortran.dg/warning-directive-4.F90: New.
From-SVN: r158079
2010-04-08 01:18:10 +08:00
|
|
|
cpp_warning_syshdr (r, CPP_W_INVALID_PCH,
|
libcpp, genmatch: Use gcc_diag instead of printf for libcpp diagnostics
When working on #embed support, or -Wheader-guard or other recent libcpp
changes, I've been annoyed by the libcpp diagnostics being visually
different from normal gcc diagnostics, especially in the area of quoting
stuff in the diagnostic messages.
Normall GCC diagnostics is gcc_diag/gcc_tdiag, one can use
%</%>, %qs etc. in there, while libcpp diagnostics was marked as printf
and in libcpp we've been very creative with quoting stuff, either
no quotes at all, or "something" quoting, or 'something' quoting, or
`something' quoting (but in none of the cases it used colors consistently
with the rest of the compiler).
Now, libcpp diagnostics is always emitted using a callback,
pfile->cb.diagnostic. On the gcc/ side, this callback is initialized with
genmatch.cc: cb->diagnostic = diagnostic_cb;
c-family/c-opts.cc: cb->diagnostic = c_cpp_diagnostic;
fortran/cpp.cc: cb->diagnostic = cb_cpp_diagnostic;
where the latter two just use diagnostic_report_diagnostic, so actually
support all the gcc_diag stuff, only the genmatch.cc case didn't.
So, the following patch changes genmatch.cc to use pp_format* instead
of vfprintf so that it supports the gcc_diag formatting (pretty-print.o
unfortunately has various dependencies, so had to link genmatch with
libcommon.a libbacktrace.a and tweak Makefile.in so that there are no
circular dependencies) and marks the libcpp diagnostic routines as
gcc_diag rather than printf. That change resulted in hundreds of
-Wformat-diag new warnings (most of them useful and resulting IMHO in
better diagnostics), so the rest of the patch is changing the format
strings to make -Wformat-diag happy and adjusting the testsuite for
the differences in how is the diagnostic reformatted.
Dunno if some out of GCC tree projects use libcpp, that case would
make it harder because one couldn't use vfprintf in the diagnostic
callback anymore, but there is always David's libdiagnostic which could
be used for that purpose IMHO.
2024-10-12 Jakub Jelinek <jakub@redhat.com>
libcpp/
* include/cpplib.h (ATTRIBUTE_CPP_PPDIAG): Define.
(struct cpp_callbacks): Use ATTRIBUTE_CPP_PPDIAG instead of
ATTRIBUTE_FPTR_PRINTF on diagnostic callback.
(cpp_error, cpp_warning, cpp_pedwarning, cpp_warning_syshdr): Use
ATTRIBUTE_CPP_PPDIAG (3, 4) instead of ATTRIBUTE_PRINTF_3.
(cpp_warning_at, cpp_pedwarning_at): Use ATTRIBUTE_CPP_PPDIAG (4, 5)
instead of ATTRIBUTE_PRINTF_4.
(cpp_error_with_line, cpp_warning_with_line, cpp_pedwarning_with_line,
cpp_warning_with_line_syshdr): Use ATTRIBUTE_CPP_PPDIAG (5, 6)
instead of ATTRIBUTE_PRINTF_5.
(cpp_error_at): Use ATTRIBUTE_CPP_PPDIAG (4, 5) instead of
ATTRIBUTE_PRINTF_4.
* Makefile.in (po/$(PACKAGE).pot): Use --language=GCC-source rather
than --language=c.
* errors.cc (cpp_diagnostic_at, cpp_diagnostic,
cpp_diagnostic_with_line): Use ATTRIBUTE_CPP_PPDIAG instead of
-ATTRIBUTE_FPTR_PRINTF.
* charset.cc (cpp_host_to_exec_charset, _cpp_valid_ucn, convert_hex,
convert_oct, convert_escape): Fix up -Wformat-diag warnings.
(cpp_interpret_string_ranges, count_source_chars): Use
ATTRIBUTE_CPP_PPDIAG instead of ATTRIBUTE_FPTR_PRINTF.
(narrow_str_to_charconst): Fix up -Wformat-diag warnings.
* directives.cc (check_eol_1, directive_diagnostics, lex_macro_node,
do_undef, glue_header_name, parse_include, do_include_common,
do_include_next, _cpp_parse_embed_params, do_embed, read_flag,
do_line, do_linemarker, register_pragma_1, do_pragma_once,
do_pragma_push_macro, do_pragma_pop_macro, do_pragma_poison,
do_pragma_system_header, do_pragma_warning_or_error, _cpp_do__Pragma,
do_else, do_elif, do_endif, parse_answer, do_assert,
cpp_define_unused): Likewise.
* expr.cc (cpp_classify_number, parse_defined, eval_token,
_cpp_parse_expr, reduce, check_promotion): Likewise.
* files.cc (_cpp_find_file, finish_base64_embed,
_cpp_pop_file_buffer): Likewise.
* init.cc (sanity_checks): Likewise.
* lex.cc (_cpp_process_line_notes, maybe_warn_bidi_on_char,
_cpp_warn_invalid_utf8, _cpp_skip_block_comment,
warn_about_normalization, forms_identifier_p, maybe_va_opt_error,
identifier_diagnostics_on_lex, cpp_maybe_module_directive): Likewise.
* macro.cc (class vaopt_state, builtin_has_include_1,
builtin_has_include, builtin_has_embed, _cpp_warn_if_unused_macro,
_cpp_builtin_macro_text, builtin_macro, stringify_arg,
_cpp_arguments_ok, collect_args, enter_macro_context,
_cpp_save_parameter, parse_params, create_iso_definition,
_cpp_create_definition, check_trad_stringification): Likewise.
* pch.cc (cpp_valid_state): Likewise.
* traditional.cc (_cpp_scan_out_logical_line, recursive_macro):
Likewise.
gcc/
* Makefile.in (generated_files): Remove {gimple,generic}-match*.
(generated_match_files): New variable. Add a dependency of
$(filter-out $(OBJS-libcommon),$(ALL_HOST_OBJS)) files on those.
(build/genmatch$(build_exeext)): Depend on and link against
libcommon.a and $(LIBBACKTRACE).
* genmatch.cc: Include pretty-print.h and input.h.
(ggc_internal_cleared_alloc, ggc_free): Remove.
(fatal): New function.
(line_table): Remove.
(linemap_client_expand_location_to_spelling_point): Remove.
(diagnostic_cb): Use gcc_diag rather than printf format. Use
pp_format_verbatim on a temporary pretty_printer instead of
vfprintf.
(fatal_at, warning_at): Use gcc_diag rather than printf format.
(output_line_directive): Rename location_hash to loc_hash.
(parser::eat_ident, parser::parse_operation, parser::parse_expr,
parser::parse_pattern, parser::finish_match_operand): Fix up
-Wformat-diag warnings.
gcc/c-family/
* c-lex.cc (c_common_has_attribute,
c_common_lex_availability_macro): Fix up -Wformat-diag warnings.
gcc/testsuite/
* c-c++-common/cpp/counter-2.c: Adjust expected diagnostics for
libcpp diagnostic formatting changes.
* c-c++-common/cpp/embed-3.c: Likewise.
* c-c++-common/cpp/embed-4.c: Likewise.
* c-c++-common/cpp/embed-16.c: Likewise.
* c-c++-common/cpp/embed-18.c: Likewise.
* c-c++-common/cpp/eof-2.c: Likewise.
* c-c++-common/cpp/eof-3.c: Likewise.
* c-c++-common/cpp/fmax-include-depth.c: Likewise.
* c-c++-common/cpp/has-builtin.c: Likewise.
* c-c++-common/cpp/line-2.c: Likewise.
* c-c++-common/cpp/line-3.c: Likewise.
* c-c++-common/cpp/macro-arg-count-1.c: Likewise.
* c-c++-common/cpp/macro-arg-count-2.c: Likewise.
* c-c++-common/cpp/macro-ranges.c: Likewise.
* c-c++-common/cpp/named-universal-char-escape-4.c: Likewise.
* c-c++-common/cpp/named-universal-char-escape-5.c: Likewise.
* c-c++-common/cpp/pr88974.c: Likewise.
* c-c++-common/cpp/va-opt-error.c: Likewise.
* c-c++-common/cpp/va-opt-pedantic.c: Likewise.
* c-c++-common/cpp/Wheader-guard-2.c: Likewise.
* c-c++-common/cpp/Wheader-guard-3.c: Likewise.
* c-c++-common/cpp/Winvalid-utf8-1.c: Likewise.
* c-c++-common/cpp/Winvalid-utf8-2.c: Likewise.
* c-c++-common/cpp/Winvalid-utf8-3.c: Likewise.
* c-c++-common/diagnostic-format-sarif-file-bad-utf8-pr109098-1.c:
Likewise.
* c-c++-common/diagnostic-format-sarif-file-bad-utf8-pr109098-3.c:
Likewise.
* c-c++-common/pr68833-3.c: Likewise.
* c-c++-common/raw-string-directive-1.c: Likewise.
* gcc.dg/analyzer/named-constants-Wunused-macros.c: Likewise.
* gcc.dg/binary-constants-4.c: Likewise.
* gcc.dg/builtin-redefine.c: Likewise.
* gcc.dg/cpp/19951025-1.c: Likewise.
* gcc.dg/cpp/c11-warning-1.c: Likewise.
* gcc.dg/cpp/c11-warning-2.c: Likewise.
* gcc.dg/cpp/c11-warning-3.c: Likewise.
* gcc.dg/cpp/c23-elifdef-2.c: Likewise.
* gcc.dg/cpp/c23-warning-2.c: Likewise.
* gcc.dg/cpp/embed-2.c: Likewise.
* gcc.dg/cpp/embed-3.c: Likewise.
* gcc.dg/cpp/embed-4.c: Likewise.
* gcc.dg/cpp/expr.c: Likewise.
* gcc.dg/cpp/gnu11-elifdef-2.c: Likewise.
* gcc.dg/cpp/gnu11-elifdef-3.c: Likewise.
* gcc.dg/cpp/gnu11-elifdef-4.c: Likewise.
* gcc.dg/cpp/gnu11-warning-1.c: Likewise.
* gcc.dg/cpp/gnu11-warning-2.c: Likewise.
* gcc.dg/cpp/gnu11-warning-3.c: Likewise.
* gcc.dg/cpp/gnu23-warning-2.c: Likewise.
* gcc.dg/cpp/include6.c: Likewise.
* gcc.dg/cpp/pr35322.c: Likewise.
* gcc.dg/cpp/tr-warn6.c: Likewise.
* gcc.dg/cpp/undef2.c: Likewise.
* gcc.dg/cpp/warn-comments.c: Likewise.
* gcc.dg/cpp/warn-comments-2.c: Likewise.
* gcc.dg/cpp/warn-comments-3.c: Likewise.
* gcc.dg/cpp/warn-cxx-compat.c: Likewise.
* gcc.dg/cpp/warn-cxx-compat-2.c: Likewise.
* gcc.dg/cpp/warn-deprecated.c: Likewise.
* gcc.dg/cpp/warn-deprecated-2.c: Likewise.
* gcc.dg/cpp/warn-long-long.c: Likewise.
* gcc.dg/cpp/warn-long-long-2.c: Likewise.
* gcc.dg/cpp/warn-normalized-1.c: Likewise.
* gcc.dg/cpp/warn-normalized-2.c: Likewise.
* gcc.dg/cpp/warn-normalized-3.c: Likewise.
* gcc.dg/cpp/warn-normalized-4-bytes.c: Likewise.
* gcc.dg/cpp/warn-normalized-4-unicode.c: Likewise.
* gcc.dg/cpp/warn-redefined.c: Likewise.
* gcc.dg/cpp/warn-redefined-2.c: Likewise.
* gcc.dg/cpp/warn-traditional.c: Likewise.
* gcc.dg/cpp/warn-traditional-2.c: Likewise.
* gcc.dg/cpp/warn-trigraphs-1.c: Likewise.
* gcc.dg/cpp/warn-trigraphs-2.c: Likewise.
* gcc.dg/cpp/warn-trigraphs-3.c: Likewise.
* gcc.dg/cpp/warn-trigraphs-4.c: Likewise.
* gcc.dg/cpp/warn-undef.c: Likewise.
* gcc.dg/cpp/warn-undef-2.c: Likewise.
* gcc.dg/cpp/warn-unused-macros.c: Likewise.
* gcc.dg/cpp/warn-unused-macros-2.c: Likewise.
* gcc.dg/pch/counter-2.c: Likewise.
* g++.dg/cpp0x/udlit-error1.C: Likewise.
* g++.dg/cpp23/named-universal-char-escape1.C: Likewise.
* g++.dg/cpp23/named-universal-char-escape2.C: Likewise.
* g++.dg/cpp23/Winvalid-utf8-1.C: Likewise.
* g++.dg/cpp23/Winvalid-utf8-2.C: Likewise.
* g++.dg/cpp23/Winvalid-utf8-3.C: Likewise.
* g++.dg/cpp23/Winvalid-utf8-4.C: Likewise.
* g++.dg/cpp23/Winvalid-utf8-5.C: Likewise.
* g++.dg/cpp23/Winvalid-utf8-6.C: Likewise.
* g++.dg/cpp23/Winvalid-utf8-7.C: Likewise.
* g++.dg/cpp23/Winvalid-utf8-8.C: Likewise.
* g++.dg/cpp23/Winvalid-utf8-9.C: Likewise.
* g++.dg/cpp23/Winvalid-utf8-10.C: Likewise.
* g++.dg/cpp23/Winvalid-utf8-11.C: Likewise.
* g++.dg/cpp23/Winvalid-utf8-12.C: Likewise.
* g++.dg/cpp/elifdef-3.C: Likewise.
* g++.dg/cpp/elifdef-5.C: Likewise.
* g++.dg/cpp/elifdef-6.C: Likewise.
* g++.dg/cpp/elifdef-7.C: Likewise.
* g++.dg/cpp/embed-1.C: Likewise.
* g++.dg/cpp/embed-2.C: Likewise.
* g++.dg/cpp/pedantic-errors.C: Likewise.
* g++.dg/cpp/warning-1.C: Likewise.
* g++.dg/cpp/warning-2.C: Likewise.
* g++.dg/ext/bitint1.C: Likewise.
* g++.dg/ext/bitint2.C: Likewise.
2024-10-12 16:44:17 +08:00
|
|
|
"%s: not used because %qs is defined",
|
diagnostic.h (diagnostic_override_option_index): New macro to set a diagnostic's option_index.
* diagnostic.h (diagnostic_override_option_index): New macro to
set a diagnostic's option_index.
* c-tree.h (c_cpp_error): Add warning reason argument.
* opts.c (_warning_as_error_callback): New.
(register_warning_as_error_callback): Store callback for
warnings enabled via enable_warning_as_error.
(enable_warning_as_error): Call callback, minor code tidy.
* opts.h (register_warning_as_error_callback): Declare.
* c-opts.c (warning_as_error_callback): New, set cpp_opts flag in
response to -Werror=.
(c_common_init_options): Register warning_as_error_callback in opts.c.
* common.opt: Add -Wno-cpp option.
* c-common.c (struct reason_option_codes_t): Map cpp warning
reason codes to gcc option indexes.
* (c_option_controlling_cpp_error): New function, lookup the gcc
option index for a cpp warning reason code.
* (c_cpp_error): Add warning reason argument, call
c_option_controlling_cpp_error for diagnostic_override_option_index.
* doc/invoke.texi: Document -Wno-cpp.
* cpp.c (cb_cpp_error): Add warning reason argument, set a value
for diagnostic_override_option_index if CPP_W_WARNING_DIRECTIVE.
* directives.c (do_diagnostic): Add warning reason argument,
call appropriate error reporting function for code.
(directive_diagnostics): Call specific warning functions with
warning reason where appropriate.
(do_error, do_warning, do_pragma_dependency): Add warning reason
argument to do_diagnostic calls.
* macro.c (_cpp_warn_if_unused_macro, enter_macro_context,
_cpp_create_definition): Call specific warning functions with
warning reason where appropriate.
* Makefile.in: Add new diagnostic functions to gettext translations.
* include/cpplib.h (struct cpp_callbacks): Add warning reason code
to error callback.
(CPP_DL_WARNING, CPP_DL_WARNING_SYSHDR, CPP_DL_PEDWARN, CPP_DL_ERROR,
CPP_DL_ICE, CPP_DL_NOTE, CPP_DL_FATAL): Replace macros with enums.
(CPP_W_NONE, CPP_W_DEPRECATED, CPP_W_COMMENTS,
CPP_W_MISSING_INCLUDE_DIRS, CPP_W_TRIGRAPHS, CPP_W_MULTICHAR,
CPP_W_TRADITIONAL, CPP_W_LONG_LONG, CPP_W_ENDIF_LABELS,
CPP_W_NUM_SIGN_CHANGE, CPP_W_VARIADIC_MACROS,
CPP_W_BUILTIN_MACRO_REDEFINED, CPP_W_DOLLARS, CPP_W_UNDEF,
CPP_W_UNUSED_MACROS, CPP_W_CXX_OPERATOR_NAMES, CPP_W_NORMALIZE,
CPP_W_INVALID_PCH, CPP_W_WARNING_DIRECTIVE): New enums for cpp
warning reason codes.
(cpp_warning, cpp_pedwarning, cpp_warning_syshdr,
cpp_warning_with_line, cpp_pedwarning_with_line,
cpp_warning_with_line_syshdr): New specific error reporting functions.
* pch.c (cpp_valid_state): Call specific warning functions with
warning reason where appropriate.
* errors.c (cpp_diagnostic, cpp_diagnostic_with_line): New central
diagnostic handlers.
(cpp_warning, cpp_pedwarning, cpp_warning_syshdr,
cpp_warning_with_line, cpp_pedwarning_with_line,
cpp_warning_with_line_syshdr): New specific error reporting functions.
* expr.c (cpp_classify_number, eval_token, num_unary_op): Call
specific warning functions with warning reason where appropriate.
* lex.c (_cpp_process_line_notes, _cpp_skip_block_comment,
warn_about_normalization, lex_identifier_intern, lex_identifier,
_cpp_lex_direct): Ditto.
* charset.c (_cpp_valid_ucn, convert_hex, convert_escape,
narrow_str_to_charconst): Ditto.
* gcc.dg/cpp/warn-undef-2.c: New.
* gcc.dg/cpp/warn-traditional-2.c: New.
* gcc.dg/cpp/warn-comments-2.c: New.
* gcc.dg/cpp/warning-directive-1.c: New.
* gcc.dg/cpp/warn-long-long.c: New.
* gcc.dg/cpp/warn-traditional.c: New.
* gcc.dg/cpp/warn-variadic-2.c: New.
* gcc.dg/cpp/warn-undef.c: New.
* gcc.dg/cpp/warn-normalized-1.c: New.
* gcc.dg/cpp/warning-directive-2.c: New.
* gcc.dg/cpp/warn-long-long-2.c: New.
* gcc.dg/cpp/warn-variadic.c: New.
* gcc.dg/cpp/warn-normalized-2.c: New.
* gcc.dg/cpp/warning-directive-3.c: New.
* gcc.dg/cpp/warn-deprecated-2.c: New.
* gcc.dg/cpp/warn-trigraphs-1.c: New.
* gcc.dg/cpp/warn-multichar-2.c: New.
* gcc.dg/cpp/warn-normalized-3.c: New.
* gcc.dg/cpp/warning-directive-4.c: New.
* gcc.dg/cpp/warn-unused-macros.c: New.
* gcc.dg/cpp/warn-trigraphs-2.c: New.
* gcc.dg/cpp/warn-cxx-compat-2.c: New.
* gcc.dg/cpp/warn-cxx-compat.c: New.
* gcc.dg/cpp/warn-redefined.c: New.
* gcc.dg/cpp/warn-trigraphs-3.c: New.
* gcc.dg/cpp/warn-unused-macros-2.c: New.
* gcc.dg/cpp/warn-deprecated.c: New.
* gcc.dg/cpp/warn-trigraphs-4.c: New.
* gcc.dg/cpp/warn-redefined-2.c: New.
* gcc.dg/cpp/warn-comments.c: New.
* gcc.dg/cpp/warn-multichar.c: New.
* g++.dg/cpp/warning-directive-1.C: New.
* g++.dg/cpp/warning-directive-2.C: New.
* g++.dg/cpp/warning-directive-3.C: New.
* g++.dg/cpp/warning-directive-4.C: New.
* gfortran.dg/warning-directive-1.F90: New.
* gfortran.dg/warning-directive-3.F90: New.
* gfortran.dg/warning-directive-2.F90: New.
* gfortran.dg/warning-directive-4.F90: New.
From-SVN: r158079
2010-04-08 01:18:10 +08:00
|
|
|
name, first);
|
2003-08-20 12:04:47 +08:00
|
|
|
goto fail;
|
|
|
|
}
|
2003-01-10 10:22:34 +08:00
|
|
|
}
|
2007-06-01 10:12:37 +08:00
|
|
|
|
2003-04-01 04:02:40 +08:00
|
|
|
free(nl.defs);
|
2007-05-25 04:55:36 +08:00
|
|
|
nl.defs = NULL;
|
2003-01-10 10:22:34 +08:00
|
|
|
free (undeftab);
|
2007-05-25 04:55:36 +08:00
|
|
|
undeftab = NULL;
|
|
|
|
|
|
|
|
/* Read in the next value of __COUNTER__.
|
|
|
|
Check that (a) __COUNTER__ was not used in the pch or (b) __COUNTER__
|
|
|
|
has not been used in this translation unit. */
|
|
|
|
if (read (fd, &counter, sizeof (counter)) != sizeof (counter))
|
|
|
|
goto error;
|
|
|
|
if (counter && r->counter)
|
|
|
|
{
|
|
|
|
if (CPP_OPTION (r, warn_invalid_pch))
|
diagnostic.h (diagnostic_override_option_index): New macro to set a diagnostic's option_index.
* diagnostic.h (diagnostic_override_option_index): New macro to
set a diagnostic's option_index.
* c-tree.h (c_cpp_error): Add warning reason argument.
* opts.c (_warning_as_error_callback): New.
(register_warning_as_error_callback): Store callback for
warnings enabled via enable_warning_as_error.
(enable_warning_as_error): Call callback, minor code tidy.
* opts.h (register_warning_as_error_callback): Declare.
* c-opts.c (warning_as_error_callback): New, set cpp_opts flag in
response to -Werror=.
(c_common_init_options): Register warning_as_error_callback in opts.c.
* common.opt: Add -Wno-cpp option.
* c-common.c (struct reason_option_codes_t): Map cpp warning
reason codes to gcc option indexes.
* (c_option_controlling_cpp_error): New function, lookup the gcc
option index for a cpp warning reason code.
* (c_cpp_error): Add warning reason argument, call
c_option_controlling_cpp_error for diagnostic_override_option_index.
* doc/invoke.texi: Document -Wno-cpp.
* cpp.c (cb_cpp_error): Add warning reason argument, set a value
for diagnostic_override_option_index if CPP_W_WARNING_DIRECTIVE.
* directives.c (do_diagnostic): Add warning reason argument,
call appropriate error reporting function for code.
(directive_diagnostics): Call specific warning functions with
warning reason where appropriate.
(do_error, do_warning, do_pragma_dependency): Add warning reason
argument to do_diagnostic calls.
* macro.c (_cpp_warn_if_unused_macro, enter_macro_context,
_cpp_create_definition): Call specific warning functions with
warning reason where appropriate.
* Makefile.in: Add new diagnostic functions to gettext translations.
* include/cpplib.h (struct cpp_callbacks): Add warning reason code
to error callback.
(CPP_DL_WARNING, CPP_DL_WARNING_SYSHDR, CPP_DL_PEDWARN, CPP_DL_ERROR,
CPP_DL_ICE, CPP_DL_NOTE, CPP_DL_FATAL): Replace macros with enums.
(CPP_W_NONE, CPP_W_DEPRECATED, CPP_W_COMMENTS,
CPP_W_MISSING_INCLUDE_DIRS, CPP_W_TRIGRAPHS, CPP_W_MULTICHAR,
CPP_W_TRADITIONAL, CPP_W_LONG_LONG, CPP_W_ENDIF_LABELS,
CPP_W_NUM_SIGN_CHANGE, CPP_W_VARIADIC_MACROS,
CPP_W_BUILTIN_MACRO_REDEFINED, CPP_W_DOLLARS, CPP_W_UNDEF,
CPP_W_UNUSED_MACROS, CPP_W_CXX_OPERATOR_NAMES, CPP_W_NORMALIZE,
CPP_W_INVALID_PCH, CPP_W_WARNING_DIRECTIVE): New enums for cpp
warning reason codes.
(cpp_warning, cpp_pedwarning, cpp_warning_syshdr,
cpp_warning_with_line, cpp_pedwarning_with_line,
cpp_warning_with_line_syshdr): New specific error reporting functions.
* pch.c (cpp_valid_state): Call specific warning functions with
warning reason where appropriate.
* errors.c (cpp_diagnostic, cpp_diagnostic_with_line): New central
diagnostic handlers.
(cpp_warning, cpp_pedwarning, cpp_warning_syshdr,
cpp_warning_with_line, cpp_pedwarning_with_line,
cpp_warning_with_line_syshdr): New specific error reporting functions.
* expr.c (cpp_classify_number, eval_token, num_unary_op): Call
specific warning functions with warning reason where appropriate.
* lex.c (_cpp_process_line_notes, _cpp_skip_block_comment,
warn_about_normalization, lex_identifier_intern, lex_identifier,
_cpp_lex_direct): Ditto.
* charset.c (_cpp_valid_ucn, convert_hex, convert_escape,
narrow_str_to_charconst): Ditto.
* gcc.dg/cpp/warn-undef-2.c: New.
* gcc.dg/cpp/warn-traditional-2.c: New.
* gcc.dg/cpp/warn-comments-2.c: New.
* gcc.dg/cpp/warning-directive-1.c: New.
* gcc.dg/cpp/warn-long-long.c: New.
* gcc.dg/cpp/warn-traditional.c: New.
* gcc.dg/cpp/warn-variadic-2.c: New.
* gcc.dg/cpp/warn-undef.c: New.
* gcc.dg/cpp/warn-normalized-1.c: New.
* gcc.dg/cpp/warning-directive-2.c: New.
* gcc.dg/cpp/warn-long-long-2.c: New.
* gcc.dg/cpp/warn-variadic.c: New.
* gcc.dg/cpp/warn-normalized-2.c: New.
* gcc.dg/cpp/warning-directive-3.c: New.
* gcc.dg/cpp/warn-deprecated-2.c: New.
* gcc.dg/cpp/warn-trigraphs-1.c: New.
* gcc.dg/cpp/warn-multichar-2.c: New.
* gcc.dg/cpp/warn-normalized-3.c: New.
* gcc.dg/cpp/warning-directive-4.c: New.
* gcc.dg/cpp/warn-unused-macros.c: New.
* gcc.dg/cpp/warn-trigraphs-2.c: New.
* gcc.dg/cpp/warn-cxx-compat-2.c: New.
* gcc.dg/cpp/warn-cxx-compat.c: New.
* gcc.dg/cpp/warn-redefined.c: New.
* gcc.dg/cpp/warn-trigraphs-3.c: New.
* gcc.dg/cpp/warn-unused-macros-2.c: New.
* gcc.dg/cpp/warn-deprecated.c: New.
* gcc.dg/cpp/warn-trigraphs-4.c: New.
* gcc.dg/cpp/warn-redefined-2.c: New.
* gcc.dg/cpp/warn-comments.c: New.
* gcc.dg/cpp/warn-multichar.c: New.
* g++.dg/cpp/warning-directive-1.C: New.
* g++.dg/cpp/warning-directive-2.C: New.
* g++.dg/cpp/warning-directive-3.C: New.
* g++.dg/cpp/warning-directive-4.C: New.
* gfortran.dg/warning-directive-1.F90: New.
* gfortran.dg/warning-directive-3.F90: New.
* gfortran.dg/warning-directive-2.F90: New.
* gfortran.dg/warning-directive-4.F90: New.
From-SVN: r158079
2010-04-08 01:18:10 +08:00
|
|
|
cpp_warning_syshdr (r, CPP_W_INVALID_PCH,
|
libcpp, genmatch: Use gcc_diag instead of printf for libcpp diagnostics
When working on #embed support, or -Wheader-guard or other recent libcpp
changes, I've been annoyed by the libcpp diagnostics being visually
different from normal gcc diagnostics, especially in the area of quoting
stuff in the diagnostic messages.
Normall GCC diagnostics is gcc_diag/gcc_tdiag, one can use
%</%>, %qs etc. in there, while libcpp diagnostics was marked as printf
and in libcpp we've been very creative with quoting stuff, either
no quotes at all, or "something" quoting, or 'something' quoting, or
`something' quoting (but in none of the cases it used colors consistently
with the rest of the compiler).
Now, libcpp diagnostics is always emitted using a callback,
pfile->cb.diagnostic. On the gcc/ side, this callback is initialized with
genmatch.cc: cb->diagnostic = diagnostic_cb;
c-family/c-opts.cc: cb->diagnostic = c_cpp_diagnostic;
fortran/cpp.cc: cb->diagnostic = cb_cpp_diagnostic;
where the latter two just use diagnostic_report_diagnostic, so actually
support all the gcc_diag stuff, only the genmatch.cc case didn't.
So, the following patch changes genmatch.cc to use pp_format* instead
of vfprintf so that it supports the gcc_diag formatting (pretty-print.o
unfortunately has various dependencies, so had to link genmatch with
libcommon.a libbacktrace.a and tweak Makefile.in so that there are no
circular dependencies) and marks the libcpp diagnostic routines as
gcc_diag rather than printf. That change resulted in hundreds of
-Wformat-diag new warnings (most of them useful and resulting IMHO in
better diagnostics), so the rest of the patch is changing the format
strings to make -Wformat-diag happy and adjusting the testsuite for
the differences in how is the diagnostic reformatted.
Dunno if some out of GCC tree projects use libcpp, that case would
make it harder because one couldn't use vfprintf in the diagnostic
callback anymore, but there is always David's libdiagnostic which could
be used for that purpose IMHO.
2024-10-12 Jakub Jelinek <jakub@redhat.com>
libcpp/
* include/cpplib.h (ATTRIBUTE_CPP_PPDIAG): Define.
(struct cpp_callbacks): Use ATTRIBUTE_CPP_PPDIAG instead of
ATTRIBUTE_FPTR_PRINTF on diagnostic callback.
(cpp_error, cpp_warning, cpp_pedwarning, cpp_warning_syshdr): Use
ATTRIBUTE_CPP_PPDIAG (3, 4) instead of ATTRIBUTE_PRINTF_3.
(cpp_warning_at, cpp_pedwarning_at): Use ATTRIBUTE_CPP_PPDIAG (4, 5)
instead of ATTRIBUTE_PRINTF_4.
(cpp_error_with_line, cpp_warning_with_line, cpp_pedwarning_with_line,
cpp_warning_with_line_syshdr): Use ATTRIBUTE_CPP_PPDIAG (5, 6)
instead of ATTRIBUTE_PRINTF_5.
(cpp_error_at): Use ATTRIBUTE_CPP_PPDIAG (4, 5) instead of
ATTRIBUTE_PRINTF_4.
* Makefile.in (po/$(PACKAGE).pot): Use --language=GCC-source rather
than --language=c.
* errors.cc (cpp_diagnostic_at, cpp_diagnostic,
cpp_diagnostic_with_line): Use ATTRIBUTE_CPP_PPDIAG instead of
-ATTRIBUTE_FPTR_PRINTF.
* charset.cc (cpp_host_to_exec_charset, _cpp_valid_ucn, convert_hex,
convert_oct, convert_escape): Fix up -Wformat-diag warnings.
(cpp_interpret_string_ranges, count_source_chars): Use
ATTRIBUTE_CPP_PPDIAG instead of ATTRIBUTE_FPTR_PRINTF.
(narrow_str_to_charconst): Fix up -Wformat-diag warnings.
* directives.cc (check_eol_1, directive_diagnostics, lex_macro_node,
do_undef, glue_header_name, parse_include, do_include_common,
do_include_next, _cpp_parse_embed_params, do_embed, read_flag,
do_line, do_linemarker, register_pragma_1, do_pragma_once,
do_pragma_push_macro, do_pragma_pop_macro, do_pragma_poison,
do_pragma_system_header, do_pragma_warning_or_error, _cpp_do__Pragma,
do_else, do_elif, do_endif, parse_answer, do_assert,
cpp_define_unused): Likewise.
* expr.cc (cpp_classify_number, parse_defined, eval_token,
_cpp_parse_expr, reduce, check_promotion): Likewise.
* files.cc (_cpp_find_file, finish_base64_embed,
_cpp_pop_file_buffer): Likewise.
* init.cc (sanity_checks): Likewise.
* lex.cc (_cpp_process_line_notes, maybe_warn_bidi_on_char,
_cpp_warn_invalid_utf8, _cpp_skip_block_comment,
warn_about_normalization, forms_identifier_p, maybe_va_opt_error,
identifier_diagnostics_on_lex, cpp_maybe_module_directive): Likewise.
* macro.cc (class vaopt_state, builtin_has_include_1,
builtin_has_include, builtin_has_embed, _cpp_warn_if_unused_macro,
_cpp_builtin_macro_text, builtin_macro, stringify_arg,
_cpp_arguments_ok, collect_args, enter_macro_context,
_cpp_save_parameter, parse_params, create_iso_definition,
_cpp_create_definition, check_trad_stringification): Likewise.
* pch.cc (cpp_valid_state): Likewise.
* traditional.cc (_cpp_scan_out_logical_line, recursive_macro):
Likewise.
gcc/
* Makefile.in (generated_files): Remove {gimple,generic}-match*.
(generated_match_files): New variable. Add a dependency of
$(filter-out $(OBJS-libcommon),$(ALL_HOST_OBJS)) files on those.
(build/genmatch$(build_exeext)): Depend on and link against
libcommon.a and $(LIBBACKTRACE).
* genmatch.cc: Include pretty-print.h and input.h.
(ggc_internal_cleared_alloc, ggc_free): Remove.
(fatal): New function.
(line_table): Remove.
(linemap_client_expand_location_to_spelling_point): Remove.
(diagnostic_cb): Use gcc_diag rather than printf format. Use
pp_format_verbatim on a temporary pretty_printer instead of
vfprintf.
(fatal_at, warning_at): Use gcc_diag rather than printf format.
(output_line_directive): Rename location_hash to loc_hash.
(parser::eat_ident, parser::parse_operation, parser::parse_expr,
parser::parse_pattern, parser::finish_match_operand): Fix up
-Wformat-diag warnings.
gcc/c-family/
* c-lex.cc (c_common_has_attribute,
c_common_lex_availability_macro): Fix up -Wformat-diag warnings.
gcc/testsuite/
* c-c++-common/cpp/counter-2.c: Adjust expected diagnostics for
libcpp diagnostic formatting changes.
* c-c++-common/cpp/embed-3.c: Likewise.
* c-c++-common/cpp/embed-4.c: Likewise.
* c-c++-common/cpp/embed-16.c: Likewise.
* c-c++-common/cpp/embed-18.c: Likewise.
* c-c++-common/cpp/eof-2.c: Likewise.
* c-c++-common/cpp/eof-3.c: Likewise.
* c-c++-common/cpp/fmax-include-depth.c: Likewise.
* c-c++-common/cpp/has-builtin.c: Likewise.
* c-c++-common/cpp/line-2.c: Likewise.
* c-c++-common/cpp/line-3.c: Likewise.
* c-c++-common/cpp/macro-arg-count-1.c: Likewise.
* c-c++-common/cpp/macro-arg-count-2.c: Likewise.
* c-c++-common/cpp/macro-ranges.c: Likewise.
* c-c++-common/cpp/named-universal-char-escape-4.c: Likewise.
* c-c++-common/cpp/named-universal-char-escape-5.c: Likewise.
* c-c++-common/cpp/pr88974.c: Likewise.
* c-c++-common/cpp/va-opt-error.c: Likewise.
* c-c++-common/cpp/va-opt-pedantic.c: Likewise.
* c-c++-common/cpp/Wheader-guard-2.c: Likewise.
* c-c++-common/cpp/Wheader-guard-3.c: Likewise.
* c-c++-common/cpp/Winvalid-utf8-1.c: Likewise.
* c-c++-common/cpp/Winvalid-utf8-2.c: Likewise.
* c-c++-common/cpp/Winvalid-utf8-3.c: Likewise.
* c-c++-common/diagnostic-format-sarif-file-bad-utf8-pr109098-1.c:
Likewise.
* c-c++-common/diagnostic-format-sarif-file-bad-utf8-pr109098-3.c:
Likewise.
* c-c++-common/pr68833-3.c: Likewise.
* c-c++-common/raw-string-directive-1.c: Likewise.
* gcc.dg/analyzer/named-constants-Wunused-macros.c: Likewise.
* gcc.dg/binary-constants-4.c: Likewise.
* gcc.dg/builtin-redefine.c: Likewise.
* gcc.dg/cpp/19951025-1.c: Likewise.
* gcc.dg/cpp/c11-warning-1.c: Likewise.
* gcc.dg/cpp/c11-warning-2.c: Likewise.
* gcc.dg/cpp/c11-warning-3.c: Likewise.
* gcc.dg/cpp/c23-elifdef-2.c: Likewise.
* gcc.dg/cpp/c23-warning-2.c: Likewise.
* gcc.dg/cpp/embed-2.c: Likewise.
* gcc.dg/cpp/embed-3.c: Likewise.
* gcc.dg/cpp/embed-4.c: Likewise.
* gcc.dg/cpp/expr.c: Likewise.
* gcc.dg/cpp/gnu11-elifdef-2.c: Likewise.
* gcc.dg/cpp/gnu11-elifdef-3.c: Likewise.
* gcc.dg/cpp/gnu11-elifdef-4.c: Likewise.
* gcc.dg/cpp/gnu11-warning-1.c: Likewise.
* gcc.dg/cpp/gnu11-warning-2.c: Likewise.
* gcc.dg/cpp/gnu11-warning-3.c: Likewise.
* gcc.dg/cpp/gnu23-warning-2.c: Likewise.
* gcc.dg/cpp/include6.c: Likewise.
* gcc.dg/cpp/pr35322.c: Likewise.
* gcc.dg/cpp/tr-warn6.c: Likewise.
* gcc.dg/cpp/undef2.c: Likewise.
* gcc.dg/cpp/warn-comments.c: Likewise.
* gcc.dg/cpp/warn-comments-2.c: Likewise.
* gcc.dg/cpp/warn-comments-3.c: Likewise.
* gcc.dg/cpp/warn-cxx-compat.c: Likewise.
* gcc.dg/cpp/warn-cxx-compat-2.c: Likewise.
* gcc.dg/cpp/warn-deprecated.c: Likewise.
* gcc.dg/cpp/warn-deprecated-2.c: Likewise.
* gcc.dg/cpp/warn-long-long.c: Likewise.
* gcc.dg/cpp/warn-long-long-2.c: Likewise.
* gcc.dg/cpp/warn-normalized-1.c: Likewise.
* gcc.dg/cpp/warn-normalized-2.c: Likewise.
* gcc.dg/cpp/warn-normalized-3.c: Likewise.
* gcc.dg/cpp/warn-normalized-4-bytes.c: Likewise.
* gcc.dg/cpp/warn-normalized-4-unicode.c: Likewise.
* gcc.dg/cpp/warn-redefined.c: Likewise.
* gcc.dg/cpp/warn-redefined-2.c: Likewise.
* gcc.dg/cpp/warn-traditional.c: Likewise.
* gcc.dg/cpp/warn-traditional-2.c: Likewise.
* gcc.dg/cpp/warn-trigraphs-1.c: Likewise.
* gcc.dg/cpp/warn-trigraphs-2.c: Likewise.
* gcc.dg/cpp/warn-trigraphs-3.c: Likewise.
* gcc.dg/cpp/warn-trigraphs-4.c: Likewise.
* gcc.dg/cpp/warn-undef.c: Likewise.
* gcc.dg/cpp/warn-undef-2.c: Likewise.
* gcc.dg/cpp/warn-unused-macros.c: Likewise.
* gcc.dg/cpp/warn-unused-macros-2.c: Likewise.
* gcc.dg/pch/counter-2.c: Likewise.
* g++.dg/cpp0x/udlit-error1.C: Likewise.
* g++.dg/cpp23/named-universal-char-escape1.C: Likewise.
* g++.dg/cpp23/named-universal-char-escape2.C: Likewise.
* g++.dg/cpp23/Winvalid-utf8-1.C: Likewise.
* g++.dg/cpp23/Winvalid-utf8-2.C: Likewise.
* g++.dg/cpp23/Winvalid-utf8-3.C: Likewise.
* g++.dg/cpp23/Winvalid-utf8-4.C: Likewise.
* g++.dg/cpp23/Winvalid-utf8-5.C: Likewise.
* g++.dg/cpp23/Winvalid-utf8-6.C: Likewise.
* g++.dg/cpp23/Winvalid-utf8-7.C: Likewise.
* g++.dg/cpp23/Winvalid-utf8-8.C: Likewise.
* g++.dg/cpp23/Winvalid-utf8-9.C: Likewise.
* g++.dg/cpp23/Winvalid-utf8-10.C: Likewise.
* g++.dg/cpp23/Winvalid-utf8-11.C: Likewise.
* g++.dg/cpp23/Winvalid-utf8-12.C: Likewise.
* g++.dg/cpp/elifdef-3.C: Likewise.
* g++.dg/cpp/elifdef-5.C: Likewise.
* g++.dg/cpp/elifdef-6.C: Likewise.
* g++.dg/cpp/elifdef-7.C: Likewise.
* g++.dg/cpp/embed-1.C: Likewise.
* g++.dg/cpp/embed-2.C: Likewise.
* g++.dg/cpp/pedantic-errors.C: Likewise.
* g++.dg/cpp/warning-1.C: Likewise.
* g++.dg/cpp/warning-2.C: Likewise.
* g++.dg/ext/bitint1.C: Likewise.
* g++.dg/ext/bitint2.C: Likewise.
2024-10-12 16:44:17 +08:00
|
|
|
"%s: not used because %<__COUNTER__%> is invalid",
|
diagnostic.h (diagnostic_override_option_index): New macro to set a diagnostic's option_index.
* diagnostic.h (diagnostic_override_option_index): New macro to
set a diagnostic's option_index.
* c-tree.h (c_cpp_error): Add warning reason argument.
* opts.c (_warning_as_error_callback): New.
(register_warning_as_error_callback): Store callback for
warnings enabled via enable_warning_as_error.
(enable_warning_as_error): Call callback, minor code tidy.
* opts.h (register_warning_as_error_callback): Declare.
* c-opts.c (warning_as_error_callback): New, set cpp_opts flag in
response to -Werror=.
(c_common_init_options): Register warning_as_error_callback in opts.c.
* common.opt: Add -Wno-cpp option.
* c-common.c (struct reason_option_codes_t): Map cpp warning
reason codes to gcc option indexes.
* (c_option_controlling_cpp_error): New function, lookup the gcc
option index for a cpp warning reason code.
* (c_cpp_error): Add warning reason argument, call
c_option_controlling_cpp_error for diagnostic_override_option_index.
* doc/invoke.texi: Document -Wno-cpp.
* cpp.c (cb_cpp_error): Add warning reason argument, set a value
for diagnostic_override_option_index if CPP_W_WARNING_DIRECTIVE.
* directives.c (do_diagnostic): Add warning reason argument,
call appropriate error reporting function for code.
(directive_diagnostics): Call specific warning functions with
warning reason where appropriate.
(do_error, do_warning, do_pragma_dependency): Add warning reason
argument to do_diagnostic calls.
* macro.c (_cpp_warn_if_unused_macro, enter_macro_context,
_cpp_create_definition): Call specific warning functions with
warning reason where appropriate.
* Makefile.in: Add new diagnostic functions to gettext translations.
* include/cpplib.h (struct cpp_callbacks): Add warning reason code
to error callback.
(CPP_DL_WARNING, CPP_DL_WARNING_SYSHDR, CPP_DL_PEDWARN, CPP_DL_ERROR,
CPP_DL_ICE, CPP_DL_NOTE, CPP_DL_FATAL): Replace macros with enums.
(CPP_W_NONE, CPP_W_DEPRECATED, CPP_W_COMMENTS,
CPP_W_MISSING_INCLUDE_DIRS, CPP_W_TRIGRAPHS, CPP_W_MULTICHAR,
CPP_W_TRADITIONAL, CPP_W_LONG_LONG, CPP_W_ENDIF_LABELS,
CPP_W_NUM_SIGN_CHANGE, CPP_W_VARIADIC_MACROS,
CPP_W_BUILTIN_MACRO_REDEFINED, CPP_W_DOLLARS, CPP_W_UNDEF,
CPP_W_UNUSED_MACROS, CPP_W_CXX_OPERATOR_NAMES, CPP_W_NORMALIZE,
CPP_W_INVALID_PCH, CPP_W_WARNING_DIRECTIVE): New enums for cpp
warning reason codes.
(cpp_warning, cpp_pedwarning, cpp_warning_syshdr,
cpp_warning_with_line, cpp_pedwarning_with_line,
cpp_warning_with_line_syshdr): New specific error reporting functions.
* pch.c (cpp_valid_state): Call specific warning functions with
warning reason where appropriate.
* errors.c (cpp_diagnostic, cpp_diagnostic_with_line): New central
diagnostic handlers.
(cpp_warning, cpp_pedwarning, cpp_warning_syshdr,
cpp_warning_with_line, cpp_pedwarning_with_line,
cpp_warning_with_line_syshdr): New specific error reporting functions.
* expr.c (cpp_classify_number, eval_token, num_unary_op): Call
specific warning functions with warning reason where appropriate.
* lex.c (_cpp_process_line_notes, _cpp_skip_block_comment,
warn_about_normalization, lex_identifier_intern, lex_identifier,
_cpp_lex_direct): Ditto.
* charset.c (_cpp_valid_ucn, convert_hex, convert_escape,
narrow_str_to_charconst): Ditto.
* gcc.dg/cpp/warn-undef-2.c: New.
* gcc.dg/cpp/warn-traditional-2.c: New.
* gcc.dg/cpp/warn-comments-2.c: New.
* gcc.dg/cpp/warning-directive-1.c: New.
* gcc.dg/cpp/warn-long-long.c: New.
* gcc.dg/cpp/warn-traditional.c: New.
* gcc.dg/cpp/warn-variadic-2.c: New.
* gcc.dg/cpp/warn-undef.c: New.
* gcc.dg/cpp/warn-normalized-1.c: New.
* gcc.dg/cpp/warning-directive-2.c: New.
* gcc.dg/cpp/warn-long-long-2.c: New.
* gcc.dg/cpp/warn-variadic.c: New.
* gcc.dg/cpp/warn-normalized-2.c: New.
* gcc.dg/cpp/warning-directive-3.c: New.
* gcc.dg/cpp/warn-deprecated-2.c: New.
* gcc.dg/cpp/warn-trigraphs-1.c: New.
* gcc.dg/cpp/warn-multichar-2.c: New.
* gcc.dg/cpp/warn-normalized-3.c: New.
* gcc.dg/cpp/warning-directive-4.c: New.
* gcc.dg/cpp/warn-unused-macros.c: New.
* gcc.dg/cpp/warn-trigraphs-2.c: New.
* gcc.dg/cpp/warn-cxx-compat-2.c: New.
* gcc.dg/cpp/warn-cxx-compat.c: New.
* gcc.dg/cpp/warn-redefined.c: New.
* gcc.dg/cpp/warn-trigraphs-3.c: New.
* gcc.dg/cpp/warn-unused-macros-2.c: New.
* gcc.dg/cpp/warn-deprecated.c: New.
* gcc.dg/cpp/warn-trigraphs-4.c: New.
* gcc.dg/cpp/warn-redefined-2.c: New.
* gcc.dg/cpp/warn-comments.c: New.
* gcc.dg/cpp/warn-multichar.c: New.
* g++.dg/cpp/warning-directive-1.C: New.
* g++.dg/cpp/warning-directive-2.C: New.
* g++.dg/cpp/warning-directive-3.C: New.
* g++.dg/cpp/warning-directive-4.C: New.
* gfortran.dg/warning-directive-1.F90: New.
* gfortran.dg/warning-directive-3.F90: New.
* gfortran.dg/warning-directive-2.F90: New.
* gfortran.dg/warning-directive-4.F90: New.
From-SVN: r158079
2010-04-08 01:18:10 +08:00
|
|
|
name);
|
2015-05-06 03:41:11 +08:00
|
|
|
goto fail;
|
2007-05-25 04:55:36 +08:00
|
|
|
}
|
2003-01-10 10:22:34 +08:00
|
|
|
|
|
|
|
/* We win! */
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
error:
|
re PR preprocessor/12847 (xxx.c:1:20: xxxx.h: No such file or directory)
PR preprocessor/12847
* cppfiles.c, cppexp.c, cpperror.c, cpplib.h, cpplib.c, cpplex.c,
cppinit.c, cpptrad.c, cppmacro.c, fix-header.c, cpppch.c, c-pch.c,
c-incpath.c, cppcharset.c (DL_WARNING, DL_WARNING_SYSHDR, DL_PEDWARN,
DL_ERROR, DL_ICE, DL_EXTRACT, DL_WARNING_P): Prefix macro names with
"CPP_".
From-SVN: r73183
2003-11-02 06:56:54 +08:00
|
|
|
cpp_errno (r, CPP_DL_ERROR, "while reading precompiled header");
|
2003-01-10 10:22:34 +08:00
|
|
|
|
|
|
|
fail:
|
2011-04-21 02:19:03 +08:00
|
|
|
free (namebuf);
|
|
|
|
free (undeftab);
|
|
|
|
free (nl.defs);
|
2003-01-10 10:22:34 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2004-06-10 04:10:13 +08:00
|
|
|
/* Save all the existing macros. */
|
2003-01-10 10:22:34 +08:00
|
|
|
|
2007-06-01 10:12:37 +08:00
|
|
|
struct save_macro_data
|
2003-01-10 10:22:34 +08:00
|
|
|
{
|
2004-06-10 04:10:13 +08:00
|
|
|
uchar **defns;
|
2003-01-10 10:22:34 +08:00
|
|
|
size_t count;
|
2004-06-10 04:10:13 +08:00
|
|
|
size_t array_size;
|
2003-01-10 10:22:34 +08:00
|
|
|
char **saved_pragmas;
|
|
|
|
};
|
|
|
|
|
2004-06-10 04:10:13 +08:00
|
|
|
/* Save the definition of a single macro, so that it will persist
|
|
|
|
across a PCH restore. Because macro data is in GCed memory, which
|
|
|
|
will be blown away by PCH, it must be temporarily copied to
|
|
|
|
malloced memory. (The macros will refer to identifier nodes which
|
|
|
|
are also GCed and so on, so the copying is done by turning them
|
|
|
|
into self-contained strings.) The assumption is that most macro
|
|
|
|
definitions will come from the PCH file, not from the compilation
|
|
|
|
before the PCH file is loaded, so it doesn't matter that this is
|
|
|
|
a little expensive.
|
|
|
|
|
|
|
|
It would reduce the cost even further if macros defined in the PCH
|
|
|
|
file were not saved in this way, but this is not done (yet), except
|
|
|
|
for builtins, and for #assert by default. */
|
2003-01-10 10:22:34 +08:00
|
|
|
|
2007-06-01 10:12:37 +08:00
|
|
|
static int
|
2004-06-10 04:10:13 +08:00
|
|
|
save_macros (cpp_reader *r, cpp_hashnode *h, void *data_p)
|
2003-01-10 10:22:34 +08:00
|
|
|
{
|
|
|
|
struct save_macro_data *data = (struct save_macro_data *)data_p;
|
2010-06-12 02:37:34 +08:00
|
|
|
|
[CPP PATCH] node type
https://gcc.gnu.org/ml/gcc-patches/2018-08/msg01164.html
* include/cpplib.h (NODE_BUILTIN, NODE_MACRO_ARG): Delete.
Renumber others.
(enum node_type): Replace NT_MACRO with NT_USER_MACRO,
NT_BUILTIN_MACRO, NT_MACRO_ARG. Delete NT_ASSERTION.
(NTV_MACRO, NTV_ANSWER, NTV_BUILTIN, NTV_ARGUMENT, NTV_NONE):
Delete.
(CPP_HASHNODE_VALUE_IDX): Delete.
(union _cpp_hashnode_value): GTY tag from enum node_type directly.
(struct cpp_hashnode): Adjust GTY desc for value field.
(cpp_user_macro_p, cpp_builtin_macro_p, cpp_macro_p): Adjust.
* directives.c (undefine_macros): Clear value.anwers, adjust flag
clearing.
(_cpp_test_assertion): No need to check NT_ASSERTION.
(do_assert, do_unassert): Likewise.
* init.c (cpp_init_special_builtins): Set type not flags.
* macro.c (struct macro_arg_saved_data): Add type field.
(cpp_get_token_1): Check type not NT_VOID.
(_cpp_free_definition): Adjust flag clearing. Nullify
value.answers.
(_cpp_save_parameter, _cpp_unsave_parameters): Save and restore
type.
(lex_expansion_token): Check type not flags.
(_cpp_create_definition): Set type to NT_USER_MACRO.
(_cpp_notify_macro_use): Adjust type checking.
* pch.c (write_macdef, count_defs, write_defs, cpp_valid_state)
(save_macros): Adjust node type/flag handling.
* traditional.c (_cpp_scan_out_logical_line): Check type not flags.
From-SVN: r263667
2018-08-21 00:32:29 +08:00
|
|
|
if (cpp_user_macro_p (h))
|
2003-01-10 10:22:34 +08:00
|
|
|
{
|
2004-06-10 04:10:13 +08:00
|
|
|
if (data->count == data->array_size)
|
|
|
|
{
|
|
|
|
data->array_size *= 2;
|
2007-06-01 10:12:37 +08:00
|
|
|
data->defns = XRESIZEVEC (uchar *, data->defns, (data->array_size));
|
2004-06-10 04:10:13 +08:00
|
|
|
}
|
2007-06-01 10:12:37 +08:00
|
|
|
|
[CPP PATCH] node type
https://gcc.gnu.org/ml/gcc-patches/2018-08/msg01164.html
* include/cpplib.h (NODE_BUILTIN, NODE_MACRO_ARG): Delete.
Renumber others.
(enum node_type): Replace NT_MACRO with NT_USER_MACRO,
NT_BUILTIN_MACRO, NT_MACRO_ARG. Delete NT_ASSERTION.
(NTV_MACRO, NTV_ANSWER, NTV_BUILTIN, NTV_ARGUMENT, NTV_NONE):
Delete.
(CPP_HASHNODE_VALUE_IDX): Delete.
(union _cpp_hashnode_value): GTY tag from enum node_type directly.
(struct cpp_hashnode): Adjust GTY desc for value field.
(cpp_user_macro_p, cpp_builtin_macro_p, cpp_macro_p): Adjust.
* directives.c (undefine_macros): Clear value.anwers, adjust flag
clearing.
(_cpp_test_assertion): No need to check NT_ASSERTION.
(do_assert, do_unassert): Likewise.
* init.c (cpp_init_special_builtins): Set type not flags.
* macro.c (struct macro_arg_saved_data): Add type field.
(cpp_get_token_1): Check type not NT_VOID.
(_cpp_free_definition): Adjust flag clearing. Nullify
value.answers.
(_cpp_save_parameter, _cpp_unsave_parameters): Save and restore
type.
(lex_expansion_token): Check type not flags.
(_cpp_create_definition): Set type to NT_USER_MACRO.
(_cpp_notify_macro_use): Adjust type checking.
* pch.c (write_macdef, count_defs, write_defs, cpp_valid_state)
(save_macros): Adjust node type/flag handling.
* traditional.c (_cpp_scan_out_logical_line): Check type not flags.
From-SVN: r263667
2018-08-21 00:32:29 +08:00
|
|
|
const uchar * defn = cpp_macro_definition (r, h);
|
|
|
|
size_t defnlen = ustrlen (defn);
|
2004-06-10 04:10:13 +08:00
|
|
|
|
[CPP PATCH] node type
https://gcc.gnu.org/ml/gcc-patches/2018-08/msg01164.html
* include/cpplib.h (NODE_BUILTIN, NODE_MACRO_ARG): Delete.
Renumber others.
(enum node_type): Replace NT_MACRO with NT_USER_MACRO,
NT_BUILTIN_MACRO, NT_MACRO_ARG. Delete NT_ASSERTION.
(NTV_MACRO, NTV_ANSWER, NTV_BUILTIN, NTV_ARGUMENT, NTV_NONE):
Delete.
(CPP_HASHNODE_VALUE_IDX): Delete.
(union _cpp_hashnode_value): GTY tag from enum node_type directly.
(struct cpp_hashnode): Adjust GTY desc for value field.
(cpp_user_macro_p, cpp_builtin_macro_p, cpp_macro_p): Adjust.
* directives.c (undefine_macros): Clear value.anwers, adjust flag
clearing.
(_cpp_test_assertion): No need to check NT_ASSERTION.
(do_assert, do_unassert): Likewise.
* init.c (cpp_init_special_builtins): Set type not flags.
* macro.c (struct macro_arg_saved_data): Add type field.
(cpp_get_token_1): Check type not NT_VOID.
(_cpp_free_definition): Adjust flag clearing. Nullify
value.answers.
(_cpp_save_parameter, _cpp_unsave_parameters): Save and restore
type.
(lex_expansion_token): Check type not flags.
(_cpp_create_definition): Set type to NT_USER_MACRO.
(_cpp_notify_macro_use): Adjust type checking.
* pch.c (write_macdef, count_defs, write_defs, cpp_valid_state)
(save_macros): Adjust node type/flag handling.
* traditional.c (_cpp_scan_out_logical_line): Check type not flags.
From-SVN: r263667
2018-08-21 00:32:29 +08:00
|
|
|
data->defns[data->count] = (uchar *) xmemdup (defn, defnlen, defnlen + 2);
|
|
|
|
data->defns[data->count][defnlen] = '\n';
|
2003-01-10 10:22:34 +08:00
|
|
|
data->count++;
|
|
|
|
}
|
[CPP PATCH] node type
https://gcc.gnu.org/ml/gcc-patches/2018-08/msg01164.html
* include/cpplib.h (NODE_BUILTIN, NODE_MACRO_ARG): Delete.
Renumber others.
(enum node_type): Replace NT_MACRO with NT_USER_MACRO,
NT_BUILTIN_MACRO, NT_MACRO_ARG. Delete NT_ASSERTION.
(NTV_MACRO, NTV_ANSWER, NTV_BUILTIN, NTV_ARGUMENT, NTV_NONE):
Delete.
(CPP_HASHNODE_VALUE_IDX): Delete.
(union _cpp_hashnode_value): GTY tag from enum node_type directly.
(struct cpp_hashnode): Adjust GTY desc for value field.
(cpp_user_macro_p, cpp_builtin_macro_p, cpp_macro_p): Adjust.
* directives.c (undefine_macros): Clear value.anwers, adjust flag
clearing.
(_cpp_test_assertion): No need to check NT_ASSERTION.
(do_assert, do_unassert): Likewise.
* init.c (cpp_init_special_builtins): Set type not flags.
* macro.c (struct macro_arg_saved_data): Add type field.
(cpp_get_token_1): Check type not NT_VOID.
(_cpp_free_definition): Adjust flag clearing. Nullify
value.answers.
(_cpp_save_parameter, _cpp_unsave_parameters): Save and restore
type.
(lex_expansion_token): Check type not flags.
(_cpp_create_definition): Set type to NT_USER_MACRO.
(_cpp_notify_macro_use): Adjust type checking.
* pch.c (write_macdef, count_defs, write_defs, cpp_valid_state)
(save_macros): Adjust node type/flag handling.
* traditional.c (_cpp_scan_out_logical_line): Check type not flags.
From-SVN: r263667
2018-08-21 00:32:29 +08:00
|
|
|
|
2003-01-10 10:22:34 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Prepare to restore the state, by saving the currently-defined
|
|
|
|
macros in 'data'. */
|
|
|
|
|
|
|
|
void
|
* cpplib.h, cpphash.h, cppcharset.c, cpperror.c, cppexp.c
* cppfiles.c, cpphash.c, cppinit.c, cpplex.c, cpplib.c
* cppmacro.c, cpppch.c, cpptrad.c, cppspec.c: Convert to
ISO C: new-style function declarations, no need for PARAMS,
no special punctuation on indirect function calls, use string
constant concatenation where convenient.
From-SVN: r68070
2003-06-17 14:17:44 +08:00
|
|
|
cpp_prepare_state (cpp_reader *r, struct save_macro_data **data)
|
2003-01-10 10:22:34 +08:00
|
|
|
{
|
2005-05-28 23:52:48 +08:00
|
|
|
struct save_macro_data *d = XNEW (struct save_macro_data);
|
2007-06-01 10:12:37 +08:00
|
|
|
|
2004-06-10 04:10:13 +08:00
|
|
|
d->array_size = 512;
|
2005-05-28 23:52:48 +08:00
|
|
|
d->defns = XNEWVEC (uchar *, d->array_size);
|
2004-06-10 04:10:13 +08:00
|
|
|
d->count = 0;
|
2003-01-10 10:22:34 +08:00
|
|
|
cpp_forall_identifiers (r, save_macros, d);
|
|
|
|
d->saved_pragmas = _cpp_save_pragma_names (r);
|
|
|
|
*data = d;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Given a precompiled header that was previously determined to be valid,
|
2007-06-01 10:12:37 +08:00
|
|
|
apply all its definitions (and undefinitions) to the current state.
|
2003-01-10 10:22:34 +08:00
|
|
|
DEPNAME is passed to deps_restore. */
|
|
|
|
|
|
|
|
int
|
* cpplib.h, cpphash.h, cppcharset.c, cpperror.c, cppexp.c
* cppfiles.c, cpphash.c, cppinit.c, cpplex.c, cpplib.c
* cppmacro.c, cpppch.c, cpptrad.c, cppspec.c: Convert to
ISO C: new-style function declarations, no need for PARAMS,
no special punctuation on indirect function calls, use string
constant concatenation where convenient.
From-SVN: r68070
2003-06-17 14:17:44 +08:00
|
|
|
cpp_read_state (cpp_reader *r, const char *name, FILE *f,
|
|
|
|
struct save_macro_data *data)
|
2003-01-10 10:22:34 +08:00
|
|
|
{
|
2004-10-08 20:50:12 +08:00
|
|
|
size_t i;
|
2004-06-10 04:10:13 +08:00
|
|
|
struct lexer_state old_state;
|
2007-05-25 04:55:36 +08:00
|
|
|
unsigned int counter;
|
2003-01-10 10:22:34 +08:00
|
|
|
|
2007-06-01 10:12:37 +08:00
|
|
|
/* Restore spec_nodes, which will be full of references to the old
|
2003-01-10 10:22:34 +08:00
|
|
|
hashtable entries and so will now be invalid. */
|
|
|
|
{
|
|
|
|
struct spec_nodes *s = &r->spec_nodes;
|
|
|
|
s->n_defined = cpp_lookup (r, DSC("defined"));
|
|
|
|
s->n_true = cpp_lookup (r, DSC("true"));
|
|
|
|
s->n_false = cpp_lookup (r, DSC("false"));
|
|
|
|
s->n__VA_ARGS__ = cpp_lookup (r, DSC("__VA_ARGS__"));
|
2017-11-14 04:17:42 +08:00
|
|
|
s->n__VA_OPT__ = cpp_lookup (r, DSC("__VA_OPT__"));
|
2003-01-10 10:22:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
old_state = r->state;
|
|
|
|
r->state.in_directive = 1;
|
|
|
|
r->state.prevent_expansion = 1;
|
|
|
|
r->state.angled_headers = 0;
|
|
|
|
|
2004-06-10 04:10:13 +08:00
|
|
|
/* Run through the carefully-saved macros, insert them. */
|
|
|
|
for (i = 0; i < data->count; i++)
|
2003-01-10 10:22:34 +08:00
|
|
|
{
|
|
|
|
cpp_hashnode *h;
|
2004-06-10 04:10:13 +08:00
|
|
|
size_t namelen;
|
|
|
|
uchar *defn;
|
2003-01-10 10:22:34 +08:00
|
|
|
|
2005-02-14 16:52:24 +08:00
|
|
|
namelen = ustrcspn (data->defns[i], "( \n");
|
2004-06-10 04:10:13 +08:00
|
|
|
h = cpp_lookup (r, data->defns[i], namelen);
|
|
|
|
defn = data->defns[i] + namelen;
|
2003-01-10 10:22:34 +08:00
|
|
|
|
2004-06-10 04:10:13 +08:00
|
|
|
/* The PCH file is valid, so we know that if there is a definition
|
|
|
|
from the PCH file it must be the same as the one we had
|
|
|
|
originally, and so do not need to restore it. */
|
|
|
|
if (h->type == NT_VOID)
|
2003-01-10 10:22:34 +08:00
|
|
|
{
|
2004-06-10 04:10:13 +08:00
|
|
|
if (cpp_push_buffer (r, defn, ustrchr (defn, '\n') - defn, true)
|
2003-10-02 15:30:34 +08:00
|
|
|
!= NULL)
|
2003-01-10 10:22:34 +08:00
|
|
|
{
|
cppfiles.c (ENABLE_VALGRIND_CHECKING, [...]): Remove.
* cppfiles.c (ENABLE_VALGRIND_CHECKING, VALGRIND_DISCARD,
MMAP_THRESHOLD, TEST_THRESHOLD, SHOULD_MMAP): Remove.
(struct include_file): Remove fefcnt, mapped members.
(open_file, stack_include_file, _cpp_pop_file_buffer): Disable caching.
(read_include_file): Don't use mmap, terminate buffers in '\r'.
(purge_cache): Don't use munmap.
* cpphash.h (CPP_BUF_COLUMN): Update.
(lexer_state): Remove lexing_comment.
(struct _cpp_line_note): New.
(struct cpp_buffer): New members cur_note, notes_used, notes_cap,
next_line and need_line. Remove col_adjust and saved_flags.
(_cpp_process_line_notes, _cpp_clean_line, _cpp_get_fresh_line,
_cpp_skip_block_comment, scan_out_logical_line): New.
(_cpp_init_mbchar): Remove.
* cppinit.c (init_library): Remove call to _cpp_init_mbchar.
(cpp_read_main_file): Set line to 1 earlier.
(post_options): -traditional-cpp doesn't want trigraphs.
* cpplex.c (MULTIBYTE_CHARS): Remove code predicated on this.
(add_line_note, _cpp_clean_line, _cpp_process_line_notes,
_cpp_get_fresh_line): New.
(handle_newline, skip_escaped_newlines, trigraph_p,
continue_after_nul, _cpp_init_mbchar): Remove.
(get_effective_char): Update.
(_cpp_skip_block_comment): Rename from skip_block_comment, simplify.
(skip_line_comment): Simplify.
(skip_whitespace, parse_identifier, parse_slow, parse_number,
parse_string): Update.
(cpp_lex_direct): Use clean lines and process line notes. Update.
(cpp_interpret_charconst): No MULTIBYTE_CHARS.
* cpplib.c (prepare_directive_trad): Call scan_out_logical_line
directly.
(_cpp_handle_directive): Don't set saved_flags.
(run_directive, destringize_and_run, cpp_define, cpp_define_builtin,
cpp_undef, handle_assertion, cpp_push_buffer): Update.
(_cpp_pop_buffer): Free notes.
* cppmacro.c (builtin_macro, paste_tokens): \n terminate buffer.
* cpppch.c (cpp_read_state): \n terminate buffer.
* cpptrad.c (skip_escaped_newlines, handle_newline): Remove.
(copy_comment): Use _cpp_skip_block_comment.
(skip_whitespace, lex_identifier, _cpp_read_logical_line_trad):
Simplify.
(_cpp_overlay_buffer, _cpp_remove_overlay, push_replacement_text,
save_replacement_text): Update.
(scan_out_logical_line): Update to use clean lines and process
line notes.
* fix-header.c (read_scan_file): Update.
testsuite:
* gcc.dg/cpp/_Pragma4.c: Remove stray space.
* gcc.dg/cpp/trad/escaped-eof.c: Correct line number.
From-SVN: r65808
2003-04-19 08:22:51 +08:00
|
|
|
_cpp_clean_line (r);
|
2024-02-01 04:50:11 +08:00
|
|
|
|
|
|
|
/* ??? Using r->line_table->highest_line is not ideal here, but we
|
|
|
|
do need to use some location that is relative to the new line
|
|
|
|
map just loaded, not the old one that was in effect when these
|
|
|
|
macros were lexed. The proper fix is to remember the file name
|
|
|
|
and line number where each macro was defined, and then add
|
|
|
|
these locations into the new line map. See PR105608. */
|
|
|
|
if (!_cpp_create_definition (r, h, r->line_table->highest_line))
|
2003-01-10 10:22:34 +08:00
|
|
|
abort ();
|
|
|
|
_cpp_pop_buffer (r);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
abort ();
|
|
|
|
}
|
|
|
|
|
2004-06-10 04:10:13 +08:00
|
|
|
free (data->defns[i]);
|
|
|
|
}
|
2003-01-10 10:22:34 +08:00
|
|
|
r->state = old_state;
|
2004-06-10 04:10:13 +08:00
|
|
|
|
|
|
|
_cpp_restore_pragma_names (r, data->saved_pragmas);
|
|
|
|
|
|
|
|
free (data);
|
2003-01-10 10:22:34 +08:00
|
|
|
|
|
|
|
if (deps_restore (r->deps, f, CPP_OPTION (r, restore_pch_deps) ? name : NULL)
|
|
|
|
!= 0)
|
|
|
|
goto error;
|
|
|
|
|
2004-01-17 08:37:47 +08:00
|
|
|
if (! _cpp_read_file_entries (r, f))
|
|
|
|
goto error;
|
|
|
|
|
2007-05-25 04:55:36 +08:00
|
|
|
if (fread (&counter, sizeof (counter), 1, f) != 1)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
if (!r->counter)
|
|
|
|
r->counter = counter;
|
|
|
|
|
2009-11-12 02:37:19 +08:00
|
|
|
/* Read pushed macros. */
|
|
|
|
if (! _cpp_restore_pushed_macros (r, f))
|
|
|
|
goto error;
|
2003-01-10 10:22:34 +08:00
|
|
|
return 0;
|
2007-06-01 10:12:37 +08:00
|
|
|
|
2003-01-10 10:22:34 +08:00
|
|
|
error:
|
re PR preprocessor/12847 (xxx.c:1:20: xxxx.h: No such file or directory)
PR preprocessor/12847
* cppfiles.c, cppexp.c, cpperror.c, cpplib.h, cpplib.c, cpplex.c,
cppinit.c, cpptrad.c, cppmacro.c, fix-header.c, cpppch.c, c-pch.c,
c-incpath.c, cppcharset.c (DL_WARNING, DL_WARNING_SYSHDR, DL_PEDWARN,
DL_ERROR, DL_ICE, DL_EXTRACT, DL_WARNING_P): Prefix macro names with
"CPP_".
From-SVN: r73183
2003-11-02 06:56:54 +08:00
|
|
|
cpp_errno (r, CPP_DL_ERROR, "while reading precompiled header");
|
2003-01-10 10:22:34 +08:00
|
|
|
return -1;
|
|
|
|
}
|