aboutsummaryrefslogtreecommitdiff
path: root/libcpp
AgeCommit message (Collapse)AuthorFilesLines
2017-07-07libcpp: preserve ranges within macro expansions (PR c++/79300)David Malcolm2-6/+15
gcc/testsuite/ChangeLog: PR c++/79300 * g++.dg/diagnostic/pr79300.C: New test case. libcpp/ChangeLog: PR c++/79300 * line-map.c (linemap_macro_loc_to_def_point): Preserve range information for macro expansions by delaying resolving ad-hoc locations until within the loop. From-SVN: r250058
2017-07-06diagnostics: fix end-points of ranges within macros (PR c++/79300)David Malcolm3-7/+34
gcc/ChangeLog: PR c++/79300 * diagnostic-show-locus.c (layout::layout): Use start and finish spelling location for the start and finish of each range. * genmatch.c (linemap_client_expand_location_to_spelling_point): Add unused aspect param. * input.c (expand_location_1): Add "aspect" param, and use it to access the correct part of the location. (expand_location): Pass LOCATION_ASPECT_CARET to new param of expand_location_1. (expand_location_to_spelling_point): Likewise. (linemap_client_expand_location_to_spelling_point): Add "aspect" param, and pass it to expand_location_1. gcc/testsuite/ChangeLog: PR c++/79300 * c-c++-common/Wmisleading-indentation-3.c (fn_14): Update expected underlining within macro expansion. * c-c++-common/pr70264.c: Likewise. * g++.dg/plugin/diagnostic-test-expressions-1.C (test_within_macro_1): New test. (test_within_macro_2): Likewise. (test_within_macro_3): Likewise. (test_within_macro_4): Likewise. * gcc.dg/format/diagnostic-ranges.c (test_macro_3): Update expected underlining within macro expansion. (test_macro_4): Likewise. * gcc.dg/plugin/diagnostic-test-expressions-1.c (test_within_macro_1): New test. (test_within_macro_2): Likewise. (test_within_macro_3): Likewise. (test_within_macro_4): Likewise. * gcc.dg/spellcheck-fields-2.c (test_macro): Update expected underlining within macro expansion. libcpp/ChangeLog: PR c++/79300 * include/line-map.h (enum location_aspect): New enum. (linemap_client_expand_location_to_spelling_point): Add enum location_aspect param. * line-map.c (rich_location::get_expanded_location): Update for new param of linemap_client_expand_location_to_spelling_point. (rich_location::maybe_add_fixit): Likewise. (fixit_hint::affects_line_p): Likewise. From-SVN: r250022
2017-06-21line-map.c (location_adhoc_data_update): Perform addition in uintptr_t type ↵Jakub Jelinek2-2/+11
rather than char * type. * line-map.c (location_adhoc_data_update): Perform addition in uintptr_t type rather than char * type. Read *data using ptrdiff_t type instead of int64_t. (get_combined_adhoc_loc): Change offset type to ptrdiff_t from int64_t. From-SVN: r249446
2017-06-20Prevent fix-it hints from affecting more than one lineDavid Malcolm3-2/+28
Attempts to apply a removal or replacement fix-it hint to a source range that covers multiple lines currently lead to nonsensical results from the printing code in diagnostic-show-locus.c. We were already filtering them out in edit-context.c (leading to -fdiagnostics-generate-patch not generating any output for the whole TU). Reject attempts to add such fix-it hints within rich_location, fixing the diagnostic-show-locus.c issue. gcc/ChangeLog: * diagnostic-show-locus.c (selftest::test_fixit_deletion_affecting_newline): New function. (selftest::diagnostic_show_locus_c_tests): Call it. libcpp/ChangeLog: * include/line-map.h (class rich_location): Document that attempts to delete or replace a range *affecting* multiple lines will fail. * line-map.c (rich_location::maybe_add_fixit): Implement this restriction. From-SVN: r249403
2017-06-15PR c++/80560 - warn on undefined memory operations involving non-trivial typesMartin Sebor1-2/+3
gcc/c-family/ChangeLog: PR c++/80560 * c.opt (-Wclass-memaccess): New option. gcc/cp/ChangeLog: PR c++/80560 * call.c (first_non_public_field, maybe_warn_class_memaccess): New functions. (has_trivial_copy_assign_p, has_trivial_copy_p): Ditto. (build_cxx_call): Call maybe_warn_class_memaccess. gcc/ChangeLog: PR c++/80560 * dumpfile.c (dump_register): Avoid calling memset to initialize a class with a default ctor. * gcc.c (struct compiler): Remove const qualification. * genattrtab.c (gen_insn_reserv): Replace memset with initialization. * hash-table.h: Ditto. * ipa-cp.c (allocate_and_init_ipcp_value): Replace memset with assignment. * ipa-prop.c (ipa_free_edge_args_substructures): Ditto. * omp-low.c (lower_omp_ordered_clauses): Replace memset with default ctor. * params.h (struct param_info): Make struct members non-const. * tree-switch-conversion.c (emit_case_bit_tests): Replace memset with default initialization. * vec.h (vec_copy_construct, vec_default_construct): New helper functions. (vec<T>::copy, vec<T>::splice, vec<T>::reserve): Replace memcpy with vec_copy_construct. (vect<T>::quick_grow_cleared): Replace memset with default ctor. (vect<T>::vec_safe_grow_cleared, vec_safe_grow_cleared): Same. * doc/invoke.texi (-Wclass-memaccess): Document. libcpp/ChangeLog: PR c++/80560 * line-map.c (line_maps::~line_maps): Avoid calling htab_delete with a null pointer. (linemap_init): Avoid calling memset on an object of a non-trivial type. libitm/ChangeLog: PR c++/80560 * beginend.cc (GTM::gtm_thread::rollback): Avoid calling memset on an object of a non-trivial type. (GTM::gtm_transaction_cp::commit): Use assignment instead of memcpy to copy an object. * method-ml.cc (orec_iterator::reinit): Avoid -Wclass-memaccess. gcc/testsuite/ChangeLog: PR c++/80560 * g++.dg/Wclass-memaccess.C: New test. From-SVN: r249234
2017-06-09Add support for mutually-incompatible fix-it hintsDavid Malcolm3-1/+32
This patch adds a method: rich_location::fixits_cannot_be_auto_applied for ensuring that mutually-incompatible fix-its hints don't lead to insane output from -fdiagnostics-generate-patch. Fix-it hints within such rich_location instances are printed as normal by diagnostic_show_locus, but don't affect the output of -fdiagnostics-generate-patch. gcc/ChangeLog: * diagnostic.c (diagnostic_report_diagnostic): Only add fixits to the edit_context if they can be auto-applied. gcc/testsuite/ChangeLog: * gcc.dg/plugin/diagnostic-test-show-locus-bw.c (test_mutually_exclusive_suggestions): New test function. * gcc.dg/plugin/diagnostic-test-show-locus-generate-patch.c (test_mutually_exclusive_suggestions): New test function. * gcc.dg/plugin/diagnostic-test-show-locus-parseable-fixits.c (test_mutually_exclusive_suggestions): New test function. * gcc.dg/plugin/diagnostic_plugin_test_show_locus.c (test_show_locus): Add special-case for "test_mutually_exclusive_suggestions". libcpp/ChangeLog: * include/line-map.h (rich_location::fixits_cannot_be_auto_applied): New method. (rich_location::fixits_can_be_auto_applied_p): New accessor. (rich_location::m_fixits_cannot_be_auto_applied): New field. * line-map.c (rich_location::rich_location): Initialize new field. From-SVN: r249081
2017-06-05libcpp: add callback for comment-handlingDavid Malcolm3-0/+22
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-05-02Support fix-it hints that add new linesDavid Malcolm3-8/+69
Previously fix-it hints couldn't contain newlines. This is due to the need to print something user-readable for them within diagnostic-show-locus, and for handling them within edit-context for printing diffs and regenerating content. This patch enables limited support for fix-it hints with newlines, for suggesting adding new lines. Such a fix-it hint must have exactly one newline character, at the end of the content. It must be an insertion at the beginning of a line (so that e.g. fix-its that split a pre-existing line are still rejected). They are printed by diagnostic-show-locus with a '+' in the left-hand margin, like this: test.c:42:4: note: suggest adding 'break;' here + break; case 'b': ^~~~~~~~~ and the printer injects "spans" if the insertion location is not near the primary range of the diagnostic e.g.: test.c:4:2: note: unrecognized 'putchar'; suggest including '<stdio.h>' test.c:1:1: +#include <stdio.h> test.c:4:2: putchar (ch); ^~~~~~~ gcc/ChangeLog: * diagnostic-show-locus.c (layout::should_print_annotation_line_p): Make private. (layout::print_annotation_line): Make private. (layout::annotation_line_showed_range_p): Make private. (layout::show_ruler): Make private. (layout::print_source_line): Make private. Pass in line and line_width, rather than calling location_get_source_line. Drop returned value. (layout::print_leading_fixits): New method. (layout::print_any_fixits): Rename to... (layout::print_trailing_fixits): ...this, and make private. Don't print newline fixits. (diagnostic_show_locus): Move logic for printing one row into... (layout::print_line): ...this new function. Move the location_get_source_line call and error-handling from print_source_line to here. Call print_leading_fixits, and rename print_any_fixits to print_trailing_fixits. (selftest::test_fixit_insert_containing_newline): Update now that newlines are partially supported. (selftest::test_fixit_insert_containing_newline_2): New test. (selftest::test_fixit_replace_containing_newline): Update comments. (selftest::diagnostic_show_locus_c_tests): Call the new test. * edit-context.c (class added_line): New class. (class edited_line): Describe newline handling in comment. (edited_line::actually_edited_p): New method. (edited_line::print_content): Delete redundant decl. (edited_line::m_predecessors): New field. (edited_file::print_content): Call edited_line::print_content. (edited_file::print_diff): Update to support newlines. (edited_file::print_diff_hunk): Likewise. (edited_file::print_run_of_changed_lines): New function. (edited_file::print_diff_line): Convert to... (print_diff_line): ...this. (edited_file::get_effective_line_count): New function. (edited_line::edited_line): Initialize new field m_predecessors. (edited_line::~edited_line): Clean up m_predecessors. (edited_line::apply_fixit): Handle newlines. (edited_line::get_effective_line_count): New function. (edited_line::print_content): New function. (edited_line::print_diff_lines): New function. (selftest::test_applying_fixits_insert_containing_newline): New test. (selftest::test_applying_fixits_replace_containing_newline): New test. (selftest::insert_line): New function. (selftest::test_applying_fixits_multiple_lines): Add example of inserting a line. (selftest::edit_context_c_tests): Call the new tests. gcc/testsuite/ChangeLog: * gcc.dg/plugin/diagnostic-test-show-locus-bw.c (test_fixit_insert_newline): New function. * gcc.dg/plugin/diagnostic-test-show-locus-color.c (test_fixit_insert_newline): New function. * gcc.dg/plugin/diagnostic-test-show-locus-generate-patch.c (test_fixit_insert_newline): New function. * gcc.dg/plugin/diagnostic-test-show-locus-parseable-fixits.c (test_fixit_insert_newline): New function. * gcc.dg/plugin/diagnostic_plugin_test_show_locus.c (test_show_locus): Handle test_fixit_insert_newline. libcpp/ChangeLog: * include/line-map.h (class rich_location): Update description of newline handling. (class fixit_hint): Likewise. (fixit_hint::ends_with_newline_p): New decl. * line-map.c (rich_location::maybe_add_fixit): Support newlines in fix-it hints that are insertions of single lines at the start of a line. Don't consolidate into such fix-it hints. (fixit_hint::ends_with_newline_p): New method. From-SVN: r247522
2017-05-01Regenerate .pot files.Joseph Myers2-1/+5
gcc/po: * gcc.pot: Regenerate. libcpp/po: * cpplib.pot: Regenerate. From-SVN: r247447
2017-05-01Eliminate fixit_hint class hierarchyDavid Malcolm3-213/+127
The original implementation of fix-it hints (r230674) had an abstract base class "fixit_hint" and three subclasses, representing each of insertions, replacements, and deletions. Having multiple classes for fix-it hints was a nuisance, as it required per-class logic everywhere that the hints were handled. In r239632 I eliminated the deletion subclass in favor of replacement with the empty string (two subclasses are easier than three). This patch eliminates the class hierarchy altogether by implementing insertion in terms of replacement, by representing replacements via a half-open interval (so that for an insertion, start == next location, and we're effectively replacing an empty range at the insertion point with the new string). This greatly simplifies the code for handling fix-it hints; for example it allows removal of a parallel class hierarchy of line_event within edit-context.c. It also improves consolidation of hints: we can now consolidate insertions at the same location, affecting a couple of tests (selftest::test_one_liner_many_fixits and gcc.dg/Wmissing-braces-fixits.c). gcc/ChangeLog: * diagnostic-show-locus.c (layout::get_expanded_location): Rewrite to use new fixit_hint representation, using the "replace" logic. (get_line_span_for_fixit_hint): Likewise. (layout::print_any_fixits): Likewise. (selftest::test_one_liner_many_fixits): Rename to... (selftest::test_one_liner_many_fixits_1): ...this, and update comment and expected output to reflect that the multiple fix-it hints are now consolidated into one insertion. (selftest::test_one_liner_many_fixits_2): New test. (selftest::test_diagnostic_show_locus_one_liner): Update for above. (selftest::test_fixit_consolidation): Update for fix-it API change. * diagnostic.c (print_parseable_fixits): Likewise. * edit-context.c (edited_line::m_line_events): Convert from auto_vec <line_event *> to auto_vec <line_event>. (class line_event): Convert from abstract base class to a concrete class, taking over the role of replace_event. (class insert_event): Delete. (class replace_event): Rename to class line_event. Convert to half-open range. (edit_context::add_fixits): Reimplement. (edit_context::apply_insert): Delete. (edit_context::apply_replace): Rename to... (edit_context::apply_fixit): ...this. Convert to half-open range. (edited_file::apply_insert): Delete. (edited_file::apply_replace): Rename to... (edited_file::apply_fixit): ...this. (edited_line::~edited_line): Drop deletion of events. (edited_line::apply_insert): Delete. (edited_line::apply_replace): Rename to... (edited_line::apply_fixit): ...this. Convert to half-open range. Update for change to type of m_line_events. * edit-context.h (edit_context::apply_insert): Delete. (edit_context::apply_replace): Rename to... (edit_context::apply_fixit): ...this. gcc/testsuite/ChangeLog: * gcc.dg/Wmissing-braces-fixits.c: Update expected output to reflect insertion fix-it hints at the same location now being consolidated. libcpp/ChangeLog: * include/line-map.h (source_range::intersects_line_p): Delete. (rich_location::add_fixit): Delete. (rich_location::maybe_add_fixit): New method. (class fixit_hint): Reimplement in terms of... (class fixit_replace): ...this. (class fixit_insert): Delete. * line-map.c (linemap_position_for_loc_and_offset): Drop overzealous linemap_assert_fails. (source_range::intersects_line_p): Rename to... (fixit_hint::affects_line_p): New function. (rich_location::add_fixit_insert_before): Reimplement in terms of maybe_add_fixit, moving validation there. (rich_location::add_fixit_insert_after): Likewise. (column_before_p): Delete. (rich_location::add_fixit_replace): Reimplement in terms of maybe_add_fixit, moving validation there. Convert closed input range to half-open range. (rich_location::add_fixit): Delete. (rich_location::maybe_add_fixit): New function. (fixit_insert::fixit_insert): Delete. (fixit_insert::~fixit_insert): Delete. (fixit_insert::affects_line_p): Delete. (fixit_insert::maybe_append_replace): Delete. (fixit_replace::fixit_replace): Rename to... (fixit_hint::fixit_hint): ...this, rewriting as necessary. (fixit_replace::~fixit_replace): Delete. (fixit_replace::affects_line_p): Delete. (fixit_replace::maybe_append_replace): Rename to... (fixit_hint::maybe_append): ...this, rewriting as necessary. From-SVN: r247445
2017-05-01* fr.po: Update.Joseph Myers2-20/+10
From-SVN: r247420
2017-04-24Regenerate .pot files.Joseph Myers2-2/+6
gcc/po: * gcc.pot: Regenerate. libcpp/po: * cpplib.pot: Regenerate. From-SVN: r247113
2017-04-03Fix numerous typos in commentsJonathan Wakely4-3/+9
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 Schwab2-1/+7
* 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-03-16* init.c (cpp_init_builtins): Update __cplusplus for C++17.Jason Merrill2-1/+5
From-SVN: r246211
2017-02-09* Makefile.in (po/$(PACKAGE).pot): Adjust bug reporting URL.Gerald Pfeifer2-1/+5
From-SVN: r245298
2017-01-31* de.po, eo.po: Update.Joseph Myers3-16/+19
From-SVN: r245046
2017-01-27* sr.po: Update.Joseph Myers2-9/+12
From-SVN: r244996
2017-01-23* da.po: Update.Joseph Myers2-2/+6
From-SVN: r244836
2017-01-10Fix issues with unrepresentable column numbers (PR c++/77949)David Malcolm2-1/+28
PR c++/77949 identifies an ICE when the C++ frontend attempts to emit a fix-it hint inserting a missing semicolon at column 4097 of a source file. This column value exceeds LINE_MAP_MAX_COLUMN_NUMBER and hence isn't representable using a location_t. Attempting to do so leads to these problems, which this patch fixes: (a) when encountering a column number > LINE_MAP_MAX_COLUMN_NUMBER we create a new linemap with m_column_and_range_bits == 0, but linemap_position_for_column doesn't check for this, and hence can emit a bogus location_t value that's calculated relative to the previous linemap start, but which will be decoded relative to the new linemap, leading to very large incorrect line values. (b) when encountering a column number that can't be represented, and for which the linemap was pre-existing, the code would hit this assertion: if (linemap_assert_fails (column < (1u << map->m_column_and_range_bits))) around a bail-out condition. The patch replaces this assertion with a simple conditional, to stop the ICE when this occurs, and fixes the bit count (effective column bits, vs column+range bits) (c) the C++ frontend wasn't checking for failure of linemap_position_for_loc_and_offset when considering emitting the fix-it hint. The patch adds a conditional, so that no fix-it hint is emitted if the location is bogus. gcc/cp/ChangeLog: PR c++/77949 * parser.c (cp_parser_class_specifier_1): Only suggest inserting a missing semicolon if we have a valid insertion location for the fix-it hint. gcc/ChangeLog: PR c++/77949 * input.c (selftest::test_accessing_ordinary_linemaps): Verify that we correctly handle column numbers greater than LINE_MAP_MAX_COLUMN_NUMBER. gcc/testsuite/ChangeLog: PR c++/77949 * g++.dg/diagnostic/pr77949.C: New test case. libcpp/ChangeLog: PR c++/77949 * line-map.c (linemap_position_for_column): When calling linemap_start_line, detect if a new linemap was created with 0 column bits, and bail out early if this is the case. (linemap_position_for_loc_and_offset): Replace overzealous linemap_assert_fails with a simple conditional; use correct bit count. From-SVN: r244292
2017-01-10* da.po: Update.Joseph Myers2-8/+11
From-SVN: r244288
2017-01-09* vi.po: Update.Joseph Myers2-10/+13
From-SVN: r244230
2017-01-07Fix linemap corruption after very wide source lines (PR c++/72803)David Malcolm2-1/+9
PR c++/72803 describes an issue where a fix-it hint is to be emitted at column 512 of a 511-column source line, leading to an ICE. The root cause is a bug in linemap_line_start, when transitioning from lines >= 512 in width to narrow lines. The wide line in the reproducer has a line map with: m_column_and_range_bits = 15, m_range_bits = 5 giving 10 effective bits for representing columns, so that columns <= 1023 can be represented. When parsing the following line, linemap_line_start (..., ..., max_column_hint=0); is called. This leads to the "add_map" logic, due to this condition: || (max_column_hint <= 80 && effective_column_bits >= 10) i.e. the new line is sufficiently narrower than the old one to potentially use a new linemap (so as to conserve values within the location_t space). It then attempts to avoid allocating a new line map. Part of the logic to determine if we really need a new line map is this condition: SOURCE_COLUMN (map, highest) >= (1U << column_bits) The above condition is incorrect: we need to determine if the highest column we've handed out will fit within the proposed *effective* column bits, but "column_bits" here is the column plus the range bits, rather than just the column bits. Hence in this case linemap_line_start erroneously decides that we don't need a new line map, and updates the column bits within the existing line map, so any location_t values we've already handed out within it that are offset from the start by >= (1<<new_column_and_range_bits) effectively change meaning, leading to incorrect line&column information when decoding them, and various "interesting" ways for the linemap code to fail. The fix is to use the effective column bits in the above conditional. gcc/ChangeLog: PR c++/72803 * input.c (selftest::test_accessing_ordinary_linemaps): Verify that the transition from a max line width >= 1<<10 to narrower lines works correctly. gcc/testsuite/ChangeLog: PR c++/72803 * g++.dg/diagnostic/pr72803.C: New test case. libcpp/ChangeLog: PR c++/72803 * line-map.c (linemap_line_start): When determining if the highest column given out so far will fit into a proposed change to the current map, use the effective number of column bits, rather than the total number of column + range bits. From-SVN: r244199
2017-01-05* pt_BR.po, ru.po: Update.Joseph Myers3-17/+19
From-SVN: r244080
2017-01-04* fi.po: Update.Joseph Myers2-7/+10
From-SVN: r244042
2017-01-03Update .po files from TP.Joseph Myers22-4719/+4677
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, nl.po, pr_BR.po, ru.po, sr.po, sv.po, tr.po, uk.po, vi.po, zh_CN.po, zh_TW.po: Update. From-SVN: r244032
2017-01-01Update copyright years.Jakub Jelinek27-28/+32
From-SVN: r243994
2017-01-01Regenerate .pot files.Joseph Myers2-75/+79
gcc/po: * gcc.pot: Regenerate. libcpp/po: * cpplib.pot: Regenerate. From-SVN: r243991
2016-12-15Fix use-after-free lexing unterminated raw strings (PR preprocessor/78811)David Malcolm2-19/+29
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 Malcolm2-0/+13
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-23system.h (HAVE_DESIGNATED_INITIALIZERS, [...]): Do not use "defined" in macros.Paolo Bonzini4-6/+27
gcc: 2016-11-23 Paolo Bonzini <bonzini@gnu.org> * system.h (HAVE_DESIGNATED_INITIALIZERS, HAVE_DESIGNATED_UNION_INITIALIZERS): Do not use "defined" in macros. * doc/cpp.texi (Defined): Mention -Wexpansion-to-defined. * doc/cppopts.texi (Invocation): Document -Wexpansion-to-defined. * doc/invoke.texi (Warning Options): Document -Wexpansion-to-defined. gcc/c-family: 2016-11-23 Paolo Bonzini <bonzini@gnu.org> * c.opt (Wexpansion-to-defined): New. gcc/testsuite: 2016-11-23 Paolo Bonzini <bonzini@gnu.org> * gcc.dg/cpp/defined.c: Mark newly introduced warnings and adjust for warning->pedwarn change. * gcc.dg/cpp/defined-syshdr.c, gcc.dg/cpp/defined-Wexpansion-to-defined.c, gcc.dg/cpp/defined-Wextra-Wno-expansion-to-defined.c, gcc.dg/cpp/defined-Wextra.c, gcc.dg/cpp/defined-Wno-expansion-to-defined.c: New testcases. libcpp: 2016-11-23 Paolo Bonzini <bonzini@gnu.org> * include/cpplib.h (struct cpp_options): Add new member warn_expansion_to_defined. (CPP_W_EXPANSION_TO_DEFINED): New enum member. * expr.c (parse_defined): Warn for all uses of "defined" in macros, and tie warning to CPP_W_EXPANSION_TO_DEFINED. Make it a pedwarning instead of a warning. * system.h (HAVE_DESIGNATED_INITIALIZERS): Do not use "defined" in macros. From-SVN: r242743
2016-11-17Fix locations within raw stringsDavid Malcolm2-1/+17
Whilst investigating PR preprocessor/78324 I noticed that the substring location code currently doesn't handle raw strings correctly, by not skipping the 'R', opening quote, delimiter and opening parenthesis. For example, an attempt to underline chars 4-7 with caret at 6 of this raw string yields this erroneous output: __emit_string_literal_range (R"foo(0123456789)foo", ~~^~ With the patch, the correct range/caret is printed: __emit_string_literal_range (R"foo(0123456789)foo", ~~^~ gcc/ChangeLog: * input.c (selftest::test_lexer_string_locations_long_line): New function. (selftest::test_lexer_string_locations_raw_string_multiline): New function. (selftest::input_c_tests): Call the new functions, via for_each_line_table_case. gcc/testsuite/ChangeLog: * gcc.dg/plugin/diagnostic-test-string-literals-1.c (test_raw_string_one_liner): New function. (test_raw_string_multiline): New function. libcpp/ChangeLog: * charset.c (cpp_interpret_string_1): Skip locations from loc_reader when advancing 'p' when handling raw strings. From-SVN: r242552
2016-11-16re PR bootstrap/72823 (r239175 causes build failure)Jakub Jelinek4-4/+30
PR bootstrap/72823 * configure.ac (ENABLE_ASSERT_CHECKING): Define if gcc configure would define that macro. * configure: Regenerated. * config.in: Regenerated. From-SVN: r242510
2016-11-08[AArch64] Optimized implementation of search_line_fast for the CPP lexerRichard Earnshaw2-0/+99
* lex.c (search_line_fast): New implementation for AArch64. From-SVN: r241964
2016-10-29* eo.po: Update.Joseph Myers2-7/+10
From-SVN: r241673
2016-10-25input.c/libcpp: fix lifetimes of path buffersDavid Malcolm2-0/+5
Running "make selftest-valgrind" showed various leaks of the form: 408 bytes in 24 blocks are definitely lost in loss record 572 of 679 at 0x4A0645D: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so) by 0x1B0D057: xmalloc (xmalloc.c:148) by 0x1ACCAA1: append_file_to_dir(char const*, cpp_dir*) [clone .isra.3] (files.c:1567) by 0x1ACD56F: _cpp_find_file (files.c:390) by 0x1ACF8FB: cpp_read_main_file(cpp_reader*, char const*) (init.c:632) by 0x1AB3D97: selftest::lexer_test::lexer_test(selftest::line_table_case const&, char const*, selftest::lexer_test_options*) (input.c:2014) by 0x1AB792B: selftest::test_lexer_string_locations_u8(selftest::line_table_case const&) (input.c:2713) by 0x1ABA22A: selftest::for_each_line_table_case(void (*)(selftest::line_table_case const&)) (input.c:3227) by 0x1ABA381: selftest::input_c_tests() (input.c:3260) by 0x1A295F1: selftest::run_tests() (selftest-run-tests.c:62) by 0xF20DC4: toplev::run_self_tests() (toplev.c:2076) by 0xF20FCD: toplev::main(int, char**) (toplev.c:2153) Fix the leak by freeing the file->path in destroy_cpp_file. However, doing so would lead to a use-after-free in input.c's file cache since the filenames in this cache are the libcpp file->path buffers. Hence we need to ensure that any references to the file in the input.c cache are purged before cleaning up file->path. This is normally done by the temp_source_file dtor. Hence we need to reorder things to that the temp_source_file dtor runs before cleaning up the cpp_parser. The patch does this by introducing a wrapper class around cpp_parser *, so that the dtor can run after the dtor for temp_source_file. gcc/ChangeLog: * input.c (fcache::file_patch): Add comment about lifetime. (selftest::cpp_reader_ptr): New class. (selftest::lexer_test): Convert m_parser from cpp_reader * to a cpp_reader_ptr, and move m_tempfile to after it. (selftest::lexer_test::lexer_test): Update for above reordering. (lexer_test::~lexer_test): Move cleanup of m_parser to cpp_reader_ptr's dtor. libcpp/ChangeLog: * files.c (destroy_cpp_file): Free file->path. From-SVN: r241536
2016-10-25Implement ~line_maps ()David Malcolm3-8/+17
line_maps instances such as the global line_table are GC-managed, but the htab within location_adhoc_data_map.htab is not GC-managed. Previously this was deleted manually by a call to location_adhoc_data_fini within toplev::main. However, on adding a call to forcibly_ggc_collect after the selftests, all of the htabs for the various line_tables created during the selftests start showing up as leaks in "make selftest-valgrind", e.g.: 13,536 (1,344 direct, 12,192 indirect) bytes in 12 blocks are definitely lost in loss record 1,065 of 1,086 at 0x4A081D4: calloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so) by 0x16DB3B0: xcalloc (xmalloc.c:163) by 0x16D8D34: htab_create_typed_alloc (hashtab.c:358) by 0x16D8DBD: htab_create_alloc (hashtab.c:286) by 0x16A2CCC: linemap_init(line_maps*, unsigned int) (line-map.c:353) by 0x1685605: selftest::line_table_test::line_table_test(selftest::line_table_case const&) (input.c:1624) by 0x167D09C: selftest::test_applying_fixits_modernize_named_init(selftest::line_table_case const&) (edit-context.c:1430) by 0x1686827: selftest::for_each_line_table_case(void (*)(selftest::line_table_case const&)) (input.c:3227) by 0x167F067: selftest::edit_context_c_tests() (edit-context.c:1658) by 0x1616E67: selftest::run_tests() (selftest-run-tests.c:71) by 0xC0DB25: toplev::run_self_tests() (toplev.c:2076) by 0x618EB4: toplev::main(int, char**) (toplev.c:2153) This patch removes the manual one-time cleanup in favor of adding a destructor to class line_maps, which cleans up the non-GC-managed htab. Doing so improves "make selftest-valgrind" from: ==61118== LEAK SUMMARY: ==61118== definitely lost: 121,248 bytes in 1,515 blocks ==61118== indirectly lost: 974,344 bytes in 959 blocks ==61118== possibly lost: 0 bytes in 0 blocks ==61118== still reachable: 1,332,599 bytes in 3,684 blocks ==61118== suppressed: 0 bytes in 0 blocks to: ==57182== LEAK SUMMARY: ==57182== definitely lost: 13,840 bytes in 556 blocks ==57182== indirectly lost: 0 bytes in 0 blocks ==57182== possibly lost: 0 bytes in 0 blocks ==57182== still reachable: 1,355,703 bytes in 3,684 blocks ==57182== suppressed: 0 bytes in 0 blocks gcc/ChangeLog: * toplev.c (toplev::main): Remove call to location_adhoc_data_fini. libcpp/ChangeLog: * include/line-map.h (line_maps::~line_maps): New dtor. (location_adhoc_data_fini): Delete decl. * line-map.c (line_maps::~line_maps): New dtor. (location_adhoc_data_fini): Delete. From-SVN: r241533
2016-10-21re PR preprocessor/71681 (header.gcc file lookup is broken for -remap)Andris Pavenis2-3/+14
2016-10-21 Andris Pavenis <andris.pavenis@iki.fi> PR preprocessor/71681 * files.c (remap_filename): Fix handling -remap in subdirectories. From-SVN: r241413
2016-10-12gcc/Jakub Jelinek4-11/+104
* 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 Jelinek2-6/+15
* 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 Jelinek2-8/+93
* 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
2016-10-08c-lex.c (c_lex_with_flags): For CPP_COMMENT token with PREV_FALLTHROUGH...Jakub Jelinek2-18/+25
* c-lex.c (c_lex_with_flags) <case CPP_COMMENT>: For CPP_COMMENT token with PREV_FALLTHROUGH, skip all following CPP_PADDING and CPP_COMMENT tokens and set add_flags to PREV_FALLTHROUGH afterwards. * doc/invoke.texi (-Wimplicit-fallthrough): Document the accepted FALLTHRU comment styles. * lex.c (fallthrough_comment_p): Fix off-by-one size comparison errors, cleanup. (_cpp_lex_direct): Allow arbitrary comments in between fallthrough_comment_p comment and following token. * c-c++-common/Wimplicit-fallthrough-23.c: New test. * c-c++-common/Wimplicit-fallthrough-24.c: New test. From-SVN: r240884
2016-10-05re PR target/77847 (PowerPC big endian power7/power8 do not bootstrap due to ↵Kelvin Nilsen2-0/+9
fall through error) libcpp/ChangeLog: 2016-10-04 Kelvin Nilsen <kelvin@gcc.gnu.org> PR target/77847 * lex.c (search_line_fast): Add a FALLTHROUGH comment to correct compiler error in the version of this function that is conditionally compiled when GCC_VERSION >= 4005 and both __ALTIVEC__ and __BIG_ENDIAN__ symbols are defined. From-SVN: r240783
2016-09-26Implement -Wimplicit-fallthrough.Marek Polacek3-2/+112
Co-Authored-By: Jakub Jelinek <jakub@redhat.com> From-SVN: r240485
2016-09-23Provide location information for terminator characters (PR preprocessor/77672)David Malcolm2-1/+15
substring_loc::get_location currently fails for the final terminator character in a STRING_CST from the C frontend, so that format_warning_va falls back to using the location of the string as a whole. This patch tweaks things [1] so that we use the final closing quote as the location of the terminator character, as requested in PR preprocessor/77672. [1] specifically, cpp_interpret_string_1. gcc/ChangeLog: PR preprocessor/77672 * input.c (selftest::test_lexer_string_locations_simple): Update test to expect location information of the terminator character at the location of the final closing quote. (selftest::test_lexer_string_locations_hex): Likewise. (selftest::test_lexer_string_locations_oct): Likewise. (selftest::test_lexer_string_locations_letter_escape_1): Likewise. (selftest::test_lexer_string_locations_letter_escape_2): Likewise. (selftest::test_lexer_string_locations_ucn4): Likewise. (selftest::test_lexer_string_locations_ucn8): Likewise. (selftest::test_lexer_string_locations_u8): Likewise. (selftest::test_lexer_string_locations_utf8_source): Likewise. (selftest::test_lexer_string_locations_concatenation_1): Likewise. (selftest::test_lexer_string_locations_concatenation_2): Likewise. (selftest::test_lexer_string_locations_concatenation_3): Likewise. (selftest::test_lexer_string_locations_macro): Likewise. (selftest::test_lexer_string_locations_long_line): Likewise. gcc/testsuite/ChangeLog: PR preprocessor/77672 * gcc.dg/plugin/diagnostic-test-string-literals-1.c (test_terminator_location): New function. libcpp/ChangeLog: PR preprocessor/77672 * charset.c (cpp_interpret_string_1): Add a source_range for the NUL-terminator, using the location of the trailing quote of the final string. From-SVN: r240434
2016-09-21Add from_macro_definition_at predicate for locations.Jason Merrill3-6/+45
gcc/ * input.h (from_macro_definition_at): New. libcpp/ * line-map.c (linemap_location_from_macro_definition_p): New. * line-map.h: Declare it. From-SVN: r240330
2016-09-15fix-it hints can't contain newlinesDavid Malcolm3-0/+23
I hope to implement newline support within fix-it hints at some point, but currently it's not supported, and leads to misleading diagnostic output, so for now, fail gracefully. gcc/ChangeLog: * diagnostic-show-locus.c (selftest::test_fixit_insert_containing_newline): New function. (selftest::test_fixit_replace_containing_newline): New function. (selftest::diagnostic_show_locus_c_tests): Call the above. libcpp/ChangeLog: * include/line-map.h (class rich_location): Note that newlines aren't supported in fix-it text. * line-map.c (rich_location::add_fixit_insert_before): Reject attempts to add fix-its containing newlines. (rich_location::add_fixit_replace): Likewise. From-SVN: r240169
2016-09-13fix-it hints: insert_before vs insert_afterDavid Malcolm3-17/+169
The API for adding "insert text" fix-it hints was unclear about exactly where the text should be inserted relative to the given insertion point. This patch clarifies things by renaming the pertinent methods from richloc.add_fixit_insert to richloc.add_fixit_insert_before and adding: richloc.add_fixit_insert_after The latter allows us to consolidate some failure-handling into class rich_location, rather than having to have every such diagnostic check for it. The patch also adds a description of how fix-it hints work to the comment for class rich_location within libcpp/include/line-map.h. gcc/c-family/ChangeLog: * c-common.c (warn_logical_not_parentheses): Replace rich_location::add_fixit_insert calls with add_fixit_insert_before and add_fixit_insert_after, eliminating the "next_loc" calculation. gcc/c/ChangeLog: * c-parser.c (c_parser_declaration_or_fndef): Update for renaming of add_fixit_insert to add_fixit_insert_before. gcc/cp/ChangeLog: * parser.c (cp_parser_class_specifier_1): Update for renaming of add_fixit_insert to add_fixit_insert_before. (cp_parser_class_head): Likewise. gcc/ChangeLog: * diagnostic-show-locus.c (selftest::test_one_liner_fixit_insert): Rename to... (selftest::test_one_liner_fixit_insert_before): ...this, and update for renaming of add_fixit_insert to add_fixit_insert_before. (selftest::test_one_liner_fixit_insert_after): New function. (selftest::test_one_liner_fixit_validation_adhoc_locations): Update for renaming of add_fixit_insert to add_fixit_insert_before. (selftest::test_one_liner_many_fixits): Likewise. (selftest::test_diagnostic_show_locus_one_liner): Update for renaming, call new test function. (selftest::test_diagnostic_show_locus_fixit_lines): Update for renaming of add_fixit_insert to add_fixit_insert_before. (selftest::test_fixit_consolidation): Likewise. * diagnostic.c (selftest::test_print_parseable_fixits_insert): Likewise. * edit-context.c (selftest::test_applying_fixits_insert): Rename to... (selftest::test_applying_fixits_insert_before): ...this. (selftest::test_applying_fixits_insert): Update for renaming of add_fixit_insert to add_fixit_insert_before. (selftest::test_applying_fixits_insert_after): New function. (selftest::test_applying_fixits_insert_after_at_line_end): New function. (selftest::test_applying_fixits_insert_after_failure): New function. (selftest::test_applying_fixits_multiple): Update for renaming of add_fixit_insert to add_fixit_insert_before. (selftest::change_line): Likewise. (selftest::test_applying_fixits_unreadable_file): Likewise. (selftest::test_applying_fixits_line_out_of_range): Likewise. (selftest::test_applying_fixits_column_validation): Likewise. (selftest::test_applying_fixits_column_validation): Likewise. (selftest::edit_context_c_tests): Update for renamed test function; call new test functions. gcc/testsuite/ChangeLog: * gcc.dg/plugin/diagnostic_plugin_test_show_locus.c (test_show_locus): Replace rich_location::add_fixit_insert calls with add_fixit_insert_before and add_fixit_insert_after. libcpp/ChangeLog: * include/line-map.h (class rich_location): Add description of fix-it hints to leading comment. (rich_location::add_fixit_insert): Rename both overloaded methods to.. (rich_location::add_fixit_insert_before): ...this, updating their comments. (rich_location::add_fixit_insert_after): Two new overloaded methods. (rich_location::stop_supporting_fixits): New method. * line-map.c (rich_location::add_fixit_insert): Rename both overloaded methods to.. (rich_location::add_fixit_insert_before): ...this, updating their comments. (rich_location::add_fixit_insert_after): Two new methods. (rich_location::reject_impossible_fixit): Split out failure-handling into... (rich_location::stop_supporting_fixits): New method. From-SVN: r240115
2016-09-02Introduce class edit_contextDavid Malcolm2-0/+6
gcc/ChangeLog: * Makefile.in (OBJS-libcommon): Add edit-context.o. * diagnostic-color.c (color_dict): Add "diff-filename", "diff-hunk", "diff-delete", and "diff-insert". (parse_gcc_colors): Update default value of GCC_COLORS in comment to reflect above changes. * doc/invoke.texi (-fdiagnostics-color): Update description of default GCC_COLORS, and of the supported capabilities. * edit-context.c: New file. * edit-context.h: New file. * input.c (struct fcache): Add field "missing_trailing_newline". (diagnostics_file_cache_forcibly_evict_file): Initialize it to true. (add_file_to_cache_tab): Likewise. (fcache::fcache): Likewise. (get_next_line): Update c->missing_trailing_newline. (location_missing_trailing_newline): New function. * input.h (location_missing_trailing_newline): New decl. * selftest-run-tests.c (selftest::run_tests): Call edit_context_c_tests. * selftest.h (edit_context_c_tests): New decl. libcpp/ChangeLog: * include/line-map.h (rich_location::seen_impossible_fixit_p): New accessor. From-SVN: r239963
2016-08-31diagnostic-show-locus.c: handle fixits on lines outside the regular rangesDavid Malcolm3-6/+14
The diagnostic_show_locus implementation determines the set of line spans that need printing based on the ranges within the rich_location (in layout::calculate_line_spans). Currently this doesn't take into account fix-it hints, and hence we fail to print fix-it hints that are on lines outside of those ranges. This patch updates the implementation to take fix-it hints into account when calculating the pertinent line spans, so that such fix-it hints do get printed. It also adds some validation, to ensure that we don't attempt to print fix-its hints affecting a different source file. gcc/ChangeLog: * diagnostic-show-locus.c (class layout): Add field m_fixit_hints. (layout_range::intersects_line_p): New method. (test_range_contains_point_for_single_point): Rename to... (test_layout_range_for_single_point): ...this, and add testing for layout_range::intersects_line_p. (test_range_contains_point_for_single_line): Rename to... (test_layout_range_for_single_line): ...this, and add testing for layout_range::intersects_line_p. (test_range_contains_point_for_multiple_lines): Rename to... (test_layout_range_for_multiple_lines): ...this, and add testing for layout_range::intersects_line_p. (layout::layout): Populate m_fixit_hints. (layout::get_expanded_location): Handle the case of a line-span for a fix-it hint. (layout::validate_fixit_hint_p): New method. (get_line_span_for_fixit_hint): New function. (layout::calculate_line_spans): Add spans for fixit-hints. (layout::should_print_annotation_line_p): New method. (layout::print_any_fixits): Drop param "richloc", instead using validated fixits in m_fixit_hints. Add "const" to hint pointers. (diagnostic_show_locus): Avoid printing blank annotation lines. (selftest::test_diagnostic_context::test_diagnostic_context): Initialize show_column and start_span. (selftest::test_diagnostic_context::start_span_cb): New static function. (selftest::test_diagnostic_show_locus_fixit_lines): New function. (selftest::diagnostic_show_locus_c_tests): Update for function renamings. Call test_diagnostic_show_locus_fixit_lines. libcpp/ChangeLog: * include/line-map.h (class fixit_remove): Remove stray decl. (fixit_hint::affects_line_p): Make const. (fixit_insert::affects_line_p): Likewise. (fixit_replace::affects_line_p): Likewise. * line-map.c (fixit_insert::affects_line_p): Likewise. (fixit_replace::affects_line_p): Likewise. From-SVN: r239906