Commit Graph

558 Commits

Author SHA1 Message Date
Tom de Vries c830c7d5c7 [libcpp] Remove semicolon after do {} while (0) in BUF_APPEND
2017-11-05  Tom de Vries  <tom@codesourcery.com>

	PR other/82784
	* lex.c (BUF_APPEND): Remove semicolon after
	"do {} while (0)".

From-SVN: r254424
2017-11-05 09:58:16 +00:00
David Malcolm 64a5912c9e diagnostics: get rid of *_at_rich_loc in favor of overloading
Adding a fix-it hint currently involves changing e.g.:

  error_at (token->location,
            "unknown type name %qE; did you mean %qs?",
            token->value, hint);
to:

  gcc_rich_location richloc (token->location);
  richloc.add_fixit_replace (hint);
  error_at_rich_loc (&richloc,
                     "unknown type name %qE; did you mean %qs?",
                     token->value, hint);

to make the change from taking a location_t to a rich_location *.

This patch renames the "*_at_rich_loc" diagnostic entrypoints to use
the same function names for rich_location * as for location_t,
via overloading, to simplify the above change to just changing from:

  error_at (token->location,
            "unknown type name %qE; did you mean %qs?",
            token->value, hint);
to:

  gcc_rich_location richloc (token->location);
  richloc.add_fixit_replace (hint);
  error_at (&richloc,
            "unknown type name %qE; did you mean %qs?",
            token->value, hint);

thus saving space (and typing) and usually avoiding the need to reindent
the "error_at" invocation.

With this change, 0 is no longer acceptable as a location_t to these
entrypoints, as e.g.:

../../src/gcc/auto-profile.c:855:37: error: call of overloaded
'inform(int, const char [18])' is ambiguous
       inform (0, "Not expected TAG.");
                                     ^
In file included from ../../src/gcc/auto-profile.c:35:0:
../../src/gcc/diagnostic-core.h:88:13: note: candidate:
'void inform(location_t, const char*, ...)'
 extern void inform (location_t, const char *, ...) ATTRIBUTE_GCC_DIAG(2,3);
             ^~~~~~
../../src/gcc/diagnostic-core.h:89:13: note: candidate:
'void inform(rich_location*, const char*, ...)'
 extern void inform (rich_location *, const char *, ...) ATTRIBUTE_GCC_DIAG(2,3);
             ^~~~~~

Such locations now need to be spelled out as UNKNOWN_LOCATION,
rather than 0.

I considered making the API take a rich_location & rather than a
rich_location *, but doing so would mean replacing
  diagnostic_set_info
and
  diagnostic_set_info_translated
with a constructor for diagnostic_info, which was a more invasive
change.  Maybe in the future.

gcc/ChangeLog:
	* auto-profile.c (autofdo_source_profile::read): Use
	UNKNOWN_LOCATION rather than 0.
	* diagnostic-core.h (warning_at_rich_loc): Rename to...
	(warning_at): ...this overload.
	(warning_at_rich_loc_n): Rename to...
	(warning_n): ...this overload.
	(error_at_rich_loc): Rename to...
	(error_at): ...this overload.
	(pedwarn_at_rich_loc): Rename to...
	(pedwarn): ...this overload.
	(permerror_at_rich_loc): Rename to...
	(permerror): ...this overload.
	(inform_at_rich_loc): Rename to...
	(inform): ...this overload.
	* diagnostic.c: (diagnostic_n_impl): Delete location_t-based decl.
	(diagnostic_n_impl_richloc): Rename to...
	(diagnostic_n_impl): ...this rich_location *-based decl.
	(inform_at_rich_loc): Rename to...
	(inform): ...this, and add an assertion.
	(inform_n): Update for removal of location_t-based diagnostic_n_impl.
	(warning_at_rich_loc): Rename to...
	(warning_at): ...this, and add an assertion.
	(warning_at_rich_loc_n): Rename to...
	(warning_n): ...this, and add an assertion.
	(warning_n): Update location_t-based implementation for removal of
	location_t-based diagnostic_n_impl.
	(pedwarn_at_rich_loc): Rename to...
	(pedwarn): ...this, and add an assertion.
	(permerror_at_rich_loc): Rename to...
	(permerror): ...this, and add an assertion.
	(error_n): Update for removal of location_t-based diagnostic_n_impl.
	(error_at_rich_loc): Rename to...
	(error_at): ...this, and add an assertion.
	* gcc.c (do_spec_1): Use UNKNOWN_LOCATION rather than 0.
	(driver::do_spec_on_infiles): Likewise.
	* substring-locations.c (format_warning_va): Update for renaming
	of inform_at_rich_loc.

gcc/c-family/ChangeLog:
	* c-common.c (binary_op_error): Update for renaming of
	error_at_rich_loc.
	(c_parse_error): Likewise.
	* c-warn.c (warn_logical_not_parentheses): Likewise for
	renaming of inform_at_rich_loc.
	(warn_for_restrict): Likewise for renaming of
	warning_at_rich_loc_n.

gcc/c/ChangeLog:
	* c-decl.c (implicit_decl_warning): Update for renaming of
	pedwarn_at_rich_loc and warning_at_rich_loc.
	(implicitly_declare): Likewise for renaming of inform_at_rich_loc.
	(undeclared_variable): Likewise for renaming of error_at_rich_loc.
	* c-parser.c (c_parser_declaration_or_fndef): Likewise.
	(c_parser_struct_or_union_specifier): Likewise for renaming of
	pedwarn_at_rich_loc.
	(c_parser_parameter_declaration): Likewise for renaming of
	error_at_rich_loc.
	* c-typeck.c (build_component_ref): Likewise.
	(build_unary_op): Likewise for renaming of inform_at_rich_loc.
	(pop_init_level): Likewise for renaming of warning_at_rich_loc.
	(set_init_label): Likewise for renaming of error_at_rich_loc.

gcc/cp/ChangeLog:
	* class.c (explain_non_literal_class): Use UNKNOWN_LOCATION rather
	than 0.
	* name-lookup.c (suggest_alternatives_for): Update for renaming of
	inform_at_rich_loc.
	(maybe_suggest_missing_header): Likewise.
	(suggest_alternative_in_explicit_scope): Likewise.
	* parser.c (cp_parser_diagnose_invalid_type_name): Likewise for
	renaming of error_at_rich_loc.
	(cp_parser_string_literal): Likewise.
	(cp_parser_nested_name_specifier_opt): Likewise.
	(cp_parser_cast_expression): Likewise for renaming of
	warning_at_rich_loc.
	(cp_parser_decl_specifier_seq): Likewise for renaming of
	error_at_rich_loc and warning_at_rich_loc.
	(cp_parser_elaborated_type_specifier): Likewise for renaming of
	pedwarn_at_rich_loc.
	(cp_parser_cv_qualifier_seq_opt): Likewise for renaming of
	error_at_rich_loc.
	(cp_parser_virt_specifier_seq_opt): Likewise.
	(cp_parser_class_specifier_1): Likewise.
	(cp_parser_class_head): Likewise.
	(cp_parser_member_declaration): Likewise for renaming of
	pedwarn_at_rich_loc, warning_at_rich_loc, and error_at_rich_loc.
	(cp_parser_enclosed_template_argument_list): Likewise for renaming
	of error_at_rich_loc.
	(set_and_check_decl_spec_loc): Likewise.
	* pt.c (listify): Likewise.
	* rtti.c (typeid_ok_p): Likewise.
	* semantics.c (process_outer_var_ref): Use UNKNOWN_LOCATION rather
	than 0.
	* typeck.c (access_failure_info::maybe_suggest_accessor): Update
	for renaming of inform_at_rich_loc.
	(finish_class_member_access_expr): Likewise for renaming of
	error_at_rich_loc.

gcc/objc/ChangeLog:
	* objc-gnu-runtime-abi-01.c (objc_gnu_runtime_abi_01_init): Use
	UNKNOWN_LOCATION rather than 0.

gcc/testsuite/ChangeLog:
	* gcc.dg/plugin/diagnostic_plugin_show_trees.c (show_tree): Update
	for renaming of error_at_rich_loc and inform_at_rich_loc.
	* gcc.dg/plugin/diagnostic_plugin_test_show_locus.c
	(test_show_locus): Likewise for renaming of warning_at_rich_loc.

libcpp/ChangeLog:
	* directives.c (_cpp_handle_directive): Update for renaming of
	cpp_error_at_richloc to cpp_error_at.
	* errors.c (cpp_diagnostic_at_richloc): Rename to...
	(cpp_diagnostic_at): ...this, dropping the location_t-based
	implementation.
	(cpp_diagnostic): Update for removal of location_t-based
	cpp_diagnostic_at.
	(cpp_error_at): Likewise.
	(cpp_error_at_richloc): Rename to...
	(cpp_error_at): ...this, and update for renaming of
	cpp_diagnostic_at_richloc.
	* include/cpplib.h (cpp_error_at_richloc): Rename to...
	(cpp_error_at): ...this.

From-SVN: r254280
2017-10-31 20:21:58 +00:00
Joseph Myers c76dc9c32d Add -std=c17, -std=gnu17.
C17, a bug-fix version of the C11 standard with DR resolutions
integrated, will soon go to ballot.  This patch adds corresponding
options -std=c17, -std=gnu17 (new default version, replacing
-std=gnu11 as the default), -std=iso9899:2017.  As a bug-fix version
of the standard, there is no need for flag_isoc17 or any options for
compatibility warnings; however, there is a new __STDC_VERSION__
value, so new cpplib languages CLK_GNUC17 and CLK_STDC17 are added to
support using that new value with the new options.  (If the standard
ends up being published in 2018 and being known as C18, option aliases
can be added.  Note however that -std=iso9899:199409 corresponds to a
__STDC_VERSION__ value rather than a publication date.)

(There are a couple of DR resolutions needing implementing in GCC, but
that's independent of the new options.)

(I'd propose to add -std=c2x / -std=gnu2x / -Wc11-c2x-compat for the
next major C standard revision once there are actually C2x drafts
being issued with new features included.)

Bootstrapped with no regressions for x86_64-pc-linux-gnu.

gcc:
	* doc/invoke.texi (C Dialect Options): Document -std=c17,
	-std=iso9899:2017 and -std=gnu17.
	* doc/standards.texi (C Language): Document C17 support.
	* doc/cpp.texi (Overview): Mention -std=c17.
	(Standard Predefined Macros): Document C11 and C17 values of
	__STDC_VERSION__.  Do not refer to C99 support as incomplete.
	* doc/extend.texi (Inline): Do not list individual options for
	standards newer than C99.
	* dwarf2out.c (highest_c_language, gen_compile_unit_die): Handle
	"GNU C17".
	* config/rl78/rl78.c (rl78_option_override): Handle "GNU C17"
	language name.

gcc/c-family:
	* c.opt (std=c17, std=gnu17, std=iso9899:2017): New options.
	* c-opts.c (set_std_c17): New function.
	(c_common_init_options): Use gnu17 as default C version.
	(c_common_handle_option): Handle -std=c17 and -std=gnu17.

gcc/testsuite:
	* gcc.dg/c17-version-1.c, gcc.dg/c17-version-2.c: New tests.

libcpp:
	* include/cpplib.h (enum c_lang): Add CLK_GNUC17 and CLK_STDC17.
	* init.c (lang_defaults): Add GNUC17 and STDC17 data.
	(cpp_init_builtins): Handle C17 value of __STDC_VERSION__.

From-SVN: r254216
2017-10-30 12:17:40 +00:00
Nathan Sidwell 35b82d26e5 [PATCH] preprocessor stringizing raw strings
https://gcc.gnu.org/ml/gcc-patches/2017-10/msg00611.html
	libcpp/
	PR preprocessor/82506
	* macro.c (cpp_quote_string): Escape raw LFs.

	gcc/testsuite/
	PR preprocessor/82506
	* g++.dg/cpp/string-3.C: New.

From-SVN: r253605
2017-10-10 18:56:31 +00:00
Andrew Sutton 026a79f70c Add support for -std=c++2a.
* c-common.h (cxx_dialect): Add cxx2a as a dialect.
	* opt.c: Add options for -std=c++2a and -std=gnu++2a.
	* c-opts.c (set_std_cxx2a): New.
	(c_common_handle_option): Set options when -std=c++2a is enabled.
	(c_common_post_options): Adjust comments.
	(set_std_cxx14, set_std_cxx17): Likewise.

	* doc/cpp.texi (__cplusplus): Document value for -std=c++2a
	or -std=gnu+2a.
	* doc/invoke.texi: Document -std=c++2a and -std=gnu++2a.

	* lib/target-supports.exp (check_effective_target_c++17): Return
	1 also if check_effective_target_c++2a.
	(check_effective_target_c++17_down): New.
	(check_effective_target_c++2a_only): New.
	(check_effective_target_c++2a): New.
	* g++.dg/cpp2a/cplusplus.C: New.

	* include/cpplib.h (c_lang): Add CXX2A and GNUCXX2A.
	* init.c (lang_defaults): Add rows for CXX2A and GNUCXX2A.
	(cpp_init_builtins): Set __cplusplus to 201709L for C++2a.

Co-Authored-By: Jakub Jelinek <jakub@redhat.com>

From-SVN: r252850
2017-09-15 23:16:37 +02:00
Jakub Jelinek 7b9361409d invoke.texi: Document -std=c++17 and -std=gnu++17 and document c++1z and gnu++1z as deprecated.
* doc/invoke.texi: Document -std=c++17 and -std=gnu++17 and document
	c++1z and gnu++1z as deprecated.  Change other references to
	-std=c++1z to -std=c++17 and -std=gnu++1z to -std=gnu++17.
	Change -Wc++1z-compat to -Wc++17-compat.
	* doc/cpp.texi: Document -std=c++17 defines __cplusplus 201703L.
	* dwarf2out.c (highest_c_language): Handle C++17.
	(gen_compile_unit_die): Likewise.
c-family/
	* c.opt (Wc++1z-compat): Change from option to undocumented alias.
	(Wc++17-compat): Change from undocumented alias to option.
	(Wnoexcept-type): Enable by Wc++17-compat instead of Wc++1z-compat,
	change C++1z to C++17 in description.
	(std=c++1z, std=gnu++1z): Change from option to undocumented
	deprecated alias.
	(std=c++17, std=gnu++17): Change from undocumented alias to option.
	Adjust description.
	* c-common.h (enum cxx_dialect): Rename cxx1z to cxx17.
	* c-opts.c (set_std_cxx1z): Rename to ...
	(set_std_cxx17): ... this.
	(c_common_handle_option): Rename OPT_std_c__1z to OPT_std_c__17
	and OPT_std_gnu__1z to OPT_std_gnu__17.  Adjust set_std_cxx1z
	caller.  
	(c_common_post_options): Use cxx17 instead of cxx1z.  Adjust
	comments.
cp/
	* decl.c (redeclaration_error_message): Use cxx17 instead of cxx1z,
	adjust diagnostics refering to C++1z or -std=gnu++1z or -std=c++1z
	to C++17 or -std=gnu++17 or -std=c++17.  Adjust comments.
	(cxx_init_decl_processing, next_initializable_field,
	is_direct_enum_init, check_initializer, cp_finish_decl,
	mark_inline_variable, grokdeclarator, grokparms, xref_basetypes,
	finish_function): Likewise.
	* cp-tree.h (DECL_INLINE_VAR_P): Likewise.
	* pt.c (mark_template_parm, convert_nontype_argument,
	instantiate_class_template_1, type_unification_real, unify,
	get_partial_spec_bindings, dependent_type_p_r): Likewise.
	* typeck.c (cp_build_unary_op): Likewise.
	* constexpr.c (var_in_maybe_constexpr_fn): Likewise.
	* call.c (build_user_type_conversion_1, build_over_call,
	build_special_member_call): Likewise.
	* lambda.c (begin_lambda_type): Likewise.
	* typeck2.c (process_init_constructor_record): Likewise.
	* class.c (build_base_field, finalize_literal_type_property,
	explain_non_literal_class): Likewise.
	* parser.c (cp_parser_diagnose_invalid_type_name,
	cp_parser_primary_expression, cp_parser_lambda_introducer,
	cp_parser_lambda_declarator_opt, cp_parser_selection_statement,
	cp_convert_range_for, cp_parser_perform_range_for_lookup,
	cp_parser_decomposition_declaration, cp_parser_linkage_specification,
	cp_parser_static_assert, cp_parser_simple_type_specifier,
	cp_parser_namespace_definition, cp_parser_using_declaration,
	cp_parser_init_declarator, cp_parser_type_parameter_key,
	cp_parser_exception_specification_opt, cp_parser_std_attribute_spec,
	cp_parser_constructor_declarator_p): Likewise.
	* mangle.c (struct globals): Rename need_cxx1z_warning to
	need_cxx17_warning.
	(write_exception_spec, start_mangling, mangle_decl): Likewise.
	* Make-lang.in (check-c++1z): Rename to check-c++17, depend on
	it.
	(check-c++17): New goal.  Use 17 instead of 1z.
	(check-c++-all): Use 17 instead of 1z.
testsuite/
	* lib/g++-dg.exp (g++-dg-runtest): Use 17 instead of 1z.
	* lib/target-supports.exp (check_effective_target_c++14): Use
	check_effective_target_c++17 instead of check_effective_target_c++1z.
	(check_effective_target_c++14_down): Likewise.
	(check_effective_target_c++1z_only): Rename to ...
	(check_effective_target_c++17_only): ... this.
	(check_effective_target_c++1z): Rename to ...
	(check_effective_target_c++17): ... this.
	* g++.dg/debug/dwarf2/inline-var-1.C: Use -std=c++17 or -std=gnu++17
	instead of -std=c++1z or -std=gnu++1z.  Use c++17 instead of c++1z
	and c++17_only instead of c++1z_only.  Adjust expected diagnostics
	and comments refering to 1z to 17.
	* g++.dg/debug/dwarf2/inline-var-2.C: Likewise.
	* g++.dg/template/partial5.C: Likewise.
	* g++.dg/template/nontype8.C: Likewise.
	* g++.dg/cpp1z/noexcept-type5.C: Likewise.
	* g++.dg/cpp1z/nontype3a.C: Likewise.
	* g++.dg/cpp1z/constexpr-lambda4.C: Likewise.
	* g++.dg/cpp1z/noexcept-type16.C: Likewise.
	* g++.dg/cpp1z/class-deduction32.C: Likewise.
	* g++.dg/cpp1z/pr78771.C: Likewise.
	* g++.dg/cpp1z/elide1.C: Likewise.
	* g++.dg/cpp1z/fold3.C: Likewise.
	* g++.dg/cpp1z/class-deduction2.C: Likewise.
	* g++.dg/cpp1z/noexcept-type12.C: Likewise.
	* g++.dg/cpp1z/inline-var2.C: Likewise.
	* g++.dg/cpp1z/eval-order2.C: Likewise.
	* g++.dg/cpp1z/decomp21.C: Likewise.
	* g++.dg/cpp1z/constexpr-lambda11.C: Likewise.
	* g++.dg/cpp1z/constexpr-lambda9.C: Likewise.
	* g++.dg/cpp1z/utf8-neg.C: Likewise.
	* g++.dg/cpp1z/class-deduction41.C: Likewise.
	* g++.dg/cpp1z/class-deduction23.C: Likewise.
	* g++.dg/cpp1z/nodiscard3.C: Likewise.
	* g++.dg/cpp1z/static_assert-nomsg.C: Likewise.
	* g++.dg/cpp1z/noexcept-type9.C: Likewise.
	* g++.dg/cpp1z/class-deduction21.C: Likewise.
	* g++.dg/cpp1z/range-for1.C: Likewise.
	* g++.dg/cpp1z/init-statement4.C: Likewise.
	* g++.dg/cpp1z/udlit-utf8char.C: Likewise.
	* g++.dg/cpp1z/decomp30.C: Likewise.
	* g++.dg/cpp1z/class-deduction39.C: Likewise.
	* g++.dg/cpp1z/register2.C: Likewise.
	* g++.dg/cpp1z/decomp9.C: Likewise.
	* g++.dg/cpp1z/regress1.C: Likewise.
	* g++.dg/cpp1z/direct-enum-init1.C: Likewise.
	* g++.dg/cpp1z/class-deduction30.C: Likewise.
	* g++.dg/cpp1z/abbrev2.C: Likewise.
	* g++.dg/cpp1z/nontype-auto6.C: Likewise.
	* g++.dg/cpp1z/regress2.C: Likewise.
	* g++.dg/cpp1z/decomp16.C: Likewise.
	* g++.dg/cpp1z/bool-increment1.C: Likewise.
	* g++.dg/cpp1z/aligned-new1.C: Likewise.
	* g++.dg/cpp1z/decomp3.C: Likewise.
	* g++.dg/cpp1z/register1.C: Likewise.
	* g++.dg/cpp1z/namespace-attribs.C: Likewise.
	* g++.dg/cpp1z/class-deduction1.C: Likewise.
	* g++.dg/cpp1z/decomp10.C: Likewise.
	* g++.dg/cpp1z/constexpr-if11.C: Likewise.
	* g++.dg/cpp1z/constexpr-lambda10.C: Likewise.
	* g++.dg/cpp1z/decomp27.C: Likewise.
	* g++.dg/cpp1z/noexcept-type2.C: Likewise.
	* g++.dg/cpp1z/constexpr-lambda6.C: Likewise.
	* g++.dg/cpp1z/class-deduction9.C: Likewise.
	* g++.dg/cpp1z/attributes-enum-1.C: Likewise.
	* g++.dg/cpp1z/decomp11.C: Likewise.
	* g++.dg/cpp1z/aligned-new3.C: Likewise.
	* g++.dg/cpp1z/utf8-2.C: Likewise.
	* g++.dg/cpp1z/lambda-this3.C: Likewise.
	* g++.dg/cpp1z/decomp-constexpr1.C: Likewise.
	* g++.dg/cpp1z/byte1.C: Likewise.
	* g++.dg/cpp1z/nontype-auto9.C: Likewise.
	* g++.dg/cpp1z/aggr-base4.C: Likewise.
	* g++.dg/cpp1z/constexpr-lambda1.C: Likewise.
	* g++.dg/cpp1z/nontype-auto3.C: Likewise.
	* g++.dg/cpp1z/utf8-2a.C: Likewise.
	* g++.dg/cpp1z/constexpr-lambda7.C: Likewise.
	* g++.dg/cpp1z/aggr-base6.C: Likewise.
	* g++.dg/cpp1z/cplusplus.C: Likewise.
	* g++.dg/cpp1z/class-deduction20.C: Likewise.
	* g++.dg/cpp1z/aggr-base2.C: Likewise.
	* g++.dg/cpp1z/class-deduction6.C: Likewise.
	* g++.dg/cpp1z/noexcept-type3.C: Likewise.
	* g++.dg/cpp1z/class-deduction31.C: Likewise.
	* g++.dg/cpp1z/class-deduction25.C: Likewise.
	* g++.dg/cpp1z/class-deduction18.C: Likewise.
	* g++.dg/cpp1z/fold9.C: Likewise.
	* g++.dg/cpp1z/noexcept-type8.C: Likewise.
	* g++.dg/cpp1z/abbrev1.C: Likewise.
	* g++.dg/cpp1z/constexpr-if10.C: Likewise.
	* g++.dg/cpp1z/utf8.C: Likewise.
	* g++.dg/cpp1z/noexcept-type7.C: Likewise.
	* g++.dg/cpp1z/aggr-base3.C: Likewise.
	* g++.dg/cpp1z/constexpr-lambda8.C: Likewise.
	* g++.dg/cpp1z/init-statement2.C: Likewise.
	* g++.dg/cpp1z/nontype-auto4.C: Likewise.
	* g++.dg/cpp1z/constexpr-if12.C: Likewise.
	* g++.dg/cpp1z/class-deduction40.C: Likewise.
	* g++.dg/cpp1z/nontype3.C: Likewise.
	* g++.dg/cpp1z/class-deduction14.C: Likewise.
	* g++.dg/cpp1z/fold7.C: Likewise.
	* g++.dg/cpp1z/nontype2.C: Likewise.
	* g++.dg/cpp1z/class-deduction15.C: Likewise.
	* g++.dg/cpp1z/nested-namespace-def1.C: Likewise.
	* g++.dg/cpp1z/class-deduction13.C: Likewise.
	* g++.dg/cpp1z/aligned-new7.C: Likewise.
	* g++.dg/cpp1z/noexcept-type1.C: Likewise.
	* g++.dg/cpp1z/nontype1.C: Likewise.
	* g++.dg/cpp1z/init-statement5.C: Likewise.
	* g++.dg/cpp1z/nontype-auto2.C: Likewise.
	* g++.dg/cpp1z/decomp17.C: Likewise.
	* g++.dg/cpp1z/fold4.C: Likewise.
	* g++.dg/cpp1z/constexpr-lambda2.C: Likewise.
	* g++.dg/cpp1z/fold7a.C: Likewise.
	* g++.dg/cpp1z/nontype-auto5.C: Likewise.
	* g++.dg/cpp1z/init-statement7.C: Likewise.
	* g++.dg/cpp1z/aggr-base5.C: Likewise.
	* g++.dg/cpp1z/constexpr-lambda5.C: Likewise.
	* g++.dg/cpp1z/pr79143.C: Likewise.
	* g++.dg/cpp1z/class-deduction38.C: Likewise.
	* g++.dg/cpp1z/nontype-auto8.C: Likewise.
	* g++.dg/cpp1z/class-deduction12.C: Likewise.
	* g++.dg/cpp1z/decomp20.C: Likewise.
	* g++.dg/cpp1z/class-deduction22.C: Likewise.
	* g++.dg/cpp1z/class-deduction29.C: Likewise.
	* g++.dg/cpp1z/class-deduction8.C: Likewise.
	* g++.dg/cpp1z/class-deduction43.C: Likewise.
	* g++.dg/cpp1z/feat-cxx1z.C: Likewise.
	* g++.dg/cpp1z/fold8.C: Likewise.
	* g++.dg/cpp1z/init-statement3.C: Likewise.
	* g++.dg/cpp1z/nontype-auto10.C: Likewise.
	* g++.dg/cpp1z/class-deduction36.C: Likewise.
	* g++.dg/cpp1z/noexcept-type17.C: Likewise.
	* g++.dg/cpp1z/fallthrough1.C: Likewise.
	* g++.dg/cpp1z/fold1.C: Likewise.
	* g++.dg/cpp1z/class-deduction26.C: Likewise.
	* g++.dg/cpp1z/fold-ice1.C: Likewise.
	* g++.dg/cpp1z/fold5.C: Likewise.
	* g++.dg/cpp1z/class-deduction34.C: Likewise.
	* g++.dg/cpp1z/noexcept-type6.C: Likewise.
	* g++.dg/cpp1z/class-deduction7.C: Likewise.
	* g++.dg/cpp1z/class-deduction16.C: Likewise.
	* g++.dg/cpp1z/class-deduction10.C: Likewise.
	* g++.dg/cpp1z/eval-order3.C: Likewise.
	* g++.dg/cpp1z/constexpr-lambda13.C: Likewise.
	* g++.dg/cpp1z/aggr-base2a.C: Likewise.
	* g++.dg/cpp1z/nontype-auto1.C: Likewise.
	* g++.dg/cpp1z/constexpr-lambda3.C: Likewise.
	* g++.dg/cpp1z/nontype-auto7.C: Likewise.
	* g++.dg/cpp1z/decomp15.C: Likewise.
	* g++.dg/cpp1z/noexcept-type4.C: Likewise.
	* g++.dg/cpp1z/fold-mangle.C: Likewise.
	* g++.dg/cpp1z/class-deduction35.C: Likewise.
	* g++.dg/cpp1z/decomp4.C: Likewise.
	* g++.dg/cpp1z/class-deduction42.C: Likewise.
	* g++.dg/cpp1z/init-statement8.C: Likewise.
	* g++.dg/cpp1z/inline-var1a.C: Likewise.
	* g++.dg/cpp1z/init-statement6.C: Likewise.
	* g++.dg/cpp1z/class-deduction17.C: Likewise.
	* g++.dg/cpp1z/class-deduction28.C: Likewise.
	* g++.dg/cpp1z/class-deduction27.C: Likewise.
	* g++.dg/cpp1z/decomp-bitfield1.C: Likewise.
	* g++.dg/cpp1z/attributes-enum-1a.C: Likewise.
	* g++.dg/cpp1z/class-deduction11.C: Likewise.
	* g++.dg/cpp1z/constexpr-lambda12.C: Likewise.
	* g++.dg/cpp1z/init-statement9.C: Likewise.
	* g++.dg/cpp1z/class-deduction19.C: Likewise.
	* g++.dg/cpp1z/class-deduction5.C: Likewise.
	* g++.dg/cpp1z/fold2.C: Likewise.
	* g++.dg/cpp1z/class-deduction33.C: Likewise.
	* g++.dg/cpp1z/class-deduction24.C: Likewise.
	* g++.dg/cpp1z/aggr-base1.C: Likewise.
	* g++.dg/cpp1z/fold6.C: Likewise.
	* g++.dg/cpp1z/decomp12.C: Likewise.
	* g++.dg/cpp1z/class-deduction4.C: Likewise.
	* g++.dg/cpp1z/inline-var1.C: Likewise.
	* g++.dg/cpp1z/aligned-new2.C: Likewise.
	* g++.dg/cpp1z/class-deduction3.C: Likewise.
	* g++.dg/other/error3.C: Likewise.
	* g++.dg/init/new25.C: Likewise.
	* g++.dg/init/new13.C: Likewise.
	* g++.dg/tls/diag-2.C: Likewise.
	* g++.dg/tls/diag-4.C: Likewise.
	* g++.dg/opt/noreturn-1.C: Likewise.
	* g++.dg/eh/async-unwind2.C: Likewise.
	* g++.dg/eh/spec9.C: Likewise.
	* g++.dg/eh/spec7.C: Likewise.
	* g++.dg/eh/template1.C: Likewise.
	* g++.dg/eh/cond4.C: Likewise.
	* g++.dg/eh/pr41819.C: Likewise.
	* g++.dg/eh/delete1.C: Likewise.
	* g++.dg/eh/spec3.C: Likewise.
	* g++.dg/eh/forced4.C: Likewise.
	* g++.dg/eh/spec2.C: Likewise.
	* g++.dg/eh/shadow1.C: Likewise.
	* g++.dg/eh/pr38662.C: Likewise.
	* g++.dg/eh/ehopt1.C: Likewise.
	* g++.dg/eh/spec8.C: Likewise.
	* g++.dg/eh/init-temp2.C: Likewise.
	* g++.dg/rtti/crash3.C: Likewise.
	* g++.dg/warn/Wreturn-type-3.C: Likewise.
	* g++.dg/warn/register-parm-1.C: Likewise.
	* g++.dg/warn/register-var-2.C: Likewise.
	* g++.dg/gcov/gcov-7.C: Likewise.
	* g++.dg/tree-ssa/pr45605.C: Likewise.
	* g++.dg/cpp/pr23827_cxx98_neg.C: Likewise.
	* g++.dg/lookup/exception1.C: Likewise.
	* g++.dg/ubsan/pr79589.C: Likewise.
	* g++.dg/tm/pr47340.C: Likewise.
	* g++.dg/tm/pr46567.C: Likewise.
	* g++.dg/expr/bitfield5.C: Likewise.
	* g++.dg/expr/bool1.C: Likewise.
	* g++.dg/expr/lval3.C: Likewise.
	* g++.dg/expr/lval4.C: Likewise.
	* g++.dg/expr/bitfield4.C: Likewise.
	* g++.dg/expr/bitfield6.C: Likewise.
	* g++.dg/expr/bool3.C: Likewise.
	* g++.dg/ext/has_nothrow_constructor.C: Likewise.
	* g++.dg/ext/has_nothrow_copy-7.C: Likewise.
	* g++.dg/ext/has_nothrow_copy-1.C: Likewise.
	* g++.dg/ext/has_nothrow_copy-2.C: Likewise.
	* g++.dg/ext/has_nothrow_copy-4.C: Likewise.
	* g++.dg/ext/has_nothrow_copy-5.C: Likewise.
	* g++.dg/ext/has_nothrow_copy-6.C: Likewise.
	* g++.dg/ext/has_nothrow_assign.C: Likewise.
	* g++.dg/parse/register1.C: Likewise.
	* g++.dg/parse/error15.C: Likewise.
	* g++.dg/parse/linkage2.C: Likewise.
	* g++.dg/concepts/intro2.C: Likewise.
	* g++.dg/concepts/class.C: Likewise.
	* g++.dg/concepts/traits1.C: Likewise.
	* g++.dg/concepts/req5.C: Likewise.
	* g++.dg/concepts/var-concept5.C: Likewise.
	* g++.dg/concepts/fn-concept2.C: Likewise.
	* g++.dg/concepts/traits2.C: Likewise.
	* g++.dg/concepts/placeholder2.C: Likewise.
	* g++.dg/concepts/class6.C: Likewise.
	* g++.dg/concepts/memtmpl1.C: Likewise.
	* g++.dg/concepts/friend2.C: Likewise.
	* g++.dg/concepts/template-parm3.C: Likewise.
	* g++.dg/concepts/template-parm10.C: Likewise.
	* g++.dg/concepts/explicit-spec1.C: Likewise.
	* g++.dg/concepts/explicit-spec3.C: Likewise.
	* g++.dg/concepts/var-templ2.C: Likewise.
	* g++.dg/concepts/intro5.C: Likewise.
	* g++.dg/concepts/deduction-constraint1.C: Likewise.
	* g++.dg/concepts/iconv1.C: Likewise.
	* g++.dg/concepts/constrained-parm.C: Likewise.
	* g++.dg/concepts/template-template-parm1.C: Likewise.
	* g++.dg/concepts/var-concept3.C: Likewise.
	* g++.dg/concepts/class3.C: Likewise.
	* g++.dg/concepts/memfun2.C: Likewise.
	* g++.dg/concepts/req1.C: Likewise.
	* g++.dg/concepts/disjunction1.C: Likewise.
	* g++.dg/concepts/req17.C: Likewise.
	* g++.dg/concepts/pr65848.C: Likewise.
	* g++.dg/concepts/placeholder4.C: Likewise.
	* g++.dg/concepts/decl-diagnose.C: Likewise.
	* g++.dg/concepts/intro7.C: Likewise.
	* g++.dg/concepts/pr68683.C: Likewise.
	* g++.dg/concepts/partial-spec4.C: Likewise.
	* g++.dg/concepts/template-parm5.C: Likewise.
	* g++.dg/concepts/explicit-inst1.C: Likewise.
	* g++.dg/concepts/class-deduction1.C: Likewise.
	* g++.dg/concepts/class1.C: Likewise.
	* g++.dg/concepts/req15.C: Likewise.
	* g++.dg/concepts/memfun.C: Likewise.
	* g++.dg/concepts/pr68434.C: Likewise.
	* g++.dg/concepts/inherit-ctor4.C: Likewise.
	* g++.dg/concepts/partial-spec6.C: Likewise.
	* g++.dg/concepts/var-templ1.C: Likewise.
	* g++.dg/concepts/template-parm8.C: Likewise.
	* g++.dg/concepts/explicit-inst3.C: Likewise.
	* g++.dg/concepts/class4.C: Likewise.
	* g++.dg/concepts/req6.C: Likewise.
	* g++.dg/concepts/fn8.C: Likewise.
	* g++.dg/concepts/class5.C: Likewise.
	* g++.dg/concepts/placeholder5.C: Likewise.
	* g++.dg/concepts/req16.C: Likewise.
	* g++.dg/concepts/req10.C: Likewise.
	* g++.dg/concepts/var-concept2.C: Likewise.
	* g++.dg/concepts/auto3.C: Likewise.
	* g++.dg/concepts/generic-fn-err.C: Likewise.
	* g++.dg/concepts/pr65552.C: Likewise.
	* g++.dg/concepts/partial-concept-id2.C: Likewise.
	* g++.dg/concepts/fn1.C: Likewise.
	* g++.dg/concepts/partial-spec.C: Likewise.
	* g++.dg/concepts/template-parm12.C: Likewise.
	* g++.dg/concepts/diagnostic1.C: Likewise.
	* g++.dg/concepts/intro1.C: Likewise.
	* g++.dg/concepts/explicit-inst4.C: Likewise.
	* g++.dg/concepts/req18.C: Likewise.
	* g++.dg/concepts/explicit-spec5.C: Likewise.
	* g++.dg/concepts/var-concept6.C: Likewise.
	* g++.dg/concepts/fn9.C: Likewise.
	* g++.dg/concepts/req2.C: Likewise.
	* g++.dg/concepts/template-parm7.C: Likewise.
	* g++.dg/concepts/req14.C: Likewise.
	* g++.dg/concepts/template-parm6.C: Likewise.
	* g++.dg/concepts/variadic4.C: Likewise.
	* g++.dg/concepts/fn6.C: Likewise.
	* g++.dg/concepts/req-neg1.C: Likewise.
	* g++.dg/concepts/alias3.C: Likewise.
	* g++.dg/concepts/expression2.C: Likewise.
	* g++.dg/concepts/partial-spec3.C: Likewise.
	* g++.dg/concepts/expression3.C: Likewise.
	* g++.dg/concepts/memfun-err.C: Likewise.
	* g++.dg/concepts/pr66091.C: Likewise.
	* g++.dg/concepts/explicit-spec2.C: Likewise.
	* g++.dg/concepts/equiv.C: Likewise.
	* g++.dg/concepts/friend1.C: Likewise.
	* g++.dg/concepts/fn4.C: Likewise.
	* g++.dg/concepts/var-templ3.C: Likewise.
	* g++.dg/concepts/explicit-inst2.C: Likewise.
	* g++.dg/concepts/alias2.C: Likewise.
	* g++.dg/concepts/regress/alias-decl-42.C: Likewise.
	* g++.dg/concepts/placeholder6.C: Likewise.
	* g++.dg/concepts/fn10.C: Likewise.
	* g++.dg/concepts/req3.C: Likewise.
	* g++.dg/concepts/variadic2.C: Likewise.
	* g++.dg/concepts/pr65636.C: Likewise.
	* g++.dg/concepts/intro6.C: Likewise.
	* g++.dg/concepts/class2.C: Likewise.
	* g++.dg/concepts/fn2.C: Likewise.
	* g++.dg/concepts/req20.C: Likewise.
	* g++.dg/concepts/req8.C: Likewise.
	* g++.dg/concepts/placeholder1.C: Likewise.
	* g++.dg/concepts/pr65854.C: Likewise.
	* g++.dg/concepts/member-concept.C: Likewise.
	* g++.dg/concepts/template-parm2.C: Likewise.
	* g++.dg/concepts/variadic1.C: Likewise.
	* g++.dg/concepts/fn7.C: Likewise.
	* g++.dg/concepts/intro4.C: Likewise.
	* g++.dg/concepts/req13.C: Likewise.
	* g++.dg/concepts/inherit-ctor3.C: Likewise.
	* g++.dg/concepts/explicit-spec6.C: Likewise.
	* g++.dg/concepts/auto1.C: Likewise.
	* g++.dg/concepts/alias1.C: Likewise.
	* g++.dg/concepts/fn-concept1.C: Likewise.
	* g++.dg/concepts/template-parm11.C: Likewise.
	* g++.dg/concepts/explicit-spec4.C: Likewise.
	* g++.dg/concepts/partial-concept-id1.C: Likewise.
	* g++.dg/concepts/req9.C: Likewise.
	* g++.dg/concepts/req4.C: Likewise.
	* g++.dg/concepts/pr65681.C: Likewise.
	* g++.dg/concepts/req7.C: Likewise.
	* g++.dg/concepts/req12.C: Likewise.
	* g++.dg/concepts/fn5.C: Likewise.
	* g++.dg/concepts/alias4.C: Likewise.
	* g++.dg/concepts/generic-fn.C: Likewise.
	* g++.dg/concepts/feature-macro.C: Likewise.
	* g++.dg/concepts/req19.C: Likewise.
	* g++.dg/concepts/placeholder3.C: Likewise.
	* g++.dg/concepts/intro3.C: Likewise.
	* g++.dg/concepts/partial-spec5.C: Likewise.
	* g++.dg/concepts/template-parm4.C: Likewise.
	* g++.dg/concepts/dr1430.C: Likewise.
	* g++.dg/concepts/pr65634.C: Likewise.
	* g++.dg/concepts/var-concept4.C: Likewise.
	* g++.dg/concepts/pr67249.C: Likewise.
	* g++.dg/concepts/expression.C: Likewise.
	* g++.dg/concepts/pr65575.C: Likewise.
	* g++.dg/concepts/partial-spec2.C: Likewise.
	* g++.dg/concepts/template-parm9.C: Likewise.
	* g++.dg/concepts/inherit-ctor1.C: Likewise.
	* g++.dg/concepts/equiv2.C: Likewise.
	* g++.dg/concepts/req11.C: Likewise.
	* g++.dg/concepts/template-parm1.C: Likewise.
	* g++.dg/concepts/inherit-ctor2.C: Likewise.
	* g++.dg/concepts/var-concept1.C: Likewise.
	* g++.dg/concepts/fn3.C: Likewise.
	* g++.dg/torture/pr46364.C: Likewise.
	* g++.dg/torture/stackalign/eh-alloca-1.C: Likewise.
	* g++.dg/torture/stackalign/eh-fastcall-1.C: Likewise.
	* g++.dg/torture/stackalign/eh-vararg-1.C: Likewise.
	* g++.dg/torture/stackalign/eh-vararg-2.C: Likewise.
	* g++.dg/torture/stackalign/eh-global-1.C: Likewise.
	* g++.dg/torture/stackalign/eh-thiscall-1.C: Likewise.
	* g++.dg/torture/stackalign/eh-inline-2.C: Likewise.
	* g++.dg/torture/stackalign/eh-inline-1.C: Likewise.
	* g++.dg/torture/pr52918-1.C: Likewise.
	* g++.dg/torture/pr49394.C: Likewise.
	* g++.dg/torture/pr57190.C: Likewise.
	* g++.dg/cpp0x/static_assert8.C: Likewise.
	* g++.dg/cpp0x/noexcept19.C: Likewise.
	* g++.dg/cpp0x/variadic-throw.C: Likewise.
	* g++.dg/cpp0x/variadic73.C: Likewise.
	* g++.dg/cpp0x/noexcept02.C: Likewise.
	* g++.dg/cpp0x/defaulted23.C: Likewise.
	* g++.dg/cpp0x/noexcept08.C: Likewise.
	* g++.dg/cpp0x/auto9.C: Likewise.
	* g++.dg/cpp0x/lambda/lambda-eh2.C: Likewise.
	* g++.dg/cpp0x/error5.C: Likewise.
	* c-c++-common/gomp/atomic-12.c: Likewise.
	* c-c++-common/gomp/atomic-13.c: Likewise.
	* c-c++-common/gomp/atomic-14.c: Likewise.
	* c-c++-common/Wvarargs-2.c: Likewise.
	* c-c++-common/Wvarargs.c: Likewise.
	* c-c++-common/vector-subscript-2.c: Likewise.
	* g++.old-deja/g++.robertl/eb123.C: Likewise.
	* g++.old-deja/g++.eh/tmpl3.C: Likewise.
	* g++.old-deja/g++.eh/cleanup2.C: Likewise.
	* g++.old-deja/g++.eh/badalloc1.C: Likewise.
	* g++.old-deja/g++.eh/throw2.C: Likewise.
	* g++.old-deja/g++.eh/throw1.C: Likewise.
	* g++.old-deja/g++.eh/tmpl1.C: Likewise.
	* g++.old-deja/g++.other/new7.C: Likewise.
	* g++.old-deja/g++.other/crash30.C: Likewise.
	* g++.old-deja/g++.other/regstack.C: Likewise.
	* g++.old-deja/g++.other/crash28.C: Likewise.
	* g++.old-deja/g++.jason/bool5.C: Likewise.
	* g++.old-deja/g++.mike/p10416.C: Likewise.
	* g++.old-deja/g++.mike/eh25.C: Likewise.
	* g++.old-deja/g++.mike/eh55.C: Likewise.
libcpp/
	* include/cpplib.h (enum c_lang): Rename CLK_GNUCXX1Z
	to CLK_GNUCXX17 and CLK_CXX1Z to CLK_CXX17.
	* init.c (lang_defaults, cpp_init_builtins): Likewise.
	* expr.c (cpp_classify_number): Use C++17 instead of C++1z
	in diagnostics.
libstdc++-v3/
	* testsuite/libstdc++-prettyprinters/cxx17.cc: Use -std=c++17 or
	-std=gnu++17 instead of -std=c++1z or -std=gnu++1z.  Use c++17 instead
	of c++1z and c++17_only instead of c++1z_only.  Adjust expected
	diagnostics and comments refering to 1z to 17.
	* testsuite/30_threads/lock_guard/cons/deduction.cc: Likewise.
	* testsuite/30_threads/scoped_lock/cons/deduction.cc: Likewise.
	* testsuite/30_threads/scoped_lock/cons/1.cc: Likewise.
	* testsuite/30_threads/scoped_lock/requirements/typedefs.cc: Likewise.
	* testsuite/30_threads/scoped_lock/requirements/explicit_instantiation.cc:
	Likewise.
	* testsuite/30_threads/unique_lock/cons/deduction.cc: Likewise.
	* testsuite/18_support/launder/1.cc (test02): Likewise.
	* testsuite/18_support/launder/requirements_neg.cc: Likewise.
	* testsuite/18_support/launder/requirements.cc: Likewise.
	* testsuite/18_support/byte/requirements.cc: Likewise.
	* testsuite/18_support/byte/ops.cc: Likewise.
	* testsuite/18_support/byte/global_neg.cc: Likewise.
	* testsuite/18_support/uncaught_exceptions/uncaught_exceptions.cc:
	Likewise.
	* testsuite/27_io/types/4.cc: Likewise.
	* testsuite/25_algorithms/sample/81221.cc: Likewise.
	* testsuite/25_algorithms/sample/1.cc: Likewise.
	* testsuite/25_algorithms/sample/2.cc: Likewise.
	* testsuite/25_algorithms/search/searcher.cc: Likewise.
	* testsuite/28_regex/basic_regex/ctors/deduction.cc: Likewise.
	* testsuite/experimental/filesystem/path/construct/string_view.cc:
	Likewise.
	* testsuite/24_iterators/range_access_cpp17.cc: Likewise.
	* testsuite/24_iterators/container_access.cc: Likewise.
	* testsuite/ext/pb_ds/regression/hash_map_rand.cc: Likewise.
	* testsuite/ext/pb_ds/regression/trie_set_rand.cc: Likewise.
	* testsuite/ext/pb_ds/regression/hash_set_rand.cc: Likewise.
	* testsuite/ext/pb_ds/regression/list_update_set_rand.cc: Likewise.
	* testsuite/ext/pb_ds/regression/list_update_map_rand.cc: Likewise.
	* testsuite/ext/pb_ds/regression/priority_queue_rand.cc: Likewise.
	* testsuite/ext/pb_ds/regression/tree_set_rand.cc: Likewise.
	* testsuite/ext/pb_ds/regression/tree_map_rand.cc: Likewise.
	* testsuite/ext/pb_ds/regression/trie_map_rand.cc: Likewise.
	* testsuite/20_util/shared_ptr/casts/reinterpret.cc: Likewise.
	* testsuite/20_util/shared_ptr/cons/deduction.cc: Likewise.
	* testsuite/20_util/shared_ptr/cons/array.cc: Likewise.
	* testsuite/20_util/shared_ptr/observers/array.cc (struct A): Likewise.
	* testsuite/20_util/pair/cons/deduction.cc: Likewise.
	* testsuite/20_util/variant/deduction.cc: Likewise.
	* testsuite/20_util/tuple/78939.cc: Likewise.
	* testsuite/20_util/tuple/cons/deduction.cc: Likewise.
	* testsuite/20_util/void_t/1.cc: Likewise.
	* testsuite/20_util/duration/arithmetic/constexpr_c++17.cc: Likewise.
	* testsuite/20_util/unique_ptr/cons/deduction_neg.cc: Likewise.
	* testsuite/20_util/addressof/requirements/constexpr.cc: Likewise.
	* testsuite/20_util/weak_ptr/cons/deduction.cc: Likewise.
	* testsuite/20_util/has_unique_object_representations/requirements/typedefs.cc:
	Likewise.
	* testsuite/20_util/has_unique_object_representations/requirements/explicit_instantiation.cc:
	Likewise.
	* testsuite/20_util/has_unique_object_representations/value.cc:
	Likewise.
	* testsuite/20_util/time_point/arithmetic/constexpr.cc: Likewise.
	* testsuite/20_util/function_objects/invoke/59768.cc: Likewise.
	* testsuite/20_util/function_objects/mem_fn/80478.cc: Likewise.
	* testsuite/20_util/function/cons/deduction.cc: Likewise.
	* testsuite/20_util/specialized_algorithms/memory_management_tools/destroy_neg.cc:
	Likewise.
	* testsuite/20_util/is_aggregate/requirements/typedefs.cc: Likewise.
	* testsuite/20_util/is_aggregate/requirements/explicit_instantiation.cc:
	Likewise.
	* testsuite/20_util/is_aggregate/value.cc: Likewise.
	* testsuite/26_numerics/lcm/1.cc: Likewise.
	* testsuite/26_numerics/lcm/lcm_neg.cc: Likewise.
	* testsuite/26_numerics/gcd/1.cc: Likewise.
	* testsuite/26_numerics/gcd/gcd_neg.cc: Likewise.
	* testsuite/26_numerics/valarray/deduction.cc: Likewise.
	* testsuite/26_numerics/headers/cmath/types_std_c++0x_neg.cc: Likewise.
	* testsuite/26_numerics/headers/cmath/hypot.cc: Likewise.
	* testsuite/23_containers/queue/members/emplace_cxx17_return.cc:
	Likewise.
	* testsuite/23_containers/array/cons/deduction.cc: Likewise.
	* testsuite/23_containers/array/cons/deduction_neg.cc: Likewise.
	* testsuite/23_containers/deque/modifiers/emplace/cxx17_return.cc:
	Likewise.
	* testsuite/23_containers/deque/cons/deduction.cc: Likewise.
	* testsuite/23_containers/stack/members/emplace_cxx17_return.cc:
	Likewise.
	* testsuite/23_containers/list/modifiers/emplace/cxx17_return.cc:
	Likewise.
	* testsuite/23_containers/list/cons/deduction.cc: Likewise.
	* testsuite/23_containers/forward_list/modifiers/emplace_cxx17_return.cc:
	Likewise.
	* testsuite/23_containers/forward_list/cons/deduction.cc: Likewise.
	* testsuite/23_containers/unordered_set/allocator/ext_ptr.cc: Likewise.
	* testsuite/23_containers/vector/modifiers/emplace/cxx17_return.cc:
	Likewise.
	* testsuite/23_containers/vector/cons/deduction.cc: Likewise.
	* testsuite/23_containers/vector/bool/emplace_cxx17_return.cc:
	Likewise.
	* testsuite/21_strings/basic_string/cons/char/9.cc: Likewise.
	* testsuite/21_strings/basic_string/cons/char/deduction.cc: Likewise.
	* testsuite/21_strings/basic_string/cons/char/79162.cc: Likewise.
	* testsuite/21_strings/basic_string/cons/wchar_t/9.cc: Likewise.
	* testsuite/21_strings/basic_string/cons/wchar_t/deduction.cc:
	Likewise.
	* testsuite/21_strings/basic_string/cons/wchar_t/79162.cc: Likewise.
	* testsuite/21_strings/basic_string_view/modifiers/swap/char/1.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/modifiers/swap/wchar_t/1.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/operations/compare/char/2.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/operations/compare/char/70483.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/operations/compare/wchar_t/2.cc:
	Likewise.
	* testsuite/21_strings/char_traits/requirements/constexpr_functions_c++17.cc:
	Likewise.

From-SVN: r252826
2017-09-15 18:15:46 +02:00
David Malcolm 738f7c2e12 libcpp: preserve ranges within macro expansions (PR c++/79300)
gcc/testsuite/ChangeLog:
	PR c++/79300
	* g++.dg/diagnostic/pr79300.C: New test case.

libcpp/ChangeLog:
	PR c++/79300
	* line-map.c (linemap_macro_loc_to_def_point): Preserve range
	information for macro expansions by delaying resolving ad-hoc
	locations until within the loop.

From-SVN: r250058
2017-07-07 18:49:09 +00:00
David Malcolm c471c6edcb diagnostics: fix end-points of ranges within macros (PR c++/79300)
gcc/ChangeLog:
	PR c++/79300
	* diagnostic-show-locus.c (layout::layout): Use start and finish
	spelling location for the start and finish of each range.
	* genmatch.c (linemap_client_expand_location_to_spelling_point):
	Add unused aspect param.
	* input.c (expand_location_1): Add "aspect" param, and use it
	to access the correct part of the location.
	(expand_location): Pass LOCATION_ASPECT_CARET to new param of
	expand_location_1.
	(expand_location_to_spelling_point): Likewise.
	(linemap_client_expand_location_to_spelling_point): Add "aspect"
	param, and pass it to expand_location_1.

gcc/testsuite/ChangeLog:
	PR c++/79300
	* c-c++-common/Wmisleading-indentation-3.c (fn_14): Update
	expected underlining within macro expansion.
	* c-c++-common/pr70264.c: Likewise.
	* g++.dg/plugin/diagnostic-test-expressions-1.C
	(test_within_macro_1): New test.
	(test_within_macro_2): Likewise.
	(test_within_macro_3): Likewise.
	(test_within_macro_4): Likewise.
	* gcc.dg/format/diagnostic-ranges.c (test_macro_3): Update
	expected underlining within macro expansion.
	(test_macro_4): Likewise.
	* gcc.dg/plugin/diagnostic-test-expressions-1.c
	(test_within_macro_1): New test.
	(test_within_macro_2): Likewise.
	(test_within_macro_3): Likewise.
	(test_within_macro_4): Likewise.
	* gcc.dg/spellcheck-fields-2.c (test_macro): Update expected
	underlining within macro expansion.

libcpp/ChangeLog:
	PR c++/79300
	* include/line-map.h (enum location_aspect): New enum.
	(linemap_client_expand_location_to_spelling_point): Add
	enum location_aspect param.
	* line-map.c (rich_location::get_expanded_location): Update for
	new param of linemap_client_expand_location_to_spelling_point.
	(rich_location::maybe_add_fixit): Likewise.
	(fixit_hint::affects_line_p): Likewise.

From-SVN: r250022
2017-07-06 14:17:24 +00:00
Jakub Jelinek 6d52273137 line-map.c (location_adhoc_data_update): Perform addition in uintptr_t type rather than char * type.
* line-map.c (location_adhoc_data_update): Perform addition in
	uintptr_t type rather than char * type.  Read *data using
	ptrdiff_t type instead of int64_t.
	(get_combined_adhoc_loc): Change offset type to ptrdiff_t from
	int64_t.

From-SVN: r249446
2017-06-21 12:59:12 +02:00
David Malcolm c7a980b80b Prevent fix-it hints from affecting more than one line
Attempts to apply a removal or replacement fix-it hint to a source
range that covers multiple lines currently lead to nonsensical
results from the printing code in diagnostic-show-locus.c.

We were already filtering them out in edit-context.c (leading
to -fdiagnostics-generate-patch not generating any output for
the whole TU).

Reject attempts to add such fix-it hints within rich_location,
fixing the diagnostic-show-locus.c issue.

gcc/ChangeLog:
	* diagnostic-show-locus.c
	(selftest::test_fixit_deletion_affecting_newline): New function.
	(selftest::diagnostic_show_locus_c_tests): Call it.

libcpp/ChangeLog:
	* include/line-map.h (class rich_location): Document that attempts
	to delete or replace a range *affecting* multiple lines will fail.
	* line-map.c (rich_location::maybe_add_fixit): Implement this
	restriction.

From-SVN: r249403
2017-06-20 10:40:38 +00:00
David Malcolm b09649fdc6 Add support for mutually-incompatible fix-it hints
This patch adds a method:
  rich_location::fixits_cannot_be_auto_applied
for ensuring that mutually-incompatible fix-its hints don't
lead to insane output from -fdiagnostics-generate-patch.

Fix-it hints within such rich_location instances are printed
as normal by diagnostic_show_locus, but don't affect the output
of -fdiagnostics-generate-patch.

gcc/ChangeLog:
	* diagnostic.c (diagnostic_report_diagnostic): Only add fixits
	to the edit_context if they can be auto-applied.

gcc/testsuite/ChangeLog:
	* gcc.dg/plugin/diagnostic-test-show-locus-bw.c
	(test_mutually_exclusive_suggestions): New test function.
	* gcc.dg/plugin/diagnostic-test-show-locus-generate-patch.c
	(test_mutually_exclusive_suggestions): New test function.
	* gcc.dg/plugin/diagnostic-test-show-locus-parseable-fixits.c
	(test_mutually_exclusive_suggestions): New test function.
	* gcc.dg/plugin/diagnostic_plugin_test_show_locus.c
	(test_show_locus): Add special-case for
	"test_mutually_exclusive_suggestions".

libcpp/ChangeLog:
	* include/line-map.h
	(rich_location::fixits_cannot_be_auto_applied): New method.
	(rich_location::fixits_can_be_auto_applied_p): New accessor.
	(rich_location::m_fixits_cannot_be_auto_applied): New field.
	* line-map.c (rich_location::rich_location): Initialize new field.

From-SVN: r249081
2017-06-09 20:57:38 +00:00
David Malcolm 05945a1b83 libcpp: add callback for comment-handling
gcc/testsuite/ChangeLog:
	* g++.dg/plugin/comment_plugin.c: New test plugin.
	* g++.dg/plugin/comments-1.C: New test file.
	* g++.dg/plugin/plugin.exp (plugin_test_list): Add the above.

libcpp/ChangeLog:
	* include/cpplib.h (struct cpp_callbacks): Add "comment"
	callback.
	* lex.c (_cpp_lex_direct): Call the comment callback if non-NULL.

From-SVN: r248901
2017-06-05 20:53:06 +00:00
David Malcolm ad53f12355 Support fix-it hints that add new lines
Previously fix-it hints couldn't contain newlines.  This is
due to the need to print something user-readable for them
within diagnostic-show-locus, and for handling them within
edit-context for printing diffs and regenerating content.

This patch enables limited support for fix-it hints with newlines,
for suggesting adding new lines.
Such a fix-it hint must have exactly one newline character, at the
end of the content.  It must be an insertion at the beginning of
a line (so that e.g. fix-its that split a pre-existing line are
still rejected).

They are printed by diagnostic-show-locus with a '+' in the
left-hand margin, like this:

test.c:42:4: note: suggest adding 'break;' here
+      break;
     case 'b':
     ^~~~~~~~~

and the printer injects "spans" if the insertion location is not
near the primary range of the diagnostic e.g.:

test.c:4:2: note: unrecognized 'putchar'; suggest including '<stdio.h>'
test.c:1:1:
+#include <stdio.h>

test.c:4:2:
  putchar (ch);
  ^~~~~~~

gcc/ChangeLog:
	* diagnostic-show-locus.c
	(layout::should_print_annotation_line_p): Make private.
	(layout::print_annotation_line): Make private.
	(layout::annotation_line_showed_range_p): Make private.
	(layout::show_ruler): Make private.
	(layout::print_source_line): Make private.  Pass in line and
	line_width, rather than calling location_get_source_line.  Drop
	returned value.
	(layout::print_leading_fixits): New method.
	(layout::print_any_fixits): Rename to...
	(layout::print_trailing_fixits): ...this, and make private.
	Don't print newline fixits.
	(diagnostic_show_locus): Move logic for printing one row into...
	(layout::print_line): ...this new function.  Move the
	location_get_source_line call and error-handling from
	print_source_line to here.  Call print_leading_fixits, and rename
	print_any_fixits to print_trailing_fixits.
	(selftest::test_fixit_insert_containing_newline): Update now that
	newlines are partially supported.
	(selftest::test_fixit_insert_containing_newline_2): New test.
	(selftest::test_fixit_replace_containing_newline): Update comments.
	(selftest::diagnostic_show_locus_c_tests): Call the new test.
	* edit-context.c (class added_line): New class.
	(class edited_line): Describe newline handling in comment.
	(edited_line::actually_edited_p): New method.
	(edited_line::print_content): Delete redundant decl.
	(edited_line::m_predecessors): New field.
	(edited_file::print_content): Call edited_line::print_content.
	(edited_file::print_diff): Update to support newlines.
	(edited_file::print_diff_hunk): Likewise.
	(edited_file::print_run_of_changed_lines): New function.
	(edited_file::print_diff_line): Convert to...
	(print_diff_line): ...this.
	(edited_file::get_effective_line_count): New function.
	(edited_line::edited_line): Initialize new field m_predecessors.
	(edited_line::~edited_line): Clean up m_predecessors.
	(edited_line::apply_fixit): Handle newlines.
	(edited_line::get_effective_line_count): New function.
	(edited_line::print_content): New function.
	(edited_line::print_diff_lines): New function.
	(selftest::test_applying_fixits_insert_containing_newline): New
	test.
	(selftest::test_applying_fixits_replace_containing_newline): New
	test.
	(selftest::insert_line): New function.
	(selftest::test_applying_fixits_multiple_lines): Add example of
	inserting a line.
	(selftest::edit_context_c_tests): Call the new tests.

gcc/testsuite/ChangeLog:
	* gcc.dg/plugin/diagnostic-test-show-locus-bw.c
	(test_fixit_insert_newline): New function.
	* gcc.dg/plugin/diagnostic-test-show-locus-color.c
	(test_fixit_insert_newline): New function.
	* gcc.dg/plugin/diagnostic-test-show-locus-generate-patch.c
	(test_fixit_insert_newline): New function.
	* gcc.dg/plugin/diagnostic-test-show-locus-parseable-fixits.c
	(test_fixit_insert_newline): New function.
	* gcc.dg/plugin/diagnostic_plugin_test_show_locus.c
	(test_show_locus): Handle test_fixit_insert_newline.

libcpp/ChangeLog:
	* include/line-map.h (class rich_location): Update description of
	newline handling.
	(class fixit_hint): Likewise.
	(fixit_hint::ends_with_newline_p): New decl.
	* line-map.c (rich_location::maybe_add_fixit): Support newlines
	in fix-it hints that are insertions of single lines at the start
	of a line.  Don't consolidate into such fix-it hints.
	(fixit_hint::ends_with_newline_p): New method.

From-SVN: r247522
2017-05-02 19:03:56 +00:00
David Malcolm 338035aa19 Eliminate fixit_hint class hierarchy
The original implementation of fix-it hints (r230674) had an abstract
base class "fixit_hint" and three subclasses, representing
each of insertions, replacements, and deletions.

Having multiple classes for fix-it hints was a nuisance, as it required
per-class logic everywhere that the hints were handled.

In r239632 I eliminated the deletion subclass in favor of replacement
with the empty string (two subclasses are easier than three).

This patch eliminates the class hierarchy altogether by implementing
insertion in terms of replacement, by representing replacements via
a half-open interval (so that for an insertion, start == next location,
and we're effectively replacing an empty range at the insertion point
with the new string).

This greatly simplifies the code for handling fix-it hints; for example
it allows removal of a parallel class hierarchy of line_event within
edit-context.c.

It also improves consolidation of hints: we can now consolidate
insertions at the same location, affecting a couple of tests
(selftest::test_one_liner_many_fixits and
gcc.dg/Wmissing-braces-fixits.c).

gcc/ChangeLog:
	* diagnostic-show-locus.c (layout::get_expanded_location): Rewrite
	to use new fixit_hint representation, using the "replace" logic.
	(get_line_span_for_fixit_hint): Likewise.
	(layout::print_any_fixits): Likewise.
	(selftest::test_one_liner_many_fixits): Rename to...
	(selftest::test_one_liner_many_fixits_1): ...this, and update
	comment and expected output to reflect that the multiple fix-it
	hints are now consolidated into one insertion.
	(selftest::test_one_liner_many_fixits_2): New test.
	(selftest::test_diagnostic_show_locus_one_liner): Update for
	above.
	(selftest::test_fixit_consolidation): Update for fix-it API
	change.
	* diagnostic.c (print_parseable_fixits): Likewise.
	* edit-context.c (edited_line::m_line_events): Convert from
	auto_vec <line_event *> to auto_vec <line_event>.
	(class line_event): Convert from abstract base class to a concrete
	class, taking over the role of replace_event.
	(class insert_event): Delete.
	(class replace_event): Rename to class line_event.  Convert to
	half-open range.
	(edit_context::add_fixits): Reimplement.
	(edit_context::apply_insert): Delete.
	(edit_context::apply_replace): Rename to...
	(edit_context::apply_fixit): ...this.  Convert to half-open range.
	(edited_file::apply_insert): Delete.
	(edited_file::apply_replace): Rename to...
	(edited_file::apply_fixit): ...this.
	(edited_line::~edited_line): Drop deletion of events.
	(edited_line::apply_insert): Delete.
	(edited_line::apply_replace): Rename to...
	(edited_line::apply_fixit): ...this.  Convert to half-open range.
	Update for change to type of m_line_events.
	* edit-context.h (edit_context::apply_insert): Delete.
	(edit_context::apply_replace): Rename to...
	(edit_context::apply_fixit): ...this.

gcc/testsuite/ChangeLog:
	* gcc.dg/Wmissing-braces-fixits.c: Update expected output to
	reflect insertion fix-it hints at the same location now being
	consolidated.

libcpp/ChangeLog:
	* include/line-map.h (source_range::intersects_line_p): Delete.
	(rich_location::add_fixit): Delete.
	(rich_location::maybe_add_fixit): New method.
	(class fixit_hint): Reimplement in terms of...
	(class fixit_replace): ...this.
	(class fixit_insert): Delete.
	* line-map.c (linemap_position_for_loc_and_offset): Drop overzealous
	linemap_assert_fails.
	(source_range::intersects_line_p): Rename to...
	(fixit_hint::affects_line_p): New function.
	(rich_location::add_fixit_insert_before): Reimplement in terms of
	maybe_add_fixit, moving validation there.
	(rich_location::add_fixit_insert_after): Likewise.
	(column_before_p): Delete.
	(rich_location::add_fixit_replace): Reimplement in terms of
	maybe_add_fixit, moving validation there.  Convert closed input range
	to half-open range.
	(rich_location::add_fixit): Delete.
	(rich_location::maybe_add_fixit): New function.
	(fixit_insert::fixit_insert): Delete.
	(fixit_insert::~fixit_insert): Delete.
	(fixit_insert::affects_line_p): Delete.
	(fixit_insert::maybe_append_replace): Delete.
	(fixit_replace::fixit_replace): Rename to...
	(fixit_hint::fixit_hint): ...this, rewriting as necessary.
	(fixit_replace::~fixit_replace): Delete.
	(fixit_replace::affects_line_p): Delete.
	(fixit_replace::maybe_append_replace): Rename to...
	(fixit_hint::maybe_append): ...this, rewriting as necessary.

From-SVN: r247445
2017-05-01 19:15:36 +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