aboutsummaryrefslogtreecommitdiff
path: root/libiberty/testsuite/demangle-expected
AgeCommit message (Collapse)AuthorFilesLines
2024-01-13c++, demangle: Implement ↵Jakub Jelinek1-0/+9
https://github.com/itanium-cxx-abi/cxx-abi/issues/148 non-proposal The following patch attempts to implement what apparently clang++ implemented for explicit object member function mangling, but nobody actually proposed in patch form in https://github.com/itanium-cxx-abi/cxx-abi/issues/148 2024-01-13 Jakub Jelinek <jakub@redhat.com> gcc/cp/ * mangle.cc (write_nested_name): Mangle explicit object member functions with H as per https://github.com/itanium-cxx-abi/cxx-abi/issues/148 non-proposal. gcc/testsuite/ * g++.dg/abi/mangle79.C: New test. include/ * demangle.h (enum demangle_component_type): Add DEMANGLE_COMPONENT_XOBJ_MEMBER_FUNCTION. libiberty/ * cp-demangle.c (FNQUAL_COMPONENT_CASE): Add case for DEMANGLE_COMPONENT_XOBJ_MEMBER_FUNCTION. (d_dump): Handle DEMANGLE_COMPONENT_XOBJ_MEMBER_FUNCTION. (d_nested_name): Parse H after N in nested name. (d_count_templates_scopes): Handle DEMANGLE_COMPONENT_XOBJ_MEMBER_FUNCTION. (d_print_mod): Likewise. (d_print_function_type): Likewise. * testsuite/demangle-expected: Add tests for explicit object member functions.
2023-12-01c++: mangle function template constraintsJason Merrill1-0/+8
Per https://github.com/itanium-cxx-abi/cxx-abi/issues/24 and https://github.com/itanium-cxx-abi/cxx-abi/pull/166 We need to mangle constraints to be able to distinguish between function templates that only differ in constraints. From the latter link, we want to use the template parameter mangling previously specified for lambdas to also make explicit the form of a template parameter where the argument is not a "natural" fit for it, such as when the parameter is constrained or deduced. I'm concerned about how the latter link changes the mangling for some C++98 and C++11 patterns, so I've limited template_parm_natural_p to avoid two cases found by running the testsuite with -Wabi forced on: template <class T, T V> T f() { return V; } int main() { return f<int,42>(); } template <int i> int max() { return i; } template <int i, int j, int... rest> int max() { int sub = max<j, rest...>(); return i > sub ? i : sub; } int main() { return max<1,2,3>(); } A third C++11 pattern is changed by this patch: template <template <typename...> class TT, typename... Ts> TT<Ts...> f(); template <typename> struct A { }; int main() { f<A,int>(); } I aim to resolve these with the ABI committee before GCC 14.1. We also need to resolve https://github.com/itanium-cxx-abi/cxx-abi/issues/38 (mangling references to dependent template-ids where the name is fully resolved) as references to concepts in std:: will consistently run into this area. This is why mangle-concepts1.C only refers to concepts in the global namespace so far. The library changes are to avoid trying to mangle builtins, which fails. Demangler support and test coverage is not complete yet. gcc/cp/ChangeLog: * cp-tree.h (TEMPLATE_ARGS_TYPE_CONSTRAINT_P): New. (get_concept_check_template): Declare. * constraint.cc (combine_constraint_expressions) (finish_shorthand_constraint): Use UNKNOWN_LOCATION. * pt.cc (convert_generic_types_to_packs): Likewise. * mangle.cc (write_constraint_expression) (write_tparms_constraints, write_type_constraint) (template_parm_natural_p, write_requirement) (write_requires_expr): New. (write_encoding): Mangle trailing requires-clause. (write_name): Pass parms to write_template_args. (write_template_param_decl): Factor out from... (write_closure_template_head): ...here. (write_template_args): Mangle non-natural parms and requires-clause. (write_expression): Handle REQUIRES_EXPR. include/ChangeLog: * demangle.h (enum demangle_component_type): Add DEMANGLE_COMPONENT_CONSTRAINTS. libiberty/ChangeLog: * cp-demangle.c (d_make_comp): Handle DEMANGLE_COMPONENT_CONSTRAINTS. (d_count_templates_scopes): Likewise. (d_print_comp_inner): Likewise. (d_maybe_constraints): New. (d_encoding, d_template_args_1): Call it. (d_parmlist): Handle 'Q'. * testsuite/demangle-expected: Add some constraint tests. libstdc++-v3/ChangeLog: * include/std/bit: Avoid builtins in requires-clauses. * include/std/variant: Likewise. gcc/testsuite/ChangeLog: * g++.dg/abi/mangle10.C: Disable compat aliases. * g++.dg/abi/mangle52.C: Specify ABI 18. * g++.dg/cpp2a/class-deduction-alias3.C * g++.dg/cpp2a/class-deduction-alias8.C: Avoid builtins in requires-clauses. * g++.dg/abi/mangle-concepts1.C: New test. * g++.dg/abi/mangle-ttp1.C: New test.
2023-08-22c++: constrained hidden friends [PR109751]Jason Merrill1-0/+3
r13-4035 avoided a problem with overloading of constrained hidden friends by checking satisfaction, but checking satisfaction early is inconsistent with the usual late checking and can lead to hard errors, so let's not do that after all. We were wrongly treating the different instantiations of the same friend template as the same function because maybe_substitute_reqs_for was failing to actually substitute in the case of a non-template friend. But we don't actually need to do the substitution anyway, because [temp.friend] says that such a friend can't be the same as any other declaration. After fixing that, instead of a redefinition error we got an ambiguous overload error, fixed by allowing constrained hidden friends to coexist until overload resolution, at which point they probably won't be in the same ADL overload set anyway. And we avoid mangling collisions by following the proposed mangling for these friends as a member function with an extra 'F' before the name. I demangle this by just adding [friend] to the name of the function because it's not feasible to reconstruct the actual scope of the function since the mangling ABI doesn't distinguish between class and namespace scopes. PR c++/109751 gcc/cp/ChangeLog: * cp-tree.h (member_like_constrained_friend_p): Declare. * decl.cc (member_like_constrained_friend_p): New. (function_requirements_equivalent_p): Check it. (duplicate_decls): Check it. (grokfndecl): Check friend template constraints. * mangle.cc (decl_mangling_context): Check it. (write_unqualified_name): Check it. * pt.cc (uses_outer_template_parms_in_constraints): Fix for friends. (tsubst_friend_function): Don't check satisfaction. include/ChangeLog: * demangle.h (enum demangle_component_type): Add DEMANGLE_COMPONENT_FRIEND. libiberty/ChangeLog: * cp-demangle.c (d_make_comp): Handle DEMANGLE_COMPONENT_FRIEND. (d_count_templates_scopes): Likewise. (d_print_comp_inner): Likewise. (d_unqualified_name): Handle member-like friend mangling. * testsuite/demangle-expected: Add test. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/concepts-friend11.C: Now works. Add template. * g++.dg/cpp2a/concepts-friend15.C: New test.
2023-06-13c++: Fix templated convertion operator demanglingNathan Sidwell1-0/+27
Instantiations of templated conversion operators failed to demangle for cases such as 'operator X<int>', but worked for 'operator X<int> &', due to thinking the template instantiation of X was the instantiation of the conversion operator itself. libiberty/ * cp-demangle.c (d_print_conversion): Remove incorrect template instantiation handling. * testsuite/demangle-expected: Add testcases.
2023-06-03c++: mangle noexcept-expr [PR70790]Patrick Palka1-0/+3
This implements noexcept(expr) mangling and demangling as per the Itanium ABI. PR c++/70790 gcc/cp/ChangeLog: * mangle.cc (write_expression): Handle NOEXCEPT_EXPR. libiberty/ChangeLog: * cp-demangle.c (cplus_demangle_operators): Add the noexcept operator. (d_print_comp_inner) <case DEMANGLE_COMPONENT_UNARY>: Always print parens around the operand of noexcept too. * testsuite/demangle-expected: Test noexcept operator demangling. gcc/testsuite/ChangeLog: * g++.dg/abi/mangle78.C: New test.
2022-11-15demangler: Templated lambda demanglingNathan Sidwell1-0/+53
Templated lambdas have a template-head, which is part of their signature. GCC ABI 18 mangles that into the lambda name. This adds support to the demangler. We have to introduce artificial template parameter names, as we need to refer to them from later components of the lambda signature. We use $T:n, $N:n and $TT:n for type, non-type and template parameters. Non-type parameter names are not shown in the strictly correct location -- for instance 'int (&NT) ()' would be shown as 'int (&) $N:n'. That's unfortunate, but an orthogonal issue. The 'is_lambda_arg' field is now repurposed as indicating the number of explicit template parameters (1-based). include/ * demangle.h (enum demangle_component_type): Add DEMANGLE_COMPONENT_TEMPLATE_HEAD, DEMANGLE_COMPONENT_TEMPLATE_TYPE_PARM, DEMANGLE_COMPONENT_TEMPLATE_NON_TYPE_PARM, DEMANGLE_COMPONENT_TEMPLATE_TEMPLATE_PARM, DEMANGLE_COMPONENT_TEMPLATE_PACK_PARM. libiberty/ * cp-demangle.c (struct d_print_info): Rename is_lambda_arg to lambda_tpl_parms. Augment semantics. (d_make_comp): Add checks for new components. (d_template_parm, d_template_head): New. (d_lambda): Add templated lambda support. (d_print_init): Adjust. (d_print_lambda_parm_name): New. (d_print_comp_inner): Support templated lambdas, * testsuite/demangle-expected: Add testcases.
2022-10-14middle-end, c++, i386, libgcc: std::bfloat16_t and __bf16 arithmetic supportJakub Jelinek1-0/+4
Here is a complete patch to add std::bfloat16_t support on x86 (AArch64 and ARM left for later). Almost no BFmode optabs are added by the patch, so for binops/unops it extends to SFmode first and then truncates back to BFmode. For {HF,SF,DF,XF,TF}mode -> BFmode conversions libgcc has implementations of all those conversions so that we avoid double rounding, for BFmode -> {DF,XF,TF}mode conversions to avoid growing libgcc too much it emits BFmode -> SFmode conversion first and then converts to the even wider mode, neither step should be imprecise. For BFmode -> HFmode, it first emits a precise BFmode -> SFmode conversion and then SFmode -> HFmode, because neither format is subset or superset of the other, while SFmode is superset of both. expr.cc then contains a -ffast-math optimization of the BF -> SF and SF -> BF conversions if we don't optimize for space (and for the latter if -frounding-math isn't enabled either). For x86, perhaps truncsfbf2 optab could be defined for TARGET_AVX512BF16 but IMNSHO should FAIL if !flag_finite_math || flag_rounding_math || !flag_unsafe_math_optimizations, because I think the insn doesn't raise on sNaNs, hardcodes round to nearest and flushes denormals to zero. By default (unless x86 -fexcess-precision=16) we use float excess precision for BFmode, so truncate only on explicit casts and assignments. The patch introduces a single __bf16 builtin - __builtin_nansf16b, because (__bf16) __builtin_nansf ("") will drop the sNaN into qNaN, and uses f16b suffix instead of bf16 because there would be ambiguity on log vs. logb - __builtin_logbf16 could be either log with bf16 suffix or logb with f16 suffix. In other cases libstdc++ should mostly use __builtin_*f for std::bfloat16_t overloads (we have a problem with std::nextafter though but that one we have also for std::float16_t). 2022-10-14 Jakub Jelinek <jakub@redhat.com> gcc/ * tree-core.h (enum tree_index): Add TI_BFLOAT16_TYPE. * tree.h (bfloat16_type_node): Define. * tree.cc (excess_precision_type): Promote bfloat16_type_mode like float16_type_mode. (build_common_tree_nodes): Initialize bfloat16_type_node if BFmode is supported. * expmed.h (maybe_expand_shift): Declare. * expmed.cc (maybe_expand_shift): No longer static. * expr.cc (convert_mode_scalar): Don't ICE on BF -> HF or HF -> BF conversions. If there is no optab, handle BF -> {DF,XF,TF,HF} conversions as separate BF -> SF -> {DF,XF,TF,HF} conversions, add -ffast-math generic implementation for BF -> SF and SF -> BF conversions. * builtin-types.def (BT_BFLOAT16, BT_FN_BFLOAT16_CONST_STRING): New. * builtins.def (BUILT_IN_NANSF16B): New builtin. * fold-const-call.cc (fold_const_call): Handle CFN_BUILT_IN_NANSF16B. * config/i386/i386.cc (classify_argument): Handle E_BCmode. (ix86_libgcc_floating_mode_supported_p): Also return true for BFmode for -msse2. (ix86_mangle_type): Mangle BFmode as DF16b. (ix86_invalid_conversion, ix86_invalid_unary_op, ix86_invalid_binary_op): Remove. (TARGET_INVALID_CONVERSION, TARGET_INVALID_UNARY_OP, TARGET_INVALID_BINARY_OP): Don't redefine. * config/i386/i386-builtins.cc (ix86_bf16_type_node): Remove. (ix86_register_bf16_builtin_type): Use bfloat16_type_node rather than ix86_bf16_type_node, only create it if still NULL. * config/i386/i386-builtin-types.def (BFLOAT16): Likewise. * config/i386/i386.md (cbranchbf4, cstorebf4): New expanders. gcc/c-family/ * c-cppbuiltin.cc (c_cpp_builtins): If bfloat16_type_node, predefine __BFLT16_*__ macros and for C++23 also __STDCPP_BFLOAT16_T__. Predefine bfloat16_type_node related macros for -fbuilding-libgcc. * c-lex.cc (interpret_float): Handle CPP_N_BFLOAT16. gcc/c/ * c-typeck.cc (convert_arguments): Don't promote __bf16 to double. gcc/cp/ * cp-tree.h (extended_float_type_p): Return true for bfloat16_type_node. * typeck.cc (cp_compare_floating_point_conversion_ranks): Set extended{1,2} if mv{1,2} is bfloat16_type_node. Adjust comment. gcc/testsuite/ * lib/target-supports.exp (check_effective_target_bfloat16, check_effective_target_bfloat16_runtime, add_options_for_bfloat16): New. * gcc.dg/torture/bfloat16-basic.c: New test. * gcc.dg/torture/bfloat16-builtin.c: New test. * gcc.dg/torture/bfloat16-builtin-issignaling-1.c: New test. * gcc.dg/torture/bfloat16-complex.c: New test. * gcc.dg/torture/builtin-issignaling-1.c: Allow to be includable from bfloat16-builtin-issignaling-1.c. * gcc.dg/torture/floatn-basic.h: Allow to be includable from bfloat16-basic.c. * gcc.target/i386/vect-bfloat16-typecheck_2.c: Adjust expected diagnostics. * gcc.target/i386/sse2-bfloat16-scalar-typecheck.c: Likewise. * gcc.target/i386/vect-bfloat16-typecheck_1.c: Likewise. * g++.target/i386/bfloat_cpp_typecheck.C: Likewise. libcpp/ * include/cpplib.h (CPP_N_BFLOAT16): Define. * expr.cc (interpret_float_suffix): Handle bf16 and BF16 suffixes for C++. libgcc/ * config/i386/t-softfp (softfp_extensions): Add bfsf. (softfp_truncations): Add tfbf xfbf dfbf sfbf hfbf. (CFLAGS-extendbfsf2.c, CFLAGS-truncsfbf2.c, CFLAGS-truncdfbf2.c, CFLAGS-truncxfbf2.c, CFLAGS-trunctfbf2.c, CFLAGS-trunchfbf2.c): Add -msse2. * config/i386/libgcc-glibc.ver (GCC_13.0.0): Export __extendbfsf2 and __trunc{s,d,x,t,h}fbf2. * config/i386/sfp-machine.h (_FP_NANSIGN_B): Define. * config/i386/64/sfp-machine.h (_FP_NANFRAC_B): Define. * config/i386/32/sfp-machine.h (_FP_NANFRAC_B): Define. * soft-fp/brain.h: New file. * soft-fp/truncsfbf2.c: New file. * soft-fp/truncdfbf2.c: New file. * soft-fp/truncxfbf2.c: New file. * soft-fp/trunctfbf2.c: New file. * soft-fp/trunchfbf2.c: New file. * soft-fp/truncbfhf2.c: New file. * soft-fp/extendbfsf2.c: New file. libiberty/ * cp-demangle.h (D_BUILTIN_TYPE_COUNT): Increment. * cp-demangle.c (cplus_demangle_builtin_types): Add std::bfloat16_t entry. (cplus_demangle_type): Demangle DF16b. * testsuite/demangle-expected (_Z3xxxDF16b): New test.
2022-10-11libiberty: Demangling 'M' prefixesNathan Sidwell1-0/+21
The grammar for a lambda context can include <source-name> 'M', and we were adding the component that generated to the substitution table twice. Just ignore the 'M' completely -- we'll already have done the checks we need when we saw its predecessor. A prefix cannot be the last component of a nested name, so we do not need to check for that case (although we could if we wanted to be more lenient). libiberty/ * cp-demangle.c (d_prefix): 'M' components are not (re-)added to the substitution table. * testsuite/demangle-expected: Add tests.
2022-10-07libiberty: Demangle variadic template lambdasNathan Sidwell1-0/+7
Now we have templated lambdas, we can have variadic template lambdas, and this leads to lambda signatures containing parameter packs. But just like 'auto' inside such a signature, we don't have a containing template, and thus fail. The fix is to check is_lambda_arg, just as for a template parameter. This allows us to demangle g++'s manglings of such lambdas. It's not a totally accurate demangling, because we don't mangle the template head (that's a separate issue), but it is better than failing to demangle. Due to the way we print subexprs, we add an unnecessary parens around the argument of the pack. That's an orthogonal problem, for which the solution is to have better knowledge of operator precedence. libiberty/ * cp-demangle.c (d_print_comp_inner): Allow parameter packs in a lambda signature. * testsuite/demangle-expected: Add tests.
2022-09-27c++: Implement P1467R9 - Extended floating-point types and standard names ↵Jakub Jelinek1-2/+6
compiler part except for bfloat16 [PR106652] The following patch implements the compiler part of C++23 P1467R9 - Extended floating-point types and standard names compiler part by introducing _Float{16,32,64,128} as keywords and builtin types like they are implemented for C already since GCC 7, with DF{16,32,64,128}_ mangling. It also introduces _Float{32,64,128}x for C++ with the https://github.com/itanium-cxx-abi/cxx-abi/pull/147 proposed mangling of DF{32,64,128}x. The patch doesn't add anything for bfloat16_t support, as right now __bf16 type refuses all conversions and arithmetic operations. The patch wants to keep backwards compatibility with how __float128 has been handled in C++ before, both for mangling and behavior in binary operations, overload resolution etc. So, there are some backend changes where for C __float128 and _Float128 are the same type (float128_type_node and float128t_type_node are the same pointer), but for C++ they are distinct types which mangle differently and _Float128 is treated as extended floating-point type while __float128 is treated as non-standard floating point type. The various C++23 changes about how floating-point types are changed are actually implemented as written in the spec only if at least one of the types involved is _Float{16,32,64,128,32x,64x,128x} (_FloatNx are also treated as extended floating-point types) and kept previous behavior otherwise. For float/double/long double the rules are actually written that they behave the same as before. There is some backwards incompatibility at least on x86 regarding _Float16, because that type was already used by that name and with the DF16_ mangling (but only since GCC 12 and I think it isn't that widely used in the wild yet). E.g. config/i386/avx512fp16intrin.h shows the issues, where in C or in GCC 12 in C++ one could pass 0.0f to a builtin taking _Float16 argument, but with the changes that is not possible anymore, one needs to either use 0.0f16 or (_Float16) 0.0f. We have also a problem with glibc headers, where since glibc 2.27 math.h and complex.h aren't compilable with these changes. One gets errors like: In file included from /usr/include/math.h:43, from abc.c:1: /usr/include/bits/floatn.h:86:9: error: multiple types in one declaration 86 | typedef __float128 _Float128; | ^~~~~~~~~~ /usr/include/bits/floatn.h:86:20: error: declaration does not declare anything [-fpermissive] 86 | typedef __float128 _Float128; | ^~~~~~~~~ In file included from /usr/include/bits/floatn.h:119: /usr/include/bits/floatn-common.h:214:9: error: multiple types in one declaration 214 | typedef float _Float32; | ^~~~~ /usr/include/bits/floatn-common.h:214:15: error: declaration does not declare anything [-fpermissive] 214 | typedef float _Float32; | ^~~~~~~~ /usr/include/bits/floatn-common.h:251:9: error: multiple types in one declaration 251 | typedef double _Float64; | ^~~~~~ /usr/include/bits/floatn-common.h:251:16: error: declaration does not declare anything [-fpermissive] 251 | typedef double _Float64; | ^~~~~~~~ This is from snippets like: /* The remaining of this file provides support for older compilers. */ # if __HAVE_FLOAT128 /* The type _Float128 exists only since GCC 7.0. */ # if !__GNUC_PREREQ (7, 0) || defined __cplusplus typedef __float128 _Float128; # endif where it hardcodes that C++ doesn't have _Float{16,32,64,128,32x,64x,128x} support nor {f,F}{16,32,64,128}{,x} literal suffixes nor _Complex _Float{16,32,64,128,32x,64x,128x}. The patch fixincludes this for now and hopefully if this is committed, then glibc can change those. The patch changes those # if !__GNUC_PREREQ (7, 0) || defined __cplusplus conditions to # if !__GNUC_PREREQ (7, 0) || (defined __cplusplus && !__GNUC_PREREQ (13, 0)) Another thing is mangling, as said above, Itanium C++ ABI specifies DF <number> _ as _Float{16,32,64,128} mangling, but GCC was implementing a mangling incompatible with that starting with DF for fixed point types. Fixed point was never supported in C++ though, I believe the reason why the mangling has been added was that due to a bug it would leak into the C++ FE through decltype (0.0r) etc. But that has been shortly after the mangling was added fixed (I think in the same GCC release cycle), so we now reject 0.0r etc. in C++. If we ever need the fixed point mangling, I think it can be readded but better with a different prefix so that it doesn't conflict with the published standard manglings. So, this patch also kills the fixed point mangling and implements the DF <number> _ demangling. The patch predefines __STDCPP_FLOAT{16,32,64,128}_T__ macros when those types are available, but only for C++23, while the underlying types are available in C++98 and later including the {f,F}{16,32,64,128} literal suffixes (but those with a pedwarn for C++20 and earlier). My understanding is that it needs to be predefined by the compiler, on the other side predefining even for older modes when <stdfloat> is a new C++23 header would be weird. One can find out if _Float{16,32,64,128,32x,64x,128x} is supported in C++ by __GNUC__ >= 13 && defined(__FLT{16,32,64,128,32X,64X,128X}_MANT_DIG__) (but that doesn't work well with older G++ 13 snapshots). As for std::bfloat16_t, three targets (aarch64, arm and x86) apparently "support" __bf16 type which has the bfloat16 format, but isn't really usable, e.g. {aarch64,arm,ix86}_invalid_conversion disallow any conversions from or to type with BFmode, {aarch64,arm,ix86}_invalid_unary_op disallows any unary operations on those except for ADDR_EXPR and {aarch64,arm,ix86}_invalid_binary_op disallows any binary operation on those. So, I think we satisfy: "If the implementation supports an extended floating-point type with the properties, as specified by ISO/IEC/IEEE 60559, of radix (b) of 2, storage width in bits (k) of 16, precision in bits (p) of 8, maximum exponent (emax) of 127, and exponent field width in bits (w) of 8, then the typedef-name std::bfloat16_t is defined in the header <stdfloat> and names such a type, the macro __STDCPP_BFLOAT16_T__ is defined, and the floating-point literal suffixes bf16 and BF16 are supported." because we don't really support those right now. 2022-09-27 Jakub Jelinek <jakub@redhat.com> PR c++/106652 PR c++/85518 gcc/ * tree-core.h (enum tree_index): Add TI_FLOAT128T_TYPE enumerator. * tree.h (float128t_type_node): Define. * tree.cc (build_common_tree_nodes): Initialize float128t_type_node. * builtins.def (DEF_FLOATN_BUILTIN): Adjust comment now that _Float<N> is supported in C++ too. * config/i386/i386.cc (ix86_mangle_type): Only mangle as "g" float128t_type_node. * config/i386/i386-builtins.cc (ix86_init_builtin_types): Use float128t_type_node for __float128 instead of float128_type_node and create it if NULL. * config/i386/avx512fp16intrin.h (_mm_setzero_ph, _mm256_setzero_ph, _mm512_setzero_ph, _mm_set_sh, _mm_load_sh): Use 0.0f16 instead of 0.0f. * config/ia64/ia64.cc (ia64_init_builtins): Use float128t_type_node for __float128 instead of float128_type_node and create it if NULL. * config/rs6000/rs6000-c.cc (is_float128_p): Also return true for float128t_type_node if non-NULL. * config/rs6000/rs6000.cc (rs6000_mangle_type): Don't mangle float128_type_node as "u9__ieee128". * config/rs6000/rs6000-builtin.cc (rs6000_init_builtins): Use float128t_type_node for __float128 instead of float128_type_node and create it if NULL. gcc/c-family/ * c-common.cc (c_common_reswords): Change _Float{16,32,64,128} and _Float{32,64,128}x flags from D_CONLY to 0. (shorten_binary_op): Punt if common_type returns error_mark_node. (shorten_compare): Likewise. (c_common_nodes_and_builtins): For C++ record _Float{16,32,64,128} and _Float{32,64,128}x builtin types if available. For C++ clear float128t_type_node. * c-cppbuiltin.cc (c_cpp_builtins): Predefine __STDCPP_FLOAT{16,32,64,128}_T__ for C++23 if supported. * c-lex.cc (interpret_float): For q/Q suffixes prefer float128t_type_node over float128_type_node. Allow {f,F}{16,32,64,128} suffixes for C++ if supported with pedwarn for C++20 and older. Allow {f,F}{32,64,128}x suffixes for C++ with pedwarn. Don't call excess_precision_type for C++. gcc/cp/ * cp-tree.h (cp_compare_floating_point_conversion_ranks): Implement P1467R9 - Extended floating-point types and standard names except for std::bfloat16_t for now. Declare. (extended_float_type_p): New inline function. * mangle.cc (write_builtin_type): Mangle float{16,32,64,128}_type_node as DF{16,32,64,128}_. Mangle float{32,64,128}x_type_node as DF{32,64,128}x. Remove FIXED_POINT_TYPE mangling that conflicts with that. * typeck2.cc (check_narrowing): If one of ftype or type is extended floating-point type, compare floating-point conversion ranks. * parser.cc (cp_keyword_starts_decl_specifier_p): Handle CASE_RID_FLOATN_NX. (cp_parser_simple_type_specifier): Likewise and diagnose missing _Float<N> or _Float<N>x support if not supported by target. * typeck.cc (cp_compare_floating_point_conversion_ranks): New function. (cp_common_type): If both types are REAL_TYPE and one or both are extended floating-point types, select common type based on comparison of floating-point conversion ranks and subranks. (cp_build_binary_op): Diagnose operation with floating point arguments with unordered conversion ranks. * call.cc (standard_conversion): For floating-point conversion, if either from or to are extended floating-point types, set conv->bad_p for implicit conversion from larger to smaller conversion rank or with unordered conversion ranks. (convert_like_internal): Emit a pedwarn on such conversions. (build_conditional_expr): Diagnose operation with floating point arguments with unordered conversion ranks. (convert_arg_to_ellipsis): Don't promote extended floating-point types narrower than double to double. (compare_ics): Implement P1467R9 [over.ics.rank]/4 changes. gcc/testsuite/ * g++.dg/cpp23/ext-floating1.C: New test. * g++.dg/cpp23/ext-floating2.C: New test. * g++.dg/cpp23/ext-floating3.C: New test. * g++.dg/cpp23/ext-floating4.C: New test. * g++.dg/cpp23/ext-floating5.C: New test. * g++.dg/cpp23/ext-floating6.C: New test. * g++.dg/cpp23/ext-floating7.C: New test. * g++.dg/cpp23/ext-floating8.C: New test. * g++.dg/cpp23/ext-floating9.C: New test. * g++.dg/cpp23/ext-floating10.C: New test. * g++.dg/cpp23/ext-floating.h: New file. * g++.target/i386/float16-1.C: Adjust expected diagnostics. libcpp/ * expr.cc (interpret_float_suffix): Allow {f,F}{16,32,64,128} and {f,F}{32,64,128}x suffixes for C++. include/ * demangle.h (enum demangle_component_type): Add DEMANGLE_COMPONENT_EXTENDED_BUILTIN_TYPE. (struct demangle_component): Add u.s_extended_builtin member. libiberty/ * cp-demangle.c (d_dump): Handle DEMANGLE_COMPONENT_EXTENDED_BUILTIN_TYPE. Don't handle DEMANGLE_COMPONENT_FIXED_TYPE. (d_make_extended_builtin_type): New function. (cplus_demangle_builtin_types): Add _Float entry. (cplus_demangle_type): For DF demangle it as _Float<N> or _Float<N>x rather than fixed point which conflicts with it. (d_count_templates_scopes): Handle DEMANGLE_COMPONENT_EXTENDED_BUILTIN_TYPE. Just break; for DEMANGLE_COMPONENT_FIXED_TYPE. (d_find_pack): Handle DEMANGLE_COMPONENT_EXTENDED_BUILTIN_TYPE. Don't handle DEMANGLE_COMPONENT_FIXED_TYPE. (d_print_comp_inner): Likewise. * cp-demangle.h (D_BUILTIN_TYPE_COUNT): Bump. * testsuite/demangle-expected: Replace _Z3xxxDFyuVb test with _Z3xxxDF16_DF32_DF64_DF128_CDF16_Vb. Add _Z3xxxDF32xDF64xDF128xCDF32xVb test. fixincludes/ * inclhack.def (glibc_cxx_floatn_1, glibc_cxx_floatn_2, glibc_cxx_floatn_3): New fixes. * tests/base/bits/floatn.h: New file. * fixincl.x: Regenerated.
2022-05-23demangler: C++ modules supportNathan Sidwell1-0/+67
This adds demangling support for C++ modules. A new 'W' component along with augmented behaviour of 'S' components. include/ * demangle.h (enum demangle_component_type): Add module components. libiberty/ * cp-demangle.c (d_make_comp): Adjust. (d_name, d_prefix): Adjust subst handling. Add module handling. (d_maybe_module_name): New. (d_unqualified_name): Add incoming module parm. Handle it. Adjust all callers. (d_special_name): Add 'GI' support. (d_count_template_scopes): Adjust. (d_print_comp_inner): Print module. * testsuite/demangle-expected: New test cases
2022-05-17demangler: Structured BindingsNathan Sidwell1-0/+10
C++ Structured bindings have a mangling that has yet to be formally documented. However, it's been around for a while and shows up for module support. include/ * demangle.h (enum demangle_component_type): Add DEMANGLE_COMPONENT_STRUCTURED_BINDING. libiberty/ * cp-demangle.c (d_make_comp): Adjust. (d_unqualified_name): Add 'DC' support. (d_count_template_scopes): Adjust. (d_print_comp_inner): Add structured binding. * testsuite/demangle-expected: Add testcases.
2021-12-30libiberty: support digits in cpp mangled clone namesLancelot SIX1-0/+5
Currently libiberty fails to demangle the name of cloned functions if the clone-type-identifier contains numbers. This can be observed with the following example: $ cat > ex.cc <<EOT void foo (float *, float *) __attribute__((target_clones("avx2,avx,sse4.1,default"))); void foo (float *, float *) {} EOT $ gcc -c ex.cc $ nm -C ex.o | grep foo 0000000000000000 i foo(float*, float*) 0000000000000026 t foo(float*, float*) [clone .avx.1] 0000000000000013 t _Z3fooPfS_.avx2.0 0000000000000000 t foo(float*, float*) [clone .default.3] 0000000000000000 W foo(float*, float*) [clone .resolver] 0000000000000039 t _Z3fooPfS_.sse4_1.2 In this example, gcc creates clones for the FOO function, each matching one of the specified targets. When inspecting the binary, nm (and other libiberty-based tools, including gdb) fails to demangle the symbol names if the clone identifier contains numbers. Form my understanding of the mangling convention[1], clone names are part of vendor-specific suffixes and do not have rule preventing them from containing digits. This commit proposes to fix the demangling. With this commit (ported to binutils), nm gives the following output: $ nm-new -C ex.o | grep foo 0000000000000000 i foo(float*, float*) 0000000000000026 t foo(float*, float*) [clone .avx.1] 0000000000000013 t foo(float*, float*) [clone .avx2.0] 0000000000000000 t foo(float*, float*) [clone .default.3] 0000000000000000 W foo(float*, float*) [clone .resolver] 0000000000000039 t foo(float*, float*) [clone .sse4_1.2] Tested on x86_86-linux with 'make check-libiberty'. [1] https://itanium-cxx-abi.github.io/cxx-abi/abi.html#mangling libiberty/ChangeLog: * cp-demangle.c (d_clone_suffix): Support digits in clone tag names. * testsuite/demangle-expected: Check demangling of clone symbols with digits in name.
2021-03-30c++: Adjust mangling of __alignof__ [PR88115]Patrick Palka1-2/+2
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.
2020-12-21c++: Fix demangling of <unresolved-name>Jason Merrill1-0/+3
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-21c++: Fix demangling of qualified-id after '.'Jason Merrill1-0/+3
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-21c++: Fix demangling of x.operator typeJason Merrill1-0/+6
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-11-11c++: Change the mangling of __alignof__ [PR88115]Patrick Palka1-0/+7
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-07-14demangler: don't treat lambda as a substitution candidateIan Lance Taylor1-5/+9
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-10c++: Support non-type template parms of union type.Jason Merrill1-0/+9
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-04-27demangler: Handle <=> operator in the demangler [PR94797]Jakub Jelinek1-0/+3
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-03-02Fix a libiberty testsuite failureNick Clifton1-1/+1
* testsuite/demangle-expected: Update expected demangling of enable_if pattern.
2020-01-18[libiberty] Update demangler to handle co_await operator.Iain Sandoe1-0/+3
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.
2019-11-16* testsuite/demangle-expected: Fix test.Miguel Saldivar1-1/+1
From-SVN: r278357
2019-11-04PR c++/91979 - mangling nullptr expressionKamlesh Kumar1-0/+4
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-10-28cp-demangle.c (d_print_mod): Add a space before printing `complex` and ↵Miguel Saldivar1-1/+1
`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-04-30cp-demangle (d_print_comp_inner): Guard against a NULL 'typed_name'.Ben L1-0/+4
* cp-demangle (d_print_comp_inner): Guard against a NULL 'typed_name'. * testsuite/demangle-expected: Add testcase. From-SVN: r270695
2019-04-30cp-demangle.c (d_encoding): Guard against NULL return values from d_right (dc).Ben L1-0/+5
* cp-demangle.c (d_encoding): Guard against NULL return values from d_right (dc). * testsuite/demangle-expected: Add testcase. From-SVN: r270694
2019-04-29cp-demangle.c (d_expression_1): Don't peek ahead unless the current char is ↵Ben L1-0/+4
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
2018-12-22Remove support for demangling GCC 2.x era mangling schemes.Jason Merrill1-3389/+52
libiberty/ * cplus-dem.c: Remove cplus_mangle_opname, cplus_demangle_opname, internal_cplus_demangle, and all subroutines. (libiberty_demanglers): Remove entries for ancient GNU (pre-3.0), Lucid, ARM, HP, and EDG demangling styles. (cplus_demangle): Remove 'work' variable. Don't call internal_cplus_demangle. include/ * demangle.h: Remove support for ancient GNU (pre-3.0), Lucid, ARM, HP, and EDG demangling styles. From-SVN: r267363
2018-11-05Implement P0732R2, class types in non-type template parameters.Jason Merrill1-0/+6
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
2017-09-26re PR demangler/82195 (Undemangleable lambda)Nathan Sidwell1-20/+29
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-21[demangler PATCH]: Revert and update generic lambda demanglingNathan Sidwell1-6/+11
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-15[demangler] Fix nested generic lambdaNathan Sidwell1-0/+14
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[Demangle PATCH] Some pre-fix cleanupsNathan Sidwell1-3/+4
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-04-27PR demangler/80513 check for overflows and invalid characters in thunksJonathan Wakely1-0/+15
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-03-08Fix PR demangler/70909 and 67264 (endless demangler recursion)Mark Wielaard1-0/+31
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-01-18Fix PR70182 -- missing "on" in mangling of unresolved operatorsMarkus Trippelsdorf1-0/+7
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-18Fix PR77489 -- mangling of discriminator >= 1Markus Trippelsdorf1-0/+16
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
2016-12-13re PR c++/78761 (C++14, compiler generate mangled name that can not be ↵Jakub Jelinek1-0/+3
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-12re PR other/78252 (C++ demangler crashes with infinite recursion with lambda ↵Nathan Sidwell1-0/+29
(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-11-15libiberty: demangler crash with missing :? or fold expression component.Mark Wielaard1-0/+8
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-15libiberty: Fix some demangler crashes caused by reading past end of input.Mark Wielaard1-0/+20
In various situations the cplus_demangle () function could read past the end of input causing crashes. Add checks in various places to not advance the demangle string location and fail early when end of string is reached. Add various examples of input strings to the testsuite that would crash test-demangle before the fixes. Found by using the American Fuzzy Lop (afl) fuzzer. libiberty/ChangeLog: * cplus-dem.c (demangle_signature): After 'H', template function, no success and don't advance position if end of string reached. (demangle_template): After 'z', template name, return zero on premature end of string. (gnu_special): Guard strchr against searching for zero characters. (do_type): If member, only advance mangled string when 'F' found. * testsuite/demangle-expected: Add examples of strings that could crash the demangler by reading past end of input. From-SVN: r242450
2016-11-07Implement P0012R1, Make exception specifications part of the type system.Jason Merrill1-0/+10
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-01Implement P0136R1, Rewording inheriting constructors.Jason Merrill1-0/+4
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-08-04re PR c++/71696 (Libiberty Demangler segfaults (6))Marcel Böhme1-0/+5
2016-08-04 Marcel Böhme <boehme.marcel@gmail.com> PR c++/71696 * cplus-dem.c: Prevent infinite recursion when there is a cycle in the referencing of remembered mangled types. (work_stuff): New stack to keep track of the remembered mangled types that are currently being processed. (push_processed_type): New method to push currently processed remembered type onto the stack. (pop_processed_type): New method to pop currently processed remembered type from the stack. (work_stuff_copy_to_from): Copy values of new variables. (delete_non_B_K_work_stuff): Free stack memory. (demangle_args): Push/Pop currently processed remembered type. (do_type): Do not demangle a cyclic reference and push/pop referenced remembered type. From-SVN: r239143
2016-07-18Demangle C++17 fold-expressions.Jason Merrill1-0/+12
* 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-15PR c++/71814 - mangling sizeof... (sP and sZ)Jason Merrill1-0/+6
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-13re PR c++/70926 (Libiberty Demangler segfaults (5))Marcel Böhme1-0/+13
PR c++/70926 * cplus-dem.c: Handle large values and overflow when demangling length variables. (demangle_template_value_parm): Read only until end of mangled string. (do_hpacc_template_literal): Likewise. (do_type): Handle overflow when demangling array indices. From-SVN: r238313
2016-05-18cplus-dem.c (enum type_kind_t): Add tk_rvalue_reference constant.Artemiy Volkov1-0/+115
* cplus-dem.c (enum type_kind_t): Add tk_rvalue_reference constant. (demangle_template_value_parm): Handle tk_rvalue_reference type kind. (do_type): Support 'O' type id (rvalue references). * testsuite/demangle-expected: Add tests. From-SVN: r236434