aboutsummaryrefslogtreecommitdiff
path: root/libcpp
AgeCommit message (Collapse)AuthorFilesLines
2025-05-23Update ChangeLog and version files for releasereleases/gcc-14.3.0Richard Biener2-0/+8
2025-05-09Daily bump.GCC Administrator1-0/+13
2025-05-08libcpp: Further fixes for incorrect line numbers in large files [PR120061]Jakub Jelinek2-16/+40
The backport of the PR108900 fix to 14 branch broke building chromium because static_assert (__LINE__ == expected_line_number, ""); now triggers as the __LINE__ values are off by one. This isn't the case on the trunk and 15 branch because we've switched to 64-bit location_t and so one actually needs far longer header files to trigger it. https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120061#c11 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120061#c12 contain (large) testcases in patch form which show on the 14 branch that the first one used to fail before the PR108900 backport and now works correctly, while the second one attempts to match the chromium behavior and it used to pass before the PR108900 backport and now it FAILs. The two testcases show rare problematic cases, because do_include_common -> parse_include -> check_eol -> check_eol_1 -> cpp_get_token_1 -> _cpp_lex_token -> _cpp_lex_direct -> linemap_line_start triggers there /* Allocate the new line_map. However, if the current map only has a single line we can sometimes just increase its column_bits instead. */ if (line_delta < 0 || last_line != ORDINARY_MAP_STARTING_LINE_NUMBER (map) || SOURCE_COLUMN (map, highest) >= (1U << (column_bits - range_bits)) || ( /* We can't reuse the map if the line offset is sufficiently large to cause overflow when computing location_t values. */ (to_line - ORDINARY_MAP_STARTING_LINE_NUMBER (map)) >= (((uint64_t) 1) << (CHAR_BIT * sizeof (linenum_type) - column_bits))) || range_bits < map->m_range_bits) map = linemap_check_ordinary (const_cast <line_map *> (linemap_add (set, LC_RENAME, ORDINARY_MAP_IN_SYSTEM_HEADER_P (map), ORDINARY_MAP_FILE_NAME (map), to_line))); and so creates a new ordinary map on the line right after the (problematic) #include line. Now, in the spot that r14-11679-g8a884140c2bcb7 patched, pfile->line_table->highest_location in all 3 tests (also https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120061#c13 ) is before the decrement the start of the line after the #include line and so the decrement is really desirable in that case to put highest_location [jakub@tucnak gcc-15]$ git log -1 --format=%B r15-9638-gbfcb5da69a41f7a5e41faab39b763d9d7c8bd2ea | cat libcpp: Further fixes for incorrect line numbers in large files [PR120061] The backport of the PR108900 fix to 14 branch broke building chromium because static_assert (__LINE__ == expected_line_number, ""); now triggers as the __LINE__ values are off by one. This isn't the case on the trunk and 15 branch because we've switched to 64-bit location_t and so one actually needs far longer header files to trigger it. https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120061#c11 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120061#c12 contain (large) testcases in patch form which show on the 14 branch that the first one used to fail before the PR108900 backport and now works correctly, while the second one attempts to match the chromium behavior and it used to pass before the PR108900 backport and now it FAILs. The two testcases show rare problematic cases, because do_include_common -> parse_include -> check_eol -> check_eol_1 -> cpp_get_token_1 -> _cpp_lex_token -> _cpp_lex_direct -> linemap_line_start triggers there /* Allocate the new line_map. However, if the current map only has a single line we can sometimes just increase its column_bits instead. */ if (line_delta < 0 || last_line != ORDINARY_MAP_STARTING_LINE_NUMBER (map) || SOURCE_COLUMN (map, highest) >= (1U << (column_bits - range_bits)) || ( /* We can't reuse the map if the line offset is sufficiently large to cause overflow when computing location_t values. */ (to_line - ORDINARY_MAP_STARTING_LINE_NUMBER (map)) >= (((uint64_t) 1) << (CHAR_BIT * sizeof (linenum_type) - column_bits))) || range_bits < map->m_range_bits) map = linemap_check_ordinary (const_cast <line_map *> (linemap_add (set, LC_RENAME, ORDINARY_MAP_IN_SYSTEM_HEADER_P (map), ORDINARY_MAP_FILE_NAME (map), to_line))); and so creates a new ordinary map on the line right after the (problematic) #include line. Now, in the spot that r14-11679-g8a884140c2bcb7 patched, pfile->line_table->highest_location in all 3 tests (also https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120061#c13 ) is before the decrement the start of the line after the #include line and so the decrement is really desirable in that case to put highest_location somewhere on the line where the #include actually is. But at the same time it is also undesirable, because if we do decrement it, then linemap_add LC_ENTER called from _cpp_do_file_change will then /* Generate a start_location above the current highest_location. If possible, make the low range bits be zero. */ location_t start_location = set->highest_location + 1; unsigned range_bits = 0; if (start_location < LINE_MAP_MAX_LOCATION_WITH_COLS) range_bits = set->default_range_bits; start_location += (1 << range_bits) - 1; start_location &= ~((1 << range_bits) - 1); linemap_assert (!LINEMAPS_ORDINARY_USED (set) || (start_location >= MAP_START_LOCATION (LINEMAPS_LAST_ORDINARY_MAP (set)))); and we can end up with the new LC_ENTER ordinary map having the same start_location as the preceding LC_RENAME one. Next thing that happens is computation of included_from: if (reason == LC_ENTER) { if (set->depth == 0) map->included_from = 0; else /* The location of the end of the just-closed map. */ map->included_from = (((map[0].start_location - 1 - map[-1].start_location) & ~((1 << map[-1].m_column_and_range_bits) - 1)) + map[-1].start_location); The normal case (e.g. with the testcase included at the start of this comment) is that map[-1] starts somewhere earlier and so map->included_from computation above nicely computes location_t which expands to the start of the #include line. With r14-11679 reverted, for #c11 as well as #c12 map[0].start_location == map[-1].start_location above, and so it is ((location_t) -1 & ~((1 << map[-1].m_column_and_range_bits) - 1))) + map[-1].start_location, which happens to be start of the #include line. For #c11 map[0].start_location is 0x500003a0 and map[-1] has m_column_and_range_bits 7 and map[-2] has m_column_and_range_bits 12 and map[0].included_from is set to 0x50000320. For #c12 map[0].start_location is 0x606c0402 and map[-2].start_location is 0x606c0400 and m_column_and_range_bits is 0 for all 3 maps. map[0].included_from is set to 0x606c0401. The last important part is again in linemap_add when doing LC_LEAVE: /* (MAP - 1) points to the map we are leaving. The map from which (MAP - 1) got included should be the map that comes right before MAP in the same file. */ from = linemap_included_from_linemap (set, map - 1); /* A TO_FILE of NULL is special - we use the natural values. */ if (to_file == NULL) { to_file = ORDINARY_MAP_FILE_NAME (from); to_line = SOURCE_LINE (from, from[1].start_location); sysp = ORDINARY_MAP_IN_SYSTEM_HEADER_P (from); } Here it wants to compute the right to_line which ought to be the line after the #include directive. On the #c11 testcase that doesn't work correctly though, because map[-1].included_from is 0x50000320, from[0] for that is LC_ENTER with start_location 0x4080 and m_column_and_range_bits 12 but note that we've earlier computed map[-1].start_location + (-1 & 0xffffff80) and so only decreased by 7 bits, so to_line is still on the line with #include and not after it. In the #c12 that doesn't happen, all the ordinary maps involved there had 0 m_column_and_range_bits and so this computes correct line. Below is a fix for the trunk including testcases using the location_overflow_plugin hack to simulate the bugs without needing huge files (in the 14 case it is just 330KB and almost 10MB, but in the 15 case it would need to be far bigger). The pre- r15-9018 trunk has FAIL: gcc.dg/plugin/location-overflow-test-pr116047.c -fplugin=./location_overflow_plugin.so scan-file static_assert[^\n\r]*6[^\n\r]*== 6 and current trunk FAIL: gcc.dg/plugin/location-overflow-test-pr116047.c -fplugin=./location_overflow_plugin.so scan-file static_assert[^\n\r]*6[^\n\r]*== 6 FAIL: gcc.dg/plugin/location-overflow-test-pr120061.c -fplugin=./location_overflow_plugin.so scan-file static_assert[^\n\r]*5[^\n\r]*== 5 and with the patch everything PASSes. The patch reverts the r14-11679 change, because it is incorrect, we really need to decrement it even when crossing ordinary map boundaries, so that the location is not on the line after the #include line but somewhere on the #include line. It also patches two spots in linemap_add mentioned above to make sure we get correct locations both in the included_from location_t when doing LC_ENTER (second line-map.cc hunk) and when doing LC_LEAVE to compute the right to_line (first line-map.cc hunk), both in presence of an added LC_RENAME with the same start_location as the following LC_ENTER (i.e. the problematic cases). The LC_ENTER hunk is mostly to ensure included_form location_t is at the start of the #include line (column 0), without it we can decrease include_from not enough and end up at some random column in the middle of the line, because it is masking away map[-1].m_column_and_range_bits bits even when in the end the resulting include_from location_t will be found in map[-2] map with perhaps different m_column_and_range_bits. That alone doesn't fix the bug though. The more important is the LC_LEAVE hunk and the problem there is caused by linemap_line_start not actually doing r = set->highest_line + (line_delta << map->m_column_and_range_bits); when adding a new map (the LC_RENAME one because we need to switch to different number of directly encoded ranges, or columns, etc.). So, in the original PR108900 case that to_line = SOURCE_LINE (from, from[1].start_location); doesn't do the right thing, from there is the last < 0x50000000 map with m_column_and_range_bits 12, from[1] is the first one above it and map[-1].included_from is the correct location of column 0 on the #include line, but as the new LC_RENAME map has been created without actually increasing highest_location to be on the new line (we've just set to_line of the new LC_RENAME map to the correct line), to_line = SOURCE_LINE (from, from[1].start_location); stays on the same source line. I've tried to just replace that with to_line = SOURCE_LINE (from, linemap_included_from (map - 1)) + 1; i.e. just find out the #include line from map[-1].included_from and add 1 to it, unfortunately that breaks the c-c++-common/cpp/line-4.c test where we expect to stay on the same 0 line for LC_LEAVE from <command line> and gcc.dg/cpp/trad/Wunused.c, gcc.dg/cpp/trad/builtins.c and c-c++-common/analyzer/named-constants-via-macros-traditional.c tests all with -traditional-cpp preprocessing where to_line is also off-by-one from the expected one. So, this patch instead conditionalizes it, uses the to_line = SOURCE_LINE (from, linemap_included_from (map - 1)) + 1; way only if from[1] is a LC_RENAME map (rather than the usual LC_ENTER one), that should limit it to the problematic cases of when parse_include peeked after EOL and had to create LC_RENAME map with the same start_location as the LC_ENTER after it. Some further justification for the LC_ENTER hunk, using the https://gcc.gnu.org/pipermail/gcc-patches/2025-May/682774.html testcase (old is 14 before r14-11679, vanilla current 14 and new with the 14 patch) I get $ /usr/src/gcc-14/obj/gcc/cc1.old -quiet -std=c23 pr116047.c -nostdinc In file included from pr116047-1.h:327677:21, from pr116047.c:4: pr116047-2.h:1:1: error: unknown type name ‘a’ 1 | a b c; | ^ pr116047-2.h:1:5: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘c’ 1 | a b c; | ^ pr116047-1.h:327677:1: error: static assertion failed: "" 327677 | #include "pr116047-2.h" | ^~~~~~~~~~~~~ $ /usr/src/gcc-14/obj/gcc/cc1.vanilla -quiet -std=c23 pr116047.c -nostdinc In file included from pr116047-1.h:327678, from pr116047.c:4: pr116047-2.h:1:1: error: unknown type name ‘a’ 1 | a b c; | ^ pr116047-2.h:1:5: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘c’ 1 | a b c; | ^ $ /usr/src/gcc-14/obj/gcc/cc1.new -quiet -std=c23 pr116047.c -nostdinc In file included from pr116047-1.h:327677, from pr116047.c:4: pr116047-2.h:1:1: error: unknown type name ‘a’ 1 | a b c; | ^ pr116047-2.h:1:5: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘c’ 1 | a b c; | ^ pr116047-1.h has on lines 327677+327678: #include "pr116047-2.h" static_assert (__LINE__ == 327678, ""); so the static_assert failure is something that was dealt mainly in the LC_LEAVE hunk and files.cc reversion, but please have a look at the In file included from lines. 14.2 emits correct line (#include "pr116047-2.h" is indeed on line 327677) but some random column in there (which is not normally printed for smaller headers; 21 is the . before extension in the filename). Current trunk emits incorrect line (327678 instead of 327677, clearly it didn't decrement). And the patched compiler emits the right line with no column, as would be printed if I remove e.g. 300000 newlines from the file. 2025-05-08 Jakub Jelinek <jakub@redhat.com> PR preprocessor/108900 PR preprocessor/116047 PR preprocessor/120061 * files.cc (_cpp_stack_file): Revert 2025-03-28 change. * line-map.cc (linemap_add): Use SOURCE_LINE (from, linemap_included_from (map - 1)) + 1; instead of SOURCE_LINE (from, from[1].start_location); to compute to_line for LC_LEAVE if from[1].reason is LC_RENAME. For LC_ENTER included_from computation, look at map[-2] or even lower if map[-1] has the same start_location as map[0]. * gcc.dg/plugin/plugin.exp: Add location-overflow-test-pr116047.c and location-overflow-test-pr120061.c. * gcc.dg/plugin/location_overflow_plugin.c (plugin_init): Don't error on unknown values, instead just break. * gcc.dg/plugin/location-overflow-test-pr116047.c: New test. * gcc.dg/plugin/location-overflow-test-pr116047-1.h: New test. * gcc.dg/plugin/location-overflow-test-pr116047-2.h: New test. * gcc.dg/plugin/location-overflow-test-pr120061.c: New test. * gcc.dg/plugin/location-overflow-test-pr120061-1.h: New test. * gcc.dg/plugin/location-overflow-test-pr120061-2.h: New test.
2025-04-25Daily bump.GCC Administrator1-0/+9
2025-04-23libcpp: Fix incorrect line numbers in large files [PR108900]Jeremy Bettis1-0/+9
This patch addresses an issue in the C preprocessor where incorrect line number information is generated when processing files with a large number of lines. The problem arises from improper handling of location intervals in the line map, particularly when locations exceed LINE_MAP_MAX_LOCATION_WITH_PACKED_RANGES. By ensuring that the highest location is not decremented if it would move to a different ordinary map, this fix resolves the line number discrepancies observed in certain test cases. This change improves the accuracy of line number reporting, benefiting users relying on precise code coverage and debugging information. Tested x86_64-linux. libcpp/ChangeLog: PR preprocessor/108900 * files.cc (_cpp_stack_file): Do not decrement highest_location across distinct maps. Signed-off-by: Jeremy Bettis <jbettis@google.com> Signed-off-by: Yash Shinde <Yash.Shinde@windriver.com> (cherry picked from commit d9b56c65a2697e0d7a6c0f15f1977803dc94579b)
2025-03-28Daily bump.GCC Administrator1-0/+5
2025-03-27libcpp: Add missing configure check for setlocale.Roland McGrath3-3/+6
libcpp/ * configure.ac: Check for setlocale. * configure, config.in: Regenerated.
2024-12-17Daily bump.GCC Administrator1-0/+4
2024-12-16Update cpplib sr.poJoseph Myers1-30/+19
* sr.po: Update.
2024-11-26Daily bump.GCC Administrator1-0/+6
2024-11-25libcpp: Fix ICE lexing invalid raw string in a deferred pragma [PR117118]Lewis Hyatt1-1/+2
The PR shows that we ICE after lexing an invalid unterminated raw string, because lex_raw_string() pops the main buffer unexpectedly. Resolve by handling this case the same way as for other directives. libcpp/ChangeLog: PR preprocessor/117118 * lex.cc (lex_raw_string): Treat an unterminated raw string the same way for a deferred pragma as is done for other directives. gcc/testsuite/ChangeLog: PR preprocessor/117118 * c-c++-common/raw-string-directive-3.c: New test. * c-c++-common/raw-string-directive-4.c: New test.
2024-11-21Daily bump.GCC Administrator1-0/+9
2024-11-20diagnostics: fixes to SARIF output [PR109360]David Malcolm1-0/+2
When adding validation of .sarif files against the schema (PR testsuite/109360) I discovered various issues where we were generating invalid .sarif files. Specifically, in c-c++-common/diagnostic-format-sarif-file-bad-utf8-pr109098-1.c the relatedLocations for the "note" diagnostics were missing column numbers, leading to validation failure due to non-unique elements, such as multiple: "message": {"text": "invalid UTF-8 character <bf>"}}, on line 25 with no column information. Root cause is that for some diagnostics in libcpp we have a location_t representing the line as a whole, setting a column_override on the rich_location (since the line hasn't been fully read yet). We were handling this column override for plain text output, but not for .sarif output. Similarly, in diagnostic-format-sarif-file-pr111700.c there is a warning emitted on "line 0" of the file, whereas SARIF requires line numbers to be positive. We also use column == 0 internally to mean "the line as a whole", whereas SARIF required column numbers to be positive. This patch fixes these various issues. gcc/ChangeLog: PR testsuite/109360 * diagnostic-format-sarif.cc (sarif_builder::make_location_object): Pass any column override from rich_loc to maybe_make_physical_location_object. (sarif_builder::maybe_make_physical_location_object): Add "column_override" param and pass it to maybe_make_region_object. (sarif_builder::maybe_make_region_object): Add "column_override" param and use it when the location has 0 for a column. Don't add "startLine", "startColumn", "endLine", or "endColumn" if the values aren't positive. (sarif_builder::maybe_make_region_object_for_context): Don't add "startLine" or "endLine" if the values aren't positive. libcpp/ChangeLog: PR testsuite/109360 * include/rich-location.h (rich_location::get_column_override): New accessor. Signed-off-by: David Malcolm <dmalcolm@redhat.com> (cherry picked from commit 9f4fdc3acebcf6b045edea1361570658da4bc0ab)
2024-09-20Daily bump.GCC Administrator1-0/+4
2024-09-19Update cpplib zh_CN.poJoseph Myers1-198/+121
* zh_CN.po: Update.
2024-08-01Update ChangeLog and version files for releasereleases/gcc-14.2.0Jakub Jelinek2-0/+8
2024-05-07Update ChangeLog and version files for releasereleases/gcc-14.1.0Jakub Jelinek2-0/+8
2024-04-18Daily bump.GCC Administrator1-0/+6
2024-04-17libcpp: Regenerate aclocal.m4 and configure [PR 114748]Christophe Lyon2-0/+4
As discussed in the PR, aclocal.m4 and configure were incorrectly regenerated at some point. 2024-04-17 Christophe Lyon <christophe.lyon@linaro.org> PR preprocessor/114748 libcpp/ * aclocal.m4: Regenerate. * configure: Regenerate.
2024-03-15Daily bump.GCC Administrator1-0/+16
2024-03-14libcpp: Fix macro expansion for argument of __has_include [PR110558]Lewis Hyatt1-0/+3
When the file name for a #include directive is the result of stringifying a macro argument, libcpp needs to take some care to get the whitespace correct; in particular stringify_arg() needs to see a CPP_PADDING token between macro tokens so that it can figure out when to output space between tokens. The CPP_PADDING tokens are not normally generated when handling a preprocessor directive, but for #include-like directives, libcpp sets the state variable pfile->state.directive_wants_padding to TRUE so that the CPP_PADDING tokens will be output, and then everything works fine for computed includes. As the PR points out, things do not work fine for __has_include. Fix that by setting the state variable the same as is done for #include. libcpp/ChangeLog: PR preprocessor/110558 * macro.cc (builtin_has_include): Set pfile->state.directive_wants_padding prior to lexing the file name, in case it comes from macro expansion. gcc/testsuite/ChangeLog: PR preprocessor/110558 * c-c++-common/cpp/has-include-2.c: New test. * c-c++-common/cpp/has-include-2.h: New test.
2024-03-14libcpp: Fix __has_include_next ICE in the last directory of the path [PR80755]Lewis Hyatt1-4/+8
In libcpp/files.cc, the function _cpp_has_header(), which implements __has_include and __has_include_next, does not check for a NULL return value from search_path_head(), leading to an ICE tripping an assert when _cpp_find_file() tries to use it. Fix it by checking for that case and silently returning false instead. As suggested by the PR author, it is easiest to make a testcase by using the -idirafter option. To enable that, also modify the dg-additional-options testsuite procedure to make the global $srcdir available, since -idirafter requires the full path. libcpp/ChangeLog: PR preprocessor/80755 * files.cc (search_path_head): Add SUPPRESS_DIAGNOSTIC argument defaulting to false. (_cpp_has_header): Silently return false if the search path has been exhausted, rather than issuing a diagnostic and then hitting an assert. gcc/testsuite/ChangeLog: * lib/gcc-defs.exp (dg-additional-options): Make $srcdir usable in a dg-additional-options directive. * c-c++-common/cpp/has-include-next-2-dir/has-include-next-2.h: New test. * c-c++-common/cpp/has-include-next-2.c: New test.
2024-02-23Daily bump.GCC Administrator1-0/+8
2024-02-22c: Handle scoped attributes in __has*attribute and scoped attribute parsing ↵Jakub Jelinek2-2/+8
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. That leads to a question if we should return 1 or 0 from __has_attribute (gnu::unused) or not, because while [[gnu::unused]] is parsed fine in -std=gnu*/-std=c23 modes (sure, with pedwarn for < C23), we do not parse it at all in -std=c* (except for -std=c23), we only parse [[__extension__ gnu::unused]] there. While the __extension__ in there helps to avoid the pedwarn, I think it is better to be consistent between GNU and strict C < C23 modes and parse [[gnu::unused]] too; on the other side, I think parsing [[__extension__ gnu : : unused]] is too weird and undesirable. So, the following patch adds a flag during preprocessing at the point where we normally create CPP_SCOPE tokens out of 2 consecutive colons on the first CPP_COLON to mark the consecutive case (as we are tight on the bits, I've reused the PURE_ZERO flag, which is used just by the C++ FE and only ever set (both C and C++) on CPP_NUMBER tokens, this new flag has the same value and is only ever used on CPP_COLON tokens) and instead of checking loose_scope_p argument (i.e. whether it is [[__extension__ ...]] or not), it just parses CPP_SCOPE or CPP_COLON with CLONE_SCOPE flag followed by another CPP_COLON the same. The latter will never appear in >= C23 or -std=gnu* modes, though guarding its use say with flag_iso && !flag_isoc23 && doesn't really work because the __extension__ case temporarily clears flag_iso flag. This makes the -std=c11 etc. behavior more similar to -std=gnu11 or -std=c23, the only difference I'm aware of are the #define JOIN2(A, B) A##B [[vendor JOIN2(:,:) attr]] [[__extension__ vendor JOIN2(:,:) attr]] cases, which are accepted in the latter modes, but results in error in -std=c11; but the error is during preprocessing that :: doesn't form a valid preprocessing token, which is true, so just don't do that if you try to have __STRICT_ANSI__ && __STDC_VERSION__ <= 201710L compatibility. 2024-02-22 Jakub Jelinek <jakub@redhat.com> PR c/114007 gcc/ * doc/extend.texi: (__extension__): Remove comments about scope tokens vs. two colons. gcc/c-family/ * c-lex.cc (c_common_has_attribute): Parse 2 CPP_COLONs with the first one with COLON_SCOPE flag the same as CPP_SCOPE. gcc/c/ * c-parser.cc (c_parser_std_attribute): Remove loose_scope_p argument. Instead of checking it, parse 2 CPP_COLONs with the first one with COLON_SCOPE flag the same as CPP_SCOPE. (c_parser_std_attribute_list): Remove loose_scope_p argument, don't pass it to c_parser_std_attribute. (c_parser_std_attribute_specifier): Adjust c_parser_std_attribute_list caller. gcc/testsuite/ * gcc.dg/c23-attr-syntax-6.c: Adjust testcase for :: being valid even in -std=c11 even without __extension__ and : : etc. not being valid anymore even with __extension__. * gcc.dg/c23-attr-syntax-7.c: Likewise. * gcc.dg/c23-attr-syntax-8.c: New test. libcpp/ * include/cpplib.h (COLON_SCOPE): Define to PURE_ZERO. * lex.cc (_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.
2024-02-22Daily bump.GCC Administrator1-0/+4
2024-02-21Update cpplib de.poJoseph Myers1-33/+22
* de.po: Update.
2024-02-21Daily bump.GCC Administrator1-0/+4
2024-02-20Update cpplib sv.poJoseph Myers1-38/+19
* sv.po: Update.
2024-02-20Daily bump.GCC Administrator1-0/+10
2024-02-19Update cpplib es.poJoseph Myers1-29/+18
* es.po: Update.
2024-02-19Update .po filesJoseph Myers23-5579/+6721
gcc/po/ * be.po, da.po, de.po, el.po, es.po, fi.po, fr.po, hr.po, id.po, ja.po, nl.po, ru.po, sr.po, sv.po, tr.po, uk.po, vi.po, zh_CN.po, zh_TW.po: Update. libcpp/po/ * be.po, ca.po, da.po, de.po, el.po, eo.po, es.po, fi.po, fr.po, id.po, ja.po, ka.po, nl.po, pt_BR.po, ro.po, ru.po, sr.po, sv.po, tr.po, uk.po, vi.po, zh_CN.po, zh_TW.po: Update.
2024-02-17Daily bump.GCC Administrator1-0/+4
2024-02-16Regenerate .pot filesJoseph Myers1-256/+287
gcc/po/ * gcc.pot: Regenerate. libcpp/po/ * cpplib.pot: Regenerate.
2024-02-02Daily bump.GCC Administrator1-0/+6
2024-02-01libcpp: Stabilize the location for macros restored after PCH load [PR105608]Lewis Hyatt1-1/+8
libcpp currently lacks the infrastructure to assign correct locations to macros that were defined prior to loading a PCH and then restored afterwards. While I plan to address that fully for GCC 15, this patch improves things by using at least a valid location, even if it's not the best one. Without this change, libcpp uses pfile->directive_line as the location for the restored macros, but this location_t applies to the old line map, not the one that was just restored from the PCH, so the resulting location is unpredictable and depends on what was stored in the line maps before. With this change, all restored macros get assigned locations at the line of the #include that triggered the PCH restore. A future patch will store the actual file name and line number of each definition and then synthesize locations in the new line map pointing to the right place. gcc/c-family/ChangeLog: PR preprocessor/105608 * c-pch.cc (c_common_read_pch): Adjust line map so that libcpp assigns a location to restored macros which is the same location that triggered the PCH include. libcpp/ChangeLog: PR preprocessor/105608 * pch.cc (cpp_read_state): Set a valid location for restored macros.
2024-01-05Daily bump.GCC Administrator1-0/+7
2024-01-04libcpp: add function to check XID propertiesRaiki Tamura2-0/+43
This commit adds a new function intended for checking the XID properties of a possibly unicode character, as well as the accompanying enum describing the possible properties. libcpp/ChangeLog: * charset.cc (cpp_check_xid_property): New. * include/cpplib.h (cpp_check_xid_property): New. (enum cpp_xid_property): New. Signed-off-by: Raiki Tamura <tamaron1203@gmail.com>
2024-01-03Update copyright years.Jakub Jelinek27-29/+29
2024-01-03Update Copyright year in ChangeLog filesJakub Jelinek1-1/+1
2023 -> 2024
2023-12-14Daily bump.GCC Administrator1-0/+7
2023-12-13libcpp: Fix valgrind errors on pr88974.c [PR112956]Jakub Jelinek1-1/+4
On the c-c++-common/cpp/pr88974.c testcase I'm seeing ==600549== Conditional jump or move depends on uninitialised value(s) ==600549== at 0x1DD3A05: cpp_get_token_1(cpp_reader*, unsigned int*) (macro.cc:3050) ==600549== by 0x1DBFC7F: _cpp_parse_expr (expr.cc:1392) ==600549== by 0x1DB9471: do_if(cpp_reader*) (directives.cc:2087) ==600549== by 0x1DBB4D8: _cpp_handle_directive (directives.cc:572) ==600549== by 0x1DCD488: _cpp_lex_token (lex.cc:3682) ==600549== by 0x1DD3A97: cpp_get_token_1(cpp_reader*, unsigned int*) (macro.cc:2936) ==600549== by 0x7F7EE4: scan_translation_unit (c-ppoutput.cc:350) ==600549== by 0x7F7EE4: preprocess_file(cpp_reader*) (c-ppoutput.cc:106) ==600549== by 0x7F6235: c_common_init() (c-opts.cc:1280) ==600549== by 0x704C8B: lang_dependent_init (toplev.cc:1837) ==600549== by 0x704C8B: do_compile (toplev.cc:2135) ==600549== by 0x704C8B: toplev::main(int, char**) (toplev.cc:2306) ==600549== by 0x7064BA: main (main.cc:39) error. The problem is that _cpp_lex_direct can leave result->src_loc uninitialized in some cases and later on we use that location_t. _cpp_lex_direct essentially does: cppchar_t c; ... cpp_token *result = pfile->cur_token++; fresh_line: result->flags = 0; ... if (buffer->need_line) { if (pfile->state.in_deferred_pragma) { result->type = CPP_PRAGMA_EOL; ... // keeps result->src_loc uninitialized; return result; } if (!_cpp_get_fresh_line (pfile)) { result->type = CPP_EOF; if (!pfile->state.in_directive && !pfile->state.parsing_args) { result->src_loc = pfile->line_table->highest_line; ... } ... // otherwise result->src_loc is sometimes uninitialized here return result; } ... } ... result->src_loc = pfile->line_table->highest_line; ... c = *buffer->cur++; switch (c) { ... case '\n': ... buffer->need_line = true; if (pfile->state.in_deferred_pragma) { result->type = CPP_PRAGMA_EOL; ... return result; } goto fresh_line; ... } ... So, if _cpp_lex_direct is called without buffer->need_line initially set, result->src_loc is always initialized (and actually hundreds of tests rely on that exact value it has), even when c == '\n' and we set that flag later on and goto fresh_line. For CPP_PRAGMA_EOL case we have in that case separate handling and don't goto. But if _cpp_lex_direct is called with buffer->need_line initially set and either decide to return a CPP_PRAGMA_EOL token or if getting a new line fails for some reason and we return an CPP_ERROR token and we are in directive or parsing args state, it is kept uninitialized and can be whatever the allocation left it there as. The following patch attempts to keep the status quo, use value that was returned previously if it was initialized (i.e. we went through the goto fresh_line; statement in c == '\n' handling) and only initialize result->src_loc if it was uninitialized before. 2023-12-13 Jakub Jelinek <jakub@redhat.com> PR preprocessor/112956 * lex.cc (_cpp_lex_direct): Initialize c to 0. For CPP_PRAGMA_EOL tokens and if c == 0 also for CPP_EOF set result->src_loc to highest locus.
2023-11-29Daily bump.GCC Administrator1-0/+6
2023-11-27libcpp: Fix unsigned promotion for unevaluated divide by zero [PR112701]Lewis Hyatt1-0/+1
When libcpp encounters a divide by zero while processing a constant expression "x/y", it returns "x" as a fallback. The value of the fallback is not normally important, since an error will be generated anyway, but if the expression appears in an unevaluated context, such as "0 ? 0/0u : -1", then there will be no error, and the fallback value will be meaningful to the extent that it may cause promotion from signed to unsigned of an operand encountered later. As the PR notes, libcpp does not do the unsigned promotion correctly in this case; fix it by making the fallback return value unsigned as necessary. libcpp/ChangeLog: PR preprocessor/112701 * expr.cc (num_div_op): Set unsignedp appropriately when returning a stub value for divide by 0. gcc/testsuite/ChangeLog: PR preprocessor/112701 * gcc.dg/cpp/expr.c: Add additional tests to cover divide by 0 in an unevaluated context, where the unsignedness still matters.
2023-11-28Daily bump.GCC Administrator1-0/+10
2023-11-27c-family: Implement __has_feature and __has_extension [PR60512]Alex Coplan3-1/+14
This patch implements clang's __has_feature and __has_extension in GCC. Currently the patch aims to implement all documented features (and some undocumented ones) following the documentation at https://clang.llvm.org/docs/LanguageExtensions.html with the exception of the legacy features for C++ type traits. These are omitted, since as the clang documentation notes, __has_builtin is the correct "modern" way to query for these (which GCC already implements). gcc/c-family/ChangeLog: PR c++/60512 * c-common.cc (struct hf_feature_info): New. (c_common_register_feature): New. (init_has_feature): New. (has_feature_p): New. * c-common.h (c_common_has_feature): New. (c_family_register_lang_features): New. (c_common_register_feature): New. (has_feature_p): New. * c-lex.cc (init_c_lex): Plumb through has_feature callback. (c_common_has_builtin): Generalize and move common part ... (c_common_lex_availability_macro): ... here. (c_common_has_feature): New. * c-ppoutput.cc (init_pp_output): Plumb through has_feature. gcc/c/ChangeLog: PR c++/60512 * c-lang.cc (c_family_register_lang_features): New. * c-objc-common.cc (struct c_feature_info): New. (c_register_features): New. * c-objc-common.h (c_register_features): New. gcc/cp/ChangeLog: PR c++/60512 * cp-lang.cc (c_family_register_lang_features): New. * cp-objcp-common.cc (struct cp_feature_selector): New. (cp_feature_selector::has_feature): New. (struct cp_feature_info): New. (cp_register_features): New. * cp-objcp-common.h (cp_register_features): New. gcc/ChangeLog: PR c++/60512 * doc/cpp.texi: Document __has_{feature,extension}. gcc/objc/ChangeLog: PR c++/60512 * objc-act.cc (struct objc_feature_info): New. (objc_nonfragile_abi_p): New. (objc_common_register_features): New. * objc-act.h (objc_common_register_features): New. * objc-lang.cc (c_family_register_lang_features): New. gcc/objcp/ChangeLog: PR c++/60512 * objcp-lang.cc (c_family_register_lang_features): New. libcpp/ChangeLog: PR c++/60512 * include/cpplib.h (struct cpp_callbacks): Add has_feature. (enum cpp_builtin_type): Add BT_HAS_{FEATURE,EXTENSION}. * init.cc: Add __has_{feature,extension}. * macro.cc (_cpp_builtin_macro_text): Handle BT_HAS_{FEATURE,EXTENSION}. gcc/testsuite/ChangeLog: PR c++/60512 * c-c++-common/has-feature-common.c: New test. * c-c++-common/has-feature-pedantic.c: New test. * g++.dg/ext/has-feature.C: New test. * gcc.dg/asan/has-feature-asan.c: New test. * gcc.dg/has-feature.c: New test. * gcc.dg/ubsan/has-feature-ubsan.c: New test. * obj-c++.dg/has-feature.mm: New test. * objc.dg/has-feature.m: New test. Co-Authored-By: Iain Sandoe <iain@sandoe.co.uk>
2023-11-25Daily bump.GCC Administrator1-0/+10
2023-11-24libcpp: configure: drop unused Valgrind detectionAlexander Monakov4-131/+9
When top-level configure has either --enable-checking=valgrind or --enable-valgrind-annotations, we want to activate a couple of workarounds in libcpp. They do not use anything from the Valgrind API, so just delete all detection. libcpp/ChangeLog: * config.in: Regenerate. * configure: Regenerate. * configure.ac (ENABLE_VALGRIND_CHECKING): Delete. (ENABLE_VALGRIND_ANNOTATIONS): Rename to ENABLE_VALGRIND_WORKAROUNDS. Delete Valgrind header checks. * lex.cc (new_buff): Adjust for renaming. (_cpp_free_buff): Ditto.
2023-11-21Daily bump.GCC Administrator1-0/+5
2023-11-20Trivial typo fix in variadicMarc Poulhiès1-10/+10
Fix all occurences of varadic, except for Rust (will be part of another change). gcc/ChangeLog: * config/nvptx/nvptx.h (struct machine_function): Fix typo in variadic. * config/nvptx/nvptx.cc (nvptx_function_arg_advance): Adjust to use fixed name. (nvptx_declare_function_name): Likewise. (nvptx_call_args): Likewise. (nvptx_expand_call): Likewise. gcc/cp/ChangeLog: * lambda.cc (compare_lambda_sig): Fix typo in variadic. libcpp/ChangeLog: * macro.cc (parse_params): Fix typo in variadic. (create_iso_definition): Likewise. Signed-off-by: Marc Poulhiès <dkm@kataplop.net>
2023-11-20Daily bump.GCC Administrator1-0/+11