From d00b1b023ecfc3ddc3fe952c0063dab7529d5f7a Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Sat, 26 Sep 2020 10:07:41 +0200 Subject: powerpc, libcpp: Fix gcc build with clang on power8 [PR97163] libcpp has two specialized altivec implementations of search_line_fast, one for power8+ and the other one otherwise. Both use __attribute__((altivec(vector))) and the GCC builtins rather than altivec.h and the APIs from there, which is fine, but should be restricted to when libcpp is built with GCC, so that it can be relied on. The second elif is and thus e.g. when built with clang it isn't picked, but the first one was just guarded with and so according to the bugreporter clang fails miserably on that. The following patch fixes that by adding the same GCC_VERSION requirement as the second version. I don't know where the 4.5 in there comes from and the exact version doesn't matter that much, as long as it is above 4.2 that clang pretends to be and smaller or equal to 4.8 as the oldest gcc we support as bootstrap compiler ATM. Furthermore, the patch fixes the comment, the version it is talking about is not pre-GCC 5, but actually the GCC 5+ one. 2020-09-26 Jakub Jelinek PR bootstrap/97163 * lex.c (search_line_fast): Only use _ARCH_PWR8 Altivec version for GCC >= 4.5. --- libcpp/lex.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'libcpp') diff --git a/libcpp/lex.c b/libcpp/lex.c index 9aec9e0..2fe77d1 100644 --- a/libcpp/lex.c +++ b/libcpp/lex.c @@ -531,11 +531,11 @@ init_vectorized_lexer (void) search_line_fast = impl; } -#elif defined(_ARCH_PWR8) && defined(__ALTIVEC__) +#elif (GCC_VERSION >= 4005) && defined(_ARCH_PWR8) && defined(__ALTIVEC__) /* A vection of the fast scanner using AltiVec vectorized byte compares and VSX unaligned loads (when VSX is available). This is otherwise - the same as the pre-GCC 5 version. */ + the same as the AltiVec version. */ ATTRIBUTE_NO_SANITIZE_UNDEFINED static const uchar * -- cgit v1.1 From 91dd4a3864110704c921ab8467f568ff42c38e5c Mon Sep 17 00:00:00 2001 From: GCC Administrator Date: Sun, 27 Sep 2020 00:16:24 +0000 Subject: Daily bump. --- libcpp/ChangeLog | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'libcpp') diff --git a/libcpp/ChangeLog b/libcpp/ChangeLog index 7fb267e..b6b6b18 100644 --- a/libcpp/ChangeLog +++ b/libcpp/ChangeLog @@ -1,3 +1,9 @@ +2020-09-26 Jakub Jelinek + + PR bootstrap/97163 + * lex.c (search_line_fast): Only use _ARCH_PWR8 Altivec version + for GCC >= 4.5. + 2020-09-17 Patrick Palka PR c/80076 -- cgit v1.1 From d1c566d72d9361b37213881222c7e2713cdf05b7 Mon Sep 17 00:00:00 2001 From: Nathan Sidwell Date: Thu, 8 Oct 2020 12:11:37 -0700 Subject: libcpp: Directly peek for initial line marker Using the tokenizer to sniff for an initial line marker for preprocessed input is a little brittle, particularly with -fdirectives-only. If there is no marker we'll happily munch initial comments. This patch directly sniffs the buffer. This is safe because the initial line marker was machine generated and must be right at the beginning of the file. Anything else is not such a line marker. The same is true for the initial directory marker. For that tokenizing the string is simplest, but at that point it's either a regular line marker or a directory marker. If it's a regular marker, unwinding tokens is fine. libcpp/ * internal.h (enum include_type): Rename IT_MAIN_INJECT to IT_PRE_MAIN. * init.c (cpp_read_main_file): If there is no line marker, adjust the initial line marker. (read_original_filename): Return bool, peek the buffer directly before trying to tokenize. (read_original_directory): Likewise. Directly prod the string literal. * files.c (_cpp_stack_file): Adjust for IT_PRE_MAIN change. --- libcpp/files.c | 10 ++-- libcpp/init.c | 142 +++++++++++++++++++++++++++++++----------------------- libcpp/internal.h | 4 +- 3 files changed, 89 insertions(+), 67 deletions(-) (limited to 'libcpp') diff --git a/libcpp/files.c b/libcpp/files.c index b890b8e..5af4136 100644 --- a/libcpp/files.c +++ b/libcpp/files.c @@ -948,10 +948,12 @@ _cpp_stack_file (cpp_reader *pfile, _cpp_file *file, include_type type, /* Add line map and do callbacks. */ _cpp_do_file_change (pfile, LC_ENTER, file->path, - /* With preamble injection, start on line zero, so - the preamble doesn't appear to have been - included from line 1. */ - type == IT_MAIN_INJECT ? 0 : 1, sysp); + /* With preamble injection, start on line zero, + so the preamble doesn't appear to have been + included from line 1. Likewise when + starting preprocessed, we expect an initial + locating line. */ + type == IT_PRE_MAIN ? 0 : 1, sysp); return true; } diff --git a/libcpp/init.c b/libcpp/init.c index aba5854..84c0a9e 100644 --- a/libcpp/init.c +++ b/libcpp/init.c @@ -36,7 +36,7 @@ along with this program; see the file COPYING3. If not see static void init_library (void); static void mark_named_operators (cpp_reader *, int); -static void read_original_filename (cpp_reader *); +static bool read_original_filename (cpp_reader *); static void read_original_directory (cpp_reader *); static void post_options (cpp_reader *); @@ -681,94 +681,114 @@ cpp_read_main_file (cpp_reader *pfile, const char *fname, bool injecting) return NULL; _cpp_stack_file (pfile, pfile->main_file, - injecting ? IT_MAIN_INJECT : IT_MAIN, 0); + injecting || CPP_OPTION (pfile, preprocessed) + ? IT_PRE_MAIN : IT_MAIN, 0); /* For foo.i, read the original filename foo.c now, for the benefit of the front ends. */ if (CPP_OPTION (pfile, preprocessed)) - read_original_filename (pfile); + if (!read_original_filename (pfile)) + { + /* We're on line 1 after all. */ + auto *last = linemap_check_ordinary + (LINEMAPS_LAST_MAP (pfile->line_table, false)); + last->to_line = 1; + /* Inform of as-if a file change. */ + _cpp_do_file_change (pfile, LC_RENAME_VERBATIM, LINEMAP_FILE (last), + LINEMAP_LINE (last), LINEMAP_SYSP (last)); + } return ORDINARY_MAP_FILE_NAME (LINEMAPS_LAST_ORDINARY_MAP (pfile->line_table)); } -/* For preprocessed files, if the first tokens are of the form # NUM. - handle the directive so we know the original file name. This will - generate file_change callbacks, which the front ends must handle - appropriately given their state of initialization. */ -static void +/* For preprocessed files, if the very first characters are + '#[01]', then handle a line directive so we know the + original file name. This will generate file_change callbacks, + which the front ends must handle appropriately given their state of + initialization. We peek directly into the character buffer, so + that we're not confused by otherwise-skipped white space & + comments. We can be very picky, because this should have been + machine-generated text (by us, no less). This way we do not + interfere with the module directive state machine. */ + +static bool read_original_filename (cpp_reader *pfile) { - const cpp_token *token, *token1; - - /* Lex ahead; if the first tokens are of the form # NUM, then - process the directive, otherwise back up. */ - token = _cpp_lex_direct (pfile); - if (token->type == CPP_HASH) + auto *buf = pfile->buffer->next_line; + + if (pfile->buffer->rlimit - buf > 4 + && buf[0] == '#' + && buf[1] == ' ' + // Also permit '1', as that's what used to be here + && (buf[2] == '0' || buf[2] == '1') + && buf[3] == ' ') { - pfile->state.in_directive = 1; - token1 = _cpp_lex_direct (pfile); - _cpp_backup_tokens (pfile, 1); - pfile->state.in_directive = 0; - - /* If it's a #line directive, handle it. */ - if (token1->type == CPP_NUMBER - && _cpp_handle_directive (pfile, token->flags & PREV_WHITE)) + const cpp_token *token = _cpp_lex_direct (pfile); + gcc_checking_assert (token->type == CPP_HASH); + if (_cpp_handle_directive (pfile, token->flags & PREV_WHITE)) { read_original_directory (pfile); - return; + return true; } } - /* Backup as if nothing happened. */ - _cpp_backup_tokens (pfile, 1); + return false; } /* For preprocessed files, if the tokens following the first filename line is of the form # "/path/name//", handle the - directive so we know the original current directory. */ + directive so we know the original current directory. + + As with the first line peeking, we can do this without lexing by + being picky. */ static void read_original_directory (cpp_reader *pfile) { - const cpp_token *hash, *token; - - /* Lex ahead; if the first tokens are of the form # NUM, then - process the directive, otherwise back up. */ - hash = _cpp_lex_direct (pfile); - if (hash->type != CPP_HASH) + auto *buf = pfile->buffer->next_line; + + if (pfile->buffer->rlimit - buf > 4 + && buf[0] == '#' + && buf[1] == ' ' + // Also permit '1', as that's what used to be here + && (buf[2] == '0' || buf[2] == '1') + && buf[3] == ' ') { - _cpp_backup_tokens (pfile, 1); - return; - } - - token = _cpp_lex_direct (pfile); + const cpp_token *hash = _cpp_lex_direct (pfile); + gcc_checking_assert (hash->type == CPP_HASH); + pfile->state.in_directive = 1; + const cpp_token *number = _cpp_lex_direct (pfile); + gcc_checking_assert (number->type == CPP_NUMBER); + const cpp_token *string = _cpp_lex_direct (pfile); + pfile->state.in_directive = 0; - if (token->type != CPP_NUMBER) - { - _cpp_backup_tokens (pfile, 2); - return; - } + const unsigned char *text = nullptr; + size_t len = 0; + if (string->type == CPP_STRING) + { + /* The string value includes the quotes. */ + text = string->val.str.text; + len = string->val.str.len; + } + if (len < 5 + || !IS_DIR_SEPARATOR (text[len - 2]) + || !IS_DIR_SEPARATOR (text[len - 3])) + { + /* That didn't work out, back out. */ + _cpp_backup_tokens (pfile, 3); + return; + } - token = _cpp_lex_direct (pfile); + if (pfile->cb.dir_change) + { + /* Smash the string directly, it's dead at this point */ + char *smashy = (char *)text; + smashy[len - 3] = 0; + + pfile->cb.dir_change (pfile, smashy + 1); + } - if (token->type != CPP_STRING - || ! (token->val.str.len >= 5 - && IS_DIR_SEPARATOR (token->val.str.text[token->val.str.len-2]) - && IS_DIR_SEPARATOR (token->val.str.text[token->val.str.len-3]))) - { - _cpp_backup_tokens (pfile, 3); - return; + /* We should be at EOL. */ } - - if (pfile->cb.dir_change) - { - char *debugdir = (char *) alloca (token->val.str.len - 3); - - memcpy (debugdir, (const char *) token->val.str.text + 1, - token->val.str.len - 4); - debugdir[token->val.str.len - 4] = '\0'; - - pfile->cb.dir_change (pfile, debugdir); - } } /* This is called at the end of preprocessing. It pops the last diff --git a/libcpp/internal.h b/libcpp/internal.h index 4bafe1c..b728df7 100644 --- a/libcpp/internal.h +++ b/libcpp/internal.h @@ -124,8 +124,8 @@ enum include_type IT_CMDLINE, /* -include */ IT_DEFAULT, /* forced header */ IT_MAIN, /* main, start on line 1 */ - IT_MAIN_INJECT, /* main, but there will be an injected preamble - before line 1 */ + IT_PRE_MAIN, /* main, but there will be a preamble before line + 1 */ IT_DIRECTIVE_HWM = IT_IMPORT + 1, /* Directives below this. */ IT_HEADER_HWM = IT_DEFAULT + 1 /* Header files below this. */ -- cgit v1.1 From da9df699753d126e64d72c7ac0d0c0a552417b22 Mon Sep 17 00:00:00 2001 From: GCC Administrator Date: Fri, 9 Oct 2020 00:16:27 +0000 Subject: Daily bump. --- libcpp/ChangeLog | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'libcpp') diff --git a/libcpp/ChangeLog b/libcpp/ChangeLog index b6b6b18..1aa2764 100644 --- a/libcpp/ChangeLog +++ b/libcpp/ChangeLog @@ -1,3 +1,15 @@ +2020-10-08 Nathan Sidwell + + * internal.h (enum include_type): Rename IT_MAIN_INJECT to + IT_PRE_MAIN. + * init.c (cpp_read_main_file): If there is no line marker, adjust + the initial line marker. + (read_original_filename): Return bool, peek the buffer directly + before trying to tokenize. + (read_original_directory): Likewise. Directly prod the string + literal. + * files.c (_cpp_stack_file): Adjust for IT_PRE_MAIN change. + 2020-09-26 Jakub Jelinek PR bootstrap/97163 -- cgit v1.1 From 5abe05b4331250b6a7798ce87c0a82adc2bd70f3 Mon Sep 17 00:00:00 2001 From: Nathan Sidwell Date: Mon, 19 Oct 2020 07:57:50 -0700 Subject: preprocessor: Fix non-fn fn-like macro at EOF [PR97471] We inject EOF tokens between macro argument lists, but had confused/stale logic in the non-fn invocation. Renamed the magic 'eof' token, as it's now only used for macro argument termination. Always rewind the non-OPEN_PAREN token. libcpp/ * internal.h (struct cpp_reader): Rename 'eof' field to 'endarg'. * init.c (cpp_create_reader): Adjust. * macro.c (collect_args): Use endarg for separator. Always rewind in the not-fn case. gcc/testsuite/ * c-c++-common/cpp/pr97471.c: New. --- libcpp/init.c | 6 ++++-- libcpp/internal.h | 4 ++-- libcpp/macro.c | 20 ++++++++------------ 3 files changed, 14 insertions(+), 16 deletions(-) (limited to 'libcpp') diff --git a/libcpp/init.c b/libcpp/init.c index 84c0a9e..454a183 100644 --- a/libcpp/init.c +++ b/libcpp/init.c @@ -248,8 +248,10 @@ cpp_create_reader (enum c_lang lang, cpp_hash_table *table, /* Set up static tokens. */ pfile->avoid_paste.type = CPP_PADDING; pfile->avoid_paste.val.source = NULL; - pfile->eof.type = CPP_EOF; - pfile->eof.flags = 0; + pfile->avoid_paste.src_loc = 0; + pfile->endarg.type = CPP_EOF; + pfile->endarg.flags = 0; + pfile->endarg.src_loc = 0; /* Create a token buffer for the lexer. */ _cpp_init_tokenrun (&pfile->base_run, 250); diff --git a/libcpp/internal.h b/libcpp/internal.h index b728df7..b1a2a99 100644 --- a/libcpp/internal.h +++ b/libcpp/internal.h @@ -517,9 +517,9 @@ struct cpp_reader set to -1 to disable it or to a non-negative value to enable it. */ time_t source_date_epoch; - /* EOF token, and a token forcing paste avoidance. */ + /* A token forcing paste avoidance, and one demarking macro arguments. */ cpp_token avoid_paste; - cpp_token eof; + cpp_token endarg; /* Opaque handle to the dependencies of mkdeps.c. */ class mkdeps *deps; diff --git a/libcpp/macro.c b/libcpp/macro.c index 2c7d732..9cb3b10 100644 --- a/libcpp/macro.c +++ b/libcpp/macro.c @@ -1241,7 +1241,8 @@ collect_args (cpp_reader *pfile, const cpp_hashnode *node, ntokens--; arg->count = ntokens; - set_arg_token (arg, &pfile->eof, pfile->eof.src_loc, + /* Append an EOF to mark end-of-argument. */ + set_arg_token (arg, &pfile->endarg, token->src_loc, ntokens, MACRO_ARG_TOKEN_NORMAL, CPP_OPTION (pfile, track_macro_expansion)); @@ -1328,17 +1329,12 @@ funlike_invocation_p (cpp_reader *pfile, cpp_hashnode *node, return collect_args (pfile, node, pragma_buff, num_args); } - /* CPP_EOF can be the end of macro arguments, or the end of the - file. We mustn't back up over the latter. Ugh. */ - if (token->type != CPP_EOF || token == &pfile->eof) - { - /* Back up. We may have skipped padding, in which case backing - up more than one token when expanding macros is in general - too difficult. We re-insert it in its own context. */ - _cpp_backup_tokens (pfile, 1); - if (padding) - _cpp_push_token_context (pfile, NULL, padding, 1); - } + /* Back up. We may have skipped padding, in which case backing + up more than one token when expanding macros is in general + too difficult. We re-insert it in its own context. */ + _cpp_backup_tokens (pfile, 1); + if (padding) + _cpp_push_token_context (pfile, NULL, padding, 1); return NULL; } -- cgit v1.1 From 970d683f67777319990b30302a21a860990e2ec8 Mon Sep 17 00:00:00 2001 From: GCC Administrator Date: Tue, 20 Oct 2020 00:16:29 +0000 Subject: Daily bump. --- libcpp/ChangeLog | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'libcpp') diff --git a/libcpp/ChangeLog b/libcpp/ChangeLog index 1aa2764..411b2be 100644 --- a/libcpp/ChangeLog +++ b/libcpp/ChangeLog @@ -1,3 +1,10 @@ +2020-10-19 Nathan Sidwell + + * internal.h (struct cpp_reader): Rename 'eof' field to 'endarg'. + * init.c (cpp_create_reader): Adjust. + * macro.c (collect_args): Use endarg for separator. Always rewind + in the not-fn case. + 2020-10-08 Nathan Sidwell * internal.h (enum include_type): Rename IT_MAIN_INJECT to -- cgit v1.1 From dbcc6b1577bedd2bf5879393c862b6c461787503 Mon Sep 17 00:00:00 2001 From: Nathan Sidwell Date: Tue, 20 Oct 2020 07:51:40 -0700 Subject: preprocessor: Further fix for EOF in macro args [PR97471] My previous attempt at fixing this was incorrect. The problem occurs earlier in that _cpp_lex_direct processes the unwinding EOF needs in collect_args mode. This patch changes it not to do that, in the same way as directive parsing works. Also collect_args shouldn't push_back such fake EOFs, and neither should funlike_invocation_p. libcpp/ * lex.c (_cpp_lex_direct): Do not complete EOF processing when parsing_args. * macro.c (collect_args): Do not unwind fake EOF. (funlike_invocation_p): Do not unwind fake EOF. (cpp_context): Replace abort with gcc_assert. gcc/testsuite/ * gcc.dg/cpp/endif.c: Move to ... * c-c++-common/cpp/endif.c: ... here. * gcc.dg/cpp/endif.h: Move to ... * c-c++-common/cpp/endif.h: ... here. * c-c++-common/cpp/eof-2.c: Adjust diagnostic. * c-c++-common/cpp/eof-3.c: Adjust diagnostic. --- libcpp/lex.c | 5 ++++- libcpp/macro.c | 34 ++++++++++++++++++---------------- 2 files changed, 22 insertions(+), 17 deletions(-) (limited to 'libcpp') diff --git a/libcpp/lex.c b/libcpp/lex.c index 2fe77d1..fb22292 100644 --- a/libcpp/lex.c +++ b/libcpp/lex.c @@ -2768,7 +2768,10 @@ _cpp_lex_direct (cpp_reader *pfile) if (!_cpp_get_fresh_line (pfile)) { result->type = CPP_EOF; - if (!pfile->state.in_directive) + /* Not a real EOF in a directive or arg parsing -- we refuse + to advance to the next file now, and will once we're out + of those modes. */ + if (!pfile->state.in_directive && !pfile->state.parsing_args) { /* Tell the compiler the line number of the EOF token. */ result->src_loc = pfile->line_table->highest_line; diff --git a/libcpp/macro.c b/libcpp/macro.c index 9cb3b10..0874028 100644 --- a/libcpp/macro.c +++ b/libcpp/macro.c @@ -1259,13 +1259,10 @@ collect_args (cpp_reader *pfile, const cpp_hashnode *node, if (token->type == CPP_EOF) { - /* We still need the CPP_EOF to end directives, to end - pre-expansion of a macro argument, and at the end of the main - file. We do not want it at the end of a -include'd (forced) - header file. */ - if (pfile->state.in_directive - || !pfile->line_table->depth - || pfile->context->prev) + /* Unless the EOF is marking the end of an argument, it's a fake + one from the end of a file that _cpp_clean_line will not have + advanced past. */ + if (token == &pfile->endarg) _cpp_backup_tokens (pfile, 1); cpp_error (pfile, CPP_DL_ERROR, "unterminated argument list invoking macro \"%s\"", @@ -1328,13 +1325,19 @@ funlike_invocation_p (cpp_reader *pfile, cpp_hashnode *node, pfile->state.parsing_args = 2; return collect_args (pfile, node, pragma_buff, num_args); } - - /* Back up. We may have skipped padding, in which case backing - up more than one token when expanding macros is in general - too difficult. We re-insert it in its own context. */ - _cpp_backup_tokens (pfile, 1); - if (padding) - _cpp_push_token_context (pfile, NULL, padding, 1); + + /* Back up. A CPP_EOF is either an EOF from an argument we're + expanding, or a fake one from lex_direct. We want to backup the + former, but not the latter. We may have skipped padding, in + which case backing up more than one token when expanding macros + is in general too difficult. We re-insert it in its own + context. */ + if (token->type != CPP_EOF || token == &pfile->endarg) + { + _cpp_backup_tokens (pfile, 1); + if (padding) + _cpp_push_token_context (pfile, NULL, padding, 1); + } return NULL; } @@ -2638,8 +2641,7 @@ _cpp_pop_context (cpp_reader *pfile) cpp_context *context = pfile->context; /* We should not be popping the base context. */ - if (context == &pfile->base_context) - abort (); + gcc_assert (context != &pfile->base_context); if (context->c.macro) { -- cgit v1.1 From e2e04288542667307df925f7d0a4b0fa2030f741 Mon Sep 17 00:00:00 2001 From: GCC Administrator Date: Wed, 21 Oct 2020 00:16:36 +0000 Subject: Daily bump. --- libcpp/ChangeLog | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'libcpp') diff --git a/libcpp/ChangeLog b/libcpp/ChangeLog index 411b2be..61bfe81 100644 --- a/libcpp/ChangeLog +++ b/libcpp/ChangeLog @@ -1,3 +1,11 @@ +2020-10-20 Nathan Sidwell + + * lex.c (_cpp_lex_direct): Do not complete EOF processing when + parsing_args. + * macro.c (collect_args): Do not unwind fake EOF. + (funlike_invocation_p): Do not unwind fake EOF. + (cpp_context): Replace abort with gcc_assert. + 2020-10-19 Nathan Sidwell * internal.h (struct cpp_reader): Rename 'eof' field to 'endarg'. -- cgit v1.1