comparison libcpp/pch.c @ 111:04ced10e8804

gcc 7
author kono
date Fri, 27 Oct 2017 22:46:09 +0900
parents f6334be47118
children 84e7813d76e9
comparison
equal deleted inserted replaced
68:561a7518be6b 111:04ced10e8804
1 /* Part of CPP library. (Precompiled header reading/writing.) 1 /* Part of CPP library. (Precompiled header reading/writing.)
2 Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2008, 2009, 2010 2 Copyright (C) 2000-2017 Free Software Foundation, Inc.
3 Free Software Foundation, Inc.
4 3
5 This program is free software; you can redistribute it and/or modify it 4 This program is free software; you can redistribute it and/or modify it
6 under the terms of the GNU General Public License as published by the 5 under the terms of the GNU General Public License as published by the
7 Free Software Foundation; either version 3, or (at your option) any 6 Free Software Foundation; either version 3, or (at your option) any
8 later version. 7 later version.
54 switch (hn->type) 53 switch (hn->type)
55 { 54 {
56 case NT_VOID: 55 case NT_VOID:
57 if (! (hn->flags & NODE_POISONED)) 56 if (! (hn->flags & NODE_POISONED))
58 return 1; 57 return 1;
58 /* XXX Really fallthru? */
59 /* FALLTHRU */
59 60
60 case NT_MACRO: 61 case NT_MACRO:
61 if ((hn->flags & NODE_BUILTIN) 62 if ((hn->flags & NODE_BUILTIN)
62 && (!pfile->cb.user_builtin_macro 63 && (!pfile->cb.user_builtin_macro
63 || !pfile->cb.user_builtin_macro (pfile, hn))) 64 || !pfile->cb.user_builtin_macro (pfile, hn)))
186 const struct cpp_string *b = (const struct cpp_string *) b_p; 187 const struct cpp_string *b = (const struct cpp_string *) b_p;
187 return (a->len == b->len 188 return (a->len == b->len
188 && memcmp (a->text, b->text, a->len) == 0); 189 && memcmp (a->text, b->text, a->len) == 0);
189 } 190 }
190 191
192 /* Free memory associated with cpp_string. */
193
194 static void
195 cpp_string_free (void *a_p)
196 {
197 struct cpp_string *a = (struct cpp_string *) a_p;
198 free ((void *) a->text);
199 free (a);
200 }
201
191 /* Save the current definitions of the cpp_reader for dependency 202 /* Save the current definitions of the cpp_reader for dependency
192 checking purposes. When writing a precompiled header, this should 203 checking purposes. When writing a precompiled header, this should
193 be called at the same point in the compilation as cpp_valid_state 204 be called at the same point in the compilation as cpp_valid_state
194 would be called when reading the precompiled header back in. */ 205 would be called when reading the precompiled header back in. */
195 206
197 cpp_save_state (cpp_reader *r, FILE *f) 208 cpp_save_state (cpp_reader *r, FILE *f)
198 { 209 {
199 /* Save the list of non-void identifiers for the dependency checking. */ 210 /* Save the list of non-void identifiers for the dependency checking. */
200 r->savedstate = XNEW (struct cpp_savedstate); 211 r->savedstate = XNEW (struct cpp_savedstate);
201 r->savedstate->definedhash = htab_create (100, cpp_string_hash, 212 r->savedstate->definedhash = htab_create (100, cpp_string_hash,
202 cpp_string_eq, NULL); 213 cpp_string_eq, cpp_string_free);
203 cpp_forall_identifiers (r, save_idents, r->savedstate); 214 cpp_forall_identifiers (r, save_idents, r->savedstate);
204 215
205 /* Write out the list of defined identifiers. */ 216 /* Write out the list of defined identifiers. */
206 cpp_forall_identifiers (r, write_macdef, f); 217 cpp_forall_identifiers (r, write_macdef, f);
207 218
219 { 230 {
220 case NT_MACRO: 231 case NT_MACRO:
221 if (hn->flags & NODE_BUILTIN) 232 if (hn->flags & NODE_BUILTIN)
222 return 1; 233 return 1;
223 234
224 /* else fall through. */ 235 /* fall through. */
225 236
226 case NT_VOID: 237 case NT_VOID:
227 { 238 {
228 struct cpp_string news; 239 struct cpp_string news;
229 void **slot; 240 void **slot;
258 { 269 {
259 case NT_MACRO: 270 case NT_MACRO:
260 if (hn->flags & NODE_BUILTIN) 271 if (hn->flags & NODE_BUILTIN)
261 return 1; 272 return 1;
262 273
263 /* else fall through. */ 274 /* fall through. */
264 275
265 case NT_VOID: 276 case NT_VOID:
266 { 277 {
267 struct cpp_string news; 278 struct cpp_string news;
268 void **slot; 279 void **slot;
335 { 346 {
336 cpp_errno (r, CPP_DL_ERROR, "while writing precompiled header"); 347 cpp_errno (r, CPP_DL_ERROR, "while writing precompiled header");
337 return -1; 348 return -1;
338 } 349 }
339 free (ss->definedstrs); 350 free (ss->definedstrs);
351 free (ss->defs);
352 htab_delete (ss->definedhash);
340 353
341 /* Free the saved state. */ 354 /* Free the saved state. */
342 free (ss); 355 free (ss);
343 r->savedstate = NULL; 356 r->savedstate = NULL;
344 357
615 /* It's ok if __GCC_HAVE_DWARF2_CFI_ASM becomes undefined, 628 /* It's ok if __GCC_HAVE_DWARF2_CFI_ASM becomes undefined,
616 as in, when the PCH file is created with -g and we're 629 as in, when the PCH file is created with -g and we're
617 attempting to use it without -g. Restoring the PCH file 630 attempting to use it without -g. Restoring the PCH file
618 is supposed to bring in this definition *and* enable the 631 is supposed to bring in this definition *and* enable the
619 generation of call frame information, so that precompiled 632 generation of call frame information, so that precompiled
620 definitions that take this macro into accout, to decide 633 definitions that take this macro into account, to decide
621 what asm to emit, won't issue .cfi directives when the 634 what asm to emit, won't issue .cfi directives when the
622 compiler doesn't. */ 635 compiler doesn't. */
623 if (!(h->flags & NODE_USED) 636 if (!(h->flags & NODE_USED)
624 && m.name_length == sizeof ("__GCC_HAVE_DWARF2_CFI_ASM") - 1 637 && m.name_length == sizeof ("__GCC_HAVE_DWARF2_CFI_ASM") - 1
625 && !memcmp (namebuf, "__GCC_HAVE_DWARF2_CFI_ASM", m.name_length)) 638 && !memcmp (namebuf, "__GCC_HAVE_DWARF2_CFI_ASM", m.name_length))
700 { 713 {
701 if (CPP_OPTION (r, warn_invalid_pch)) 714 if (CPP_OPTION (r, warn_invalid_pch))
702 cpp_warning_syshdr (r, CPP_W_INVALID_PCH, 715 cpp_warning_syshdr (r, CPP_W_INVALID_PCH,
703 "%s: not used because `__COUNTER__' is invalid", 716 "%s: not used because `__COUNTER__' is invalid",
704 name); 717 name);
705 goto fail; 718 goto fail;
706 } 719 }
707 720
708 /* We win! */ 721 /* We win! */
709 return 0; 722 return 0;
710 723
711 error: 724 error:
712 cpp_errno (r, CPP_DL_ERROR, "while reading precompiled header"); 725 cpp_errno (r, CPP_DL_ERROR, "while reading precompiled header");
713 return -1;
714 726
715 fail: 727 fail:
716 if (namebuf != NULL) 728 free (namebuf);
717 free (namebuf); 729 free (undeftab);
718 if (undeftab != NULL) 730 free (nl.defs);
719 free (undeftab);
720 if (nl.defs != NULL)
721 free (nl.defs);
722 return 1; 731 return 1;
723 } 732 }
724 733
725 /* Save all the existing macros. */ 734 /* Save all the existing macros. */
726 735
824 struct spec_nodes *s = &r->spec_nodes; 833 struct spec_nodes *s = &r->spec_nodes;
825 s->n_defined = cpp_lookup (r, DSC("defined")); 834 s->n_defined = cpp_lookup (r, DSC("defined"));
826 s->n_true = cpp_lookup (r, DSC("true")); 835 s->n_true = cpp_lookup (r, DSC("true"));
827 s->n_false = cpp_lookup (r, DSC("false")); 836 s->n_false = cpp_lookup (r, DSC("false"));
828 s->n__VA_ARGS__ = cpp_lookup (r, DSC("__VA_ARGS__")); 837 s->n__VA_ARGS__ = cpp_lookup (r, DSC("__VA_ARGS__"));
838 s->n__has_include__ = cpp_lookup (r, DSC("__has_include__"));
839 s->n__has_include_next__ = cpp_lookup (r, DSC("__has_include_next__"));
829 } 840 }
830 841
831 old_state = r->state; 842 old_state = r->state;
832 r->state.in_directive = 1; 843 r->state.in_directive = 1;
833 r->state.prevent_expansion = 1; 844 r->state.prevent_expansion = 1;