Commit Graph

214 Commits

Author SHA1 Message Date
Patrick Palka a3bf6ce7f2 c++: Adjust mangling of __alignof__ [PR88115]
r11-4926 made __alignof__ get mangled differently from alignof,
encoding __alignof__ as a vendor extended operator.  But this
mangling is problematic for the reasons mentioned in
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88115#c6.

This patch changes our mangling of __alignof__ to instead use the
new "vendor extended expression" syntax that's proposed in
https://github.com/itanium-cxx-abi/cxx-abi/issues/112.  Clang does
the same thing already, so after this patch Clang and GCC agree
about the mangling of __alignof__(type) and __alignof__(expr).

gcc/cp/ChangeLog:

	PR c++/88115
	* mangle.c (write_expression): Adjust the mangling of
	__alignof__.

include/ChangeLog:

	PR c++/88115
	* demangle.h (enum demangle_component_type): Add
	DEMANGLE_COMPONENT_VENDOR_EXPR.

libiberty/ChangeLog:

	PR c++/88115
	* cp-demangle.c (d_dump, d_make_comp, d_expression_1)
	(d_count_templates_scopes): Handle DEMANGLE_COMPONENT_VENDOR_EXPR.
	(d_print_comp_inner): Likewise.
	<case DEMANGLE_COMPONENT_EXTENDED_OPERATOR>: Revert r11-4926
	change.
	<case DEMANGLE_COMPONENT_UNARY>: Likewise.
	* testsuite/demangle-expected: Adjust __alignof__ tests.

gcc/testsuite/ChangeLog:

	PR c++/88115
	* g++.dg/cpp0x/alignof7.C: Adjust expected mangling.
2021-03-30 22:57:11 -04:00
Jakub Jelinek 99dee82307 Update copyright years. 2021-01-04 10:26:59 +01:00
Jason Merrill 58fb912c15 c++: Fix demangling of <unresolved-name>
The ABI for unresolved scoped names on the RHS of . and -> used to be

  sr <type> <unqualified-id>

That changed years ago to something more complex, but G++ was never updated.
This change was particularly incompatible for simple qualified-ids like
A::x, which were previously mangled as sr1A1x, and now sr1AE1x.

This obviously makes life hard for demanglers, which can't know whether to
consume that E or not.  To work around this, we now try demangling with the
newer ABI, and if that fails and we saw an "sr", try again with the older
ABI.

libiberty/ChangeLog:

	PR c++/67343
	* cp-demangle.h (struct d_info): Add unresolved_name_state.
	* cp-demangle.c (d_prefix): Add subst parm.
	(d_nested_name): Pass it.
	(d_unresolved_name): Split out from...
	(d_expression_1): ...here.
	(d_demangle_callback): Maybe retry with old sr mangling.
	* testsuite/demangle-expected: Add test.
2020-12-21 21:13:41 -05:00
Jason Merrill 8cd42d3cc2 c++: Fix demangling of qualified-id after '.'
The demangler was assuming that only an unqualified-id could appear after
. or ->.

libiberty/ChangeLog:

	* cp-demangle.c (d_expression_1): Recognize qualified-id
	on RHS of dt/pt.
	* testsuite/demangle-expected: Add test.
2020-12-21 16:39:48 -05:00
Jason Merrill 7169049332 c++: Fix demangling of x.operator type
d_operator_name decides whether "cv" indicates a cast or a conversion
operator based on is_expression.  "on" specifies that we want the conversion
operator.

libiberty/ChangeLog:

	* cp-demangle.c (d_unqualified_name): Clear is_expression.
	* testsuite/demangle-expected: Add tests.
2020-12-21 15:46:14 -05:00
Patrick Palka b1c9b3c340 c++: Change the mangling of __alignof__ [PR88115]
This patch changes the mangling of __alignof__ to v111__alignof__,
making its mangling distinct from that of alignof(type) and
alignof(expr).

How we mangle ALIGNOF_EXPR now depends on its ALIGNOF_EXPR_STD_P flag,
which after the previous patch gets consistently set for alignof(type)
as well as alignof(expr).

gcc/c-family/ChangeLog:

	PR c++/88115
	* c-opts.c (c_common_post_options): Update latest_abi_version.

gcc/ChangeLog:

	PR c++/88115
	* common.opt (-fabi-version): Document =15.
	* doc/invoke.texi (C++ Dialect Options): Likewise.

gcc/cp/ChangeLog:

	PR c++/88115
	* mangle.c (write_expression): Mangle __alignof_ differently
	from alignof when the ABI version is at least 15.

libiberty/ChangeLog:

	PR c++/88115
	* cp-demangle.c (d_print_comp_inner)
	<case DEMANGLE_COMPONENT_EXTENDED_OPERATOR>: Don't print the
	"operator " prefix for __alignof__.
	<case DEMANGLE_COMPONENT_UNARY>: Always print parens around the
	operand of __alignof__.
	* testsuite/demangle-expected: Test demangling for __alignof__.

gcc/testsuite/ChangeLog:

	PR c++/88115
	* g++.dg/abi/macro0.C: Adjust.
	* g++.dg/cpp0x/alignof7.C: New test.
	* g++.dg/cpp0x/alignof8.C: New test.
2020-11-11 15:11:23 -05:00
Ian Lance Taylor bae45b8be5 demangler: don't treat lambda as a substitution candidate
libiberty/ChangeLog:

	PR demangler/96143
	* cp-demangle.c (d_lambda): Don't add substitution candidate.
	* testsuite/demangle-expected: Update a few existing test cases
	accordingly, and add a new test case.
2020-07-14 10:25:48 -07:00
Jason Merrill 6324c52bba c++: Support non-type template parms of union type.
Another thing newly allowed by P1907R1.  The ABI group has discussed
representing unions with designated initializers, and has separately
specified how to represent designators; this patch implements both.

gcc/cp/ChangeLog:

	* tree.c (structural_type_p): Allow unions.
	* mangle.c (write_expression): Express unions with a designator.

libiberty/ChangeLog:

	* cp-demangle.c (cplus_demangle_operators): Add di, dx, dX.
	(d_expression_1): Handle di and dX.
	(is_designated_init, d_maybe_print_designated_init): New.
	(d_print_comp_inner): Use d_maybe_print_designated_init.
	* testsuite/demangle-expected: Add designator tests.

gcc/testsuite/ChangeLog:

	* g++.dg/cpp2a/nontype-class-union1.C: New test.
2020-07-10 08:36:50 -04:00
Jakub Jelinek 76458c912b demangler: Handle <=> operator in the demangler [PR94797]
The demangler didn't handle spaceship operator.

2020-04-27  Jakub Jelinek  <jakub@redhat.com>

	PR demangler/94797
	* cp-demangle.c (cplus_demangle_operators): Add ss <=> operator.
	* testsuite/demangle-expected: Add operator<=> test.
2020-04-27 20:59:25 +02:00
Iain Sandoe 7ebbff3acb [libiberty] Update demangler to handle co_await operator.
C++20 coroutines introduces a new operator with a mangling of 'aw'.
This patch adds that to libiberty's demangler.

libiberty/ChangeLog:

2020-01-18  Iain Sandoe  <iain@sandoe.co.uk>

	* cp-demangle.c (cplus_demangle_operators): Add the co_await
	operator.
	* testsuite/demangle-expected: Test co_await operator mangling.
2020-01-18 12:15:12 +00:00
Jakub Jelinek 8d9254fc8a Update copyright years.
From-SVN: r279813
2020-01-01 12:51:42 +01:00
Jeff Law 513e0aa0c4 [PATCH] Fix slowness in demangler
* cp-demangle.c (d_print_init): Remove const from 4th param.
	(cplus_demangle_fill_name): Initialize d->d_counting.
	(cplus_demangle_fill_extended_operator): Likewise.
	(cplus_demangle_fill_ctor): Likewise.
	(cplus_demangle_fill_dtor): Likewise.
	(d_make_empty): Likewise.
	(d_count_templates_scopes): Remobe const from 3rd param,
	Return on dc->d_counting > 1,
	Increment dc->d_counting.
        * cp-demint.c (cplus_demangle_fill_component): Initialize d->d_counting.
	(cplus_demangle_fill_builtin_type): Likewise.
	(cplus_demangle_fill_operator): Likewise.

	* demangle.h (struct demangle_component): Add member
	d_counting.

From-SVN: r278359
2019-11-16 10:14:14 -07:00
Kamlesh Kumar e0c866ddfd PR c++/91979 - mangling nullptr expression
2019-11-04  Kamlesh Kumar  <kamleshbhalui@gmail.com>

gcc/cp
        * cp/mangle.c (write_template_arg_literal): Handle nullptr
        mangling.
gcc
	* common.opt (-fabi-version): Document =14.
	* doc/invoke.texi (C++ Dialect Options): Likewise.
gcc/c-family
        * c-opts.c (c_common_post_options): Update
        latest_abi_version.
libiberty
        * cp-demangle.c (d_expr_primary): Handle
        nullptr demangling.
        * testsuite/demangle-expected: Added test.

From-SVN: r277801
2019-11-04 18:24:25 -05:00
Paul Pluzhnikov 1c40e11956 cp-demangle.c (d_number): Avoid signed int overflow.
2019-10-29 Paul Pluzhnikov  <ppluzhnikov@google.com>

	* cp-demangle.c (d_number): Avoid signed int overflow.

From-SVN: r277575
2019-10-29 08:29:59 -07:00
Miguel Saldivar 420fb10c09 cp-demangle.c (d_print_mod): Add a space before printing `complex` and `imaginary`, as opposed to after.
* cp-demangle.c (d_print_mod): Add a space before printing `complex`
	and `imaginary`, as opposed to after.
	* testsuite/demangle-expected: Adjust test.

From-SVN: r277535
2019-10-28 13:14:48 -06:00
Michael Forney 2a1c064a94 cp-demangle.c: Don't define CP_DYNAMIC_ARRAYS if __STDC_NO_VLA__ is non-zero.
* cp-demangle.c: Don't define CP_DYNAMIC_ARRAYS if __STDC_NO_VLA__
	is non-zero.

From-SVN: r271819
2019-05-31 12:25:48 -06:00
Ben L 80024f3180 cp-demangle (d_print_comp_inner): Guard against a NULL 'typed_name'.
* cp-demangle (d_print_comp_inner): Guard against a NULL 'typed_name'.
    * testsuite/demangle-expected: Add testcase.

From-SVN: r270695
2019-04-30 08:22:41 -06:00
Ben L 927e42fd52 cp-demangle.c (d_encoding): Guard against NULL return values from d_right (dc).
* cp-demangle.c (d_encoding): Guard against NULL return values from
     d_right (dc).
     * testsuite/demangle-expected: Add testcase.

From-SVN: r270694
2019-04-30 08:20:11 -06:00
Ben L 956bea2cd6 cp-demangle.c (d_expression_1): Don't peek ahead unless the current char is valid.
* cp-demangle.c (d_expression_1): Don't peek ahead unless the current
	char is valid.
	* testsuite/demangle-expected: Add testcase.

From-SVN: r270664
2019-04-29 16:19:01 -06:00
Nick Clifton 6fe6bd7c08 Fix a stack exhaustion bug in libiberty's demangler when decoding a pathalogically constructed mangled name.
PR 89394
	* cp-demangle.c (cplus_demangle_fill_name): Reject negative
	lengths.
	(d_count_templates_scopes): Replace num_templates and num_scopes
	parameters with a struct d_print_info pointer parameter.  Adjust
	body of the function accordingly.  Add recursion counter and check
	that the recursion limit is not reached.
	(d_print_init): Pass dpi parameter to d_count_templates_scopes.
	Reset recursion counter afterwards, unless the recursion limit was
	reached.

From-SVN: r270258
2019-04-10 14:44:47 +00:00
Tom Honermann 2d91f79dc9 Implement P0482R5, char8_t: A type for UTF-8 characters and strings
gcc/cp/
	* cvt.c (type_promotes_to): Handle char8_t promotion.
	* decl.c (grokdeclarator): Handle invalid type specifier
	combinations involving char8_t.
	* lex.c (init_reswords): Add char8_t as a reserved word.
	* mangle.c (write_builtin_type): Add name mangling for char8_t (Du).
	* parser.c (cp_keyword_starts_decl_specifier_p)
	(cp_parser_simple_type_specifier): Recognize char8_t as a simple
	type specifier.
	(cp_parser_string_literal): Use char8_array_type_node for the type
	of CPP_UTF8STRING.
	(cp_parser_set_decl_spec_type): Tolerate char8_t typedefs in system
	headers.
	* rtti.c (emit_support_tinfos): type_info support for char8_t.
	* tree.c (char_type_p): Recognize char8_t as a character type.
	* typeck.c (string_conv_p): Handle conversions of u8 string
	literals of char8_t type.
	(check_literal_operator_args): Handle UDLs with u8 string literals
	of char8_t type.
	* typeck2.c (ordinary_char_type_p): New.
	(digest_init_r): Disallow initializing a char array with a u8 string
	literal.
gcc/c-family/
	* c-common.c (c_common_reswords): Add char8_t.
	(fix_string_type): Use char8_t for the type of u8 string literals.
	(c_common_get_alias_set): char8_t doesn't alias.
	(c_common_nodes_and_builtins): Define char8_t as a builtin type in
	C++.
	(c_stddef_cpp_builtins): Add __CHAR8_TYPE__.
	(keyword_begins_type_specifier): Add RID_CHAR8.
	* c-common.h (rid): Add RID_CHAR8.
	(c_tree_index): Add CTI_CHAR8_TYPE and CTI_CHAR8_ARRAY_TYPE.
	Define D_CXX_CHAR8_T and D_CXX_CHAR8_T_FLAGS.
	Define char8_type_node and char8_array_type_node.
	* c-cppbuiltin.c (cpp_atomic_builtins): Predefine
	__GCC_ATOMIC_CHAR8_T_LOCK_FREE.
	(c_cpp_builtins): Predefine __cpp_char8_t.
	* c-lex.c (lex_string): Use char8_array_type_node as the type of
	CPP_UTF8STRING.
	(lex_charconst): Use char8_type_node as the type of CPP_UTF8CHAR.
	* c-opts.c: If not otherwise specified, enable -fchar8_t when
	targeting C++2a.
	* c.opt: Add the -fchar8_t command line option.
libiberty/
	* cp-demangle.c (cplus_demangle_builtin_types)
	(cplus_demangle_type): Add name demangling for char8_t (Du).
	* cp-demangle.h: Increase D_BUILTIN_TYPE_COUNT to accommodate the
	new char8_t type.

From-SVN: r267923
2019-01-14 14:55:51 -05:00
Sandra Loosemore adcb167e03 PR other/16615 [2/5]
2019-01-09  Sandra Loosemore  <sandra@codesourcery.com>

	PR other/16615 [2/5]

	include/
	* libiberty.h: Mechanically replace "can not" with "cannot".
	* plugin-api.h: Likewise.

	libiberty/
	* cp-demangle.c: Mechanically replace "can not" with "cannot".
	* floatformat.c: Likewise.
	* strerror.c: Likewise.

From-SVN: r267784
2019-01-09 16:39:49 -05:00
Jakub Jelinek a554497024 Update copyright years.
From-SVN: r267494
2019-01-01 13:31:55 +01:00
Nick Clifton e96d1d8c78 Add a recursion limit to libiberty's demangling code. The limit is enabled by default, but can be disabled via a new demangling option.
include	* demangle.h (DMGL_NO_RECURSE_LIMIT): Define.
        (DEMANGLE_RECURSION_LIMIT): Define

	PR 87681
	PR 87675
	PR 87636
	PR 87350
	PR 87335
libiberty * cp-demangle.h (struct d_info): Add recursion_level field.
	* cp-demangle.c (d_function_type): Add recursion counter.
	If the recursion limit is reached and the check is not disabled,
	then return with a failure result.
	(cplus_demangle_init_info): Initialise the recursion_level field.
        (d_demangle_callback): If the recursion limit is enabled, check
	for a mangled string that is so long that there is not enough
	stack space for the local arrays.
        * cplus-dem.c (struct work): Add recursion_level field.
	(squangle_mop_up): Set the numb and numk fields to zero.
	(work_stuff_copy_to_from): Handle the case where a btypevec or 
	ktypevec field is NULL.
	(demangle_nested_args): Add recursion counter.  If
	the recursion limit is not disabled and reached, return with a
	failure result.

From-SVN: r266886
2018-12-07 10:33:30 +00:00
Jason Merrill 4be5c72cf3 Implement P0732R2, class types in non-type template parameters.
There is one significant piece of this that is not implemented yet: the
reliance on defaulted operator<=>, which someone else has been working on.
So, for the moment those lines are commented out of the testcases.

One tricky bit was treating template parameters of classtype as const
lvalues without making their decltype const; for this I used a
VIEW_CONVERT_EXPR wrapper, which previously could only appear in templates
as location wrappers.

The user-defined literal parts of P0732R2 are in the next patch.

gcc/cp/
	* error.c (dump_simple_decl): Look through a template parm object.
	* mangle.c (write_template_arg): Likewise.
	(mangle_template_parm_object): New.
	* pt.c (template_parm_object_p, get_template_parm_object): New.
	(invalid_tparm_referent_p): Factor from convert_nontype_argument.
	(convert_nontype_argument, invalid_nontype_parm_type_p): Handle
	class-type template arguments.
	* tree.c (lvalue_kind): Likewise.
gcc/c-family/
	* c-cppbuiltin.c (c_cpp_builtins): Add
	__cpp_nontype_template_parameter_class.
libiberty/
	* cp-demangle.c (d_dump, d_make_comp, d_count_templates_scopes)
	(d_print_comp_inner): Handle DEMANGLE_COMPONENT_TPARM_OBJ.
	(d_special_name): Handle TA.
	(d_expresion_1): Fix demangling of brace-enclosed initializer list.
include/
	* demangle.h (enum demangle_component_type): Add
	DEMANGLE_COMPONENT_TPARM_OBJ.

From-SVN: r265789
2018-11-05 02:47:02 -05:00
David Malcolm b2353e5931 libiberty: fix URL for demangler ABI
libiberty/ChangeLog:
	* cp-demangle.c: Update URL for g++ V3 ABI.

From-SVN: r258155
2018-03-02 20:20:37 +00:00
Jakub Jelinek 85ec4feb11 Update copyright years.
From-SVN: r256169
2018-01-03 11:03:58 +01:00
Nathan Sidwell 68aac47f3a re PR demangler/82195 (Undemangleable lambda)
PR demangler/82195
	* cp-demangle.c (d_encoding): Strip return type when name is a
	LOCAL_NAME.
	(d_local_name): Strip return type of enclosing TYPED_NAME.
	* testsuite/demangle-expected: Add and adjust tests.

From-SVN: r253186
2017-09-26 02:38:12 +00:00
Nathan Sidwell 7cd7dbdadf [demangler PATCH]: Revert and update generic lambda demangling
https://gcc.gnu.org/ml/gcc-patches/2017-09/msg01482.html
	PR demangler/82195
	* cp-demangle.c (d_name): Revert addition of 'toplevel' parm.
	(has_return_type): Recurse for DEMANGLE_COMPONENT_LOCAL_NAME.
	(d_encoding): Revert d_name change.  Use is_fnqual_component_type
	to strip modifiers that do not belong.
	(d_special_name, d_class_enum_type): Revert d_name call change.
	(d_expresion_1): Commonize DEMANGLE_COMPONENT_UNARY building.
	(d_local_name): Revert parsing of a function type.
	(d_print_comp_inner): An inner LOCAL_NAME might contain a
	TEMPLATE.
	* testsuite/demangle-expected: Add & adjust tests

From-SVN: r253075
2017-09-21 15:52:31 +00:00
Nathan Sidwell fa0cdfb651 [demangler] Fix nested generic lambda
https://gcc.gnu.org/ml/gcc-patches/2017-09/msg00994.html
	PR demangler/82195
	* cp-demangle.c (d_name): Add 'toplevel' parm.  Pass to	...
	(d_local_name): ... here.  Parse trailing function args on nested
	local_name.
	(d_encoding, d_special_name, d_class_enum_type): Adjust d_name calls.
	* testsuite/demangle-expected: Add tests.

From-SVN: r252815
2017-09-15 12:23:57 +00:00
Nathan Sidwell 9d89efebaa [Demangle PATCH] Some pre-fix cleanups
https://gcc.gnu.org/ml/gcc-patches/2017-09/msg00983.html

	* cp-demangle.c (is_fnqual_component_type): Reimplement using
	FNQUAL_COMPONENT_CASE.
	(d_encoding): Hold bare_function_type in local var.
	(d_local_name): Build name in both cases and build result once.
	Collapse switch-if to single conditional.
	* testsuite/demangle-expected: Realign blank lines with tests.

From-SVN: r252802
2017-09-15 10:50:05 +00:00
Jonathan Wakely de3b531c9a PR demangler/80513 check for overflows and invalid characters in thunks
PR demangler/80513
	* cp-demangle.c (d_number): Check for overflow.
	* cplus-dem.c (consume_count): Fix overflow check.
	(gnu_special): Check for underscore after thunk delta.
	* testsuite/demangle-expected: Add tests for overflows and invalid
	characters in thunks.

From-SVN: r247300
2017-04-27 10:44:28 +01:00
Mark Wielaard 6b086d35b7 libiberty: Limit demangler maximum d_print_comp recursion call depth.
The fix for PR demangler/70909 and 67264 (endless demangler recursion)
catches when a demangle_component is printed in a cycle. But that doesn't
protect the call stack blowing up from non-cyclic nested types printed
recursively through d_print_comp. This can happen by a (very) long mangled
string that simply creates a very deep pointer or qualifier chain. Limit
the recursive d_print_comp call depth for a d_print_info to 1K nested
types.

libiberty/ChangeLog:

        * cp-demangle.c (MAX_RECURSION_COUNT): New constant.
        (struct d_print_info): Add recursion field.
        (d_print_init): Initialize recursion.
        (d_print_comp): Check and update d_print_info recursion depth.

From-SVN: r247056
2017-04-21 09:02:03 +00:00
Mark Wielaard 13b6ef76dc libiberty: Always return NULL if d_add_substitution fails.
d_add_substitution can fail for various reasons, like when the subs array
is full. If d_add_substitution fails d_substitution should return NULL
early and not try to continue. Every other call of d_add_substitution
is handled in the same way.

libiberty/ChangeLog:

	* cp-demangle.c (d_substitution): Return NULL if d_add_substitution
	fails.

From-SVN: r247055
2017-04-21 09:01:56 +00:00
Mark Wielaard 1240212c6b libiberty: Don't update and remove did_subs field from demangler structs.
The d_info field did_subs was used for estimating the string output
size. It was no longer used when the malloc-less callback interface
was introduced in 2007 (svn r121305). But the field was still updated.
When backtracking was introduced in 2013 (svn r205292) did_subs was
also added to the d_info_checkpoint struct. But except for updating
the field it was still not used.

Since it is never used just stop updating the field and remove it
from the two structs.

libiberty/ChangeLog:

	* cp-demangle.h (struct d_info): Remove did_subs field.
	* cp-demangle.c (struct d_info_checkpoint): Likewise.
	(d_template_param): Don't update did_subs.
	(d_substitution): Likewise.
	(d_checkpoint): Don't assign did_subs.
	(d_backtrack): Likewise.
	(cplus_demangle_init_info): Don't initialize did_subs.

From-SVN: r247054
2017-04-21 09:01:44 +00:00
Mark Wielaard 9905ca975c libiberty: Initialize d_printing in all cplus_demangle_fill_* functions.
While integrating the d_printing recursion guard change into gdb I
noticed we forgot to initialize the demangle_component d_printing
field in cplus_demangle_fill_{name,extended_operator,ctor,dtor}.
As is done in cplus_demangle_fill_{component,builtin_type,operator}.
It happened to work because in gcc all demangle_components were
allocated through d_make_empty. But gdb has its own allocation
mechanism (as might other users).

libiberty/ChangeLog:

       * cp-demangle.c (cplus_demangle_fill_name): Initialize
       demangle_component d_printing.
       (cplus_demangle_fill_extended_operator): Likewise.
       (cplus_demangle_fill_ctor): Likewise.
       (cplus_demangle_fill_dtor): Likewise.

From-SVN: r246105
2017-03-13 18:26:47 +00:00
Mark Wielaard a46586c34f Fix PR demangler/70909 and 67264 (endless demangler recursion)
ChangeLog:

       PR demangler/70909
       PR demangler/67264
       * include/demangle.h: Add d_printing to struct demangle_component
       and pass struct demangle_component as non const.

libiberty/ChangeLog:

       PR demangler/70909
       PR demangler/67264
       * cp-demangle.c: Fix endless recursion. Pass
       struct demangle_component as non const.
       (d_make_empty): Initialize variable.
       (d_print_comp_inner): Limit recursion.
       (d_print_comp): Decrement variable.
       * cp-demint.c (cplus_demangle_fill_component): Initialize
       variable.
       (cplus_demangle_fill_builtin_type): Likewise.
       (cplus_demangle_fill_operator): Likewise.
       * testsuite/demangle-expected: Add tests.

From-SVN: r245978
2017-03-08 14:28:38 +00:00
Markus Trippelsdorf 4bbc35f33f Fix PR70182 -- missing "on" in mangling of unresolved operators
The ABI says:

<unresolved-name>
   ::= [gs] <base-unresolved-name>
   ::= sr <unresolved-type> <base-unresolved-name>
   ::= srN <unresolved-type> <unresolved-qualifier-level>+ E <base-unresolved-name>
   ::= [gs] sr <unresolved-qualifier-level>+ E <base-unresolved-name>

<base-unresolved-name>
   ::= <simple-id>
   ::= on <operator-name>
   ::= on <operator-name> <template-args>
   ::= dn <destructor-name

libiberty:

	PR c++/70182
	* cp-demangle.c (d_unqualified_name): Handle "on" for
	operator names.
	* testsuite/demangle-expected: Add tests.

gcc/cp:

	PR c++/70182
	* mangle.c (write_template_args): Add "on" for operator names.

gcc:

	PR c++/70182
	* doc/invoke.texi (fabi-version): Mention mangling fix for
	operator names.

From-SVN: r244567
2017-01-18 08:49:11 +00:00
Markus Trippelsdorf f6efea5163 Fix PR77489 -- mangling of discriminator >= 1
libiberty:

	PR c++/77489
	* cp-demangle.c (d_discriminator): Handle discriminator >= 10.
	* testsuite/demangle-expected: Add tests for discriminator.

gcc:
	PR c++/77489
	* doc/invoke.texi (fabi-version): Document discriminator mangling.

gcc/cp:

	PR c++/77489
	* mangle.c (write_discriminator): Handle discriminator >= 10.

From-SVN: r244566
2017-01-18 08:40:05 +00:00
Jakub Jelinek 2afd3180c5 Update copyright years.
From-SVN: r244052
2017-01-04 12:30:51 +01:00
Jakub Jelinek 816f431440 re PR c++/78761 (C++14, compiler generate mangled name that can not be demangled)
PR c++/78761
	* cp-demangle.c (cplus_demangle_type): Demangle Dc as decltype(auto).
	* testsuite/demangle-expected: Add test for decltype(auto).

From-SVN: r243593
2016-12-13 07:16:05 +01:00
Nathan Sidwell 8e09a726e6 re PR other/78252 (C++ demangler crashes with infinite recursion with lambda (auto))
libiberty/
	PR c++/78252
	* cp-demangle.c (struct d_print_info): Add is_lambda_arg field.
	(d_print_init): Initialize it.
	(d_print_comp_inner) <DEMANGLE_COMPONENT_TEMPLATE_PARAM>: Check
	is_lambda_arg for auto.
	<DEMANGLE_COMPONENT_REFERENCE,
	DEMANGLE_COMPONENT_RVALUE_REFERENCE>: Skip smashing check when
	is_lambda_arg.
	<DEMANGLE_COMPONENT_LAMBDA>: Increment is_lambda_arg around arg
	printing.
	* testsuite/demangle-expected: Add lambda auto mangling cases.

	gcc/testsuite/
	PR c++/78252
	* g++.dg/cpp1y/lambda-mangle-1.C: New.

From-SVN: r243566
2016-12-12 17:00:37 +00:00
Nathan Sidwell 8684b29203 * cp-demangle.c (d_print_comp_inner): Fix parameter indentation.
From-SVN: r242963
2016-11-29 15:28:52 +00:00
Mark Wielaard 168126e598 libiberty: demangler crash with missing :? or fold expression component.
When constructing an :? or fold expression that requires a third
expression only the first and second were explicitly checked to
not be NULL. Since the third expression is also required in these
constructs it needs to be explicitly checked and rejected when missing.
Otherwise the demangler will crash once it tries to d_print the
NULL component. Added two examples to demangle-expected of strings
that would crash before this fix.

Found by American Fuzzy Lop (afl) fuzzer.

From-SVN: r242451
2016-11-15 19:31:59 +00:00
Jason Merrill 51dc660315 Implement P0012R1, Make exception specifications part of the type system.
gcc/cp/
	* cp-tree.h (enum tsubst_flags): Add tf_fndecl_type.
	(flag_noexcept_type, ce_type): New.
	* call.c (build_conv): Add ck_fnptr.
	(enum conversion_kind): Change ck_tsafe to ck_fnptr.
	(convert_like_real): Likewise.
	(standard_conversion): Likewise.  Allow function pointer
	conversions for pointers to member functions.
	(reference_compatible_p): Allow function pointer conversions.
	(direct_reference_binding): Likewise.
	(reference_binding): Reference-compatible is no longer a subset of
	reference-related.
	(is_subseq): Also strip ck_lvalue after next_conversion.
	* class.c (instantiate_type): Check fnptr_conv_p.
	(resolve_address_of_overloaded_function): Likewise.
	* cvt.c (can_convert_tx_safety): Now static.
	(noexcept_conv_p, fnptr_conv_p, strip_fnptr_conv): New.
	* decl.c (flag_noexcept_type): Define.
	(cxx_init_decl_processing): Set it.
	(bad_specifiers): Check it.
	(grokdeclarator) [cdk_function]: Add exception-spec to type here.
	* lambda.c (maybe_add_lambda_conv_op): Add exception-spec to
	returned pointer.
	* mangle.c (struct globals): Add need_cxx1z_warning.
	(mangle_decl): Check it.
	(write_exception_spec): New.
	(write_function_type): Call it.
	(canonicalize_for_substitution): Handle exception spec.
	(write_type): Likewise.
	(write_encoding): Set processing_template_decl across mangling of
	partially-instantiated type.
	* pt.c (determine_specialization): Pass tf_fndecl_type.
	(tsubst_decl, fn_type_unification): Likewise.
	(tsubst): Strip tf_fndecl_type, pass it to
	tsubst_exception_specification.
	(convert_nontype_argument_function): Handle function pointer
	conversion.
	(convert_nontype_argument): Likewise.
	(unify, for_each_template_parm_r): Walk into noexcept-specifier.
	* rtti.c (ptr_initializer): Encode noexcept.
	* tree.c (canonical_eh_spec): New.
	(build_exception_variant): Use it.
	* typeck.c (composite_pointer_type): Handle fnptr conversion.
	(comp_except_specs): Compare canonical EH specs.
	(structural_comptypes): Call it.
gcc/c-family/
	* c.opt (Wc++1z-compat): New.
	* c-cppbuiltin.c (c_cpp_builtins): Add __cpp_noexcept_function_type.
libstdc++-v3/
	* include/bits/c++config (_GLIBCXX_NOEXCEPT_PARM)
	(_GLIBCXX_NOEXCEPT_QUAL): New.
	* include/std/type_traits (is_function): Use them.
	* libsubc++/new (launder): Likewise.
	* libsupc++/cxxabi.h (__pbase_type_info::__masks): Add
	__noexcept_mask.
	* libsupc++/pbase_type_info.cc (__do_catch): Handle function
	pointer conversion.
libiberty/
	* cp-demangle.c (is_fnqual_component_type): New.
	(d_encoding, d_print_comp_inner, d_print_mod_list): Use it.
	(FNQUAL_COMPONENT_CASE): New.
	(d_make_comp, has_return_type, d_print_comp_inner)
	(d_print_function_type): Use it.
	(next_is_type_qual): New.
	(d_cv_qualifiers, d_print_mod): Handle noexcept and throw-spec.
include/
	* demangle.h (enum demangle_component_type): Add
	DEMANGLE_COMPONENT_NOEXCEPT, DEMANGLE_COMPONENT_THROW_SPEC.

From-SVN: r241944
2016-11-07 18:09:29 -05:00
Jason Merrill 31f7f784fe Implement P0136R1, Rewording inheriting constructors.
gcc/c-family/
	* c.opt (-fnew-inheriting-ctors): New.
	* c-opts.c: Default to on for ABI 11+.
gcc/cp/
	* call.c (enum rejection_reason_code): Add rr_inherited_ctor.
	(inherited_ctor_rejection): New.
	(add_function_candidate): Reject inherited ctors for copying.
	(enforce_access): Use strip_inheriting_ctors.
	(print_z_candidate): Likewise.  Handle rr_inherited_ctor.
	(convert_like_real): Avoid copying inheriting ctor parameters.
	(build_over_call): Likewise.  A base ctor inheriting from vbase
	has no parms.  Sorry about varargs.
	(joust): A local constructor beats inherited with the same convs.
	* class.c (add_method): Handle hiding inheriting ctors.
	(one_inherited_ctor): Handle new semantics.
	(add_implicitly_declared_members): Pass using_decl down.
	(build_clone): A base ctor inheriting from vbase has no parms.
	* cp-tree.h (DECL_INHERITED_CTOR): Store this instead of the base.
	(SET_DECL_INHERITED_CTOR): Likewise.
	(DECL_INHERITED_CTOR_BASE): Adjust.
	* constexpr.c: Adjust.
	* error.c (dump_function_decl): Decorate inheriting ctors.
	* init.c (emit_mem_initializers): Suppress access control in
	inheriting ctor.
	* mangle.c (write_special_name_constructor): Handle new inheriting
	ctor mangling.
	* method.c (strip_inheriting_ctors, inherited_ctor_binfo)
	(ctor_omit_inherited_parms, binfo_inherited_from): New.
	(synthesized_method_walk): Use binfo_inherited_from.  Suppress
	access control in inheriting ctor.
	(deduce_inheriting_ctor): Deleted if ambiguous ctor inheritance.
	(maybe_explain_implicit_delete): Explain ambigous ctor inheritance.
	(add_one_base_init, do_build_copy_constructor): Adjust.
	(locate_fn_flags, explain_implicit_non_constexpr): Adjust.
	(implicitly_declare_fn): Adjust.
	(get_inherited_ctor): Remove.
	* name-lookup.c (do_class_using_decl): Check for indirect ctor
	inheritance.
	* optimize.c (cdtor_comdat_group): Adjust for new mangling.
	(maybe_clone_body): Handle omitted parms in base clone.
	(maybe_thunk_body): Don't thunk if base clone omits parms.
	* pt.c (tsubst_decl): Adjust.
	(instantiate_template_1): Suppress access control in inheriting
	ctor.
	(fn_type_unification): Do deduction with inherited ctor.
	* tree.c (special_function_p): Adjust.
gcc/
	* tree-inline.c (copy_tree_body_r): Only copy the taken branch of
	a COND_EXPR with constant condition.
libiberty/
	* cp-demangle.c (d_ctor_dtor_name): Handle inheriting constructor.

From-SVN: r241765
2016-11-01 21:50:29 -04:00
Mark Wielaard 99e77371ca Fix -Wshadow warning in libiberty/cp-demangle.c
valgrind contains a copy of the libiberty demangler which gets compiled
with -Wshadow. That shows the following warning:

cp-demangle.c: In function ‘d_substitution’:
cp-demangle.c:3772:35: warning: declaration of ‘c’ shadows a previous local
        struct demangle_component *c;
                                   ^
cp-demangle.c:3708:8: note: shadowed declaration is here
   char c;
        ^

Fix that by renaming the struct demangle_component variable to dc.

libiberty/ChangeLog:

	* cp-demangle.c (d_substitution): Change struct demangle_component
	variable name from c to dc.

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

From-SVN: r239410
2016-08-12 10:30:47 +00:00
Jason Merrill 7864eaaff7 Demangle C++17 fold-expressions.
* cp-demangle.c (cplus_demangle_operators): Add f[lrLR].
	(d_expression_1): Handle them.
	(d_maybe_print_fold_expression): New.
	(d_print_comp_inner): Use it.
	(d_index_template_argument): Handle negative index.

From-SVN: r238437
2016-07-18 11:28:51 -04:00
Jason Merrill 34bbc4c502 PR c++/71814 - mangling sizeof... (sP and sZ)
gcc/cp/
	* mangle.c (write_expression): Handle sizeof... an argument pack.
libiberty/
	* cp-demangle.c (cplus_demangle_operators): Add sP and sZ.
	(d_print_comp_inner): Handle them.
	(d_template_args_1): Split out from d_template_args.
	(d_args_length): New.

From-SVN: r238389
2016-07-15 14:38:15 -04:00