From e9a2e208dd763bf71b0cc9db8526ef8f47ee289e Mon Sep 17 00:00:00 2001 From: Nathan Sidwell Date: Mon, 2 Nov 2020 08:29:58 -0800 Subject: cpplib: Macro use location and comparison Our macro use hook passes a location, but doesn't recieve it from the using location. This patch adds the extra location_t parameter and passes it though. A second cleanup is breaking out the macro comparison code from the redefinition warning. That;ll turn out useful for modules. Finally, there's a filename comparison needed for the location optimization of rewinding from line 2 (occurs during the emission of builtin macros). libcpp/ * internal.h (_cpp_notify_macro_use): Add location parm. (_cpp_maybe_notify_macro_use): Likewise. * directives.c (_cpp_do_file_change): Check we've not changed file when optimizing a rewind. (do_ifdef): Pass location to _cpp_maybe_notify_macro_use. (do_ifndef): Likewise. Delete obsolete comment about powerpc. * expr.c (parse_defined): Pass location to _cpp_maybe_notify_macro_use. * macro.c (enter_macro_context): Likewise. (warn_of_redefinition): Break out helper function. Call it. (compare_macros): New function broken out of warn_of_redefinition. (_cpp_new_macro): Zero all fields. (_cpp_notify_macro_use): Add location parameter. --- libcpp/expr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'libcpp/expr.c') diff --git a/libcpp/expr.c b/libcpp/expr.c index 2ae9be0..e01a47a 100644 --- a/libcpp/expr.c +++ b/libcpp/expr.c @@ -1070,7 +1070,7 @@ parse_defined (cpp_reader *pfile) "this use of \"defined\" may not be portable"); _cpp_mark_macro_used (node); - _cpp_maybe_notify_macro_use (pfile, node); + _cpp_maybe_notify_macro_use (pfile, node, token->src_loc); /* A possible controlling macro of the form #if !defined (). _cpp_parse_expr checks there was no other junk on the line. */ -- cgit v1.1 From e400a64936efdc2424044aa74c0424df16242d2d Mon Sep 17 00:00:00 2001 From: Joseph Myers Date: Fri, 13 Nov 2020 22:45:22 +0000 Subject: c: C2x binary constants C2x adds binary integer constants (approved at the last WG14 meeting, though not yet added to the working draft in git). Configure libcpp to consider these a standard feature in C2x mode, with appropriate updates to diagnostics including support for diagnosing them with -std=c2x -Wc11-c2x-compat. Bootstrapped with no regressions for x86_64-pc-linux-gnu. gcc/testsuite/ 2020-11-13 Joseph Myers * gcc.dg/binary-constants-2.c, gcc.dg/binary-constants-3.c, gcc.dg/system-binary-constants-1.c: Update expected diagnostics. * gcc.dg/c11-binary-constants-1.c, gcc.dg/c11-binary-constants-2.c, gcc.dg/c2x-binary-constants-1.c, gcc.dg/c2x-binary-constants-2.c, gcc.dg/c2x-binary-constants-3.c: New tests. libcpp/ 2020-11-13 Joseph Myers * expr.c (cpp_classify_number): Update diagnostic for binary constants for C. Also diagnose binary constants for -Wc11-c2x-compat. * init.c (lang_defaults): Enable binary constants for GNUC2X and STDC2X. --- libcpp/expr.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) (limited to 'libcpp/expr.c') diff --git a/libcpp/expr.c b/libcpp/expr.c index e01a47a..b98c038 100644 --- a/libcpp/expr.c +++ b/libcpp/expr.c @@ -812,14 +812,21 @@ cpp_classify_number (cpp_reader *pfile, const cpp_token *token, if ((result & CPP_N_IMAGINARY) && CPP_PEDANTIC (pfile)) cpp_error_with_line (pfile, CPP_DL_PEDWARN, virtual_location, 0, "imaginary constants are a GCC extension"); - if (radix == 2 - && !CPP_OPTION (pfile, binary_constants) - && CPP_PEDANTIC (pfile)) - cpp_error_with_line (pfile, CPP_DL_PEDWARN, virtual_location, 0, - CPP_OPTION (pfile, cplusplus) - ? N_("binary constants are a C++14 feature " - "or GCC extension") - : N_("binary constants are a GCC extension")); + if (radix == 2) + { + if (!CPP_OPTION (pfile, binary_constants) + && CPP_PEDANTIC (pfile)) + cpp_error_with_line (pfile, CPP_DL_PEDWARN, virtual_location, 0, + CPP_OPTION (pfile, cplusplus) + ? N_("binary constants are a C++14 feature " + "or GCC extension") + : N_("binary constants are a C2X feature " + "or GCC extension")); + else if (CPP_OPTION (pfile, cpp_warn_c11_c2x_compat) > 0) + cpp_warning_with_line (pfile, CPP_W_C11_C2X_COMPAT, + virtual_location, 0, + "binary constants are a C2X feature"); + } if (radix == 10) result |= CPP_N_DECIMAL; -- 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/expr.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'libcpp/expr.c') diff --git a/libcpp/expr.c b/libcpp/expr.c index b98c038..2ba7726 100644 --- a/libcpp/expr.c +++ b/libcpp/expr.c @@ -1068,6 +1068,7 @@ parse_defined (cpp_reader *pfile) } } + bool is_defined = false; if (node) { if ((pfile->context != initial_context @@ -1075,9 +1076,11 @@ parse_defined (cpp_reader *pfile) && CPP_OPTION (pfile, warn_expansion_to_defined)) cpp_pedwarning (pfile, CPP_W_EXPANSION_TO_DEFINED, "this use of \"defined\" may not be portable"); - + is_defined = _cpp_defined_macro_p (node); + if (!_cpp_maybe_notify_macro_use (pfile, node, token->src_loc)) + /* It wasn't a macro after all. */ + is_defined = false; _cpp_mark_macro_used (node); - _cpp_maybe_notify_macro_use (pfile, node, token->src_loc); /* A possible controlling macro of the form #if !defined (). _cpp_parse_expr checks there was no other junk on the line. */ @@ -1093,7 +1096,7 @@ parse_defined (cpp_reader *pfile) result.unsignedp = false; result.high = 0; result.overflow = false; - result.low = node && _cpp_defined_macro_p (node); + result.low = is_defined; return result; } -- cgit v1.1