Commit Graph

545 Commits

Author SHA1 Message Date
GCC Administrator 303f81ad7e Update ChangeLog and version files for release
From-SVN: r247493
2017-05-02 12:42:24 +00:00
Jonathan Wakely 5764ee3c84 Fix numerous typos in comments
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-04-03 23:30:56 +01:00
Andreas Schwab 8c00ae2406 Fix search_line_fast for aarch64/ILP32
* 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-21 11:10:17 +00:00
Jason Merrill 85e653c925 * init.c (cpp_init_builtins): Update __cplusplus for C++17.
From-SVN: r246211
2017-03-16 17:16:39 -04:00
Gerald Pfeifer e228c50f3a * Makefile.in (po/$(PACKAGE).pot): Adjust bug reporting URL.
From-SVN: r245298
2017-02-09 08:55:46 +00:00
David Malcolm b9f4757f8e Fix issues with unrepresentable column numbers (PR c++/77949)
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 21:54:09 +00:00
David Malcolm 5ccf1d8d10 Fix linemap corruption after very wide source lines (PR c++/72803)
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-07 21:33:59 +00:00
Jakub Jelinek cbe34bb5ed Update copyright years.
From-SVN: r243994
2017-01-01 13:07:43 +01:00
David Malcolm a3998c2fb1 Fix use-after-free lexing unterminated raw strings (PR preprocessor/78811)
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-15 18:05:05 +00:00
David Malcolm 470a60b2c4 re PR preprocessor/78680 (ICE in get_substring_ranges_for_loc, at input.c:1398)
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-12-12 17:37:48 +00:00
Paolo Bonzini fb2675cb46 system.h (HAVE_DESIGNATED_INITIALIZERS, [...]): Do not use "defined" in macros.
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-23 10:06:07 +00:00
David Malcolm b8f564124e Fix locations within raw strings
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-17 15:55:26 +00:00
Jakub Jelinek 3549e181bd re PR bootstrap/72823 (r239175 causes build failure)
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-16 21:10:27 +01:00
Richard Earnshaw a6ac871cdf [AArch64] Optimized implementation of search_line_fast for the CPP lexer
* lex.c (search_line_fast): New implementation for AArch64.

From-SVN: r241964
2016-11-08 13:29:32 +00:00
David Malcolm f5ea989d50 input.c/libcpp: fix lifetimes of path buffers
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-25 19:24:01 +00:00
David Malcolm 2be1b79650 Implement ~line_maps ()
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-25 18:10:44 +00:00
Andris Pavenis 58f3096372 re PR preprocessor/71681 (header.gcc file lookup is broken for -remap)
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-21 18:52:25 +03:00
Jakub Jelinek 70f6d5e19b gcc/
* 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-12 01:19:06 +02:00
Jakub Jelinek ee19ef45ba invoke.texi: Document accepting Else, fallthrough.
* 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-08 12:54:27 +02:00
Jakub Jelinek 81b02905b0 invoke.texi (-Wimplicit-fallthrough): Document FALLTHRU comment style changes.
* 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-08 12:53:05 +02:00
Jakub Jelinek 7bad794aa0 c-lex.c (c_lex_with_flags): For CPP_COMMENT token with PREV_FALLTHROUGH...
* 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-08 12:48:54 +02:00
Kelvin Nilsen 67ef83c61f re PR target/77847 (PowerPC big endian power7/power8 do not bootstrap due to 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-10-05 12:36:48 +00:00
Marek Polacek 81fea426da Implement -Wimplicit-fallthrough.
Co-Authored-By: Jakub Jelinek <jakub@redhat.com>

From-SVN: r240485
2016-09-26 09:42:50 +00:00
David Malcolm bbd6fcf320 Provide location information for terminator characters (PR preprocessor/77672)
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-23 14:14:52 +00:00
Jason Merrill 63cb392608 Add from_macro_definition_at predicate for locations.
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-21 15:59:29 -04:00
David Malcolm 3131620863 fix-it hints can't contain newlines
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-15 23:57:01 +00:00
David Malcolm 254830bab2 fix-it hints: insert_before vs insert_after
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-13 16:08:59 +00:00
David Malcolm c65236d682 Introduce class edit_context
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-09-02 18:00:57 +00:00
David Malcolm 3d4f9f878d diagnostic-show-locus.c: handle fixits on lines outside the regular ranges
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
2016-08-31 18:54:55 +00:00
David Malcolm b816477a5a Remove arbitrary limits from rich_location
This patch eliminates the hard-coded limits within rich_location
(up to 3 ranges, up to 2 fixits).  The common case is still
handled by embedding the values inside rich_location - it only
uses dynamic allocation if these limits are exceeded, so
creation of rich_location instances on the stack should still
be fast.  This is implemented via a new container class,
semi_embedded_vec <T, N>.

gcc/ChangeLog:
	* diagnostic-show-locus.c (colorizer::begin_state): Support more
	than 3 ranges per diagnostic by alternating between color 1 and
	color 2.
	(layout::layout): Replace use of rich_location::MAX_RANGES
	with richloc->get_num_locations ().
	(layout::calculate_line_spans): Replace use of
	rich_location::MAX_RANGES with m_layout_ranges.length ().
	(layout::print_annotation_line): Handle arbitrary numbers of
	ranges in caret-printing by defaulting to '^'.
	(selftest::test_one_liner_many_fixits): New function.
	(test_diagnostic_show_locus_one_liner): Call it.
	* diagnostic.c (diagnostic_initialize): Update for renaming
	of rich_location::MAX_RANGES to
	rich_location::STATICALLY_ALLOCATED_RANGES.
	* diagnostic.h (struct diagnostic_context): Likewise.

gcc/testsuite/ChangeLog:
	* gcc.dg/plugin/diagnostic-test-show-locus-bw.c
	(test_many_nested_locations): New function.
	* gcc.dg/plugin/diagnostic_plugin_test_show_locus.c
	(test_show_locus): Handle "test_many_nested_locations".

libcpp/ChangeLog:
	* include/line-map.h (class semi_embedded_vec): New class.
	(semi_embedded_vec<T, NUM_EMBEDDED>::semi_embedded_vec): New ctor.
	(semi_embedded_vec<T, NUM_EMBEDDED>::~semi_embedded_vec): New
	dtor.
	(semi_embedded_vec<T, NUM_EMBEDDED>::operator[]): New methods.
	(semi_embedded_vec<T, NUM_EMBEDDED>::push): New method.
	(semi_embedded_vec<T, NUM_EMBEDDED>::truncate): New method.
	(rich_location::get_num_locations): Reimplement in terms of
	m_ranges.
	(rich_location::get_range): Make non-inline.
	(rich_location::get_num_fixit_hints): Reimplement in terms of
	m_fixit_hints.
	(rich_location::add_fixit): New function.
	(rich_location::MAX_RANGES): Rename to...
	(rich_location::STATICALLY_ALLOCATED_RANGES): ...this.
	(rich_location::MAX_FIXIT_HINTS): Rename to...
	(rich_location::STATICALLY_ALLOCATED_RANGES): ...this, and make
	private.
	(rich_location::m_num_ranges): Eliminate in favor of...
	(rich_location::m_ranges): ...this, converting from a fixed-size
	array to a semi_embedded_vec.
	(rich_location::m_num_fixit_hints): Eliminate in favor of...
	(rich_location::m_fixit_hints): ...this, converting from a
	fixed-size array to a semi_embedded_vec.
	* line-map.c (rich_location::rich_location): Update for above
	changes.
	(rich_location::~rich_location): Likewise.
	(rich_location::get_loc): Likewise.
	(rich_location::get_range): New methods.
	(rich_location::add_range): Update for above changes.
	(rich_location::set_range): Likewise.
	(rich_location::add_fixit_insert): Likewise.
	(rich_location::add_fixit_replace): Likewise.
	(rich_location::get_last_fixit_hint): Likewise.
	(rich_location::reject_impossible_fixit): Likewise.
	(rich_location::add_fixit): New method.

From-SVN: r239879
2016-08-31 00:35:01 +00:00
David Malcolm f908779801 rich_location: add convenience overloads for adding fix-it hints
Adding a fix-it hint to a diagnostic usually follows one of these
patterns:
(a) an insertion fix-its, with the insertion at the primary caret location
(b) a removals/replacements, affecting the range of the primary location

(other cases are possible, e.g. multiple fix-its, and affecting other
locations, but these are the common ones)

Given these common cases, this patch adds overloads of the rich_location
methods for adding fix-it hints, so that the location information can
be omitted if it matches that of the primary location within the
rich_location.

Similarly when adding "remove" and "replace" fix-it hints to a diagnostic,
it's tedious to have to extract the source_range from a location_t
(aka source_location).  To make this more convenient, this patch
adds overload of the rich_location::add_fixit_remove/replace methods,
accepting a source_location directly.

The patch updates the various in-tree users of fix-it hints to use
the new simpler API where appropriate.  I didn't touch the case where
there are multiple fix-its in one rich_location, as it seems better to
be more explicit about locations for this case (adding a pair of parens
in warn_logical_not_parentheses).

The above makes the gcc_rich_location::add_fixit_misspelled_id overload
taking a const char * rather redundant, so I eliminated it.

gcc/c/ChangeLog:
	* c-decl.c (implicit_decl_warning): Use add_fixit_replace
	rather than add_fixit_misspelled_id.
	(undeclared_variable): Likewise.
	* c-parser.c (c_parser_declaration_or_fndef): Likewise.  Remove
	now-redundant "here" params from add_fixit_insert method calls.
	(c_parser_parameter_declaration): Likewise.
	* c-typeck.c (build_component_ref): Remove now-redundant range
	param from add_fixit_replace method calls.

gcc/cp/ChangeLog:
	* name-lookup.c (suggest_alternatives_for): Use add_fixit_replace
	rather than add_fixit_misspelled_id.
	* parser.c (cp_parser_diagnose_invalid_type_name): Likewise.

gcc/ChangeLog:
	* diagnostic-show-locus.c (test_one_liner_fixit_insert): Remove
	redundant location param.
	(test_one_liner_fixit_remove): Likewise.
	(test_one_liner_fixit_replace): Likewise.
	(test_one_liner_fixit_replace_equal_secondary_range): Likewise.
	* gcc-rich-location.c
	(gcc_rich_location::add_fixit_misspelled_id): Eliminate call to
	get_range_from_loc.  Drop overload taking a const char *.
	* gcc-rich-location.h
	(gcc_rich_location::add_fixit_misspelled_id): Drop overload taking
	a const char *.

libcpp/ChangeLog:
	* include/line-map.h (rich_location::add_fixit_insert): Add
	comments.  Add overload omitting the source_location param.
	(rich_location::add_fixit_remove): Add comments.  Add overloads
	omitting the range, and accepting a source_location.
	(rich_location::add_fixit_replace): Likewise.
	* line-map.c (rich_location::add_fixit_insert): Add comments.  Add
	overload omitting the source_location param.
	(rich_location::add_fixit_remove): Add comments.  Add overloads
	omitting the range, and accepting a source_location.
	(rich_location::add_fixit_replace): Likewise.

From-SVN: r239861
2016-08-30 13:54:48 +00:00
David Malcolm 2aa514130a Allow the use of ad-hoc locations for fix-it hints
Currently the fix-it validator rejects ad-hoc locations.
Fix this by calling get_pure_location on the input locations to
add_fixit_insert/replace.  Doing so requires moving get_pure_location
from gcc to libcpp.

gcc/ChangeLog:
	* diagnostic-show-locus.c
	(selftest::test_one_liner_fixit_validation_adhoc_locations): New
	function.
	(selftest::test_diagnostic_show_locus_one_liner): Call it.
	* input.c (get_pure_location): Move to libcpp/line-map.c.
	* input.h (get_pure_location): Convert decl to an inline function
	calling implementation in libcpp.

libcpp/ChangeLog:
	* include/line-map.h (get_pure_location): New decl.
	* line-map.c (get_pure_location): Move here, from gcc/input.c, adding
	a line_maps * param.
	(rich_location::add_fixit_insert): Call get_pure_location on "where".
	(rich_location::add_fixit_replace): Call get_pure_location on the
	end-points.

From-SVN: r239843
2016-08-29 20:42:57 +00:00
David Malcolm ee90851679 Add validation and consolidation of fix-it hints
The first aspect of this patch is to add some checking of fix-it hints.
The idea is to put this checking within the rich_location machinery,
rather than requiring every diagnostic to implement it for itself.

The fixits within a rich_location are "atomic": all must be valid for
any to be applicable.

We reject any fixits involving locations above
LINE_MAP_MAX_LOCATION_WITH_COLS.

There's no guarantee that it's sane to modify a macro, so we reject
any fix-its that touch them.

For example, note the attempt to provide a fix-it for the definition
of the macro FIELD:

spellcheck-fields-2.c: In function ‘test_macro’:
spellcheck-fields-2.c:26:15: error: ‘union u’ has no member named ‘colour’; did you mean ‘color’?
 #define FIELD colour
               ^
               color
spellcheck-fields-2.c:27:15: note: in expansion of macro ‘FIELD’
   return ptr->FIELD;
               ^~~~~

After this patch, the fixit is not displayed:

spellcheck-fields-2.c: In function ‘test_macro’:
spellcheck-fields-2.c:26:15: error: ‘union u’ has no member named ‘colour’; did you mean ‘color’?
 #define FIELD colour
               ^
spellcheck-fields-2.c:27:15: note: in expansion of macro ‘FIELD’
   return ptr->FIELD;
               ^~~~~

We might want some way for a diagnostic to opt-in to fix-its that
affect macros, but for now it's simplest to reject them.

The other aspect of this patch is fix-it consolidation: in some cases
neighboring fix-its can be merged.  For example, in a diagnostic to
modernize old-style struct initializers from:

 struct s example = {
- foo: 1,
+ .foo = 1,
 };

one approach would be to replace the "foo" with ".foo" and the ":"
with " =".  This would give two "replace" fix-its:

  foo: 1,
  --- FIXIT 1
  .foo
     - FIXIT 2
     =

This patch allows them to be consolidated into a single "replace" fix-it:

  foo: 1,
  ----
  .foo =

gcc/ChangeLog:
	* diagnostic-show-locus.c
	(selftest::test_fixit_consolidation): New function.
	(selftest::diagnostic_show_locus_c_tests): Call it.
	* gcc-rich-location.h (gcc_rich_location): Eliminate unused
	constructor based on source_range.

gcc/testsuite/ChangeLog:
	* gcc.dg/spellcheck-fields-2.c (test): Move
	dg-begin/end-multiline-output within function body.
	(test_macro): New function.

libcpp/ChangeLog:
	* include/line-map.h (rich_location): Eliminate unimplemented
	constructor based on source_range.
	(rich_location::get_last_fixit_hint): New method.
	(rich_location::reject_impossible_fixit): New method.
	(rich_location): Add fields m_line_table and
	m_seen_impossible_fixit.
	(fixit_hint::maybe_append_replace): New pure virtual function.
	(fixit_insert::maybe_append_replace): New function.
	(fixit_replace::maybe_append_replace): New function.
	* line-map.c (rich_location::rich_location): Initialize
	m_line_table and m_seen_impossible_fixit.
	(rich_location::add_fixit_insert): Call
	reject_impossible_fixit and bail out if true.
	(column_before_p): New function.
	(rich_location::add_fixit_replace): Call reject_impossible_fixit
	and bail out if true.  Attempt to consolidate with neighboring
	fixits.
	(rich_location::get_last_fixit_hint): New method.
	(rich_location::reject_impossible_fixit): New method.
	(fixit_insert::maybe_append_replace): New method.
	(fixit_replace::maybe_append_replace): New method.

From-SVN: r239789
2016-08-26 21:25:41 +00:00
David Malcolm d672cded1f line-map.h: add source_range::from_locations
libcpp/ChangeLog:
	* include/line-map.h (source_range::from_locations): New method.

From-SVN: r239711
2016-08-23 20:20:48 +00:00
David Malcolm 2ffe0809cb Reimplement removal fix-it hints in terms of replace
This patch eliminates class fixit_remove, reimplementing
rich_location::add_fixit_remove in terms of replacement with the
empty string.  Deleting the removal subclass simplifies
fixit-handling code, as we only have two concrete fixit_hint
subclasses to deal with, rather than three.

The patch also fixes some problems in diagnostic-show-locus.c for
situations where a replacement fix-it has a different range to the
range of the diagnostic, by unifying the drawing of the two kinds of
fixits.  For example, this:

  foo = bar.field;
      ^
            m_field

becomes:

  foo = bar.field;
      ^
            -----
            m_field

showing the range to be replaced.

gcc/ChangeLog:
	* diagnostic-show-locus.c
	(layout::annotation_line_showed_range_p): New method.
	(layout::print_any_fixits): Remove case fixit_hint::REMOVE.
	Reimplement case fixit_hint::REPLACE to cover removals, and
	replacements where the range of the replacement isn't one
	of the ranges in the rich_location.
	(test_one_liner_fixit_replace): Likewise.
	(selftest::test_one_liner_fixit_replace_non_equal_range): New
	function.
	(selftest::test_one_liner_fixit_replace_equal_secondary_range):
	New function.
	(selftest::test_diagnostic_show_locus_one_liner): Call the new
	functions.
	* diagnostic.c (print_parseable_fixits): Remove case
	fixit_hint::REMOVE.

libcpp/ChangeLog:
	* include/line-map.h (fixit_hint::kind): Delete REPLACE.
	(class fixit_remove): Delete.
	* line-map.c (rich_location::add_fixit_remove): Reimplement
	by calling add_fixit_replace with an empty string.
	(fixit_remove::fixit_remove): Delete.
	(fixit_remove::affects_line_p): Delete.

From-SVN: r239632
2016-08-19 21:18:05 +00:00
Joseph Myers c65699efcc Implement C _FloatN, _FloatNx types.
ISO/IEC TS 18661-3:2015 defines C bindings to IEEE interchange and
extended types, in the form of _FloatN and _FloatNx type names with
corresponding fN/FN and fNx/FNx constant suffixes and FLTN_* / FLTNX_*
<float.h> macros.  This patch implements support for this feature in
GCC.

The _FloatN types, for N = 16, 32, 64 or >= 128 and a multiple of 32,
are types encoded according to the corresponding IEEE interchange
format (endianness unspecified; may use either the NaN conventions
recommended in IEEE 754-2008, or the MIPS NaN conventions, since the
choice of convention is only an IEEE recommendation, not a
requirement).  The _FloatNx types, for N = 32, 64 and 128, are IEEE
"extended" types: types extending a narrower format with range and
precision at least as big as those specified in IEEE 754 for each
extended type (and with unspecified representation, but still
following IEEE semantics for their values and operations - and with
the set of values being determined by the precision and the maximum
exponent, which means that while Intel "extended" is suitable for
_Float64x, m68k "extended" is not).  These types are always distinct
from and not compatible with each other and the standard floating
types float, double, long double; thus, double, _Float64 and _Float32x
may all have the same ABI, but they are three still distinct types.
The type names may be used with _Complex to construct corresponding
complex types (unlike __float128, which acts more like a typedef name
than a keyword - thus, this patch may be considered to fix PR
c/32187).  The new suffixes can be combined with GNU "i" and "j"
suffixes for constants of complex types (e.g. 1.0if128, 2.0f64i).

The set of types supported is implementation-defined.  In this GCC
patch, _Float32 is SFmode if that is suitable; _Float32x and _Float64
are DFmode if that is suitable; _Float128 is TFmode if that is
suitable; _Float64x is XFmode if that is suitable, and otherwise
TFmode if that is suitable.  There is a target hook to override the
choices if necessary.  "Suitable" means both conforming to the
requirements of that type, and supported as a scalar type including in
libgcc.  The ABI is whatever the back end does for scalars of that
mode (but note that _Float32 is passed without promotion in variable
arguments, unlike float).  All the existing issues with exceptions and
rounding modes for existing types apply equally to the new type names.

No GCC port supports a floating-point format suitable for _Float128x.
Although there is HFmode support for ARM and AArch64, use of that for
_Float16 is not enabled.  Supporting _Float16 would require additional
work on the excess precision aspects of TS 18661-3: there are new
values of FLT_EVAL_METHOD, which are not currently supported in GCC,
and FLT_EVAL_METHOD == 0 now means that operations and constants on
types narrower than float are evaluated to the range and precision of
float.  Implementing that, so that _Float16 gets evaluated with excess
range and precision, would involve changes to the excess precision
infrastructure so that the _Float16 case is enabled by default, unlike
the x87 case which is only enabled for -fexcess-precision=standard.
Other differences between _Float16 and __fp16 would also need to be
disentangled.

GCC has some prior support for nonstandard floating-point types in the
form of __float80 and __float128.  Where these were previously types
distinct from long double, they are made by this patch into aliases
for _Float64x / _Float128 if those types have the required properties.

In principle the set of possible _FloatN types is infinite.  This
patch hardcodes the four such types for N <= 128, but with as much
code as possible using loops over types to minimize the number of
places with such hardcoding.  I don't think it's likely any further
such types will be of use in future (or indeed that formats suitable
for _Float128x will actually be implemented).  There is a corner case
that all _FloatN, for N >= 128 and a multiple of 32, should be treated
as keywords even when the corresponding type is not supported; I
intend to deal with that in a followup patch.

Tests are added for various functionality of the new types, mostly
using type-generic headers.  The tests use dg-add-options to pass any
extra options needed to enable the types; this is wired up to use the
same options as for __float128 on powerpc to enable _Float128 and
_Float64x, and effective-target keywords for runtime support do the
same hardware test as for __float128 to make sure the VSX instructions
generated by those options are supported.  (Corresponding additions
would be needed for _Float16 on ARM as well if that were enabled with
-mfp16-format=ieee required to use it rather than unconditionally
available.  Of course, -mfp16-format=alternative enables use of a
format which is not compatible with the requirements of the _Float16
type.)

C++ note: no support for the new types or constant suffixes is added
for C++.  C++ decimal floating-point support was very different from
the C support, using class types, and the same may well apply to any
future C++ bindings for IEEE interchange and extended types.  There is
a case, however, for supporting at least *f128 constants in C++, so
that code using __float128 can use the newer style for constants
throughout rather than needing to use the older *q constants in C++.
Also, if built-in functions are added that may provide a way in which
the types could leak into C++ code.

Fortran note: the float128_type_node used in the Fortran front end is
renamed to gfc_float128_type_node, since the semantics are different:
in particular, if long double has binary128 format, then the new
language-independent float128_type_node is a distinct type that also
has binary128 format, but the Fortran node is expected to be NULL in
that case.  Likewise, Fortran's complex_float128_type_node is renamed
to gfc_complex_float128_type_node.

PowerPC note: the back end had an inconsistency that if TFmode was
binary128, *q constants were TFmode instead of KFmode but __float128
was KFmode.  This patch follows the same logic as for *q constants, so
that _Float128 prefers TFmode (and __float128 becomes an alias for
_Float128).

ARM note: __fp16 is promoted to double (by convert_arguments) when
passed without a prototype / in variable arguments.  But this is only
about the argument promotion; it is not handled as promoting in
c-common.c:self_promoting_args_p / c-typeck.c:c_type_promotes_to,
meaning that a K&R function definition for an argument of type __fp16
corresponds to a prototype with an argument of that type, not to one
with an argument of type double, whereas a float argument in a K&R
function definition corresponds to a double prototype argument - and
the same functions are also what's involved in making va_arg give a
warning and generate a call to abort when called with type float.
This is preserved by this patch, while arranging for _Float16 not to
be promoted when passed without a prototype / in variable arguments
(the promotion of float being considered a legacy feature, not applied
to any new types in C99 or later).

TS 18661-3 extends the set of decimal floating-point types similarly,
and adds new constant suffixes for the existing types, but this patch
does not do anything regarding that extension.

This patch does nothing regarding built-in functions, although
type-generic functions such as __builtin_isinf work for the new types
and associated tests are included.  There are at least two levels of
built-in function support possible for these types.  The minimal
level, implemented in
<https://gcc.gnu.org/ml/gcc-patches/2016-06/msg01702.html> (which
needs updating to use dg-add-options), adds built-in functions similar
to those x86 has for __float128: __builtin_inf* __builtin_huge_val*,
__builtin_nan*, __builtin_nans*, __builtin_fabs*, __builtin_copysign*.
That would be sufficient for glibc to use the *f128 names for built-in
functions by default with *q used only for backwards compatibility
when using older GCC versions.  That would also allow c_cpp_builtins's
flag_building_libgcc code, defining __LIBGCC_%s_FUNC_EXT__, to use
such suffixes rather than the present code hardcoding logic about
target-specific constant suffixes and how those relate to function
suffixes.

Full built-in function support would cover the full range of built-in
functions for existing floating-point types, adding variants for all
the new types, except for a few obsolescent functions and
non-type-generic variants of type-generic functions.  Some but not all
references to such functions in GCC use macros such as CASE_FLT_FN to
be type-generic; a fair amount of work would be needed to identify all
places to update.  Adding all those functions would enable
optimizations (for constant arguments and otherwise) for TS 18661-3
functions, but it would also substantially expand the enum listing
built-in functions (and we've had problems with the size of that enum
in the past), and increase the amount of built-in function
initialization to do - I don't know what the startup cost involved in
built-in function initialization is, but it would be something to
consider when adding such a large set of functions.

There are also a range of optimizations, in match.pd and elsewhere,
that only operate on the three standard floating-point types.  Ideally
those would be made generic to all floating-point types, but this
patch does nothing in that regard.  Special care would be needed
regarding making sure library functions to which calls are generated
actually exist.  For example, if sqrt is called on an argument of type
_Float32, and the result converted to _Float32, this is equivalent to
doing a square root operation directly on _Float32.  But if the user's
libm does not have the sqrtf32 function, or the name is not reserved
because __STDC_WANT_IEC_60559_TYPES_EXT__ was not defined before
including <math.h>, you can only do that optimization if you convert
to a call to sqrtf instead.

DECIMAL_DIG now relates to all supported floating-point formats, not
just float, double and long double; I've raised the question with WG14
of how this relates to the formula for DECIMAL_DIG in C11 not
considering this.  TS 18661-3 says it also covers non-arithmetic
formats only supported by library conversion functions; this patch
does not add any target hooks to allow for the case where there are
such formats wider than any supported for arithmetic types (where
e.g. libc supports conversions involving the binary128 representation,
but the _Float128 type is not supported).

GCC provides its own <tgmath.h> for some targets.  No attempt is made
to adapt this to handle the new types.

Nothing is done regarding debug info for the new types (see the
"Debugger support for __float128 type?" thread on gcc@, Sep/Oct 2015).

No __SIZEOF_*__ macros are added for the new types.

Nothing is done with do_warn_double_promotion.

Nothing is done to include the new types in those determining
max_align_t, although properly it should be sufficiently aligned for
any of those types.

The logic for usual arithmetic conversions in c_common_type relies on
TYPE_PRECISION for floating-point types, which is less than ideal
(doesn't necessarily correspond to whether one type's values are
subset of another); looking in more detail at the formats might be
better.  But since I included code in build_common_tree_nodes to work
around rs6000 KFmode having precision 113 not 128, I think it should
work.  Ideally one might have errors in generic code for the case
where the two types do not have one type's values a subset of the
other (which is undefined behavior).  But the only case where this can
actually occur is mixing IBM long double with binary128 on powerpc,
and rs6000_invalid_binary_op deals with that at present.  TS 18661-3
does not fully specify the type resulting from the usual arithmetic
conversions in the case where two _FloatNx types have the same set of
values; I arranged the code to prefer the greater value of N in that
case.

The __FP_FAST_FMA* macros are not extended to cover the new types,
since there are no corresponding built-in functions (if built-in
fmafN, fmafNx are added, the macros should be extended, and the new
macros documented).  Also, only a limited set of modes is handled in
mode_has_fma.

Diagnostics relating to the use of the new types with -pedantic do not
try to distinguish them from purely nonstandard types such as __int128
and constant suffixes such as *q.

If you use an unsupported _FloatN / _FloatNx type you get a warning
about the type defaulting to int after the warning about the type not
being supported.  That's less than ideal, but it's also a pre-existing
condition if you use __int128 on a 32-bit system where it's
unsupported.

Bootstrapped with no regressions on x86_64-pc-linux-gnu.  Other
back-end changes minimally tested by building cc1 for ia64-linux-gnu,
powerpc64le-linux-gnu, pdp11-none (the last failed for unrelated
reasons).

	PR c/32187
gcc:
	* tree-core.h (TI_COMPLEX_FLOAT16_TYPE)
	(TI_COMPLEX_FLOATN_NX_TYPE_FIRST, TI_COMPLEX_FLOAT32_TYPE)
	(TI_COMPLEX_FLOAT64_TYPE, TI_COMPLEX_FLOAT128_TYPE)
	(TI_COMPLEX_FLOAT32X_TYPE, TI_COMPLEX_FLOAT64X_TYPE)
	(TI_COMPLEX_FLOAT128X_TYPE, TI_FLOAT16_TYPE, TI_FLOATN_TYPE_FIRST)
	(TI_FLOATN_NX_TYPE_FIRST, TI_FLOAT32_TYPE, TI_FLOAT64_TYPE)
	(TI_FLOAT128_TYPE, TI_FLOATN_TYPE_LAST, TI_FLOAT32X_TYPE)
	(TI_FLOATNX_TYPE_FIRST, TI_FLOAT64X_TYPE, TI_FLOAT128X_TYPE)
	(TI_FLOATNX_TYPE_LAST, TI_FLOATN_NX_TYPE_LAST): New enum
	tree_index values.
	(NUM_FLOATN_TYPES, NUM_FLOATNX_TYPES, NUM_FLOATN_NX_TYPES): New
	macros.
	(struct floatn_type_info): New structure type.
	(floatn_nx_types): New variable declaration.
	* tree.h (FLOATN_TYPE_NODE, FLOATN_NX_TYPE_NODE)
	(FLOATNX_TYPE_NODE, float128_type_node, float64x_type_node)
	(COMPLEX_FLOATN_NX_TYPE_NODE): New macros.
	* tree.c (floatn_nx_types): New variable.
	(build_common_tree_nodes): Initialize _FloatN, _FloatNx and
	corresponding complex types.
	* target.def (floatn_mode): New hook.
	* targhooks.c: Include "real.h".
	(default_floatn_mode): New function.
	* targhooks.h (default_floatn_mode): New prototype.
	* doc/extend.texi (Floating Types): Document _FloatN and _FloatNx
	types.
	* doc/sourcebuild.texi (float@var{n}, float@var{n}x): Document new
	effective-target and dg-add-options keywords.
	(float@var{n}_runtime, float@var{n}x_runtime, floatn_nx_runtime):
	Document new effective-target keywords.
	* doc/tm.texi.in (TARGET_FLOATN_MODE): New @hook.
	* doc/tm.texi: Regenerate.
	* ginclude/float.h (LDBL_DECIMAL_DIG): Define to
	__LDBL_DECIMAL_DIG__, not __DECIMAL_DIG__.
	[__STDC_WANT_IEC_60559_TYPES_EXT__]: Define macros from TS
	18661-3.
	* real.h (struct real_format): Add field ieee_bits.
	* real.c (ieee_single_format, mips_single_format)
	(motorola_single_format, spu_single_format, ieee_double_format)
	(mips_double_format, motorola_double_format)
	(ieee_extended_motorola_format, ieee_extended_intel_96_format)
	(ieee_extended_intel_128_format)
	(ieee_extended_intel_96_round_53_format, ibm_extended_format)
	(mips_extended_format, ieee_quad_format, mips_quad_format)
	(vax_f_format, vax_d_format, vax_g_format, decimal_single_format)
	(decimal_double_format, decimal_quad_format, ieee_half_format)
	(arm_half_format, real_internal_format: Initialize ieee_bits
	field.
	* config/i386/i386.c (ix86_init_builtin_types): Do not initialize
	float128_type_node.  Set float80_type_node to float64x_type_node
	if appropriate and long_double_type_node not appropriate.
	* config/ia64/ia64.c (ia64_init_builtins): Likewise.
	* config/pdp11/pdp11.c (pdp11_f_format, pdp11_d_format):
	Initialize ieee_bits field.
	* config/rs6000/rs6000.c (TARGET_FLOATN_MODE): New macro.
	(rs6000_init_builtins): Set ieee128_float_type_node to
	float128_type_node.
	(rs6000_floatn_mode): New function.

gcc/c:
	* c-tree.h (cts_floatn_nx): New enum c_typespec_keyword value.
	(struct c_declspecs): Add field floatn_nx_idx.
	* c-decl.c (declspecs_add_type, finish_declspecs): Handle _FloatN
	and _FloatNx type specifiers.
	* c-parser.c (c_keyword_starts_typename, c_token_starts_declspecs)
	(c_parser_declspecs, c_parser_attribute_any_word)
	(c_parser_objc_selector): Use CASE_RID_FLOATN_NX.
	* c-typeck.c (c_common_type): Handle _FloatN and _FloatNx types.
	(convert_arguments): Avoid promoting _FloatN and _FloatNx types
	narrower than double.

gcc/c-family:
	* c-common.h (RID_FLOAT16, RID_FLOATN_NX_FIRST, RID_FLOAT32)
	(RID_FLOAT64, RID_FLOAT128, RID_FLOAT32X, RID_FLOAT64X)
	(RID_FLOAT128X): New enum rid values.
	(CASE_RID_FLOATN_NX): New macro.
	* c-common.c (c_common_reswords): Add _FloatN and _FloatNx
	keywords.
	(c_common_type_for_mode): Check for _FloatN and _FloatNx and
	corresponding complex types.
	(c_common_nodes_and_builtins): For non-C++, register _FloatN and
	_FloatNx and corresponding complex types.
	(keyword_begins_type_specifier): Use CASE_RID_FLOATN_NX.
	* c-cppbuiltin.c (builtin_define_float_constants): Check _FloatN
	and _FloatNx types for the widest type for determining
	DECIMAL_DIG.  Define __LDBL_DECIMAL_DIG__ as well as
	__DECIMAL_DIG__ for long double.  Handle FMA_SUFFIX being NULL.
	(c_cpp_builtins): Call builtin_define_float_constants for _FloatN
	and _FloatNx types.
	* c-lex.c (interpret_float): Handle _FloatN and _FloatNx
	constants.
	* c-pretty-print.c (pp_c_floating_constant): Handle _FloatN and
	_FloatNx types.

gcc/fortran:
	* trans-types.h (float128_type_node): Rename to
	gfc_float128_type_node.
	(complex_float128_type_node): Rename to
	gfc_complex_float128_type_node.
	* iso-c-binding.def, trans-intrinsic.c, trans-types.c: All users
	changed.

gcc/testsuite:
	* lib/target-supports.exp (check_effective_target_float16)
	(check_effective_target_float32, check_effective_target_float64)
	(check_effective_target_float128, check_effective_target_float32x)
	(check_effective_target_float64x)
	(check_effective_target_float128x)
	(check_effective_target_float16_runtime)
	(check_effective_target_float32_runtime)
	(check_effective_target_float64_runtime)
	(check_effective_target_float128_runtime)
	(check_effective_target_float32x_runtime)
	(check_effective_target_float64x_runtime)
	(check_effective_target_float128x_runtime)
	(check_effective_target_floatn_nx_runtime)
	(add_options_for_float16, add_options_for_float32)
	(add_options_for_float64, add_options_for_float128)
	(add_options_for_float32x, add_options_for_float64x)
	(add_options_for_float128x): New procedures.
	* gcc.dg/dfp/floatn.c, gcc.dg/float128-typeof.c,
	gcc.dg/float128x-typeof.c, gcc.dg/float16-typeof.c,
	gcc.dg/float32-typeof.c, gcc.dg/float32x-typeof.c,
	gcc.dg/float64-typeof.c, gcc.dg/float64x-typeof.c,
	gcc.dg/floatn-arithconv.c, gcc.dg/floatn-errs.c,
	gcc.dg/floatn-typeof.h, gcc.dg/torture/float128-basic.c,
	gcc.dg/torture/float128-complex.c,
	gcc.dg/torture/float128-floath.c, gcc.dg/torture/float128-tg.c,
	gcc.dg/torture/float128x-basic.c,
	gcc.dg/torture/float128x-complex.c,
	gcc.dg/torture/float128x-floath.c, gcc.dg/torture/float128x-tg.c,
	gcc.dg/torture/float16-basic.c, gcc.dg/torture/float16-complex.c,
	gcc.dg/torture/float16-floath.c, gcc.dg/torture/float16-tg.c,
	gcc.dg/torture/float32-basic.c, gcc.dg/torture/float32-complex.c,
	gcc.dg/torture/float32-floath.c, gcc.dg/torture/float32-tg.c,
	gcc.dg/torture/float32x-basic.c,
	gcc.dg/torture/float32x-complex.c,
	gcc.dg/torture/float32x-floath.c, gcc.dg/torture/float32x-tg.c,
	gcc.dg/torture/float64-basic.c, gcc.dg/torture/float64-complex.c,
	gcc.dg/torture/float64-floath.c, gcc.dg/torture/float64-tg.c,
	gcc.dg/torture/float64x-basic.c,
	gcc.dg/torture/float64x-complex.c,
	gcc.dg/torture/float64x-floath.c, gcc.dg/torture/float64x-tg.c,
	gcc.dg/torture/floatn-basic.h, gcc.dg/torture/floatn-complex.h,
	gcc.dg/torture/floatn-convert.c, gcc.dg/torture/floatn-floath.h,
	gcc.dg/torture/floatn-tg.h,
	gcc.dg/torture/fp-int-convert-float128-ieee-timode.c,
	gcc.dg/torture/fp-int-convert-float128-ieee.c,
	gcc.dg/torture/fp-int-convert-float128x-timode.c,
	gcc.dg/torture/fp-int-convert-float128x.c,
	gcc.dg/torture/fp-int-convert-float16-timode.c,
	gcc.dg/torture/fp-int-convert-float16.c,
	gcc.dg/torture/fp-int-convert-float32-timode.c,
	gcc.dg/torture/fp-int-convert-float32.c,
	gcc.dg/torture/fp-int-convert-float32x-timode.c,
	gcc.dg/torture/fp-int-convert-float32x.c,
	gcc.dg/torture/fp-int-convert-float64-timode.c,
	gcc.dg/torture/fp-int-convert-float64.c,
	gcc.dg/torture/fp-int-convert-float64x-timode.c,
	gcc.dg/torture/fp-int-convert-float64x.c: New tests.
	* gcc.dg/torture/fp-int-convert.h (TEST_I_F): Add argument for
	maximum exponent of floating-point type.  Use it in testing
	whether 0x8...0 fits in the floating-point type.  Always treat -1
	(signed 0xf...f) as fitting in the floating-point type.
	(M_OK1): New macro.
	* gcc.dg/torture/fp-int-convert-double.c,
	gcc.dg/torture/fp-int-convert-float.c,
	gcc.dg/torture/fp-int-convert-float128-timode.c,
	gcc.dg/torture/fp-int-convert-float128.c,
	gcc.dg/torture/fp-int-convert-float80-timode.c,
	gcc.dg/torture/fp-int-convert-float80.c,
	gcc.dg/torture/fp-int-convert-long-double.c,
	gcc.dg/torture/fp-int-convert-timode.c: Update calls to TEST_I_F.

libcpp:
	* include/cpplib.h (CPP_N_FLOATN, CPP_N_FLOATNX)
	(CPP_N_WIDTH_FLOATN_NX, CPP_FLOATN_SHIFT, CPP_FLOATN_MAX): New
	macros.
	* expr.c (interpret_float_suffix): Handle fN, fNx, FN and FNx
	suffixes.

From-SVN: r239625
2016-08-19 18:43:26 +01:00
Prathamesh Kulkarni fcf830abf7 expr.c (eval_token): Append "evaluates to 0" to Wundef diagnostic.
2016-08-19  Prathamesh Kulkarni  <prathamesh.kulkarni@linaro.org>

libcpp/
	* expr.c (eval_token): Append "evaluates to 0" to Wundef diagnostic.

testsuite/
	* gcc.dg/cpp/warn-undef.c: Append "evaluates to 0" to dg-error.
	* gcc.dg/cpp/warn-undef-2.c: Likewise.

From-SVN: r239609
2016-08-19 13:17:09 +00:00
David Malcolm cb18fd07f2 Spelling suggestions for misspelled preprocessor directives
This patch allows the preprocessor to offer suggestions for misspelled
directives, taking us from e.g.:

test.c:5:2: error: invalid preprocessing directive #endfi
 #endfi
  ^~~~~

to:

test.c:5:2: error: invalid preprocessing directive #endfi; did you mean #endif?
 #endfi
  ^~~~~
  endif

gcc/c-family/ChangeLog:
	* c-common.c: Include "spellcheck.h".
	(cb_get_suggestion): New function.
	* c-common.h (cb_get_suggestion): New decl.
	* c-lex.c (init_c_lex): Initialize cb->get_suggestion to
	cb_get_suggestion.

gcc/testsuite/ChangeLog:
	* gcc.dg/cpp/misspelled-directive-1.c: New testcase.
	* gcc.dg/cpp/misspelled-directive-2.c: New testcase.

libcpp/ChangeLog:
	* directives.c (directive_names): New array.
	(_cpp_handle_directive): Offer spelling suggestions for misspelled
	directives.
	* errors.c (cpp_diagnostic_at_richloc): New function.
	(cpp_error_at_richloc): New function.
	* include/cpplib.h (struct cpp_callbacks): Add field
	"get_suggestion".
	(cpp_error_at_richloc): New decl.

From-SVN: r239585
2016-08-18 18:52:43 +00:00
Marek Polacek 9c62c87358 re PR c/7652 (-Wswitch-break : Warn if a switch case falls through)
PR c/7652
gcc/cp/
	* call.c (add_builtin_candidate): Add gcc_fallthrough.
	* cxx-pretty-print.c (pp_cxx_unqualified_id): Likewise.
	* parser.c (cp_parser_skip_to_end_of_statement): Likewise.
	(cp_parser_cache_defarg): Likewise.
libcpp/
	* pch.c (write_macdef): Add CPP_FALLTHRU.

From-SVN: r239566
2016-08-18 10:28:03 +00:00
Marek Polacek 191816a36b re PR c/7652 (-Wswitch-break : Warn if a switch case falls through)
PR c/7652
gcc/
	* alias.c (find_base_value): Adjust fall through comment.
	* cfgexpand.c (expand_debug_expr): Likewise.
	* combine.c (find_split_point): Likewise.
	(expand_compound_operation): Likewise.  Add FALLTHRU.
	(make_compound_operation): Adjust fall through comment.
	(canon_reg_for_combine): Add FALLTHRU.
	(force_to_mode): Adjust fall through comment.
	(simplify_shift_const_1): Likewise.
	(simplify_comparison): Likewise.
	* config/aarch64/aarch64-builtins.c (aarch64_simd_expand_args): Add
	FALLTHRU.
	* config/aarch64/predicates.md: Likewise.
	* config/i386/i386.c (function_arg_advance_32): Likewise.
	(ix86_gimplify_va_arg): Likewise.
	(print_reg): Likewise.
	(ix86_print_operand): Likewise.
	(ix86_build_const_vector): Likewise.
	(ix86_expand_branch): Likewise.
	(ix86_sched_init_global): Adjust fall through comment.
	(ix86_expand_args_builtin): Add FALLTHRU.
	(ix86_expand_builtin): Likewise.
	(ix86_expand_vector_init_one_var): Likewise.
	* config/rs6000/rs6000.c (rs6000_emit_vector_compare_inner): Likewise.
	(rs6000_adjust_cost): Likewise.
	(insn_must_be_first_in_group): Likewise.
	* config/rs6000/rs6000.md: Likewise.  Adjust fall through comment.
	* dbxout.c (dbxout_symbol): Adjust fall through comment.
	* df-scan.c (df_uses_record): Likewise.
	* dojump.c (do_jump): Add FALLTHRU.
	* dwarf2out.c (mem_loc_descriptor): Likewise.  Adjust fall through
	comment.
	(resolve_args_picking_1): Adjust fall through comment.
	(loc_list_from_tree_1): Likewise.
	* expmed.c (make_tree): Likewise.
	* expr.c (expand_expr_real_2): Add FALLTHRU.
	(expand_expr_real_1): Likewise.  Adjust fall through comment.
	* fold-const.c (const_binop): Adjust fall through comment.
	(fold_truth_not_expr): Likewise.
	(fold_cond_expr_with_comparison): Add FALLTHRU.
	(fold_binary_loc): Likewise.
	(contains_label_1): Adjust fall through comment.
	(multiple_of_p): Likewise.
	* gcov-tool.c (process_args): Add FALLTHRU.
	* genattrtab.c (check_attr_test): Likewise.
	(write_test_expr): Likewise.
	* genconfig.c (walk_insn_part): Likewise.
	* genpreds.c (validate_exp): Adjust fall through comment.
	(needs_variable): Likewise.
	* gensupport.c (get_alternatives_number): Add FALLTHRU.
	(subst_dup): Likewise.
	* gimple-pretty-print.c (dump_gimple_assign): Likewise.
	* gimplify.c (gimplify_addr_expr): Adjust fall through comment.
	(gimplify_scan_omp_clauses): Add FALLTHRU.
	(goa_stabilize_expr): Likewise.
	* graphite-isl-ast-to-gimple.c (substitute_ssa_name): Adjust fall
	through comment.
	* hsa-gen.c (get_address_from_value): Likewise.
	* ipa-icf.c (sem_function::hash_stmt): Likewise.
	* ira.c (ira_setup_alts): Add FALLTHRU.
	* lra-eliminations.c (lra_eliminate_regs_1): Adjust fall through
	comment.
	* lto-streamer-out.c (lto_output_tree_ref): Add FALLTHRU.
	* opts.c (common_handle_option): Likewise.
	* read-rtl.c (read_rtx_code): Likewise.
	* real.c (round_for_format): Likewise.
	* recog.c (asm_operand_ok): Likewise.
	* reginfo.c (reg_scan_mark_refs): Adjust fall through comment.
	* reload1.c (set_label_offsets): Likewise.
	(eliminate_regs_1): Likewise.
	(reload_reg_reaches_end_p): Likewise.
	* rtlanal.c (commutative_operand_precedence): Add FALLTHRU.
	(rtx_cost): Likewise.
	* sched-rgn.c (is_exception_free): Likewise.
	* simplify-rtx.c (simplify_rtx): Adjust fall through comment.
	* stor-layout.c (int_mode_for_mode): Likewise.
	* toplev.c (print_to_asm_out_file): Likewise.
	(print_to_stderr): Likewise.
	* tree-cfg.c (gimple_verify_flow_info): Likewise.
	* tree-chrec.c (chrec_fold_plus_1): Add FALLTHRU.
	(chrec_fold_multiply): Likewise.
	(evolution_function_is_invariant_rec_p): Likewise.
	(for_each_scev_op): Likewise.
	* tree-data-ref.c (siv_subscript_p): Likewise.
	(get_references_in_stmt): Likewise.
	* tree.c (find_placeholder_in_expr): Adjust fall through comment.
	(substitute_in_expr): Likewise.
	(type_cache_hasher::equal): Likewise.
	(walk_type_fields): Likewise.
	* var-tracking.c (adjust_mems): Add FALLTHRU.
	(set_dv_changed): Adjust fall through comment.
	* varasm.c (default_function_section): Add FALLTHRU.
gcc/c-family/
	* c-common.c (scalar_to_vector): Adjust fall through comment.
	* c-opts.c (c_common_handle_option): Likewise.
	* c-pragma.c (handle_pragma_pack): Add FALLTHRU.
	* c-pretty-print.c (c_pretty_printer::postfix_expression): Adjust
	fall through comment.
	* cilk.c (extract_free_variables): Add FALLTHRU.
gcc/c/
	* c-parser.c (c_parser_external_declaration): Add FALLTHRU.
	(c_parser_postfix_expression): Likewise.
	* c-typeck.c (build_unary_op): Adjust fall through comment.
	(c_mark_addressable): Likewise.
gcc/cp/
	* call.c (add_builtin_candidate): Add FALLTHRU.
	(build_integral_nontype_arg_conv): Adjust fall through comment.
	(build_new_op_1): Add FALLTHRU.
	(convert_like_real): Adjust fall through comment.
	* class.c (fixed_type_or_null): Likewise.
	* constexpr.c (cxx_eval_constant_expression): Likewise.
	(potential_constant_expression_1): Likewise.  Add FALLTHRU.
	* cp-gimplify.c (cp_gimplify_expr): Adjust fall through comment.
	(cp_fold): Add FALLTHRU.
	* cvt.c (build_expr_type_conversion): Adjust fall through comment.
	* cxx-pretty-print.c (pp_cxx_unqualified_id): Add FALLTHRU.
	(pp_cxx_qualified_id): Likewise.
	(cxx_pretty_printer::constant): Adjust fall through comment.
	(cxx_pretty_printer::primary_expression): Add FALLTHRU.
	(pp_cxx_pm_expression): Adjust fall through comment.
	(cxx_pretty_printer::expression): Add FALLTHRU.
	(cxx_pretty_printer::declaration_specifiers): Reformat code.
	(pp_cxx_type_specifier_seq): Adjust fall through comment.
	(pp_cxx_ptr_operator): Likewise.  Add FALLTHRU.
	* error.c (dump_type): Adjust fall through comment.
	(dump_decl): Likewise.
	* mangle.c (write_type): Likewise.
	* method.c (synthesized_method_walk): Add FALLTHRU.
	* name-lookup.c (arg_assoc_type): Likewise.
	* parser.c (cp_lexer_print_token): Adjust fall through comment.
	(cp_parser_primary_expression): Add FALLTHRU.
	(cp_parser_operator): Likewise.
	* pt.c (find_parameter_packs_r): Likewise.
	(tsubst_aggr_type): Adjust fall through comment.
	* semantics.c (finish_omp_clauses): Add FALLTHRU.
	* tree.c (lvalue_kind): Likewise.
gcc/fortran/
	* decl.c (match_attr_spec): Add FALLTHRU.
	* primary.c (match_arg_list_function): Likewise.
	* resolve.c (resolve_operator): Adjust fall through comment.
	(fixup_charlen): Add FALLTHRU.
	(resolve_allocate_expr): Adjust fall through comment.
	* trans-array.c (gfc_conv_ss_startstride): Add FALLTHRU.
	* trans-intrinsic.c (gfc_conv_intrinsic_len): Adjust fall through
	comment.
gcc/java/
	* expr.c (java_truthvalue_conversion): Adjust fall through comment.
	* jcf-io.c (verify_constant_pool): Likewise.
	* typeck.c (promote_type): Likewise.
gcc/objc/
	* objc-encoding.c (encode_type): Add FALLTHRU.
libcpp/
	* lex.c (search_line_fast): Add FALLTHRU.
	(_cpp_lex_direct): Likewise.
	(cpp_token_val_index): Adjust fall through comment.
	* macro.c (parse_params): Add FALLTHRU.
	* pch.c (count_defs): Adjust fall through comment.
	(write_defs): Likewise.
libiberty/
	* cp-demangle.c (d_print_mod): Add FALLTHRU.

From-SVN: r239410
2016-08-12 10:30:47 +00:00
David Malcolm e7864d68ee Fix crash in selftest::test_lexer_string_locations_ucn4 (PR bootstrap/72823)
libcpp/ChangeLog:
	PR bootstrap/72823
	* charset.c (_cpp_valid_ucn): Replace overzealous assert with one
	that allows for char_range to be non-NULL when loc_reader is NULL.

From-SVN: r239211
2016-08-06 18:06:30 +00:00
David Malcolm 88fa5555a3 On-demand locations within string-literals
gcc/c-family/ChangeLog:
	* c-common.c: Include "substring-locations.h".
	(get_cpp_ttype_from_string_type): New function.
	(g_string_concat_db): New global.
	(substring_loc::get_range): New method.
	* c-common.h (g_string_concat_db): New declaration.
	(class substring_loc): New class.
	* c-lex.c (lex_string): When concatenating strings, capture the
	locations of all tokens using a new obstack, and record the
	concatenation locations within g_string_concat_db.
	* c-opts.c (c_common_init_options): Construct g_string_concat_db
	on the ggc-heap.

gcc/ChangeLog:
	* input.c (string_concat::string_concat): New constructor.
	(string_concat_db::string_concat_db): New constructor.
	(string_concat_db::record_string_concatenation): New method.
	(string_concat_db::get_string_concatenation): New method.
	(string_concat_db::get_key_loc): New method.
	(class auto_cpp_string_vec): New class.
	(get_substring_ranges_for_loc): New function.
	(get_source_range_for_substring): New function.
	(get_num_source_ranges_for_substring): New function.
	(class selftest::lexer_test_options): New class.
	(struct selftest::lexer_test): New struct.
	(class selftest::ebcdic_execution_charset): New class.
	(selftest::ebcdic_execution_charset::s_singleton): New variable.
	(selftest::lexer_test::lexer_test): New constructor.
	(selftest::lexer_test::~lexer_test): New destructor.
	(selftest::lexer_test::get_token): New method.
	(selftest::assert_char_at_range): New function.
	(ASSERT_CHAR_AT_RANGE): New macro.
	(selftest::assert_num_substring_ranges): New function.
	(ASSERT_NUM_SUBSTRING_RANGES): New macro.
	(selftest::assert_has_no_substring_ranges): New function.
	(ASSERT_HAS_NO_SUBSTRING_RANGES): New macro.
	(selftest::test_lexer_string_locations_simple): New function.
	(selftest::test_lexer_string_locations_ebcdic): New function.
	(selftest::test_lexer_string_locations_hex): New function.
	(selftest::test_lexer_string_locations_oct): New function.
	(selftest::test_lexer_string_locations_letter_escape_1): New function.
	(selftest::test_lexer_string_locations_letter_escape_2): New function.
	(selftest::test_lexer_string_locations_ucn4): New function.
	(selftest::test_lexer_string_locations_ucn8): New function.
	(selftest::uint32_from_big_endian): New function.
	(selftest::test_lexer_string_locations_wide_string): New function.
	(selftest::uint16_from_big_endian): New function.
	(selftest::test_lexer_string_locations_string16): New function.
	(selftest::test_lexer_string_locations_string32): New function.
	(selftest::test_lexer_string_locations_u8): New function.
	(selftest::test_lexer_string_locations_utf8_source): New function.
	(selftest::test_lexer_string_locations_concatenation_1): New
	function.
	(selftest::test_lexer_string_locations_concatenation_2): New
	function.
	(selftest::test_lexer_string_locations_concatenation_3): New
	function.
	(selftest::test_lexer_string_locations_macro): New function.
	(selftest::test_lexer_string_locations_stringified_macro_argument):
	New function.
	(selftest::test_lexer_string_locations_non_string): New function.
	(selftest::test_lexer_string_locations_long_line): New function.
	(selftest::test_lexer_char_constants): New function.
	(selftest::input_c_tests): Call the new test functions once per
	case within the line_table test matrix.
	* input.h (struct string_concat): New struct.
	(struct location_hash): New struct.
	(class string_concat_db): New class.
	* substring-locations.h: New header.

gcc/testsuite/ChangeLog:
	* gcc.dg/plugin/diagnostic-test-string-literals-1.c: New file.
	* gcc.dg/plugin/diagnostic-test-string-literals-2.c: New file.
	* gcc.dg/plugin/diagnostic_plugin_test_string_literals.c: New file.
	* gcc.dg/plugin/plugin.exp (plugin_test_list): Add the above new files.

libcpp/ChangeLog:
	* charset.c (cpp_substring_ranges::cpp_substring_ranges): New
	constructor.
	(cpp_substring_ranges::~cpp_substring_ranges): New destructor.
	(cpp_substring_ranges::add_range): New method.
	(cpp_substring_ranges::add_n_ranges): New method.
	(_cpp_valid_ucn): Add "char_range" and "loc_reader" params; if
	they are non-NULL, read position information from *loc_reader
	and update char_range->m_finish accordingly.
	(convert_ucn): Add "char_range", "loc_reader", and "ranges"
	params.  If loc_reader is non-NULL, read location information from
	it, and update *ranges accordingly, using char_range.
	Conditionalize the conversion into tbuf on tbuf being non-NULL.
	(convert_hex): Likewise, conditionalizing the call to
	emit_numeric_escape on tbuf.
	(convert_oct): Likewise.
	(convert_escape): Add params "loc_reader" and "ranges".  If
	loc_reader is non-NULL, read location information from it, and
	update *ranges accordingly.  Conditionalize the conversion into
	tbuf on tbuf being non-NULL.
	(cpp_interpret_string): Rename to...
	(cpp_interpret_string_1): ...this, adding params "loc_readers" and
	"out".  Use "to" to conditionalize the initialization and usage of
	"tbuf", such as running the converter.  If "loc_readers" is
	non-NULL, use the instances within it, reading location
	information from them, and passing them to convert_escape; likewise
	write to "out" if loc_readers is non-NULL.  Check for leading
	quote and issue an error if it is not present.  Update boundary
	check from "== limit" to ">= limit" to protect against erroneous
	location values to calls that are not parsing string literals.
	(cpp_interpret_string): Reimplement in terms to
	cpp_interpret_string_1.
	(noop_error_cb): New function.
	(cpp_interpret_string_ranges): New function.
	(cpp_string_location_reader::cpp_string_location_reader): New
	constructor.
	(cpp_string_location_reader::get_next): New method.
	* include/cpplib.h (class cpp_string_location_reader): New class.
	(class cpp_substring_ranges): New class.
	(cpp_interpret_string_ranges): New prototype.
	* internal.h (_cpp_valid_ucn): Add params "char_range" and
	"loc_reader".
	* lex.c (forms_identifier_p): Pass NULL for new params to
	_cpp_valid_ucn.

From-SVN: r239175
2016-08-05 18:08:33 +00:00
Andreas Schwab 8204be6c83 * include/cpplib.h: Fix comment typo.
From-SVN: r238951
2016-08-01 12:45:32 +00:00
David Malcolm a01fc54920 Move make_location from tree.h/c to input.h/c
For some reason I added make_location and some related functions to
tree.h/c, rather than to input.h/c.  Move them there, so we can use them
without requiring tree, and add some selftest coverage.

gcc/ChangeLog:
	* input.c (get_pure_location): Move here from tree.c.
	(make_location): Likewise.  Add header comment.
	(selftest::test_accessing_ordinary_linemaps): Verify
	pure_location_p, make_location, get_location_from_adhoc_loc and
	get_range_from_loc.
	* input.h (get_pure_location): Move declaration here from tree.h.
	(get_finish): Likewise for inline function.
	(make_location): Likewise for declaration.
	* tree.c (get_pure_location): Move to input.c.
	(make_location): Likewise.
	* tree.h (get_pure_location): Move declaration to tree.h.
	(get_finish): Likewise for inline function.
	(make_location): Likewise for declaration.

libcpp/ChangeLog:
	* include/line-map.h (source_location): Fix line numbers in
	comment.

From-SVN: r238792
2016-07-27 17:21:20 +00:00
David Malcolm 741d3be543 input.c: add lexing selftests and a test matrix for line_table states
This patch adds explicit testing of lexing a source file,
generalizing this (and the test of ordinary line maps) over
a 2-dimensional test matrix covering:

  (1) line_table->default_range_bits: some frontends use a non-zero value
  and others use zero

  (2) the fallback modes within line-map.c: there are various threshold
  values for source_location/location_t beyond line-map.c changes
  behavior (disabling of the range-packing optimization, disabling
  of column-tracking).  We exercise these by starting the line_table
  at interesting values at or near these thresholds.

This helps ensures that location data works in all of these states,
and that (I hope) we don't have lingering bugs relating to the
transition between line_table states.

gcc/ChangeLog:
	* input.c: Include cpplib.h.
	(selftest::temp_source_file): New class.
	(selftest::temp_source_file::temp_source_file): New ctor.
	(selftest::temp_source_file::~temp_source_file): New dtor.
	(selftest::should_have_column_data_p): New function.
	(selftest::test_should_have_column_data_p): New function.
	(selftest::temp_line_table): New class.
	(selftest::temp_line_table::temp_line_table): New ctor.
	(selftest::temp_line_table::~temp_line_table): New dtor.
	(selftest::test_accessing_ordinary_linemaps): Add case_ param; use
	it to create a temp_line_table.
	(selftest::assert_loceq): Only verify LOCATION_COLUMN for
	locations that are known to have column data.
	(selftest::line_table_case): New struct.
	(selftest::test_reading_source_line): Move tempfile handling
	to class temp_source_file.
	(ASSERT_TOKEN_AS_TEXT_EQ): New macro.
	(selftest::assert_token_loc_eq): New function.
	(ASSERT_TOKEN_LOC_EQ): New macro.
	(selftest::test_lexer): New function.
	(selftest::boundary_locations): New array.
	(selftest::input_c_tests): Call test_should_have_column_data_p.
	Loop over a test matrix of interesting values of location and
	default_range_bits, calling test_lexer on each case in the matrix.
	Move call to test_accessing_ordinary_linemaps into the matrix.
	* selftest.h (ASSERT_EQ): Reimplement in terms of...
	(ASSERT_EQ_AT): New macro.

gcc/testsuite/ChangeLog:
	* gcc.dg/plugin/location_overflow_plugin.c (plugin_init): Avoid
	hardcoding the values of LINE_MAP_MAX_LOCATION_WITH_PACKED_RANGES
	and LINE_MAP_MAX_LOCATION_WITH_COLS.

libcpp/ChangeLog:
	* include/line-map.h (LINE_MAP_MAX_LOCATION_WITH_PACKED_RANGES):
	Move here from line-map.c.
	(LINE_MAP_MAX_LOCATION_WITH_COLS): Likewise.
	* line-map.c (LINE_MAP_MAX_LOCATION_WITH_PACKED_RANGES): Move from
	here to line-map.h.
	(LINE_MAP_MAX_LOCATION_WITH_COLS): Likewise.

From-SVN: r238213
2016-07-11 16:02:20 +00:00
David Malcolm ac81cf0b2b libcpp: Tweak to missing #include source location
This patch tweaks the error message location for missing header files.

Previously these read:

test.c:1:17: fatal error: 404.h: No such file or directory
 #include "404.h"
                 ^
compilation terminated.

With this patch, the pertinent string is underlined:

test.c:1:10: fatal error: 404.h: No such file or directory
 #include "404.h"
          ^~~~~~~
compilation terminated.

gcc/testsuite/ChangeLog:
	* c-c++-common/missing-header-1.c: New test case.
	* c-c++-common/missing-header-2.c: New test case.
	* c-c++-common/missing-header-3.c: New test case.
	* c-c++-common/missing-header-4.c: New test case.

libcpp/ChangeLog:
	* directives.c (do_include_common): Pass on "location" to
	_cpp_stack_include.
	* errors.c (cpp_diagnostic): Reimplement in terms of...
	(cpp_diagnostic_at): New function.
	(cpp_error_at): New function.
	(cpp_errno_filename): Add "loc" param and use it by using
	cpp_error_at rather than cpp_error.
	* files.c (find_file_in_dir): Add "loc" param and pass it to
	open_file_failed.
	(_cpp_find_file): Add "loc" param.  Use it to convert calls to
	cpp_error to cpp_error_at, and pass it to find_file_in_dir and
	open_file_failed.
	(read_file_guts): Add "loc" param.  Use it to convert calls to
	cpp_error to cpp_error_at.  Pass it to cpp_errno_filename.
	(read_file): Add "loc" param.  Pass it to open_file_failed and
	read_file_guts.
	(should_stack_file): Add "loc" param.  Pass it to read_file.
	(_cpp_stack_file): Add "loc" param.  Pass it to should_stack_file.
	(_cpp_stack_include): Add "loc" param.  Pass it to
	_cpp_find_file and _cpp_stack_file.
	(open_file_failed): Add "loc" param.  Pass it to
	cpp_errno_filename.
	(_cpp_fake_include): Add 0 as a source_location in call to
	_cpp_find_file.
	(_cpp_compare_file_date): Likewise.
	(cpp_push_include): Likewise for call to _cpp_stack_include.
	(cpp_push_default_include): Likewise.
	(_cpp_save_file_entries): Likewise for call to open_file_failed.
	(_cpp_has_header): Likewise for call to _cpp_find_file.
	* include/cpplib.h (cpp_errno_filename): Add source_location
	param.
	(cpp_error_at): New declaration.
	* init.c (cpp_read_main_file): Add 0 as a source_location in calls
	to _cpp_find_file and _cpp_stack_file.
	* internal.h (_cpp_find_file): Add source_location param.
	(_cpp_stack_file): Likewise.
	(_cpp_stack_include): Likewise.

From-SVN: r237715
2016-06-22 15:29:21 +00:00
David Malcolm a93eac6a84 Implement -fdiagnostics-parseable-fixits
gcc/ChangeLog:
	* common.opt (fdiagnostics-parseable-fixits): New option.
	* diagnostic.c: Include "selftest.h".
	(print_escaped_string): New function.
	(print_parseable_fixits): New function.
	(diagnostic_report_diagnostic): Call print_parseable_fixits.
	(selftest::assert_print_escaped_string): New function.
	(ASSERT_PRINT_ESCAPED_STRING_STREQ): New macro.
	(selftest::test_print_escaped_string): New function.
	(selftest::test_print_parseable_fixits_none): New function.
	(selftest::test_print_parseable_fixits_insert): New function.
	(selftest::test_print_parseable_fixits_remove): New function.
	(selftest::test_print_parseable_fixits_replace): New function.
	(selftest::diagnostic_c_tests): New function.
	* diagnostic.h (struct diagnostic_context): Add field
	"parseable_fixits_p".
	* doc/invoke.texi (Diagnostic Message Formatting Options): Add
	-fdiagnostics-parseable-fixits.
	(-fdiagnostics-parseable-fixits): New option.
	* opts.c (common_handle_option): Handle
	-fdiagnostics-parseable-fixits.
	* selftest-run-tests.c (selftest::run_tests): Call
	selftest::diagnostic_c_tests.
	* selftest.h (selftest::diagnostic_c_tests): New prototype.

gcc/testsuite/ChangeLog:
	* gcc.dg/plugin/diagnostic-test-show-locus-parseable-fixits.c: New
	file.
	* gcc.dg/plugin/plugin.exp (plugin_test_list): Add
	diagnostic-test-show-locus-parseable-fixits.c to sources for
	diagnostic_plugin_test_show_locus.c.
	* lib/gcc-defs.exp (freeform_regexps): New global.
	(dg-regexp): New function.
	(handle-dg-regexps): New function.
	* lib/gcc-dg.exp (cleanup-after-saved-dg-test): Reset
	freeform_regexps to the empty list.
	* lib/prune.exp (prune_gcc_output): Call handle-dg-regexps.

libcpp/ChangeLog:
	* include/line-map.h (fixit_hint::get_start_loc): New pure virtual
	function.
	(fixit_hint::maybe_get_end_loc): Likewise.
	(fixit_insert::get_start_loc): New function, implementing
	fixit_hint::get_start_loc.
	(fixit_insert::maybe_get_end_loc): New function, implementing
	fixit_hint::maybe_get_end_loc.
	(fixit_remove::get_start_loc): New function, implementing
	fixit_hint::get_start_loc.
	(fixit_remove::maybe_get_end_loc): New function, implementing
	fixit_hint::maybe_get_end_loc.
	(fixit_replace::get_start_loc): New function, implementing
	fixit_hint::get_start_loc.
	(fixit_replace::maybe_get_end_loc): New function, implementing
	fixit_hint::maybe_get_end_loc.

From-SVN: r237712
2016-06-22 14:42:30 +00:00
John David Anglin fe55692cb3 c-common.c (get_source_date_epoch): Use int64_t instead of long long.
* c-common.c (get_source_date_epoch): Use int64_t instead of long long.

	* gcov-tool.c (profile_rewrite): Use int64_t instead of long long.
	(do_rewrite): likewise.

	* line-map.c (location_adhoc_data_update): Use int64_t instead of
	long long.
	(get_combined_adhoc_loc): Likewise.

From-SVN: r237676
2016-06-22 01:46:06 +00:00
Eduard Sanou 15c98b2e0d c-common.c (get_source_date_epoch): Rename to cb_get_source_date_epoch.
gcc/c-family/ChangeLog:

2016-05-13  Eduard Sanou  <dhole@openmailbox.org>

	* c-common.c (get_source_date_epoch): Rename to
	cb_get_source_date_epoch.
	* c-common.c (cb_get_source_date_epoch): Use a single generic erorr
	message when the parsing fails.  Use error_at instead of fatal_error.
	* c-common.h (get_source_date_epoch): Rename to
	cb_get_source_date_epoch.
	* c-common.h (cb_get_source_date_epoch): Prototype.
	* c-common.h (MAX_SOURCE_DATE_EPOCH): Define.
	* c-common.h (c_omp_region_type): Remove trailing comma.
	* c-lex.c (init_c_lex): Set cb->get_source_date_epoch callback.
	* c-lex.c (c_lex_with_flags): Remove initialization of
	pfile->source_date_epoch.

gcc/ChangeLog:

2016-05-13  Eduard Sanou  <dhole@openmailbox.org>

	* doc/cppenv.texi: Note that the `%s` in `date` is a non-standard
	extension.
	* gcc.c (driver_handle_option): Call set_source_date_epoch_envvar.
	* gcc.c (set_source_date_epoch_envvar): New function, sets
	the SOURCE_DATE_EPOCH environment variable to the current time.

gcc/testsuite/ChangeLog:

2016-05-13  Eduard Sanou  <dhole@openmailbox.org>

	* gcc.dg/cpp/source_date_epoch-1.c: New file, test the proper
	behaviour of the macros __DATE__ and __TIME__ when SOURCE_DATE_EPOCH
	env var is set.
	* gcc.dg/cpp/source_date_epoch-2.c: New file, test the error output
	when parsing the SOURCE_DATE_EPOCH env var, and make sure it is only
	shown once.
	* lib/gcc-dg.exp (dg-set-compiler-env-var): New function, set env vars
	during compilation.
	* lib/gcc-dg.exp (restore-compiler-env-var): New function, restore env
	vars set by dg-set-compiler-env-var.

libcpp/ChangeLog:

2016-05-13  Eduard Sanou  <dhole@openmailbox.org>

	* include/cpplib.h (cpp_callbacks): Add get_source_date_epoch
	callback.
	* include/cpplib.h (cpp_init_source_date_epoch): Remove prototype.
	* init.c (cpp_init_source_date_epoch): Remove function.
	* init.c (cpp_create_reader): Initialize pfile->source_date_epoch.
	* internal.h (cpp_reader): Extend comment about source_date_epoch.
	* macro.c (_cpp_builtin_macro_text): Use get_source_date_epoch
	callback only once, read pfile->source_date_epoch on future passes.
	Check that get_source_date_epoch callback is not NULL.

From-SVN: r237001
2016-06-01 16:42:41 +00:00
Martin Liska ceb17928e5 Change ENABLE_VALGRIND_CHECKING to
* config.in: Regenerated.
	* configure: Likewise.
	* configure.ac: Handle --enable-valgrind-annotations.
	* lex.c (new_buff): Use ENABLE_VALGRIND_ANNOTATIONS instead
	of ENABLE_VALGRIND_CHECKING.
	(_cpp_free_buff): Likewise.

From-SVN: r236496
2016-05-20 08:03:25 +00:00