aboutsummaryrefslogtreecommitdiff
path: root/libcpp/lex.c
AgeCommit message (Collapse)AuthorFilesLines
2024-06-20c: Handle scoped attributes in __has*attribute and scoped attribute parsing ↵Jakub Jelinek1-2/+7
changes in -std=c11 etc. modes [PR114007] We aren't able to parse __has_attribute (vendor::attr) (and __has_c_attribute and __has_cpp_attribute) in strict C < C23 modes. While in -std=gnu* modes or in -std=c23 there is CPP_SCOPE token, in -std=c* (except for -std=c23) there are is just a pair of CPP_COLON tokens. The c-lex.cc hunk adds support for that, but always returns 0 in that case unlike the GCC 14+ version. 2024-02-22 Jakub Jelinek <jakub@redhat.com> PR c/114007 gcc/c-family/ * c-lex.c (c_common_has_attribute): Parse 2 CPP_COLONs with the first one with COLON_SCOPE flag the same as CPP_SCOPE but ensure 0 is returned then. gcc/testsuite/ * gcc.dg/c23-attr-syntax-8.c: New test. libcpp/ * include/cpplib.h (COLON_SCOPE): Define to PURE_ZERO. * lex.c (_cpp_lex_direct): When lexing CPP_COLON with another colon after it, if !CPP_OPTION (pfile, scope) set COLON_SCOPE flag on the first CPP_COLON token. (cherry picked from commit 37127ed975e09813eaa2d1cf1062055fce45dd16)
2021-12-04libcpp: Fix up handling of deferred pragmas [PR102432]Jakub Jelinek1-1/+15
The https://gcc.gnu.org/pipermail/gcc-patches/2020-November/557903.html change broke the following testcases. The problem is when a pragma namespace allows expansion (i.e. p->is_nspace && p->allow_expansion), e.g. the omp or acc namespaces do, then when parsing the second pragma token we do it with pfile->state.in_directive set, pfile->state.prevent_expansion clear and pfile->state.in_deferred_pragma clear (the last one because we don't know yet if it will be a deferred pragma or not). If the pragma line only contains a single name and newline after it, and there exists a function-like macro with the same name, the preprocessor needs to peek in funlike_invocation_p the next token whether it isn't ( but in this case it will see a newline. As pfile->state.in_directive is set, we don't read anything after the newline, pfile->buffer->need_line is set and CPP_EOF is lexed, which funlike_invocation_p doesn't push back. Because name is a function-like macro and on the pragma line there is no ( after the name, it isn't expanded, and control flow returns to do_pragma. If name is valid deferred pragma, we set pfile->state.in_deferred_pragma (and really need it set so that e.g. end_directive later on doesn't eat all the tokens from the pragma line). Before Nathan's change (which unfortunately didn't contain rationale on why it is better to do it like that), this wasn't a problem, next _cpp_lex_direct called when we want next token would return CPP_PRAGMA_EOF when it saw buffer->need_line, which would turn off pfile->state.in_deferred_pragma and following get token would already read the next line. But Nathan's patch replaced it with an assertion failure that now triggers and CPP_PRAGMA_EOL is done only when lexing the '\n'. Except for this special case that works fine, but in this case it doesn't because when peeking the token we still didn't know that it will be a deferred pragma. I've tried to fix that up in do_pragma by detecting this and pushing CPP_PRAGMA_EOL as lookahead, but that doesn't work because end_directive still needs to see pfile->state.in_deferred_pragma set. So, this patch affectively reverts part of Nathan's change, CPP_PRAGMA_EOL addition isn't done only when parsing the '\n', but is now done in both places, in the first one instead of the assertion failure. 2021-12-04 Jakub Jelinek <jakub@redhat.com> PR preprocessor/102432 * lex.c (_cpp_lex_direct): If buffer->need_line while pfile->state.in_deferred_pragma, return CPP_PRAGMA_EOL token instead of assertion failure. * c-c++-common/gomp/pr102432.c: New test. * c-c++-common/goacc/pr102432.c: New test. (cherry picked from commit 55dfce4d5cb4a366ced7e1194a1c7f04389e3087)
2021-11-29libcpp: Fix up handling of block comments in -fdirectives-only mode [PR103130]Jakub Jelinek1-1/+1
Normal preprocessing, -fdirectives-only preprocessing before the Nathan's rewrite, and all other compilers I've tried on godbolt treat even \*/ as end of a block comment, but the new -fdirectives-only handling doesn't. 2021-11-17 Jakub Jelinek <jakub@redhat.com> PR preprocessor/103130 * lex.c (cpp_directive_only_process): Treat even \*/ as end of block comment. * c-c++-common/cpp/dir-only-9.c: New test. (cherry picked from commit 049f0efeaa77b43a508172161ca040feb6bb5622)
2021-05-31libcpp: Fix up -fdirectives-only handling of // comments on last line not ↵Jakub Jelinek1-2/+3
terminated with newline [PR100646] As can be seen on the testcases, before the -fdirectives-only preprocessing rewrite the preprocessor would assume // comments are terminated by the end of file even when newline wasn't there, but now we error out. The following patch restores the previous behavior. 2021-05-20 Jakub Jelinek <jakub@redhat.com> PR preprocessor/100646 * lex.c (cpp_directive_only_process): Treat end of file as termination for !is_block comments. * gcc.dg/cpp/pr100646-1.c: New test. * gcc.dg/cpp/pr100646-2.c: New test. (cherry picked from commit d15a2d261b24adcbfe5e663b15dde3df5d2b3486)
2021-05-12libcpp: Fix up -fdirectives-only preprocessing of includes not ending with ↵Jakub Jelinek1-1/+12
newline [PR100392] If a header doesn't end with a new-line, with -fdirectives-only we right now preprocess it as int i = 1;# 2 "pr100392.c" 2 i.e. the line directive isn't on the next line, which means we fail to parse it when compiling. GCC 10 and earlier libcpp/directives-only.c had for this: if (!pfile->state.skipping && cur != base) { /* If the file was not newline terminated, add rlimit, which is guaranteed to point to a newline, to the end of our range. */ if (cur[-1] != '\n') { cur++; CPP_INCREMENT_LINE (pfile, 0); lines++; } cb->print_lines (lines, base, cur - base); } and we have the assertion /* Files always end in a newline or carriage return. We rely on this for character peeking safety. */ gcc_assert (buffer->rlimit[0] == '\n' || buffer->rlimit[0] == '\r'); So, this patch just does readd the more less same thing, so that we emit a newline after the inline even when it wasn't there before. 2021-05-12 Jakub Jelinek <jakub@redhat.com> PR preprocessor/100392 * lex.c (cpp_directive_only_process): If buffer doesn't end with '\n', add buffer->rlimit[0] character to the printed range and CPP_INCREMENT_LINE and increment line_count. * gcc.dg/cpp/pr100392.c: New test. * gcc.dg/cpp/pr100392.h: New file. (cherry picked from commit c6b664e2c4c127025e076d8b584abe0976694629)
2021-05-07libcpp: Fix up pragma preprocessing [PR100450]Jakub Jelinek1-0/+1
Since the r0-85991-ga25a8f3be322fe0f838947b679f73d6efc2a412c https://gcc.gnu.org/legacy-ml/gcc-patches/2008-02/msg01329.html changes, so that we handle macros inside of pragmas that should expand macros, during preprocessing we print those pragmas token by token, with CPP_PRAGMA printed as fputs ("#pragma ", print.outf); if (space) fprintf (print.outf, "%s %s", space, name); else fprintf (print.outf, "%s", name); where name is some identifier (so e.g. print #pragma omp parallel or #pragma omp for etc.). Because it ends in an identifier, we need to handle it like an identifier (i.e. CPP_NAME) for the decision whether a space needs to be emitted in between that #pragma whatever or #pragma whatever whatever and following token, otherwise the attached testcase is preprocessed as #pragma omp forreduction(+:red) rather than #pragma omp for reduction(+:red) The cpp_avoid_paste function is only called for this purpose. 2021-05-07 Jakub Jelinek <jakub@redhat.com> PR c/100450 * lex.c (cpp_avoid_paste): Handle token1 CPP_PRAGMA like CPP_NAME. * c-c++-common/gomp/pr100450.c: New test. (cherry picked from commit 170c850e4bd46745e2a5130b5eb09f9fceb98416)
2021-02-03libcpp: Fix up -fdirectives-only preprocessing [PR98882]Jakub Jelinek1-2/+2
GCC 11 ICEs on all -fdirectives-only preprocessing when the files don't end with a newline. The problem is in the assertion, for empty TUs buffer->cur == buffer->rlimit and so buffer->rlimit[-1] access triggers UB in the preprocessor, for non-empty TUs it refers to the last character in the file, which can be anything. The preprocessor adds a '\n' character (or '\r', in particular if the user file ends with '\r' then it adds another '\r' rather than '\n'), but that is added after the limit, i.e. at buffer->rlimit[0]. Now, if the routine handles occassional bumping of pos to buffer->rlimit + 1, I think it is just the assert that needs changing, usually we read from *pos if pos < limit and then e.g. if it is '\r', look at the following character (which could be one of those '\n' or '\r' at buffer->rlimit[0]). There is also the case where for '\\' before the limit we read following character and if it is '\n', do one thing, if it is '\r' read another character. But in that case if '\\' was the last char in the TU, the limit char will be '\n', so we are ok. 2021-02-03 Jakub Jelinek <jakub@redhat.com> PR preprocessor/98882 * lex.c (cpp_directive_only_process): Don't assert that rlimit[-1] is a newline, instead assert that rlimit[0] is either newline or carriage return. When seeing '\\' followed by '\r', check limit before accessing pos[1]. * gcc.dg/cpp/pr98882.c: New test.
2021-01-27Fix ICE for [PR target/98833].liuhongt1-4/+4
And replace __builtin_ia32_pcmpeqb128 with operator == in libcpp. gcc/ChangeLog: PR target/98833 * config/i386/sse.md (sse2_gt<mode>3): Drop !TARGET_XOP in condition. (*sse2_eq<mode>3): Ditto. gcc/testsuite/ChangeLog: PR target/98833 * gcc.target/i386/pr98833.c: New test. libcpp/ PR target/98833 * lex.c (search_line_sse2): Replace builtins with == operator.
2021-01-04Update copyright years.Jakub Jelinek1-1/+1
2020-11-24preprocessor: Add deferred macrosNathan Sidwell1-5/+13
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.
2020-11-19preprocessor: main-file cleanupNathan Sidwell1-2/+2
In preparing module patch 7 I realized there was a cleanup I could make to simplify it. This is that cleanup. Also, when doing the cleanup I noticed some macros had been turned into inline functions, but not renamed to the preprocessors internal namespace (_cpp_$INTERNAL rather than cpp_$USER). Thus, this renames those functions, deletes an internal field of the file structure, and determines whether we're in the main file by comparing to pfile->main_file, the _cpp_file of the main file. libcpp/ * internal.h (cpp_in_system_header): Rename to ... (_cpp_in_system_header): ... here. (cpp_in_primary_file): Rename to ... (_cpp_in_main_source_file): ... here. Compare main_file equality and check main_search value. * lex.c (maybe_va_opt_error, _cpp_lex_direct): Adjust for rename. * macro.c (_cpp_builtin_macro_text): Likewise. (replace_args): Likewise. * directives.c (do_include_next): Likewise. (do_pragma_once, do_pragma_system_header): Likewise. * files.c (struct _cpp_file): Delete main_file field. (pch_open): Check pfile->main_file equality. (make_cpp_file): Drop cpp_reader parm, don't set main_file. (_cpp_find_file): Adjust. (_cpp_stack_file): Check pfile->main_file equality. (struct report_missing_guard_data): Add cpp_reader field. (report_missing_guard): Check pfile->main_file equality. (_cpp_report_missing_guards): Adjust.
2020-11-18preprocessor: C++ module-directivesNathan Sidwell1-0/+392
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.
2020-11-03cpplib: EOF in pragmasNathan Sidwell1-8/+23
This patch moves the generation of PRAGMA_EOF earlier, to when we set need_line, rather than when we try and get the next line. It also prevents peeking past a PRAGMA token. libcpp/ * lex.c (cpp_peek_token): Do not peek past CPP_PRAGMA. (_cpp_lex_direct): Handle EOF in pragma when setting need_line, not when needing a line.
2020-11-03cpplib: Fix off-by-one errorNathan Sidwell1-1/+1
I noticed a fencepost error in the preprocessor. We should be checking if the next char is at the limit, not the current char (which can't be, because we're looking at it). libcpp/ * lex.c (_cpp_clean_line): Fix DOS off-by-one error.
2020-10-20preprocessor: Further fix for EOF in macro args [PR97471]Nathan Sidwell1-1/+4
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.
2020-09-26powerpc, libcpp: Fix gcc build with clang on power8 [PR97163]Jakub Jelinek1-2/+2
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 <jakub@redhat.com> PR bootstrap/97163 * lex.c (search_line_fast): Only use _ARCH_PWR8 Altivec version for GCC >= 4.5.
2020-07-28libcpp: Fix up raw string literal parsing error-recovery [PR96323]Jakub Jelinek1-1/+2
For (invalid) newline inside of the raw string literal delimiter, doing continue means we skip the needed processing of newlines. Instead of duplicating that, this patch just doesn't continue for those. 2020-07-28 Jakub Jelinek <jakub@redhat.com> PR preprocessor/96323 * lex.c (lex_raw_string): For c == '\n' don't continue after reporting an prefix delimiter error. * c-c++-common/cpp/pr96323.c: New test.
2020-05-19preprocessor: Reimplement raw string lexing [pr95149]Nathan Sidwell1-249/+273
pr95149 is a false positive static analysis checker. But it encouranged me to fix raw string lexing, which does contain a complicated macro and pointers to local variables. The reimplementation does away with that macro. Part of the complication is we need to undo some of the fresh line processing -- trigraph notes and escaped line continuations. But the undone characters need to go through the raw string processing, as they can legitimately be part of the prefix marker. however, in this reformulation we only process one line marker at a time[*], so there's a limited number of undone characters. We can arrange the buffering to make sure we don't split such an append sequence, and then simply take the characters from the append buffer. The prefix scanner had a switch statement, which I discovered was not optimized as well as an if of a bunch of explicit comparisons (pr 95208 filed). Finally I adjusted the failure mode. When we get a bad prefix, we lex up until the next '"', thus often swallowing the whole raw string. Previously we'd bail and then the lexer would usually generate stupid tokens, particularly when meeting the ending '"'. libcpp/ * lex.c (struct lit_accum): New. (bufring_append): Replace by lit_accum::append. (lex_raw_string): Reimplement, using fragments of the old version. (lex_string): Adjust lex_raw_string call. gcc/testsuite/ * c-c++-common/raw-string-14.c: Adjust errors. * c-c++-common/raw-string-16.c: Likewise. * c-c++-common/raw-string-5.c: Likewise.
2020-05-13c++: Replace "C++2a" with "C++20".Jason Merrill1-3/+3
C++20 isn't final quite yet, but all that remains is formalities, so let's go ahead and change all the references. I think for the next C++ standard we can just call it C++23 rather than C++2b, since the committee has been consistent about time-based releases rather than feature-based. gcc/c-family/ChangeLog 2020-05-13 Jason Merrill <jason@redhat.com> * c.opt (std=c++20): Make c++2a the alias. (std=gnu++20): Likewise. * c-common.h (cxx_dialect): Change cxx2a to cxx20. * c-opts.c: Adjust. * c-cppbuiltin.c: Adjust. * c-ubsan.c: Adjust. * c-warn.c: Adjust. gcc/cp/ChangeLog 2020-05-13 Jason Merrill <jason@redhat.com> * call.c, class.c, constexpr.c, constraint.cc, decl.c, init.c, lambda.c, lex.c, method.c, name-lookup.c, parser.c, pt.c, tree.c, typeck2.c: Change cxx2a to cxx20. libcpp/ChangeLog 2020-05-13 Jason Merrill <jason@redhat.com> * include/cpplib.h (enum c_lang): Change CXX2A to CXX20. * init.c, lex.c: Adjust.
2020-05-12preprocessor: EOF location is at end of file [PR95013]Nathan Sidwell1-10/+21
My recent C++ parser change to pay attention to EOF location uncovered a separate bug. The preprocesor's EOF logic would set the EOF location to be the beginning of the last line of text in the file -- not the 'line' after that, which contains no characters. Mostly. This fixes things so that when we attempt to read the last line of the main file, we don't pop the buffer until the tokenizer has a chance to create an EOF token with the correct location information. It is then responsible for popping the buffer. As it happens, raw string literal tokenizing contained a bug -- it would increment the line number prematurely, because it cached buffer->cur in a local variable, but checked buffer->cur before updating it to figure out if it was at end of file. We fix up that too. The EOF token intentionally doesn't have a column number -- it's not a position on a line, it's a non-existant line. The testsuite churn is just correcting the EOF location diagnostics. libcpp/ PR preprocessor/95013 * lex.c (lex_raw_string): Process line notes before incrementing. Correct incrementing condition. Adjust for new _cpp_get_fresh_line EOF behaviour. (_cpp_get_fresh_line): Do not pop buffer at EOF, increment line instead. (_cpp_lex_direct): Adjust for new _cpp_get_fresh_line behaviour. (cpp_directive_only_process): Assert we got a fresh line. * traditional.c (_cpp_read_logical_line_trad): Adjust for new _cpp_get_fresh_line behaviour. gcc/testsuite/ * c-c++-common/goacc/pr79428-1.c: Adjust EOF diagnostic location. * c-c++-common/gomp/pr79428-2.c: Likewise. * g++.dg/cpp0x/decltype63.C: Likewise. * g++.dg/cpp0x/gen-attrs-64.C: Likewise. * g++.dg/cpp0x/pr68726.C: Likewise. * g++.dg/cpp0x/pr78341.C: Likewise. * g++.dg/cpp1y/pr65202.C: Likewise. * g++.dg/cpp1y/pr65340.C: Likewise. * g++.dg/cpp1y/pr68578.C: Likewise. * g++.dg/cpp1z/class-deduction44.C: Likewise. * g++.dg/diagnostic/unclosed-extern-c.C: Likewise. * g++.dg/diagnostic/unclosed-function.C: Likewise. * g++.dg/diagnostic/unclosed-namespace.C: Likewise. * g++.dg/diagnostic/unclosed-struct.C: Likewise. * g++.dg/ext/pr84598.C: Likewise. * g++.dg/other/switch4.C: Likewise. * g++.dg/parse/attr4.C: Likewise. * g++.dg/parse/cond4.C: Likewise. * g++.dg/parse/crash10.C: Likewise. * g++.dg/parse/crash18.C: Likewise. * g++.dg/parse/crash27.C: Likewise. * g++.dg/parse/crash34.C: Likewise. * g++.dg/parse/crash35.C: Likewise. * g++.dg/parse/crash52.C: Likewise. * g++.dg/parse/crash59.C: Likewise. * g++.dg/parse/crash61.C: Likewise. * g++.dg/parse/crash67.C: Likewise. * g++.dg/parse/error14.C: Likewise. * g++.dg/parse/error56.C: Likewise. * g++.dg/parse/invalid1.C: Likewise. * g++.dg/parse/parameter-declaration-1.C: Likewise. * g++.dg/parse/parser-pr28152-2.C: Likewise. * g++.dg/parse/parser-pr28152.C: Likewise. * g++.dg/parse/pr68722.C: Likewise. * g++.dg/pr46852.C: Likewise. * g++.dg/pr46868.C: Likewise. * g++.dg/template/crash115.C: Likewise. * g++.dg/template/crash43.C: Likewise. * g++.dg/template/crash90.C: Likewise. * g++.dg/template/error-recovery1.C: Likewise. * g++.dg/template/error57.C: Likewise. * g++.old-deja/g++.other/crash31.C: Likewise. * gcc.dg/empty-source-2.c: Likewise. * gcc.dg/empty-source-3.c: Likewise. * gcc.dg/noncompile/pr30552-3.c: Likewise. * gcc.dg/noncompile/pr35447-1.c: Likewise. * gcc.dg/pr20245-1.c: Likewise. * gcc.dg/pr28419.c: Likewise. * gcc.dg/rtl/truncated-rtl-file.c: Likewise. * gcc.dg/unclosed-init.c: Likewise. * obj-c++.dg/property/property-neg-6.mm: Likewise. * obj-c++.dg/syntax-error-10.mm: Likewise. * obj-c++.dg/syntax-error-8.mm: Likewise. * obj-c++.dg/syntax-error-9.mm: Likewise.
2020-05-08preprocessor: Reimplement directives only processing, support raw literals.Nathan Sidwell1-0/+482
The existing directives-only code (a) punched a hole through the libcpp interface and (b) didn't support raw string literals. This reimplements this preprocessing mode. I added a proper callback interface, and adjusted c-ppoutput to use it. Sadly I cannot get rid of the libcpp/internal.h include for unrelated reasons. The new scanner is in lex.x, and works doing some backwards scanning when it finds a charater of interest. This reduces the number of cases one has to deal with in forward scanning. It may have different failure mode than forward scanning on bad tokenization. Finally, Moved some cpp tests from the c-specific dg.gcc/cpp directory to the c-c++-common/cpp shared directory, libcpp/ * directives-only.c: Delete. * Makefile.in (libcpp_a_OBJS, libcpp_a_SOURCES): Remove it. * include/cpplib.h (enum CPP_DO_task): New enum. (cpp_directive_only_preprocess): Declare. * internal.h (_cpp_dir_only_callbacks): Delete. (_cpp_preprocess_dir_only): Delete. * lex.c (do_peek_backslask, do_peek_next, do_peek_prev): New. (cpp_directives_only_process): New implementation. gcc/c-family/ Reimplement directives only processing. * c-ppoutput.c (token_streamer): Ne. (directives_only_cb): New. Swallow ... (print_lines_directives_only): ... this. (scan_translation_unit_directives_only): Reimplment using the published interface. gcc/testsuite/ * gcc.dg/cpp/counter-[23].c: Move to c-c+_-common/cpp. * gcc.dg/cpp/dir-only-*: Likewise. * c-c++-common/cpp/dir-only-[78].c: New.
2020-01-01Update copyright years.Jakub Jelinek1-1/+1
From-SVN: r279813
2019-11-05Implement C++20 operator<=>.Jason Merrill1-1/+8
There are three major pieces to this support: scalar operator<=>, synthesis of comparison operators, and rewritten/reversed overload resolution (e.g. a < b becomes 0 > b <=> a). Unlike other defaulted functions, where we use synthesized_method_walk to semi-simulate what the definition of the function will be like, this patch determines the characteristics of a comparison operator by trying to define it. My handling of non-dependent rewritten operators in templates can still use some work: build_min_non_dep_op_overload can't understand the rewrites and crashes, so I'm avoiding it for now by clearing *overload. This means we'll do name lookup again at instantiation time, which can incorrectly mean a different result. I'll poke at this more in stage 3. I'm leaving out a fourth section ("strong structural equality") even though I've implemented it, because it seems likely to change radically tomorrow. Thanks to Tim van Deurzen and Jakub for implementing lexing of the <=> operator, and Jonathan for the initial <compare> header. gcc/cp/ * cp-tree.h (struct lang_decl_fn): Add maybe_deleted bitfield. (DECL_MAYBE_DELETED): New. (enum special_function_kind): Add sfk_comparison. (LOOKUP_REWRITTEN, LOOKUP_REVERSED): New. * call.c (struct z_candidate): Add rewritten and reversed methods. (add_builtin_candidate): Handle SPACESHIP_EXPR. (add_builtin_candidates): Likewise. (add_candidates): Don't add a reversed candidate if the parms are the same. (add_operator_candidates): Split out from build_new_op_1. Handle rewritten and reversed candidates. (add_candidate): Swap conversions of reversed candidate. (build_new_op_1): Swap them back. Build a second operation for rewritten candidates. (extract_call_expr): Handle rewritten calls. (same_fn_or_template): New. (joust): Handle rewritten and reversed candidates. * class.c (add_implicitly_declared_members): Add implicit op==. (classtype_has_op, classtype_has_defaulted_op): New. * constexpr.c (cxx_eval_binary_expression): Handle SPACESHIP_EXPR. (cxx_eval_constant_expression, potential_constant_expression_1): Likewise. * cp-gimplify.c (genericize_spaceship): New. (cp_genericize_r): Use it. * cp-objcp-common.c (cp_common_init_ts): Handle SPACESHIP_EXPR. * decl.c (finish_function): Handle deleted function. * decl2.c (grokfield): SET_DECL_FRIEND_CONTEXT on defaulted friend. (mark_used): Check DECL_MAYBE_DELETED. Remove assumption that defaulted functions are non-static members. * error.c (dump_expr): Handle SPACESHIP_EXPR. * method.c (type_has_trivial_fn): False for sfk_comparison. (enum comp_cat_tag, struct comp_cat_info_t): New types. (comp_cat_cache): New array variable. (lookup_comparison_result, lookup_comparison_category) (is_cat, cat_tag_for, spaceship_comp_cat) (spaceship_type, genericize_spaceship) (common_comparison_type, early_check_defaulted_comparison) (comp_info, build_comparison_op): New. (synthesize_method): Handle sfk_comparison. Handle deleted. (get_defaulted_eh_spec, maybe_explain_implicit_delete) (explain_implicit_non_constexpr, implicitly_declare_fn) (defaulted_late_check, defaultable_fn_check): Handle sfk_comparison. * name-lookup.c (get_std_name_hint): Add comparison categories. * tree.c (special_function_p): Add sfk_comparison. * typeck.c (cp_build_binary_op): Handle SPACESHIP_EXPR. 2019-11-05 Tim van Deurzen <tim@kompiler.org> Add new tree code for the spaceship operator. gcc/cp/ * cp-tree.def: Add new tree code. * operators.def: New binary operator. * parser.c: Add new token and tree code. libcpp/ * cpplib.h: Add spaceship operator for C++. * lex.c: Implement conditional lexing of spaceship operator for C++20. 2019-11-05 Jonathan Wakely <jwakely@redhat.com> libstdc++-v3/ * libsupc++/compare: New header. * libsupc++/Makefile.am (std_HEADERS): Add compare. * include/std/version: Define __cpp_lib_three_way_comparison. * include/std/functional: #include <compare>. From-SVN: r277865
2019-10-02Handle :: tokens in C for C2x.Joseph Myers1-1/+1
As part of adding [[]]-style attributes, C2x adds the token :: for use in scoped attribute names. This patch adds corresponding support for that token in C to GCC. The token is supported both for C2x and for older gnu* standards (on the basis that extensions are normally supported in older gnu* versions; people will expect to be able to use [[]] attributes, before C2x is the default, without needing to use -std=gnu2x). There are no cases in older C standards where the token : can be followed by a token starting with : in syntactically valid sources; the only cases the :: token could break in older standard C thus are ones involving concatenation of pp-tokens where the result does not end up as tokens (e.g., gets stringized). In GNU C extensions, the main case where :: might appear in existing sources is in asm statements, and the C parser is thus made to handle it like two consecutive : tokens, which the C++ parser already does. A limited test of various positionings of :: in asm statements is added to the testsuite (in particular, to cover the syntax error when :: means too many colons but a single : would be OK), but existing tests cover a variety of styles there anyway. Technically there are cases in Objective-C and OpenMP for which this also changes how previously valid code is lexed: the objc-selector-arg syntax allows multiple consecutive : tokens (although I don't think they are particularly useful there), while OpenMP syntax includes array section syntax such as [:] which, before :: was a token, could also be written as [::> (there might be other OpenMP cases potentially affected, I didn't check all the OpenMP syntax in detail). I don't think either of those cases affects the basis for supporting the :: token in all -std=gnu* modes, or that there is any obvious need to special-case handling of CPP_SCOPE tokens for those constructs the way there is for asm statements. cpp_avoid_paste, which determines when spaces need adding between tokens in preprocessed output where there wouldn't otherwise be whitespace between them (e.g. if stringized), already inserts space between : and : unconditionally, rather than only for C++, so no change is needed there (but a C2x test is added that such space is indeed inserted). Bootstrapped with no regressions on x86-64-pc-linux-gnu. gcc/c: * c-parser.c (c_parser_asm_statement): Handle CPP_SCOPE like two CPP_COLON tokens. gcc/testsuite: * gcc.dg/asm-scope-1.c, gcc.dg/cpp/c11-scope-1.c, gcc.dg/cpp/c17-scope-1.c, gcc.dg/cpp/c2x-scope-1.c, gcc.dg/cpp/c2x-scope-2.c, gcc.dg/cpp/c90-scope-1.c, gcc.dg/cpp/c94-scope-1.c, gcc.dg/cpp/c99-scope-1.c, gcc.dg/cpp/gnu11-scope-1.c, gcc.dg/cpp/gnu17-scope-1.c, gcc.dg/cpp/gnu89-scope-1.c, gcc.dg/cpp/gnu99-scope-1.c: New tests. libcpp: * include/cpplib.h (struct cpp_options): Add member scope. * init.c (struct lang_flags, lang_defaults): Likewise. (cpp_set_lang): Set scope member of pfile. * lex.c (_cpp_lex_direct): Test CPP_OPTION (pfile, scope) not CPP_OPTION (pfile, cplusplus) for creating CPP_SCOPE tokens. From-SVN: r276434
2019-09-19Support extended characters in C/C++ identifiers (PR c/67224)Lewis Hyatt1-18/+37
libcpp/ChangeLog 2019-09-19 Lewis Hyatt <lhyatt@gmail.com> PR c/67224 * charset.c (_cpp_valid_utf8): New function to help lex UTF-8 tokens. * internal.h (_cpp_valid_utf8): Declare. * lex.c (forms_identifier_p): Use it to recognize UTF-8 identifiers. (_cpp_lex_direct): Handle UTF-8 in identifiers and CPP_OTHER tokens. Do all work in "default" case to avoid slowing down typical code paths. Also handle $ and UCN in the default case for consistency. gcc/Changelog 2019-09-19 Lewis Hyatt <lhyatt@gmail.com> PR c/67224 * doc/cpp.texi: Document support for extended characters in identifiers. * doc/cppopts.texi: Likewise. gcc/testsuite/ChangeLog 2019-09-19 Lewis Hyatt <lhyatt@gmail.com> PR c/67224 * c-c++-common/cpp/ucnid-2011-1-utf8.c: New test. * g++.dg/cpp/ucnid-1-utf8.C: New test. * g++.dg/cpp/ucnid-2-utf8.C: New test. * g++.dg/cpp/ucnid-3-utf8.C: New test. * g++.dg/cpp/ucnid-4-utf8.C: New test. * g++.dg/other/ucnid-1-utf8.C: New test. * gcc.dg/cpp/ucnid-1-utf8.c: New test. * gcc.dg/cpp/ucnid-10-utf8.c: New test. * gcc.dg/cpp/ucnid-11-utf8.c: New test. * gcc.dg/cpp/ucnid-12-utf8.c: New test. * gcc.dg/cpp/ucnid-13-utf8.c: New test. * gcc.dg/cpp/ucnid-14-utf8.c: New test. * gcc.dg/cpp/ucnid-15-utf8.c: New test. * gcc.dg/cpp/ucnid-2-utf8.c: New test. * gcc.dg/cpp/ucnid-3-utf8.c: New test. * gcc.dg/cpp/ucnid-4-utf8.c: New test. * gcc.dg/cpp/ucnid-6-utf8.c: New test. * gcc.dg/cpp/ucnid-7-utf8.c: New test. * gcc.dg/cpp/ucnid-9-utf8.c: New test. * gcc.dg/ucnid-1-utf8.c: New test. * gcc.dg/ucnid-10-utf8.c: New test. * gcc.dg/ucnid-11-utf8.c: New test. * gcc.dg/ucnid-12-utf8.c: New test. * gcc.dg/ucnid-13-utf8.c: New test. * gcc.dg/ucnid-14-utf8.c: New test. * gcc.dg/ucnid-15-utf8.c: New test. * gcc.dg/ucnid-16-utf8.c: New test. * gcc.dg/ucnid-2-utf8.c: New test. * gcc.dg/ucnid-3-utf8.c: New test. * gcc.dg/ucnid-4-utf8.c: New test. * gcc.dg/ucnid-5-utf8.c: New test. * gcc.dg/ucnid-6-utf8.c: New test. * gcc.dg/ucnid-7-utf8.c: New test. * gcc.dg/ucnid-8-utf8.c: New test. * gcc.dg/ucnid-9-utf8.c: New test. From-SVN: r275979
2019-09-05[preprocessor/91639] #includes at EOFNathan Sidwell1-1/+7
https://gcc.gnu.org/ml/gcc-patches/2019-09/msg00280.html libcpp/ PR preprocessor/91639 * directives.c (do_include_common): Tell lexer we're a #include. * files.c (_cpp_stack_file): Lexer will have always incremented. * internal.h (struct cpp_context): Extend in_directive's semantics. * lex.c (_cpp_lex_direct): Increment line for final \n when lexing for an ISO #include. * line-map.c (linemap_line_start): Remember if we overflowed. gcc/testsuite/ PR preprocessor/91639 * c-c++-common/cpp/pr91639.c: New. * c-c++-common/cpp/pr91639-one.h: New. * c-c++-common/cpp/pr91639-two.h: New. From-SVN: r275402
2019-05-19[PATCH] Fix PR 81721: ICE with PCH and Pragma warning and C++ operatorAndrew Pinski1-1/+5
libcpp/ChangeLog: 2019-05-19 Andrew Pinski <apinski@marvell.com> PR pch/81721 * lex.c (cpp_token_val_index <case SPELL_OPERATOR>): If tok->flags has NAMED_OP set, then return CPP_TOKEN_FLD_NODE. gcc/testsuite/ChangeLog: 2019-05-19 Andrew Pinski <apinski@marvell.com> PR pch/81721 * g++.dg/pch/operator-1.C: New testcase. * g++.dg/pch/operator-1.Hs: New file. From-SVN: r271395
2019-01-01Update copyright years.Jakub Jelinek1-1/+1
From-SVN: r267494
2018-11-13Eliminate source_location in favor of location_tDavid Malcolm1-4/+4
Historically GCC used location_t, while libcpp used source_location. This inconsistency has been annoying me for a while, so this patch removes source_location in favor of location_t throughout (as the latter is shorter). gcc/ChangeLog: * builtins.c: Replace "source_location" with "location_t". * diagnostic-show-locus.c: Likewise. * diagnostic.c: Likewise. * dumpfile.c: Likewise. * gcc-rich-location.h: Likewise. * genmatch.c: Likewise. * gimple.h: Likewise. * gimplify.c: Likewise. * input.c: Likewise. * input.h: Likewise. Eliminate the typedef. * omp-expand.c: Likewise. * selftest.h: Likewise. * substring-locations.h (get_source_location_for_substring): Rename to.. (get_location_within_string): ...this. * tree-cfg.c: Replace "source_location" with "location_t". * tree-cfgcleanup.c: Likewise. * tree-diagnostic.c: Likewise. * tree-into-ssa.c: Likewise. * tree-outof-ssa.c: Likewise. * tree-parloops.c: Likewise. * tree-phinodes.c: Likewise. * tree-phinodes.h: Likewise. * tree-ssa-loop-ivopts.c: Likewise. * tree-ssa-loop-manip.c: Likewise. * tree-ssa-phiopt.c: Likewise. * tree-ssa-phiprop.c: Likewise. * tree-ssa-threadupdate.c: Likewise. * tree-ssa.c: Likewise. * tree-ssa.h: Likewise. * tree-vect-loop-manip.c: Likewise. gcc/c-family/ChangeLog: * c-common.c (c_get_substring_location): Update for renaming of get_source_location_for_substring to get_location_within_string. * c-lex.c: Replace "source_location" with "location_t". * c-opts.c: Likewise. * c-ppoutput.c: Likewise. gcc/c/ChangeLog: * c-decl.c: Replace "source_location" with "location_t". * c-tree.h: Likewise. * c-typeck.c: Likewise. * gimple-parser.c: Likewise. gcc/cp/ChangeLog: * call.c: Replace "source_location" with "location_t". * cp-tree.h: Likewise. * cvt.c: Likewise. * name-lookup.c: Likewise. * parser.c: Likewise. * typeck.c: Likewise. gcc/fortran/ChangeLog: * cpp.c: Replace "source_location" with "location_t". * gfortran.h: Likewise. gcc/go/ChangeLog: * go-gcc-diagnostics.cc: Replace "source_location" with "location_t". * go-gcc.cc: Likewise. * go-linemap.cc: Likewise. * go-location.h: Likewise. * gofrontend/README: Likewise. gcc/jit/ChangeLog: * jit-playback.c: Replace "source_location" with "location_t". gcc/testsuite/ChangeLog: * g++.dg/plugin/comment_plugin.c: Replace "source_location" with "location_t". * gcc.dg/plugin/diagnostic_plugin_test_show_locus.c: Likewise. libcc1/ChangeLog: * libcc1plugin.cc: Replace "source_location" with "location_t". (plugin_context::get_source_location): Rename to... (plugin_context::get_location_t): ...this. * libcp1plugin.cc: Likewise. libcpp/ChangeLog: * charset.c: Replace "source_location" with "location_t". * directives-only.c: Likewise. * directives.c: Likewise. * errors.c: Likewise. * expr.c: Likewise. * files.c: Likewise. * include/cpplib.h: Likewise. Rename MAX_SOURCE_LOCATION to MAX_LOCATION_T. * include/line-map.h: Likewise. * init.c: Likewise. * internal.h: Likewise. * lex.c: Likewise. * line-map.c: Likewise. * location-example.txt: Likewise. * macro.c: Likewise. * pch.c: Likewise. * traditional.c: Likewise. From-SVN: r266085
2018-10-31[6/6] Preprocessor forced macro locationNathan Sidwell1-7/+7
https://gcc.gnu.org/ml/gcc-patches/2018-10/msg02044.html libcpp/ * internal.h (struct cpp_reader): Rename forced_token_location_p to forced_token_location and drop its pointerness. * include/cpplib.h (cpp_force_token_locations): Take location, not pointer to one. * init.c (cpp_create_reader): Adjust. * lex.c (cpp_read_main_file): gcc/c-family/ * c-opts.c (c_finish_options): Adjust cpp_force_token_locations call. gcc/fortran/ * cpp.c (gfc_cpp_init): Adjust cpp_force_token_locations call. From-SVN: r265692
2018-08-17[PATCH] Macro body is trailing arrayNathan Sidwell1-0/+19
https://gcc.gnu.org/ml/gcc-patches/2018-08/msg01037.html * include/cpplib.h (enum cpp_macro_kind): New. (struct cpp_macro): Make body trailing array. Add kind field, delete traditional flag. * internal.h (_cpp_new_macro): Declare. (_cpp_reserve_room): New inline. (_cpp_commit_buf): Declare. (_cpp_create_trad_definition): Return new macro. * lex.c (_cpp_commit_buff): New. * macro.c (macro_real_token_count): Count backwards. (replace_args): Pointer equality not orderedness. (_cpp_save_parameter): Use _cpp_reserve_room. (alloc_expansion_token): Delete. (lex_expansion_token): Return macro pointer. Use _cpp_reserve_room. (create_iso_definition): Allocate macro itself. Adjust for different allocation ordering. (_cpp_new_macro): New. (_cpp_create_definition): Adjust for API changes. * traditional.c (push_replacement_text): Don't set traditional flag. (save_replacement_text): Likewise. (_cpp_create_trad_definition): Allocate macro itself, Adjust for different allocation ordering. From-SVN: r263622
2018-08-16[PATCH] CPP Macro predicatesNathan Sidwell1-1/+1
https://gcc.gnu.org/ml/gcc-patches/2018-08/msg00897.html libcpp/ * include/cpplib.h (cpp_user_macro_p, cpp_builtin_macro_p) (cpp_macro_p): New inlines. * directives.c (do_pragma_poison): Use cpp_macro_p. (do_ifdef, do_ifndef): Likewise. Use _cpp_maybe_notify_macro_use. (cpp_pop_definition): Use cpp_macro_p. Move _cpp_free_definition earlier. Don't zap node directly. * expr.c (parse_defined): Use _cpp_maybe_notify_macro_use & cpp_macro_p. * files.c (should_stack_file): Use cpp_macro_p. * identifiers.c (cpp_defined): Likewise. * internal.h (_cpp_mark_macro): Use cpp_user_macro_p. (_cpp_notify_macro_use): Declare. (_cpp_maybe_notify_macro_use): New inline. * lex.c (is_macro): Use cpp_macro_p. * macro.c (_cpp_warn_if_unused_macro): Use cpp_user_macro_p. (enter_macro_context): Likewise. (_cpp_create_definition): Use cpp_builtin_macro_p, cpp_user_macro_p. Move _cpp_free_definition earlier. (_cpp_notify_macro_use): New, broken out of multiple call sites. * traditional.c (fun_like_macro_p): Use cpp_builtin_macro_p. (maybe_start_funlike, _cpp_scan_out_logical_line) (push_replacement_text): Likewise. gcc/c-family/ * c-ada-spec.c (count_ada_macro): Use cpp_user_macro_p. (store_ada_macro): Likewise. * c-ppoutput.c (cb_used_define, dump_macro): Likewise. * c-spellcheck.cc (should-suggest_as_macro_p): Likewise, gcc/ * config/rs6000/rs6000-c.c (rs6000_macro_to_expend): Use cpp_macro_p. * config/powerpcspc/powerpcspe-c.c (rs6000_macro_to_expend): Likewise. gcc/cp/ * name-lookup.c (lookup_name_fuzzy): Likewise. gcc/fortran/ * cpp.c (dump_macro): Use cpp_user_macro_p. From-SVN: r263587
2018-07-17lex.c (_cpp_lex_direct): Use CPP_DL_NOTE instead of CPP_DL_PEDWARN...Jakub Jelinek1-13/+14
* lex.c (_cpp_lex_direct): Use CPP_DL_NOTE instead of CPP_DL_PEDWARN, CPP_DL_WARNING or CPP_DL_ERROR for note that diagnostics for C++ style comments is reported only once per file and guard those calls on the preceding cpp_error returning true. * gcc.dg/cpp/pr61854-c90.c (foo): Expect a note, rather than error. * gcc.dg/cpp/pr61854-c94.c (foo): Likewise. * gcc.dg/cpp/pr61854-4.c (foo): Likewise. * gcc.dg/cpp/pr61854-8.c: New test. From-SVN: r262832
2018-02-28PR preprocessor/84517 allow double-underscore macros after string literalsJonathan Wakely1-8/+19
gcc/testsuite: PR preprocessor/84517 * g++.dg/cpp0x/udlit-macros.C: Expect a warning for ""__FILE__. libcpp: PR preprocessor/84517 * lex.c (is_macro_not_literal_suffix): New function. (lex_raw_string, lex_string): Use is_macro_not_literal_suffix to decide when to issue -Wliteral-suffix warnings. From-SVN: r258069
2018-01-14rs6000-p8swap.c (rs6000_sum_of_two_registers_p): New function.Kelvin Nilsen1-1/+1
gcc/ChangeLog: 2018-01-10 Kelvin Nilsen <kelvin@gcc.gnu.org> * config/rs6000/rs6000-p8swap.c (rs6000_sum_of_two_registers_p): New function. (rs6000_quadword_masked_address_p): Likewise. (quad_aligned_load_p): Likewise. (quad_aligned_store_p): Likewise. (const_load_sequence_p): Add comment to describe the outer-most loop. (mimic_memory_attributes_and_flags): New function. (rs6000_gen_stvx): Likewise. (replace_swapped_aligned_store): Likewise. (rs6000_gen_lvx): Likewise. (replace_swapped_aligned_load): Likewise. (replace_swapped_load_constant): Capitalize argument name in comment describing this function. (rs6000_analyze_swaps): Add a third pass to search for vector loads and stores that access quad-word aligned addresses and replace with stvx or lvx instructions when appropriate. * config/rs6000/rs6000-protos.h (rs6000_sum_of_two_registers_p): New function prototype. (rs6000_quadword_masked_address_p): Likewise. (rs6000_gen_lvx): Likewise. (rs6000_gen_stvx): Likewise. * config/rs6000/vsx.md (*vsx_le_perm_load_<mode>): For modes VSX_D (V2DF, V2DI), modify this split to select lvx instruction when memory address is aligned. (*vsx_le_perm_load_<mode>): For modes VSX_W (V4SF, V4SI), modify this split to select lvx instruction when memory address is aligned. (*vsx_le_perm_load_v8hi): Modify this split to select lvx instruction when memory address is aligned. (*vsx_le_perm_load_v16qi): Likewise. (four unnamed splitters): Modify to select the stvx instruction when memory is aligned. gcc/testsuite/ChangeLog: 2018-01-10 Kelvin Nilsen <kelvin@gcc.gnu.org> * gcc.target/powerpc/pr48857.c: Modify dejagnu directives to look for lvx and stvx instead of lxvd2x and stxvd2x and require little-endian target. Add comments. * gcc.target/powerpc/swaps-p8-28.c: Add functions for more comprehensive testing. * gcc.target/powerpc/swaps-p8-29.c: Likewise. * gcc.target/powerpc/swaps-p8-30.c: Likewise. * gcc.target/powerpc/swaps-p8-31.c: Likewise. * gcc.target/powerpc/swaps-p8-32.c: Likewise. * gcc.target/powerpc/swaps-p8-33.c: Likewise. * gcc.target/powerpc/swaps-p8-34.c: Likewise. * gcc.target/powerpc/swaps-p8-35.c: Likewise. * gcc.target/powerpc/swaps-p8-36.c: Likewise. * gcc.target/powerpc/swaps-p8-37.c: Likewise. * gcc.target/powerpc/swaps-p8-38.c: Likewise. * gcc.target/powerpc/swaps-p8-39.c: Likewise. * gcc.target/powerpc/swaps-p8-40.c: Likewise. * gcc.target/powerpc/swaps-p8-41.c: Likewise. * gcc.target/powerpc/swaps-p8-42.c: Likewise. * gcc.target/powerpc/swaps-p8-43.c: Likewise. * gcc.target/powerpc/swaps-p8-44.c: Likewise. * gcc.target/powerpc/swaps-p8-45.c: Likewise. * gcc.target/powerpc/vec-extract-2.c: Add comment and remove scan-assembler-not directives that forbid lvx and xxpermdi. * gcc.target/powerpc/vec-extract-3.c: Likewise. * gcc.target/powerpc/vec-extract-5.c: Likewise. * gcc.target/powerpc/vec-extract-6.c: Likewise. * gcc.target/powerpc/vec-extract-7.c: Likewise. * gcc.target/powerpc/vec-extract-8.c: Likewise. * gcc.target/powerpc/vec-extract-9.c: Likewise. * gcc.target/powerpc/vsx-vector-6-le.c: Change scan-assembler-times directives to reflect different numbers of expected xxlnor, xxlor, xvcmpgtdp, and xxland instructions. libcpp/ChangeLog: 2018-01-10 Kelvin Nilsen <kelvin@gcc.gnu.org> * lex.c (search_line_fast): Remove illegal coercion of an unaligned pointer value to vector pointer type and replace with use of __builtin_vec_vsx_ld () built-in function, which operates on unaligned pointer values. From-SVN: r256656
2018-01-03Update copyright years.Jakub Jelinek1-1/+1
From-SVN: r256169
2017-12-20[PATCH, PR83492] Fix selection of aarch64 big-endian shift parameters based ↵Michael Weiser1-1/+1
on __AARCH64EB__ 2017-12-20 Michael Weiser <michael.weiser@gmx.de> PR preprocessor/83492 * lex.c (search_line_fast) [__ARM_NEON && __ARM_64BIT_STATE]: Fix selection of big-endian shift parameters by using __ARM_BIG_ENDIAN. From-SVN: r255896
2017-11-13Implement __VA_OPT__Tom Tromey1-0/+30
This implements __VA_OPT__, a new preprocessor feature added in C++2A. The paper can be found here: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0306r4.html gcc/ChangeLog * doc/cpp.texi (Variadic Macros): Document __VA_OPT__. gcc/testsuite/ChangeLog * c-c++-common/cpp/va-opt-pedantic.c: New file. * c-c++-common/cpp/va-opt.c: New file. * c-c++-common/cpp/va-opt-error.c: New file. libcpp/ChangeLog * pch.c (cpp_read_state): Set n__VA_OPT__. * macro.c (vaopt_state): New class. (_cpp_arguments_ok): Check va_opt flag. (replace_args, create_iso_definition): Use vaopt_state. * lex.c (lex_identifier_intern): Possibly issue errors for __VA_OPT__. (lex_identifier): Likewise. (maybe_va_opt_error): New function. * internal.h (struct lexer_state) <va_args_ok>: Update comment. (struct spec_nodes) <n__VA_OPT__>: New field. * init.c (struct lang_flags) <va_opt>: New field. (lang_defaults): Add entries for C++2A. Update all entries for va_opt. (cpp_set_lang): Initialize va_opt. * include/cpplib.h (struct cpp_options) <va_opt>: New field. * identifiers.c (_cpp_init_hashtable): Initialize n__VA_OPT__. From-SVN: r254707
2017-11-06re PR c++/80955 (Macros expanded in definition of user-defined literals)Mukesh Kapoor1-4/+6
/libcpp 2017-11-06 Mukesh Kapoor <mukesh.kapoor@oracle.com> PR c++/80955 * lex.c (lex_string): When checking for a valid macro for the warning related to -Wliteral-suffix (CPP_W_LITERAL_SUFFIX), check that the macro name does not start with an underscore before calling is_macro(). /gcc/testsuite 2017-11-06 Mukesh Kapoor <mukesh.kapoor@oracle.com> PR c++/80955 * g++.dg/cpp0x/udlit-macros.C: New. From-SVN: r254443
2017-11-05[libcpp] Remove semicolon after do {} while (0) in BUF_APPENDTom de Vries1-1/+1
2017-11-05 Tom de Vries <tom@codesourcery.com> PR other/82784 * lex.c (BUF_APPEND): Remove semicolon after "do {} while (0)". From-SVN: r254424
2017-06-05libcpp: add callback for comment-handlingDavid Malcolm1-0/+7
gcc/testsuite/ChangeLog: * g++.dg/plugin/comment_plugin.c: New test plugin. * g++.dg/plugin/comments-1.C: New test file. * g++.dg/plugin/plugin.exp (plugin_test_list): Add the above. libcpp/ChangeLog: * include/cpplib.h (struct cpp_callbacks): Add "comment" callback. * lex.c (_cpp_lex_direct): Call the comment callback if non-NULL. From-SVN: r248901
2017-04-03Fix numerous typos in commentsJonathan Wakely1-1/+1
gcc: * alias.c (base_alias_check): Fix typo in comment. * cgraph.h (class ipa_polymorphic_call_context): Likewise. * cgraphunit.c (symbol_table::compile): Likewise. * collect2.c (maybe_run_lto_and_relink): Likewise. * config/arm/arm.c (arm_thumb1_mi_thunk): Likewise. * config/avr/avr-arch.h (avr_arch_info_t): Likewise. * config/avr/avr.c (avr_map_op_t): Likewise. * config/cr16/cr16.h (DATA_ALIGNMENT): Likewise. * config/epiphany/epiphany.c (TARGET_ARG_PARTIAL_BYTES): Likewise. * config/epiphany/epiphany.md (movcc): Likewise. * config/i386/i386.c (legitimize_pe_coff_extern_decl): Likewise. * config/m68k/m68k.c (struct _sched_ib, m68k_sched_variable_issue): Likewise. * config/mips/mips.c (mips_save_restore_reg): Likewise. * config/rx/rx.c (rx_is_restricted_memory_address): Likewise. * config/s390/s390.c (Z10_EARLYLOAD_DISTANCE): Likewise. * config/sh/sh.c (sh_rtx_costs): Likewise. * fold-const.c (fold_truth_andor): Likewise. * genautomata.c (collapse_flag): Likewise. * gengtype.h (struct type::u::s): Likewise. * gensupport.c (has_subst_attribute, add_mnemonic_string): Likewise. * input.c (FORMAT_AMOUNT): Likewise. * ipa-cp.c (class ipcp_lattice, agg_replacements_to_vector) (known_aggs_to_agg_replacement_list): Likewise. * ipa-inline-analysis.c: Likewise. * ipa-inline.h (estimate_edge_time, estimate_edge_hints): Likewise. * ipa-polymorphic-call.c (ipa_polymorphic_call_context::restrict_to_inner_class): Likewise. * loop-unroll.c (analyze_insn_to_expand_var): Likewise. * lra.c (lra_optional_reload_pseudos, lra_subreg_reload_pseudos): Likewise. * modulo-sched.c (apply_reg_moves): Likewise. * omp-expand.c (build_omp_regions_1): Likewise. * trans-mem.c (struct tm_wrapper_hasher): Likewise. * tree-ssa-loop-ivopts.c (may_eliminate_iv): Likewise. * tree-ssa-loop-niter.c (maybe_lower_iteration_bound): Likewise. * tree-vect-data-refs.c (vect_enhance_data_refs_alignment): Likewise. * value-prof.c: Likewise. * var-tracking.c (val_reset): Likewise. gcc/ada: * doc/gnat_ugn/gnat_and_program_execution.rst: Fix typo. * g-socket.adb (To_Host_Entry): Fix typo in comment. * gnat_ugn.texi: Fix typo. * raise.c (_gnat_builtin_longjmp): Fix capitalization in comment. * s-stposu.adb (Allocate_Any_Controlled): Fix typo in comment. * sem_ch3.adb (Build_Derived_Record_Type): Likewise. * sem_util.adb (Mark_Coextensions): Likewise. * sem_util.ads (Available_Full_View_Of_Component): Likewise. gcc/c: * c-array-notation.c: Fix typo in comment. gcc/c-family: * c-warn.c (do_warn_double_promotion): Fix typo in comment. gcc/cp: * class.c (update_vtable_entry_for_fn): Fix typo in comment. * decl2.c (one_static_initialization_or_destruction): Likewise. * name-lookup.c (store_bindings): Likewise. * parser.c (make_call_declarator): Likewise. * pt.c (check_explicit_specialization): Likewise. gcc/testsuite: * g++.old-deja/g++.benjamin/scope02.C: Fix typo in comment. * gcc.dg/20031012-1.c: Likewise. * gcc.dg/ipa/ipcp-1.c: Likewise. * gcc.dg/torture/matrix-3.c: Likewise. * gcc.target/powerpc/ppc-spe.c: Likewise. * gcc.target/rx/zero-width-bitfield.c: Likewise. libcpp: * include/line-map.h (LINEMAPS_MACRO_MAPS): Fix typo in comment. * lex.c (search_line_fast): Likewise. * pch.h (cpp_valid_state): Likewise. libdecnumber: * decCommon.c (decFloatFromPackedChecked): Fix typo in comment. * decNumber.c (decNumberPower, decMultiplyOp): Likewise. libgcc: * config/c6x/pr-support.c (__gnu_unwind_execute): Fix typo in comment. libitm: * libitm_i.h (sutrct gtm_thread): Fix typo in comment. From-SVN: r246664
2017-03-21Fix search_line_fast for aarch64/ILP32Andreas Schwab1-1/+1
* lex.c (search_line_fast) [__ARM_NEON && __ARM_64BIT_STATE]: Convert 64-bit value to boolean before passing to __builtin_expect. From-SVN: r246312
2017-01-01Update copyright years.Jakub Jelinek1-1/+1
From-SVN: r243994
2016-12-15Fix use-after-free lexing unterminated raw strings (PR preprocessor/78811)David Malcolm1-19/+21
gcc/ChangeLog: PR preprocessor/78680 PR preprocessor/78811 * input.c (struct selftest::lexer_test): Add field m_implicitly_expect_EOF. (selftest::lexer_error_sink): New class. (selftest::lexer_error_sink::s_singleton): New global. (selftest::lexer_test::lexer_test): Initialize new field "m_implicitly_expect_EOF". (selftest::lexer_test::~lexer_test): Conditionalize the check for the EOF token on the new field. (selftest::test_lexer_string_locations_raw_string_unterminated): New function. (selftest::input_c_tests): Call the new test. libcpp/ChangeLog: PR preprocessor/78680 PR preprocessor/78811 * lex.c (_cpp_lex_direct): Only determine the end-location of the token and build a range for non-reserved start locations. Do not do it for EOF tokens. From-SVN: r243721
2016-12-12re PR preprocessor/78680 (ICE in get_substring_ranges_for_loc, at input.c:1398)David Malcolm1-0/+7
Fix for PR preprocessor/78680 PR preprocessor/78680 identifies a crash when attempting to issue a -Wformat warning, where the format string includes a string token split across multiple physical source lines via backslash-continued lines. The issue is that libcpp is generating bogus range information for such tokens. For example, in: void fn1() { __builtin_printf("\ %ld.\n\ 2\n"); }; the range of the string token is printed as: __builtin_printf("\ ^~ whereas the range ought to be: __builtin_printf("\ ^~ %ld.\n\ ~~~~~~~ 2\n"); }; ~~~~ The root cause is that the line notes expressing the update of the buffer in lex.c aren't yet updated when the end-point of the token is computed 3095 tok_range.m_finish 3096 = linemap_position_for_column (pfile->line_table, 3097 CPP_BUF_COLUMN (buffer, buffer->cur)); so that the physical line is still regarded as that of the start of the token, and, where CPP_BUF_COLUMN uses (BUF)->line_base, line_base is still the location of the first physical line in the and hence the column information is too large (as if it were the offset in the *logical* line). (the printed range is somewhat misleading; the actual buggy range extends beyond the "\ in the line, but within diagnostic-show-locus.c layout::print_annotation_line only prints up to the xbound set by layout::print_source_line and so truncates most of the buggy range). The fix is to ensure that line notes are handled before calculating the end-point of the token range. This leads to the range for the string token being correctly computed, as: __builtin_printf("\ ^~ %ld.\n\ ~~~~~~~ 2\n"); }; ~~~~ and this leads to get_substring_ranges_for_loc failing gracefully, rather than crashing. gcc/testsuite/ChangeLog: PR preprocessor/78680 * gcc.dg/format/pr78680.c: New test case. * gcc.dg/plugin/diagnostic-test-expressions-1.c (test_multiline_token): New function. * gcc.dg/plugin/diagnostic-test-string-literals-1.c (test_backslash_continued_logical_lines): New function. libcpp/ChangeLog: PR preprocessor/78680 * lex.c (_cpp_lex_direct): Ensure line notes are processed before computing the end-point of the token. From-SVN: r243567
2016-11-08[AArch64] Optimized implementation of search_line_fast for the CPP lexerRichard Earnshaw1-0/+95
* lex.c (search_line_fast): New implementation for AArch64. From-SVN: r241964
2016-10-12gcc/Jakub Jelinek1-11/+92
* common.opt (Wimplicit-fallthrough) Turn into alias to -Wimplicit-fallthrough=3. Remove EnabledBy. (Wimplicit-fallthrough=): New option. * gimplify.c (warn_implicit_fallthrough_r): Use OPT_Wimplicit_fallthrough_ instead of OPT_Wimplicit_fallthrough. * doc/invoke.texi (-Wimplicit-fallthrough): Document as alias to -Wimplicit-fallthrough=3. (-Wimplicit-fallthrough=): Document. gcc/c-family/ * c.opt (Wextra): Add as C/C++/ObjC/ObjC++ option. (Wimplicit-fallthrough=): Enable for these languages by -Wextra. * c-opts.c (sanitize_cpp_opts): Initialize cpp_opts->cpp_warn_implicit_fallthrough. gcc/testsuite/ * c-c++-common/Wimplicit-fallthrough-25.c: New test. * c-c++-common/Wimplicit-fallthrough-26.c: New test. * c-c++-common/Wimplicit-fallthrough-27.c: New test. * c-c++-common/Wimplicit-fallthrough-28.c: New test. * c-c++-common/Wimplicit-fallthrough-29.c: New test. * c-c++-common/Wimplicit-fallthrough-30.c: New test. * c-c++-common/Wimplicit-fallthrough-31.c: New test. * c-c++-common/Wimplicit-fallthrough-32.c: New test. * c-c++-common/Wimplicit-fallthrough-33.c: New test. libcpp/ * include/cpplib.h (struct cpp_options): Add cpp_warn_implicit_fallthrough. * init.c (cpp_create_reader): Initialize it to 0. * lex.c (fallthrough_comment_p): Handle different cpp_warn_implicit_fallthrough levels. Whitespace fixes. From-SVN: r241013
2016-10-08invoke.texi: Document accepting Else, fallthrough.Jakub Jelinek1-6/+13
* doc/invoke.texi: Document accepting Else, fallthrough. * lex.c (fallthrough_comment_p): Accept Else, fallthrough. * c-c++-common/Wimplicit-fallthrough-23.c (foo): Add further tests. From-SVN: r240886
2016-10-08invoke.texi (-Wimplicit-fallthrough): Document FALLTHRU comment style changes.Jakub Jelinek1-8/+90
* doc/invoke.texi (-Wimplicit-fallthrough): Document FALLTHRU comment style changes. * lex.c (fallthrough_comment_p): Extend to handle more common FALLTHRU comment styles. * c-c++-common/Wimplicit-fallthrough-23.c (foo): Add further tests. From-SVN: r240885