diff options
author | Jakub Jelinek <jakub@redhat.com> | 2019-10-31 18:38:44 +0100 |
---|---|---|
committer | Jakub Jelinek <jakub@gcc.gnu.org> | 2019-10-31 18:38:44 +0100 |
commit | aa23e73b1a090659344ff88361135bd947064e30 (patch) | |
tree | ab29c66793009b48773fdd1844beac65d7c2a2a1 /libcpp | |
parent | 0092b21f24a6778a54caac4015db1d0ad6291a45 (diff) | |
download | gcc-aa23e73b1a090659344ff88361135bd947064e30.zip gcc-aa23e73b1a090659344ff88361135bd947064e30.tar.gz gcc-aa23e73b1a090659344ff88361135bd947064e30.tar.bz2 |
re PR preprocessor/92296 (internal compiler error: Segmentation fault #pragma push_macro("__LINE__"))
PR preprocessor/92296
* internal.h (struct def_pragma_macro): Add is_builtin bitfield.
(_cpp_restore_special_builtin): Declare.
* init.c (_cpp_restore_special_builtin): New function.
* directives.c (do_pragma_push_macro): For NT_BUILTIN_MACRO
set is_builtin and don't try to grab definition.
(cpp_pop_definition): Use _cpp_restore_special_builtin to restore
builtin macros.
* c-c++-common/cpp/pr92296-1.c: New test.
* c-c++-common/cpp/pr92296-2.c: New test.
From-SVN: r277685
Diffstat (limited to 'libcpp')
-rw-r--r-- | libcpp/ChangeLog | 11 | ||||
-rw-r--r-- | libcpp/directives.c | 7 | ||||
-rw-r--r-- | libcpp/init.c | 19 | ||||
-rw-r--r-- | libcpp/internal.h | 4 |
4 files changed, 41 insertions, 0 deletions
diff --git a/libcpp/ChangeLog b/libcpp/ChangeLog index 670e97b..a13f750 100644 --- a/libcpp/ChangeLog +++ b/libcpp/ChangeLog @@ -1,3 +1,14 @@ +2019-10-31 Jakub Jelinek <jakub@redhat.com> + + PR preprocessor/92296 + * internal.h (struct def_pragma_macro): Add is_builtin bitfield. + (_cpp_restore_special_builtin): Declare. + * init.c (_cpp_restore_special_builtin): New function. + * directives.c (do_pragma_push_macro): For NT_BUILTIN_MACRO + set is_builtin and don't try to grab definition. + (cpp_pop_definition): Use _cpp_restore_special_builtin to restore + builtin macros. + 2019-10-15 Nathan Sidwell <nathan@acm.org> * include/line-map.h (struct maps_info_ordinary): Make cache diff --git a/libcpp/directives.c b/libcpp/directives.c index 61f1fef..6e011a1 100644 --- a/libcpp/directives.c +++ b/libcpp/directives.c @@ -1582,6 +1582,8 @@ do_pragma_push_macro (cpp_reader *pfile) node = _cpp_lex_identifier (pfile, c->name); if (node->type == NT_VOID) c->is_undef = 1; + else if (node->type == NT_BUILTIN_MACRO) + c->is_builtin = 1; else { defn = cpp_macro_definition (pfile, node); @@ -2470,6 +2472,11 @@ cpp_pop_definition (cpp_reader *pfile, struct def_pragma_macro *c) if (c->is_undef) return; + if (c->is_builtin) + { + _cpp_restore_special_builtin (pfile, c); + return; + } { size_t namelen; diff --git a/libcpp/init.c b/libcpp/init.c index b094317..32b0e70 100644 --- a/libcpp/init.c +++ b/libcpp/init.c @@ -497,6 +497,25 @@ cpp_init_special_builtins (cpp_reader *pfile) } } +/* Restore macro C to builtin macro definition. */ + +void +_cpp_restore_special_builtin (cpp_reader *pfile, struct def_pragma_macro *c) +{ + size_t len = strlen (c->name); + + for (const struct builtin_macro *b = builtin_array; + b < builtin_array + ARRAY_SIZE (builtin_array); b++) + if (b->len == len && memcmp (c->name, b->name, len + 1) == 0) + { + cpp_hashnode *hp = cpp_lookup (pfile, b->name, b->len); + hp->type = NT_BUILTIN_MACRO; + if (b->always_warn_if_redefined) + hp->flags |= NODE_WARN; + hp->value.builtin = (enum cpp_builtin_type) b->value; + } +} + /* Read the builtins table above and enter them, and language-specific macros, into the hash table. HOSTED is true if this is a hosted environment. */ diff --git a/libcpp/internal.h b/libcpp/internal.h index cd1a523..e759bec 100644 --- a/libcpp/internal.h +++ b/libcpp/internal.h @@ -391,6 +391,8 @@ struct def_pragma_macro { /* Mark if we save an undefined macro. */ unsigned int is_undef : 1; + /* Nonzero if it was a builtin macro. */ + unsigned int is_builtin : 1; }; /* A cpp_reader encapsulates the "state" of a pre-processor run. @@ -722,6 +724,8 @@ extern void *_cpp_commit_buff (cpp_reader *pfile, size_t size); /* In init.c. */ extern void _cpp_maybe_push_include_file (cpp_reader *); extern const char *cpp_named_operator2name (enum cpp_ttype type); +extern void _cpp_restore_special_builtin (cpp_reader *pfile, + struct def_pragma_macro *); /* In directives.c */ extern int _cpp_test_assertion (cpp_reader *, unsigned int *); |