From 4b5f564a5d958295d51a1a7ff825896a89f22b75 Mon Sep 17 00:00:00 2001 From: Nathan Sidwell Date: Fri, 6 Nov 2020 08:53:31 -0800 Subject: libcpp: Provide date routine Joseph pointed me at cb_get_source_date_epoch, which allows repeatable builds and solves a FIXME I had on the modules branch. Unfortunately it's used exclusively to generate __DATE__ and __TIME__ values, which fallback to using a time(2) call. It'd be nicer if the preprocessor made whatever time value it determined available to the rest of the compiler. So this patch adds a new cpp_get_date function, which abstracts the call to the get_source_date_epoch hook, or uses time directly. The value is cached. Thus the timestamp I end up putting on CMI files matches __DATE__ and __TIME__ expansions. That seems worthwhile. libcpp/ * include/cpplib.h (enum class CPP_time_kind): New. (cpp_get_date): Declare. * internal.h (struct cpp_reader): Replace source_date_epoch with time_stamp and time_stamp_kind. * init.c (cpp_create_reader): Initialize them. * macro.c (_cpp_builtin_macro_text): Use cpp_get_date. (cpp_get_date): Broken out from _cpp_builtin_macro_text and genericized. --- libcpp/include/cpplib.h | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'libcpp/include/cpplib.h') diff --git a/libcpp/include/cpplib.h b/libcpp/include/cpplib.h index 8e39886..c4d7cc5 100644 --- a/libcpp/include/cpplib.h +++ b/libcpp/include/cpplib.h @@ -1040,6 +1040,15 @@ inline location_t cpp_macro_definition_location (cpp_hashnode *node) { return node->value.macro->line; } +/* Return an idempotent time stamp (possibly from SOURCE_DATE_EPOCH). */ +enum class CPP_time_kind +{ + FIXED = -1, /* Fixed time via source epoch. */ + DYNAMIC = -2, /* Dynamic via time(2). */ + UNKNOWN = -3 /* Wibbly wobbly, timey wimey. */ +}; +extern CPP_time_kind cpp_get_date (cpp_reader *, time_t *); + extern void _cpp_backup_tokens (cpp_reader *, unsigned int); extern const cpp_token *cpp_peek_token (cpp_reader *, int); -- cgit v1.1 From 1d00f8c86324c40ab2ba7933366d380e32c0a94a Mon Sep 17 00:00:00 2001 From: Joseph Myers Date: Thu, 12 Nov 2020 21:13:51 +0000 Subject: c: C2x __has_c_attribute C2x adds the __has_c_attribute preprocessor operator, similar to C++ __has_cpp_attribute. GCC implements __has_cpp_attribute as exactly equivalent to __has_attribute. (The documentation says they differ regarding the values returned for standard attributes, but that's actually only a matter of the particular nonzero value returned not being specified in the documentation for __has_attribute; the implementation makes no distinction between the two.) I don't think having them exactly equivalent is actually correct, either for __has_cpp_attribute or for __has_c_attribute. Specifically, I think it is only correct for __has_cpp_attribute or __has_c_attribute to return nonzero if the given attribute is supported, with the particular pp-tokens passed to __has_cpp_attribute or __has_c_attribute, with [[]] syntax, not if it's only accepted in __attribute__ or with gnu:: added in [[]]. For example, they should return nonzero for gnu::packed, but zero for plain packed, because [[gnu::packed]] is accepted but [[packed]] is ignored as not a standard attribute. This patch implements that for __has_c_attribute, leaving any changes to __has_cpp_attribute for the C++ maintainers. A new BT_HAS_STD_ATTRIBUTE is added for __has_c_attribute (which I think, based on the above, would actually be correct to use for __has_cpp_attribute as well). The code in c_common_has_attribute that deals with scopes has its C++ conditional removed; instead, whether the language is C or C++ is used only to determine the numeric values returned for standard attributes (and which standard attributes are handled there at all). A new argument is passed to c_common_has_attribute to distinguish BT_HAS_STD_ATTRIBUTE from BT_HAS_ATTRIBUTE, and that argument is used to stop attributes with no scope specified from being accepted with __has_c_attribute unless they are one of the known standard attributes and so handled specially. Although the standard specify constants ending with 'L' as the values for the standard attributes, there is no correctness issue with the lack of code in GCC to add that 'L' to the expansion: __has_c_attribute and __has_cpp_attribute are expanded in #if after other macro expansion has occurred, with no semantics being specified if they occur outside #if, so there is no way for a conforming program to inspect the exact text of the expansion of those macros, only to use the resulting pp-number in a #if expression, where long and int have the same set of values. Bootstrapped with no regressions for x86_64-pc-linux-gnu. gcc/ 2020-11-12 Joseph Myers * doc/cpp.texi (__has_attribute): Document when scopes are allowed for C. (__has_c_attribute): New. gcc/c-family/ 2020-11-12 Joseph Myers * c-lex.c (c_common_has_attribute): Take argument std_syntax. Allow scope for C. Handle standard attributes for C. Do not accept unscoped attributes if std_syntax and not handled as standard attributes. * c-common.h (c_common_has_attribute): Update prototype. gcc/testsuite/ 2020-11-12 Joseph Myers * gcc.dg/c2x-has-c-attribute-1.c, gcc.dg/c2x-has-c-attribute-2.c, gcc.dg/c2x-has-c-attribute-3.c, gcc.dg/c2x-has-c-attribute-4.c: New tests. libcpp/ 2020-11-12 Joseph Myers * include/cpplib.h (struct cpp_callbacks): Add bool argument to has_attribute. (enum cpp_builtin_type): Add BT_HAS_STD_ATTRIBUTE. * init.c (builtin_array): Add __has_c_attribute. (cpp_init_special_builtins): Handle BT_HAS_STD_ATTRIBUTE. * macro.c (_cpp_builtin_macro_text): Handle BT_HAS_STD_ATTRIBUTE. Update call to has_attribute for BT_HAS_ATTRIBUTE. * traditional.c (fun_like_macro): Handle BT_HAS_STD_ATTRIBUTE. --- libcpp/include/cpplib.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'libcpp/include/cpplib.h') diff --git a/libcpp/include/cpplib.h b/libcpp/include/cpplib.h index c4d7cc5..8900e77 100644 --- a/libcpp/include/cpplib.h +++ b/libcpp/include/cpplib.h @@ -672,7 +672,7 @@ struct cpp_callbacks void (*used) (cpp_reader *, location_t, cpp_hashnode *); /* Callback to identify whether an attribute exists. */ - int (*has_attribute) (cpp_reader *); + int (*has_attribute) (cpp_reader *, bool); /* Callback to determine whether a built-in function is recognized. */ int (*has_builtin) (cpp_reader *); @@ -857,6 +857,7 @@ enum cpp_builtin_type BT_TIMESTAMP, /* `__TIMESTAMP__' */ BT_COUNTER, /* `__COUNTER__' */ BT_HAS_ATTRIBUTE, /* `__has_attribute(x)' */ + BT_HAS_STD_ATTRIBUTE, /* `__has_c_attribute(x)' */ BT_HAS_BUILTIN, /* `__has_builtin(x)' */ BT_HAS_INCLUDE, /* `__has_include(x)' */ BT_HAS_INCLUDE_NEXT /* `__has_include_next(x)' */ -- cgit v1.1 From 6f1ae1ecd351348eb33b515c5e23778651bee028 Mon Sep 17 00:00:00 2001 From: "Piotr H. Dabrowski" Date: Fri, 13 Nov 2020 12:27:16 -0500 Subject: Do not warn about unused macros while processing #pragma GCC optimize libcpp PR c++/91318 * include/cpplib.h: Added cpp_define_unused(), cpp_define_formatted_unused() * directives.c: Likewise. gcc/c-family PR c++/91318 * c-cppbuiltin.c: c_cpp_builtins_optimize_pragma(): use cpp_define_unused() --- libcpp/include/cpplib.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'libcpp/include/cpplib.h') diff --git a/libcpp/include/cpplib.h b/libcpp/include/cpplib.h index 8900e77..ce00952 100644 --- a/libcpp/include/cpplib.h +++ b/libcpp/include/cpplib.h @@ -1076,8 +1076,12 @@ extern cppchar_t cpp_host_to_exec_charset (cpp_reader *, cppchar_t); /* Used to register macros and assertions, perhaps from the command line. The text is the same as the command line argument. */ extern void cpp_define (cpp_reader *, const char *); +extern void cpp_define_unused (cpp_reader *, const char *); extern void cpp_define_formatted (cpp_reader *pfile, const char *fmt, ...) ATTRIBUTE_PRINTF_2; +extern void cpp_define_formatted_unused (cpp_reader *pfile, + const char *fmt, + ...) ATTRIBUTE_PRINTF_2; extern void cpp_assert (cpp_reader *, const char *); extern void cpp_undef (cpp_reader *, const char *); extern void cpp_unassert (cpp_reader *, const char *); -- cgit v1.1 From b196e76aecb675b9f6a1e4f15419606621459401 Mon Sep 17 00:00:00 2001 From: Nathan Sidwell Date: Tue, 17 Nov 2020 08:16:50 -0800 Subject: preprocessor: new callbacks These two callbacks are needed for C++ modules. The first is for handling macros from header-units. These are resolved lazily. The second is for include-translation -- whether a #include gets turned into a header-unit import. libcpp/ * include/cpplib.h (struct cpp_callbacks): Add user_deferred_macro & translate_include. --- libcpp/include/cpplib.h | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'libcpp/include/cpplib.h') diff --git a/libcpp/include/cpplib.h b/libcpp/include/cpplib.h index ce00952..d232426 100644 --- a/libcpp/include/cpplib.h +++ b/libcpp/include/cpplib.h @@ -680,6 +680,9 @@ struct cpp_callbacks /* Callback that can change a user lazy into normal macro. */ void (*user_lazy_macro) (cpp_reader *, cpp_macro *, unsigned); + /* Callback to handle deferred cpp_macros. */ + cpp_macro *(*user_deferred_macro) (cpp_reader *, location_t, cpp_hashnode *); + /* Callback to parse SOURCE_DATE_EPOCH from environment. */ time_t (*get_source_date_epoch) (cpp_reader *); @@ -698,6 +701,11 @@ struct cpp_callbacks /* Callback for filename remapping in __FILE__ and __BASE_FILE__ macro expansions. */ const char *(*remap_filename) (const char*); + + /* Maybe translate a #include into something else. Return a + cpp_buffer containing the translation if translating. */ + char *(*translate_include) (cpp_reader *, line_maps *, location_t, + const char *path); }; #ifdef VMS -- cgit v1.1 From db87f19ae3cfc126fb39616515b57dea4df02e6d Mon Sep 17 00:00:00 2001 From: Nathan Sidwell Date: Wed, 18 Nov 2020 06:44:38 -0800 Subject: preprocessor: Update mkdeps for modules This is slightly different to the original patch I posted. This adds separate module target and dependency functions (rather than a single bi-modal function). libcpp/ * include/cpplib.h (struct cpp_options): Add modules to dep-options. * include/mkdeps.h (deps_add_module_target): Declare. (deps_add_module_dep): Declare. * mkdeps.c (class mkdeps): Add modules, module_name, cmi_name, is_header_unit fields. Adjust cdtors. (deps_add_module_target, deps_add_module_dep): New. (make_write): Write module dependencies, if enabled. --- libcpp/include/cpplib.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'libcpp/include/cpplib.h') diff --git a/libcpp/include/cpplib.h b/libcpp/include/cpplib.h index d232426..75d4d0a 100644 --- a/libcpp/include/cpplib.h +++ b/libcpp/include/cpplib.h @@ -528,6 +528,9 @@ struct cpp_options one. */ bool phony_targets; + /* Generate dependency info for modules. */ + bool modules; + /* If true, no dependency is generated on the main file. */ bool ignore_main_file; -- cgit v1.1 From 7ceb899e9343493f646434f74a149395f3913d9a Mon Sep 17 00:00:00 2001 From: Nathan Sidwell Date: Wed, 18 Nov 2020 08:27:16 -0800 Subject: preprocessor: Add support for header unit translation libcpp/ * files.c (struct _cpp_file): Add header_unit field. (_cpp_stack_file): Add header unit support. (cpp_find_header_unit): New. * include/cpplib.h (cpp_find_header_unit): Declare. --- libcpp/include/cpplib.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'libcpp/include/cpplib.h') diff --git a/libcpp/include/cpplib.h b/libcpp/include/cpplib.h index 75d4d0a..389af32 100644 --- a/libcpp/include/cpplib.h +++ b/libcpp/include/cpplib.h @@ -983,6 +983,9 @@ extern cpp_callbacks *cpp_get_callbacks (cpp_reader *) ATTRIBUTE_PURE; extern void cpp_set_callbacks (cpp_reader *, cpp_callbacks *); extern class mkdeps *cpp_get_deps (cpp_reader *) ATTRIBUTE_PURE; +extern const char *cpp_find_header_unit (cpp_reader *, const char *file, + bool angle_p, location_t); + /* This function reads the file, but does not start preprocessing. It returns the name of the original file; this is the same as the input file, except for preprocessed input. This will generate at -- cgit v1.1 From c9c3d5f28a589cd00be5748010783657189e9855 Mon Sep 17 00:00:00 2001 From: Nathan Sidwell Date: Wed, 18 Nov 2020 10:24:12 -0800 Subject: preprocessor: C++ module-directives C++20 modules introduces a new kind of preprocessor directive -- a module directive. These are directives but without the leading '#'. We have to detect them by sniffing the start of a logical line. When detected we replace the initial identifiers with unspellable tokens and pass them through to the language parser the same way deferred pragmas are. There's a PRAGMA_EOL at the logical end of line too. One additional complication is that we have to do header-name lexing after the initial tokens, and that requires changes in the macro-aware piece of the preprocessor. The above sniffer sets a counter in the lexer state, and that triggers at the appropriate point. We then do the same header-name lexing that occurs on a #include directive or has_include pseudo-macro. Except that the header name ends up in the token stream. A couple of token emitters need to deal with the new token possibility. gcc/c-family/ * c-lex.c (c_lex_with_flags): CPP_HEADER_NAMEs can now be seen. libcpp/ * include/cpplib.h (struct cpp_options): Add module_directives option. (NODE_MODULE): New node flag. (struct cpp_hashnode): Make rid-code a bitfield, increase bits in flags and swap with type field. * init.c (post_options): Create module-directive identifier nodes. * internal.h (struct lexer_state): Add directive_file_token & n_modules fields. Add module node enumerator. * lex.c (cpp_maybe_module_directive): New. (_cpp_lex_token): Call it. (cpp_output_token): Add '"' around CPP_HEADER_NAME token. (do_peek_ident, do_peek_module): New. (cpp_directives_only): Detect module-directive lines. * macro.c (cpp_get_token_1): Deal with directive_file_token triggering. --- libcpp/include/cpplib.h | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'libcpp/include/cpplib.h') diff --git a/libcpp/include/cpplib.h b/libcpp/include/cpplib.h index 389af32..630f2e0 100644 --- a/libcpp/include/cpplib.h +++ b/libcpp/include/cpplib.h @@ -487,6 +487,9 @@ struct cpp_options /* Nonzero for the '::' token. */ unsigned char scope; + /* Nonzero means tokenize C++20 module directives. */ + unsigned char module_directives; + /* Holds the name of the target (execution) character set. */ const char *narrow_charset; @@ -842,6 +845,7 @@ struct GTY(()) cpp_macro { #define NODE_USED (1 << 5) /* Dumped with -dU. */ #define NODE_CONDITIONAL (1 << 6) /* Conditional macro */ #define NODE_WARN_OPERATOR (1 << 7) /* Warn about C++ named operator. */ +#define NODE_MODULE (1 << 8) /* C++-20 module-related name. */ /* Different flavors of hash node. */ enum node_type @@ -900,11 +904,11 @@ struct GTY(()) cpp_hashnode { unsigned int directive_index : 7; /* If is_directive, then index into directive table. Otherwise, a NODE_OPERATOR. */ - unsigned char rid_code; /* Rid code - for front ends. */ + unsigned int rid_code : 8; /* Rid code - for front ends. */ + unsigned int flags : 9; /* CPP flags. */ ENUM_BITFIELD(node_type) type : 2; /* CPP node type. */ - unsigned int flags : 8; /* CPP flags. */ - /* 6 bits spare (plus another 32 on 64-bit hosts). */ + /* 5 bits spare (plus another 32 on 64-bit hosts). */ union _cpp_hashnode_value GTY ((desc ("%1.type"))) value; }; -- cgit v1.1 From 9844497a935d5e89dc92539128edccb6bb408bb1 Mon Sep 17 00:00:00 2001 From: Nathan Sidwell Date: Thu, 19 Nov 2020 07:00:51 -0800 Subject: preprocessor: main file searching This adds the capability to locate the main file on the user or system include paths. That's extremely useful to users building header units. Searching has to be requiested (plain header-unit compilation will not search). Also, to make include_next work as expected when building a header unit, we add a mechanism to retrofit a non-searched source file as one on the include path. libcpp/ * include/cpplib.h (enum cpp_main_search): New. (struct cpp_options): Add main_search field. (cpp_main_loc): Declare. (cpp_retrofit_as_include): Declare. * internal.h (struct cpp_reader): Add main_loc field. (_cpp_in_main_source_file): Not main if main is a header. * init.c (cpp_read_main_file): Use main_search option to locate main file. Set main_loc * files.c (cpp_retrofit_as_include): New. --- libcpp/include/cpplib.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'libcpp/include/cpplib.h') diff --git a/libcpp/include/cpplib.h b/libcpp/include/cpplib.h index 630f2e0..91226cf 100644 --- a/libcpp/include/cpplib.h +++ b/libcpp/include/cpplib.h @@ -308,6 +308,15 @@ enum cpp_normalize_level { normalized_none }; +enum cpp_main_search +{ + CMS_none, /* A regular source file. */ + CMS_header, /* Is a directly-specified header file (eg PCH or + header-unit). */ + CMS_user, /* Search the user INCLUDE path. */ + CMS_system, /* Search the system INCLUDE path. */ +}; + /* This structure is nested inside struct cpp_reader, and carries all the options visible to the command line. */ struct cpp_options @@ -566,6 +575,8 @@ struct cpp_options /* The maximum depth of the nested #include. */ unsigned int max_include_depth; + + cpp_main_search main_search : 8; }; /* Diagnostic levels. To get a diagnostic without associating a @@ -997,6 +1008,10 @@ extern const char *cpp_find_header_unit (cpp_reader *, const char *file, too. If there was an error opening the file, it returns NULL. */ extern const char *cpp_read_main_file (cpp_reader *, const char *, bool injecting = false); +extern location_t cpp_main_loc (const cpp_reader *); + +/* Adjust for the main file to be an include. */ +extern void cpp_retrofit_as_include (cpp_reader *); /* Set up built-ins with special behavior. Use cpp_init_builtins() instead unless your know what you are doing. */ -- cgit v1.1 From 13f93cf5336ec0085277b9a5ef88c02359527170 Mon Sep 17 00:00:00 2001 From: Nathan Sidwell Date: Tue, 24 Nov 2020 08:23:55 -0800 Subject: preprocessor: Add deferred macros Deferred macros are needed for C++ modules. Header units may export macro definitions and undefinitions. These are resolved lazily at the point of (potential) use. (The language specifies that, it's not just a useful optimization.) Thus, identifier nodes grow a 'deferred' field, which fortunately doesn't expand the structure on 64-bit systems as there was padding there. This is non-zero on NT_MACRO nodes, if the macro is deferred. When such an identifier is lexed, it is resolved via a callback that I added recently. That will either provide the macro definition, or discover it there was an overriding undef. Either way the identifier is no longer a deferred macro. Notice it is now possible for NT_MACRO nodes to have a NULL macro expansion. libcpp/ * include/cpplib.h (struct cpp_hashnode): Add deferred field. (cpp_set_deferred_macro): Define. (cpp_get_deferred_macro): Declare. (cpp_macro_definition): Reformat, add overload. (cpp_macro_definition_location): Deal with deferred macro. (cpp_alloc_token_string, cpp_compare_macro): Declare. * internal.h (_cpp_notify_macro_use): Return bool (_cpp_maybe_notify_macro_use): Likewise. * directives.c (do_undef): Check macro is not undef before warning. (do_ifdef, do_ifndef): Deal with deferred macro. * expr.c (parse_defined): Likewise. * lex.c (cpp_allocate_token_string): Break out of ... (create_literal): ... here. Call it. (cpp_maybe_module_directive): Deal with deferred macro. * macro.c (cpp_get_token_1): Deal with deferred macro. (warn_of_redefinition): Deal with deferred macro. (compare_macros): Rename to ... (cpp_compare_macro): ... here. Make extern. (cpp_get_deferred_macro): New. (_cpp_notify_macro_use): Deal with deferred macro, return bool indicating definedness. (cpp_macro_definition): Deal with deferred macro. --- libcpp/include/cpplib.h | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) (limited to 'libcpp/include/cpplib.h') diff --git a/libcpp/include/cpplib.h b/libcpp/include/cpplib.h index 91226cf..2becd2e 100644 --- a/libcpp/include/cpplib.h +++ b/libcpp/include/cpplib.h @@ -901,7 +901,7 @@ enum cpp_builtin_type union GTY(()) _cpp_hashnode_value { /* Assert (maybe NULL) */ cpp_macro * GTY((tag ("NT_VOID"))) answers; - /* Macro (never NULL) */ + /* Macro (maybe NULL) */ cpp_macro * GTY((tag ("NT_USER_MACRO"))) macro; /* Code for a builtin macro. */ enum cpp_builtin_type GTY ((tag ("NT_BUILTIN_MACRO"))) builtin; @@ -919,7 +919,11 @@ struct GTY(()) cpp_hashnode { unsigned int flags : 9; /* CPP flags. */ ENUM_BITFIELD(node_type) type : 2; /* CPP node type. */ - /* 5 bits spare (plus another 32 on 64-bit hosts). */ + /* 5 bits spare. */ + + /* On a 64-bit system there would be 32-bits of padding to the value + field. So placing the deferred index here is not costly. */ + unsigned deferred; /* Deferred index, (unless zero). */ union _cpp_hashnode_value GTY ((desc ("%1.type"))) value; }; @@ -1061,6 +1065,18 @@ inline bool cpp_macro_p (const cpp_hashnode *node) { return node->type & NT_MACRO_MASK; } +inline cpp_macro *cpp_set_deferred_macro (cpp_hashnode *node, + cpp_macro *forced = NULL) +{ + cpp_macro *old = node->value.macro; + + node->value.macro = forced; + node->type = NT_USER_MACRO; + node->flags &= ~NODE_USED; + + return old; +} +cpp_macro *cpp_get_deferred_macro (cpp_reader *, cpp_hashnode *, location_t); /* Returns true if NODE is a function-like user macro. */ inline bool cpp_fun_like_macro_p (cpp_hashnode *node) @@ -1068,11 +1084,13 @@ inline bool cpp_fun_like_macro_p (cpp_hashnode *node) return cpp_user_macro_p (node) && node->value.macro->fun_like; } -extern const unsigned char *cpp_macro_definition (cpp_reader *, - cpp_hashnode *); +extern const unsigned char *cpp_macro_definition (cpp_reader *, cpp_hashnode *); +extern const unsigned char *cpp_macro_definition (cpp_reader *, cpp_hashnode *, + const cpp_macro *); inline location_t cpp_macro_definition_location (cpp_hashnode *node) { - return node->value.macro->line; + const cpp_macro *macro = node->value.macro; + return macro ? macro->line : 0; } /* Return an idempotent time stamp (possibly from SOURCE_DATE_EPOCH). */ enum class CPP_time_kind @@ -1266,6 +1284,8 @@ extern int cpp_ideq (const cpp_token *, const char *); extern void cpp_output_line (cpp_reader *, FILE *); extern unsigned char *cpp_output_line_to_string (cpp_reader *, const unsigned char *); +extern const unsigned char *cpp_alloc_token_string + (cpp_reader *, const unsigned char *, unsigned); extern void cpp_output_token (const cpp_token *, FILE *); extern const char *cpp_type2name (enum cpp_ttype, unsigned char flags); /* Returns the value of an escape sequence, truncated to the correct @@ -1321,6 +1341,8 @@ extern void cpp_scan_nooutput (cpp_reader *); extern int cpp_sys_macro_p (cpp_reader *); extern unsigned char *cpp_quote_string (unsigned char *, const unsigned char *, unsigned int); +extern bool cpp_compare_macros (const cpp_macro *macro1, + const cpp_macro *macro2); /* In files.c */ extern bool cpp_included (cpp_reader *, const char *); -- cgit v1.1 From eccec8684142e05f2f92f0f5bd5b47dda3ba1529 Mon Sep 17 00:00:00 2001 From: JeanHeyd Meneide Date: Tue, 1 Dec 2020 14:39:47 -0700 Subject: Feature: Macros for identifying the wide and narrow execution string literal encoding gcc/c-family * c-cppbuiltin.c (c_cpp_builtins): Add predefined {__GNUC_EXECUTION_CHARSET_NAME} and _WIDE_EXECUTION_CHARSET_NAME} macros. gcc/ * doc/cpp.texi: Document new macros. gcc/testsuite/ * c-c++-common/cpp/wide-narrow-predef-macros.c: New test. libcpp/ * charset.c (init_iconv_desc): Initialize "to" and "from" fields. * directives.c (cpp_get_narrow_charset_name): New function. (cpp_get_wide_charset_name): Likewise. * include/cpplib.h (cpp_get_narrow_charset_name): Prototype. (cpp_get_wide_charset_name): Likewise. * internal.h (cset_converter): Add "to" and "from" fields. --- libcpp/include/cpplib.h | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'libcpp/include/cpplib.h') diff --git a/libcpp/include/cpplib.h b/libcpp/include/cpplib.h index 2becd2e..692aee5 100644 --- a/libcpp/include/cpplib.h +++ b/libcpp/include/cpplib.h @@ -1005,6 +1005,11 @@ extern class mkdeps *cpp_get_deps (cpp_reader *) ATTRIBUTE_PURE; extern const char *cpp_find_header_unit (cpp_reader *, const char *file, bool angle_p, location_t); +/* Call these to get name data about the various compile-time + charsets. */ +extern const char *cpp_get_narrow_charset_name (cpp_reader *) ATTRIBUTE_PURE; +extern const char *cpp_get_wide_charset_name (cpp_reader *) ATTRIBUTE_PURE; + /* This function reads the file, but does not start preprocessing. It returns the name of the original file; this is the same as the input file, except for preprocessed input. This will generate at -- cgit v1.1 From 62c5ea5228857a910b38df91c2b0fe28f4d1ddc8 Mon Sep 17 00:00:00 2001 From: Nathan Sidwell Date: Mon, 14 Dec 2020 07:21:49 -0800 Subject: preprocessor: Deferred macro support For deferred macros we also need a new field on the macro itself, so that the module machinery can determine the macro was imported. Also the documentation for the hashnode's deferred field was incomplete. libcpp/ * include/cpplib.h (struct cpp_macro): Add imported_p field. (struct cpp_hashnode): Tweak deferred field documentation. * macro.c (_cpp_new_macro): Clear new field. (cpp_get_deferred_macro, get_deferred_or_lazy_macro): Assert more. --- libcpp/include/cpplib.h | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'libcpp/include/cpplib.h') diff --git a/libcpp/include/cpplib.h b/libcpp/include/cpplib.h index 692aee5..50d28dc 100644 --- a/libcpp/include/cpplib.h +++ b/libcpp/include/cpplib.h @@ -826,7 +826,10 @@ struct GTY(()) cpp_macro { tokens. */ unsigned int extra_tokens : 1; - /* 1 bits spare (32-bit). 33 on 64-bit target. */ + /* Imported C++20 macro (from a header unit). */ + unsigned int imported_p : 1; + + /* 0 bits spare (32-bit). 32 on 64-bit target. */ union cpp_exp_u { @@ -921,9 +924,11 @@ struct GTY(()) cpp_hashnode { /* 5 bits spare. */ - /* On a 64-bit system there would be 32-bits of padding to the value + /* The deferred cookie is applicable to NT_USER_MACRO or NT_VOID. + The latter for when a macro had a prevailing undef. + On a 64-bit system there would be 32-bits of padding to the value field. So placing the deferred index here is not costly. */ - unsigned deferred; /* Deferred index, (unless zero). */ + unsigned deferred; /* Deferred cookie */ union _cpp_hashnode_value GTY ((desc ("%1.type"))) value; }; -- cgit v1.1