aboutsummaryrefslogtreecommitdiff
path: root/libiberty/d-demangle.c
AgeCommit message (Collapse)AuthorFilesLines
2024-01-03Update copyright years.Jakub Jelinek1-1/+1
2023-01-16Update copyright years.Jakub Jelinek1-1/+1
2022-01-03Update copyright years.Jakub Jelinek1-1/+1
2021-10-17[PATCH] d-demangle: properly skip anonymous symbolsLuís Ferreira1-4/+10
libiberty/ PR d/102618 * d-demangle.c (dlang_parse_qualified): Handle anonymous symbols correctly. * testsuite/d-demangle-expected: New tests to cover anonymous symbols.
2021-10-12[PATCH v2] libiberty: d-demangle: remove parenthesis where it is not neededLuís Ferreira1-6/+6
libiberty/ * d-demangle.c (dlang_parse_qualified): Remove redudant parenthesis around lhs and rhs of assignments.
2021-09-23libiberty: prevent null dereferencing on dlang_typeLuís Ferreira1-1/+1
libiberty/ * d-demangle.c (dlang_Type): Validate MANGLED is nonnull. * testsuite/d-demangle-expected: New test.
2021-09-23libiberty: prevent buffer overflow when decoding user inputLuís Ferreira1-1/+1
libiberty/ * d-demangle.c (dlang_symbol_backref): Ensure strlen of string is less than length computed by dlang_number.
2021-08-30libiberty: Add support for demangling local D template declarationsIain Buclaw1-0/+19
The D language now allows multiple different template declarations in the same function that have the same mangled name. To make the mangled names unique, a fake parent in the form `__Sddd' is added to the symbol. This information is not important for the user, so the demangler now handles and ignores it. libiberty/ChangeLog: * d-demangle.c (dlang_identifier): Skip over fake parent manglings. * testsuite/d-demangle-expected: Add tests.
2021-08-30libiberty: Add support for demangling D function literals as template value ↵Iain Buclaw1-13/+27
parameters The D language now allows instantiating templates using struct literals that have function literal fields as a value argument. libiberty/ChangeLog: * d-demangle.c (dlang_parse_arrayliteral): Add 'info' parameter. (dlang_parse_assocarray): Likewise. (dlang_parse_structlit): Likewise. (dlang_value): Likewise. Handle function literal symbols. (dlang_template_args): Pass 'info' to dlang_value. * testsuite/d-demangle-expected: Add new test.
2021-08-30libiberty: Add support for D `typeof(*null)' typesIain Buclaw1-2/+10
The D language has a new bottom type `typeof(*null)'. Null types were also incorrectly being demangled as `none', this has been fixed to be `typeof(null)'. libiberty/ChangeLog: * d-demangle.c (dlang_attributes): Handle typeof(*null). (dlang_type): Likewise. Demangle 'n' as typeof(null). * testsuite/d-demangle-expected: Update tests.
2021-01-04Update copyright years.Jakub Jelinek1-1/+1
2020-09-08ubsan: d-demangle.c:214 signed integer overflowAlan Modra1-45/+61
Running the libiberty testsuite ./test-demangle < libiberty/testsuite/d-demangle-expected libiberty/d-demangle.c:214:14: runtime error: signed integer overflow: 922337203 * 10 cannot be represented in type 'long int' On looking at silencing ubsan, I found a real bug in dlang_number. For a 32-bit long, some overflows won't be detected. For example, 21474836480. Why? Well 214748364 * 10 is 0x7FFFFFF8 (no overflow so far). Adding 8 gives 0x80000000 (which does overflow but there is no test for that overflow in the code). Then multiplying 0x80000000 * 10 = 0x500000000 = 0 won't be caught by the multiplication overflow test. The same holds for a 64-bit long using similarly crafted digit sequences. * d-demangle.c: Include limits.h. (ULONG_MAX, UINT_MAX): Provide fall-back definition. (dlang_number): Simplify and correct overflow test. Only write *ret on returning non-NULL. Make "ret" an unsigned long*. Only succeed for result of [0,UINT_MAX]. (dlang_decode_backref): Simplify and correct overflow test. Only write *ret on returning non-NULL. Only succeed for result [1,MAX_LONG]. (dlang_backref): Remove now unnecessary range check. (dlang_symbol_name_p): Likewise. (string_need): Take a size_t n arg, and use size_t tem. (string_append): Use size_t n. (string_appendn, string_prependn): Take a size_t n arg. (TEMPLATE_LENGTH_UNKNOWN): Define as -1UL. (dlang_lname, dlang_parse_template): Take an unsigned long len arg. (dlang_symbol_backref, dlang_identifier, dlang_parse_integer), (dlang_parse_integer, dlang_parse_string), (dlang_parse_arrayliteral, dlang_parse_assocarray), (dlang_parse_structlit, dlang_parse_tuple), (dlang_template_symbol_param, dlang_template_args): Use unsigned long variables. * testsuite/d-demangle-expected: Add new tests.
2020-08-26libiberty: Add support for `in' and `in ref' storage classes.Iain Buclaw1-1/+9
The storage class `in' is now a first-class citizen with its own mangle symbol, of which also permits `in ref'. Previously, `in' was an alias to `const [scope]', which is a type constructor. The mangle symbol repurposed for this is `I', which was originally used by identifier types. However, while TypeIdentifier is part of the grammar, it must be resolved to some other entity during the semantic passes, and so shouldn't appear anywhere in the mangled name. Old tests that are now no longer valid have been removed. libiberty/ChangeLog: * d-demangle.c (dlang_function_args): Handle 'in' and 'in ref' parameter storage classes. (dlang_type): Remove identifier type. * testsuite/d-demangle-expected: Update tests.
2020-05-15libiberty: Handle @live attribute in D demangler.Iain Buclaw1-0/+4
Adds support for demangling D functions annotated with the new ownership/borrowing system attribute. libiberty/ChangeLog: * d-demangle.c (dlang_attributes): Add @live attribute. * testsuite/d-demangle-expected: Add new tests.
2020-05-14libiberty: Update D symbol demangling for latest ABI spec.Iain Buclaw1-261/+508
Some small improvements and clarifications have been done in the D ABI specification to remove all ambiguities found in the current grammar, this implementation now more closely resembles the spec, whilst maintaining compatibility with the old ABI. Three new rules have been added to the ABI. 1. Back references using 'Q', analogous to C++ substitutions, compresses repeated identifiers, types, and template symbol and value parameters. 2. Template aliases to externally mangled symbols are prefixed with 'X'. This includes any symbol that isn't extern(D), or has its name overriden with pragma(mangle). This fixes an ambiguity where it was not clear whether 'V' was an encoded calling convention, or the next template value parameter. 3. Alias parameters, templates, and tuple symbols no longer encode the symbol length of its subpart. Tuples are now terminated with 'Z'. This fixes another ambiguity where the first character of the mangled name can be a digit as well, so the demangler had to figure out where to split the two adjacent numbers by trying out each combination. libiberty/ChangeLog: * d-demangle.c (enum dlang_symbol_kinds): Remove enum. (struct dlang_info): New struct (dlang_decode_backref): New function. (dlang_backref): New function. (dlang_symbol_backref): New function. (dlang_type_backref): New function. (dlang_symbol_name_p): New function. (dlang_function_type_noreturn): New function. (dlang_function_type): Add 'info' parameter. Decode function type with dlang_function_type_noreturn. (dlang_function_args): Add 'info' parameter. (dlang_type): Add 'info' parameter. Handle back referenced types. (dlang_identifier): Replace 'kind' parameter with 'info'. Handle back referenced symbols. Split off decoding of plain identifiers to... (dlang_lname): ...here. (dlang_parse_mangle): Replace 'kind' parameter with 'info'. Decode function type and return with dlang_type. (dlang_parse_qualified): Replace 'kind' parameter with 'info', add 'suffix_modifier' parameter. Decode function type with dlang_function_type_noreturn. (dlang_parse_tuple): Add 'info' parameter. (dlang_template_symbol_param): New function. (dlang_template_args): Add 'info' parameter. Decode symbol parameter with dlang_template_symbol_param. Handle back referenced values, and externally mangled parameters. (dlang_parse_template): Add 'info' parameter. (dlang_demangle_init_info): New function. (dlang_demangle): Initialize and pass 'info' parameter. * testsuite/d-demangle-expected: Add new tests. Co-Authored-By: Rainer Schuetze <r.sagitario@gmx.de>
2020-01-01Update copyright years.Jakub Jelinek1-1/+1
From-SVN: r279813
2019-04-30d-demangle.c (dlang_parse_assocarray): Correctly handle error result.Ben L1-0/+5
* d-demangle.c (dlang_parse_assocarray): Correctly handle error result. * testsuite/d-demangle-expected: Add testcase. From-SVN: r270700
2019-04-30d-demangle.c (dlang_parse_tuple): Correctly handle error result.Ben L1-0/+3
* d-demangle.c (dlang_parse_tuple): Correctly handle error result. * testsuite/d-demangle-expected: Add testcase. From-SVN: r270699
2019-04-30d-demangle.c (dlang_parse_structlit): Correctly handle error result.Ben L1-0/+3
* d-demangle.c (dlang_parse_structlit): Correctly handle error result. * testsuite/d-demangle-expected: Add testcase. From-SVN: r270698
2019-04-30d-demangle.c (dlang_parse_arrayliteral): Correctly handle error result.Ben L1-0/+3
* d-demangle.c (dlang_parse_arrayliteral): Correctly handle error result. * testsuite/d-demangle-expected: Add testcase. From-SVN: r270697
2019-04-30d-demangle.c (dlang_parse_integer): Fix stack underflow.Ben L1-3/+3
* d-demangle.c (dlang_parse_integer): Fix stack underflow. * testsuite/d-demangle-expected: Add testcase. From-SVN: r270696
2019-01-01Update copyright years.Jakub Jelinek1-1/+1
From-SVN: r267494
2018-01-03Update copyright years.Jakub Jelinek1-1/+1
From-SVN: r256169
2017-05-27d-demangle.c (dlang_identifier): Prefix mangled init symbols with ↵Iain Buclaw1-1/+2
`initializer for'. libiberty/ChangeLog: * d-demangle.c (dlang_identifier): Prefix mangled init symbols with `initializer for'. * testsuite/demangle-expected: Update tests. From-SVN: r248539
2017-05-27d-demangle.c (dlang_call_convention_p): Move declaration before dlang_type.Iain Buclaw1-24/+29
libiberty/ChangeLog: * d-demangle.c (dlang_call_convention_p): Move declaration before dlang_type. (dlang_type): Handle function types. * testsuite/d-demangle-expected: Add tests. From-SVN: r248538
2017-05-27d-demangle.c (dlang_parse_real): Remove stack buffer, write the demangled ↵Iain Buclaw1-17/+8
hexadecimal directly to string. libiberty/ChangeLog: * d-demangle.c (dlang_parse_real): Remove stack buffer, write the demangled hexadecimal directly to string. * testsuite/d-demangle-expected: Add tests. From-SVN: r248537
2017-05-01d-demangle.c (dlang_hexdigit): New function.Iain Buclaw1-52/+61
libiberty/ChangeLog: * d-demangle.c (dlang_hexdigit): New function. (ascii2hex): Remove function. (dlang_parse_string): Update to call dlang_hexdigit. * testsuite/d-demangle-expected: Add tests. From-SVN: r247455
2017-05-01d-demangle.c (strtol): Remove declaration.Iain Buclaw1-47/+57
libiberty/ChangeLog: * d-demangle.c (strtol): Remove declaration. Updated all callers to use dlang_number. (dlang_number): New function. (dlang_value): Moved check for ISDIGIT into dlang_parse_integer. * testsuite/d-demangle-expected: Add tests. From-SVN: r247453
2017-05-01d-demangle.c (dlang_parse_symbol): Remove function.Iain Buclaw1-98/+116
libiberty/ChangeLog: * d-demangle.c (dlang_parse_symbol): Remove function. (dlang_parse_qualified): New function. (dlang_parse_mangle): New function. (dlang_type): Update to call dlang_parse_qualified. (dlang_identifier): Update to call either dlang_parse_qualified or dlang_parse_mangle. (dlang_type_modifier_p): Remove function. (dlang_call_convention_p): Don't allow type modifiers in mangle. (dlang_template_args): Update to call dlang_identifier. (dlang_demangle): Update to call dlang_parse_mangle. * testsuite/d-demangle-expected: Add tests. From-SVN: r247450
2017-05-01d-demangle.c (dlang_value): Add comment explaining why cases for digits are ↵Iain Buclaw1-0/+4
required. libiberty/ChangeLog: * d-demangle.c (dlang_value): Add comment explaining why cases for digits are required. * testsuite/d-demangle-expected: Update integer value tests. From-SVN: r247436
2017-05-01d-demangle.c (dlang_parse_symbol): Skip over anonymous symbols.Iain Buclaw1-0/+4
libiberty/ChangeLog: * d-demangle.c (dlang_parse_symbol): Skip over anonymous symbols. * testsuite/d-demangle-expected: Add tests. From-SVN: r247434
2017-05-01d-demangle.c (dlang_identifier): Handle template constraint symbols.Iain Buclaw1-9/+7
libiberty/ChangeLog: * d-demangle.c (dlang_identifier): Handle template constraint symbols. (dlang_parse_template): Only advance if template symbol prefix is followed by a digit. * testsuite/d-demangle-expected: Add tests. From-SVN: r247433
2017-05-01d-demangle.c (dlang_attributes): Handle scope attributes.Iain Buclaw1-0/+4
libiberty/ChangeLog: * d-demangle.c (dlang_attributes): Handle scope attributes. * testsuite/d-demangle-expected: Add tests. From-SVN: r247432
2017-01-04Update copyright years.Jakub Jelinek1-1/+1
From-SVN: r244052
2016-01-27d-demangle.c (dlang_call_convention): Handle extern Objective-C function ↵Iain Buclaw1-2/+6
calling convention. libiberty/ChangeLog: 2016-01-26 Iain Buclaw <ibuclaw@gdcproject.org> * d-demangle.c (dlang_call_convention): Handle extern Objective-C function calling convention. (dlang_call_convention_p): Likewise. (dlang_type): Likewise. * testsuite/d-demangle-expected: Add coverage tests. From-SVN: r232864
2016-01-27d-demangle.c (dlang_function_args): Append ',' for variadic functions only ↵Iain Buclaw1-1/+3
if parameters were seen before the... libiberty/ChangeLog: 2016-01-26 Iain Buclaw <ibuclaw@gdcproject.org> * d-demangle.c (dlang_function_args): Append ',' for variadic functions only if parameters were seen before the elipsis symbol. * testsuite/d-demangle-expected: Add coverage test for parameter-less variadic functions. From-SVN: r232863
2016-01-27d-demangle.c (dlang_type): Handle function types only in the context of ↵Iain Buclaw1-8/+10
seeing a pointer type symbol. libiberty/ChangeLog: 2016-01-27 Iain Buclaw <ibuclaw@gdcproject.org> * d-demangle.c (dlang_type): Handle function types only in the context of seeing a pointer type symbol. * testsuite/d-demangle-expected: Update function pointer tests. From-SVN: r232862
2015-08-11Fix test failure on Solaris 9 where strtod() does not accept hexadecimalsIain Buclaw1-11/+4
2015-08-11 Iain Buclaw <ibuclaw@gdcproject.org> libiberty/ * d-demangle.c (dlang_parse_real): Remove call to strtod. (strtod): Remove declaration. * testsuite/d-demangle-expected: Update float and complex literal tests to check correct hexadecimal demangling. From-SVN: r226774
2015-05-16d-demangle.c (dlang_symbol_kinds): New enum.Iain Buclaw1-44/+141
libiberty/ChangeLog: 2015-05-16 Iain Buclaw <ibuclaw@gdcproject.org> * d-demangle.c (dlang_symbol_kinds): New enum. (dlang_parse_symbol): Update signature. Handle an ambiguity between pascal functions and template value arguments. Only check for a type if parsing a function, or at the top level. Return failure if the entire symbol was not successfully demangled. (dlang_identifier): Update signature. Handle an ambiguity between two adjacent digits in a mangled symbol string. (dlang_type): Update call to dlang_parse_symbol. (dlang_template_args): Likewise. (dlang_parse_template): Likewise. (dlang_demangle): Likewise. * testsuite/d-demangle-expected: Fix bad tests found, and add problematic examples to the unittests. From-SVN: r223247
2015-05-16d-demangle.c (dlang_template_args): Skip over specialized template ↵Iain Buclaw1-0/+4
parameters in mangled symbol. libiberty/ChangeLog: 2015-05-16 Iain Buclaw <ibuclaw@gdcproject.org> * d-demangle.c (dlang_template_args): Skip over specialized template parameters in mangled symbol. * testsuite/d-demangle-expected: Add coverage and unittest for specialized template parameters. From-SVN: r223246
2015-05-16d-demangle.c (dlang_type): Handle cent and ucent types.Iain Buclaw1-0/+14
libiberty/ChangeLog: 2015-05-16 Iain Buclaw <ibuclaw@gdcproject.org> * d-demangle.c (dlang_type): Handle cent and ucent types. * testsuite/d-demangle-expected: Add coverage tests for cent and ucent. From-SVN: r223245
2015-05-16d-demangle.c (dlang_attributes): Handle return attributes, ignoring return ↵Iain Buclaw1-0/+15
parameters in the mangled string. libiberty/ChangeLog: 2015-05-16 Iain Buclaw <ibuclaw@gdcproject.org> * d-demangle.c (dlang_attributes): Handle return attributes, ignoring return parameters in the mangled string. Return NULL if have encountered an unknown attribute. (dlang_function_args): Handle return parameters in the mangled string. * testsuite/d-demangle-expected: Add coverage tests for functions with return parameters and return attributes. From-SVN: r223244
2015-05-16d-demangle.c (dlang_identifier): Check encoded length of identifier to ↵Iain Buclaw1-58/+75
verify strncmp matches entire string. libiberty/ChangeLog: 2015-05-16 Iain Buclaw <ibuclaw@gdcproject.org> * d-demangle.c (dlang_identifier): Check encoded length of identifier to verify strncmp matches entire string. * testsuite/d-demangle-expected: Fix wrong test for postblit symbol. From-SVN: r223243
2015-05-16d-demangle.c (dlang_type_modifiers): New function.Iain Buclaw1-13/+98
libiberty/ChangeLog: 2015-05-16 Iain Buclaw <ibuclaw@gdcproject.org> * d-demangle.c (dlang_type_modifiers): New function. (dlang_type_modifier_p): New function. (dlang_call_convention_p): Ignore any kind of type modifier. (dlang_type): Handle and emit the type modifier after delegate types. (dlang_parse_symbol): Handle and emit the type modifier after the symbol. * testsuite/d-demangle-expected: Add coverage tests for all valid usages of function symbols with type modifiers. From-SVN: r223242
2015-05-16d-demangle.c (dlang_call_convention): Return NULL if have reached the end of ↵Iain Buclaw1-6/+6
the symbol, but expected something to read. libiberty/ChangeLog: 2015-05-16 Iain Buclaw <ibuclaw@gdcproject.org> * d-demangle.c (dlang_call_convention): Return NULL if have reached the end of the symbol, but expected something to read. (dlang_attributes): Likewise. (dlang_function_type): Likewise. (dlang_type): Likewise. (dlang_identifier): Likewise. (dlang_value): Likewise. From-SVN: r223241
2015-05-16d-demangle.c (dlang_parse_string): Represent embedded whitespace or ↵Iain Buclaw1-2/+33
non-printable characters as hex or escape... libiberty/ChangeLog: 2015-05-16 Iain Buclaw <ibuclaw@gdcproject.org> * d-demangle.c (dlang_parse_string): Represent embedded whitespace or non-printable characters as hex or escape sequences. * testsuite/d-demangle-expected: Add test for templates with tabs and newlines embedded into the signature. From-SVN: r223240
2014-10-14Use strtod instead of strtold in libiberty/d-demangle.cJoel Brobecker1-5/+5
strtold is currently used to decode templates which have a floating-point value encoded inside; but this routine is not available on some systems, such as Solaris 2.9 for instance. This patch fixes the issue by replace the use of strtold by strtod. It reduces a bit the precision, but it should still remain acceptable in most cases. libiberty/ChangeLog: * d-demangle.c: Replace strtold with strtod in global comment. (strtold): Remove declaration. (strtod): New declaration. (dlang_parse_real): Declare value as double instead of long double. Replace call to strtold by call to strtod. Update format in call to snprintf. From-SVN: r216216
2014-09-23demangle.h (DMGL_DLANG): New macro.Iain Buclaw1-0/+1338
include/: * demangle.h (DMGL_DLANG): New macro. (DMGL_STYLE_MASK): Add DMGL_DLANG. (demangling_styles): Add dlang_demangling. (DLANG_DEMANGLING_STYLE_STRING): New macro. (DLANG_DEMANGLING): New macro. (dlang_demangle): New prototype. libiberty/: * Makefile.in (CFILES): Add d-demangle.c. (REQUIRED_OFILES): Add d-demangle.o. * cplus-dem.c (libiberty_demanglers): Add dlang_demangling case. (cplus_demangle): Likewise. * d-demangle.c: New file. * testsuite/Makefile.in (really-check): Add check-d-demangle. * testsuite/d-demangle-expected: New file. From-SVN: r215530