xref: /illumos-gate/usr/src/test/util-tests/tests/demangle/rust.c (revision d48be21240dfd051b689384ce2b23479d757f2d8)
1 /*
2  * Copyright (c) 2014 Alex Crichton
3  *
4  * Permission is hereby granted, free of charge, to any
5  * person obtaining a copy of this software and associated
6  * documentation files (the "Software"), to deal in the
7  * Software without restriction, including without
8  * limitation the rights to use, copy, modify, merge,
9  * publish, distribute, sublicense, and/or sell copies of
10  * the Software, and to permit persons to whom the Software
11  * is furnished to do so, subject to the following
12  * conditions:
13  *
14  * The above copyright notice and this permission notice
15  * shall be included in all copies or substantial portions
16  * of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
19  * ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
20  * TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
21  * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
22  * SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
23  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
24  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
25  * IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26  * DEALINGS IN THE SOFTWARE.
27  */
28 /*
29  * Copyright 2019 Joyent, Inc.
30  * Copyright 2021 Jason King
31  */
32 
33 /*
34  * Test cases taken from rustc-demangle 0.1.9
35  */
36 #include <errno.h>
37 #include <err.h>
38 #include <locale.h>
39 #include <stdio.h>
40 #include <stdlib.h>
41 #include <string.h>
42 #include <sys/sysmacros.h>
43 #include <demangle-sys.h>
44 
45 #define	TEST_LOCALE "C.UTF-8"
46 
47 typedef struct rust_test_case {
48 	const char *mangled;
49 	const char *demangled;
50 } rust_test_case_t;
51 #define	T(_m, _d) { .mangled = _m, .demangled = _d }
52 #define	T_ERR(_m) { .mangled = _m }
53 
54 typedef struct rust_test_grp {
55 	const char		*name;
56 	rust_test_case_t	tests[];
57 } rust_test_grp_t;
58 
59 #define	GROUP(_n, ...)			\
60 	static rust_test_grp_t _n = {	\
61 		.name = #_n,		\
62 		.tests = {		\
63 			__VA_ARGS__,	\
64 			{ NULL, NULL }	\
65 		}			\
66 	}
67 
68 /* BEGIN CSTYLED */
69 
70 GROUP(demangle,
71     T_ERR("test"),
72     T("_ZN4testE", "test"),
73     T_ERR("_ZN4test"),
74     T("_ZN4test1a2bcE", "test::a::bc"));
75 
76 GROUP(demangle_dollars,
77     T("_ZN4$RP$E", ")"),
78     T("_ZN8$RF$testE", "&test"),
79     T("_ZN8$BP$test4foobE", "*test::foob"),
80     T("_ZN9$u20$test4foobE", " test::foob"),
81     T("_ZN35Bar$LT$$u5b$u32$u3b$$u20$4$u5d$$GT$E", "Bar<[u32; 4]>"));
82 
83 GROUP(demangle_many_dollars,
84     T("_ZN13test$u20$test4foobE", "test test::foob"),
85     T("_ZN12test$BP$test4foobE", "test*test::foob"));
86 
87 GROUP(demangle_osx,
88     T("__ZN5alloc9allocator6Layout9for_value17h02a996811f781011E",
89     "alloc::allocator::Layout::for_value::h02a996811f781011"),
90     T("__ZN38_$LT$core..option..Option$LT$T$GT$$GT$6unwrap18_MSG_FILE_LINE_COL17haf7cb8d5824ee659E",
91     "<core::option::Option<T>>::unwrap::_MSG_FILE_LINE_COL::haf7cb8d5824ee659"),
92     T("__ZN4core5slice89_$LT$impl$u20$core..iter..traits..IntoIterator$u20$for$u20$$RF$$u27$a$u20$$u5b$T$u5d$$GT$9into_iter17h450e234d27262170E",
93     "core::slice::<impl core::iter::traits::IntoIterator for &'a [T]>::into_iter::h450e234d27262170"));
94 
95 GROUP(demangle_elements_beginning_with_underscore,
96     T("_ZN13_$LT$test$GT$E", "<test>"),
97     T("_ZN28_$u7b$$u7b$closure$u7d$$u7d$E", "{{closure}}"),
98     T("_ZN15__STATIC_FMTSTRE", "__STATIC_FMTSTR"));
99 
100 GROUP(demangle_trait_impls,
101     T("_ZN71_$LT$Test$u20$$u2b$$u20$$u27$static$u20$as$u20$foo..Bar$LT$Test$GT$$GT$3barE",
102     "<Test + 'static as foo::Bar<Test>>::bar"));
103 
104 GROUP(invalid_no_chop, T_ERR("_ZNfooE"));
105 
106 GROUP(handle_assoc_types,
107     T("_ZN151_$LT$alloc..boxed..Box$LT$alloc..boxed..FnBox$LT$A$C$$u20$Output$u3d$R$GT$$u20$$u2b$$u20$$u27$a$GT$$u20$as$u20$core..ops..function..FnOnce$LT$A$GT$$GT$9call_once17h69e8f44b3723e1caE",
108     "<alloc::boxed::Box<alloc::boxed::FnBox<A, Output=R> + 'a> as core::ops::function::FnOnce<A>>::call_once::h69e8f44b3723e1ca"));
109 
110 /* C++ mangled names that aren't valid rust names */
111 GROUP(cplusplus_as_rust, T_ERR("_ZN7mozilla3dom13BrowserParent22RecvUpdateContentCacheERKNS_12ContentCacheE"));
112 
113 GROUP(v0_crate_with_leading_digit,
114     T("_RNvC6_123foo3bar", "123foo::bar"));
115 
116 GROUP(v0_utf8_idents,
117     T("_RNqCs4fqI2P2rA04_11utf8_identsu30____7hkackfecea1cbdathfdh9hlq6y",
118     "utf8_idents::საჭმელად_გემრიელი_სადილი"));
119 
120 GROUP(v0_closure,
121     T("_RNCNCNgCs6DXkGYLi8lr_2cc5spawn00B5_",
122     "cc::spawn::{closure#0}::{closure#0}"),
123     T("_RNCINkXs25_NgCsbmNqQUJIY6D_4core5sliceINyB9_4IterhENuNgNoBb_4iter8iterator8Iterator9rpositionNCNgNpB9_6memchr7memrchrs_0E0Bb_",
124     "<core::slice::Iter<u8> as core::iter::iterator::Iterator>::rposition::<core::slice::memchr::memrchr::{closure#1}>::{closure#0}"));
125 
126 GROUP(v0_dyn_trait,
127     T("_RINbNbCskIICzLVDPPb_5alloc5alloc8box_freeDINbNiB4_5boxed5FnBoxuEp6OutputuEL_ECs1iopQbuBiw2_3std",
128     "alloc::alloc::box_free::<dyn alloc::boxed::FnBox<(), Output = ()>>"));
129 
130 GROUP(v0_const_generics,
131     T("_RMC0INtC8arrayvec8ArrayVechKj7b_E", "<arrayvec::ArrayVec<u8, 123>>"),
132     T("_RMCs4fqI2P2rA04_13const_genericINtB0_8UnsignedKhb_E", "<const_generic::Unsigned<11>>"),
133     T("_RMCs4fqI2P2rA04_13const_genericINtB0_6SignedKs98_E", "<const_generic::Signed<152>>"),
134     T("_RMCs4fqI2P2rA04_13const_genericINtB0_6SignedKanb_E", "<const_generic::Signed<-11>>"),
135     T("_RMCs4fqI2P2rA04_13const_genericINtB0_4BoolKb0_E", "<const_generic::Bool<false>>"),
136     T("_RMCs4fqI2P2rA04_13const_genericINtB0_4BoolKb1_E", "<const_generic::Bool<true>>"),
137     T("_RMCs4fqI2P2rA04_13const_genericINtB0_4CharKc76_E", "<const_generic::Char<'v'>>"),
138     T("_RMCs4fqI2P2rA04_13const_genericINtB0_4CharKca_E", "<const_generic::Char<'\\n'>>"),
139     T("_RMCs4fqI2P2rA04_13const_genericINtB0_4CharKc2202_E", "<const_generic::Char<'∂'>>"));
140 
141 GROUP(v0_exponential_explosion,
142     T("_RMC0TTTTTTpB8_EB7_EB6_EB5_EB4_EB3_E",
143     "<((((((_, _), (_, _)), ((_, _), (_, _))), (((_, _), (_, _)), ((_, _), (_, _)))), "
144     "((((_, _), (_, _)), ((_, _), (_, _))), (((_, _), (_, _)), ((_, _), (_, _))))), "
145     "(((((_, _), (_, _)), ((_, _), (_, _))), (((_, _), (_, _)), ((_, _), (_, _)))), "
146     "((((_, _), (_, _)), ((_, _), (_, _))), (((_, _), (_, _)), ((_, _), (_, _))))))>"));
147 
148 GROUP(v0_thinlto,
149     T("_RC3foo.llvm.9D1C9369", "foo"),
150     T("_RC3foo.llvm.9D1C9369@@16", "foo"),
151     T("_RNvC9backtrace3foo.llvm.A5310EB9", "backtrace::foo"));
152 
153 GROUP(v0_demangle_extra_suffix,
154     T("_RNvNtNtNtNtCs92dm3009vxr_4rand4rngs7adapter9reseeding4fork23FORK_HANDLER_REGISTERED.0.0",
155     "rand::rngs::adapter::reseeding::fork::FORK_HANDLER_REGISTERED.0.0"));
156 
157 /*
158  * From Rust RFC2603
159  */
160 GROUP(v0_generic_func,
161     T("_RINvNtC3std3mem8align_ofdE", "std::mem::align_of::<f64>"),
162     T("_RINvNtC3std3mem8align_ofNtNtC3std3mem12DiscriminantE",
163     "std::mem::align_of::<std::mem::Discriminant>"),
164     T("_RINvNtC3std3mem8align_ofQTReuEE",
165     "std::mem::align_of::<&mut (&str, ())>"));
166 
167 GROUP(v0_eddyb,
168     T("_RNvXsa_NtNtCs7hxHya3g3Sg_4core3ptr6uniqueINtB5_6UniqueNtNtNtCshRVCqTKO4VO_5cargo4util4toml10TomlTargetEINtNtB9_7convert4FromINtNtB7_8non_null7NonNullBQ_EE4fromBW_",
169       "<core::ptr::unique::Unique<cargo::util::toml::TomlTarget> as core::convert::From<core::ptr::non_null::NonNull<cargo::util::toml::TomlTarget>>>::from"),
170     T("_RNvXsG_NtNtCs2ZCqZGLqlfc_3std3ffi6os_strNtB5_5OsStrINtNtCs7hxHya3g3Sg_4core7convert5AsRefBC_E6as_ref",
171       "<std::ffi::os_str::OsStr as core::convert::AsRef<std::ffi::os_str::OsStr>>::as_ref"),
172     T("_RNvMs_NtCs7hxHya3g3Sg_4core6resultINtB4_6ResultNtNtB6_5alloc6LayoutNtBL_9LayoutErrE6unwrapCsdJWFNQ9j01_12aho_corasick",
173       "<core::result::Result<core::alloc::Layout, core::alloc::LayoutErr>>::unwrap"),
174     T("_RINvNtCs7hxHya3g3Sg_4core3mem7size_ofFUKCEPaECs2ZCqZGLqlfc_3std",
175       "core::mem::size_of::<unsafe extern \"C\" fn() -> *const i8>"),
176     T("_RINvCsc1o8JKpgQAm_4test28___rust_begin_short_backtraceFEuEB2_",
177       "test::__rust_begin_short_backtrace::<fn()>"),
178     T("_ZN4core5array104_$LT$impl$u20$core..iter..traits..collect..IntoIterator$u20$for$u20$$RF$$u5b$$RF$str$u3b$$u20$_$u5d$$GT$9into_iter17hc066f1a15f41761dE",
179       "core::array::<impl core::iter::traits::collect::IntoIterator for &[&str; _]>::into_iter::hc066f1a15f41761d"));
180 
181 GROUP(v0_afl_fast,
182     T_ERR("_RMC0TTTTTTPB8_yB7_EB6_EB5_EB4_EB3_E"),
183     T_ERR("_RMC0TTTTTTpB8_yB7_eB6_EB5_EB4_EB3_E"),
184     T_ERR("_RMC0TTTTTTpB4_yB7_EB6_EB5_EB4_EB3_E"),
185     T_ERR("_RMC0TTTTTTpB4_yB7_EB6_EB5_EB4_EB3_E"),
186     T_ERR("_RMC0TTTTTTTB8_yB7_EB6_EB5_EB4_EB3_E"),
187     T_ERR("_RMC0TTTTTTSB8_yB7_EB6_EB5_EB4_EB3_E"),
188     T_ERR("_RMC0TTTTTTRB8_yB7_EB6_EB5_EB4_EB3_E"),
189     T_ERR("_RMC0TTTTTTQB8_yB7_EB6_EB5_EB4_EB3_E"),
190     T_ERR("_RMC0TTTTTTOB8_yB7_EB6_EB5_EB4_EB3_E"),
191     T_ERR("_RMC0TTTTTTpB8_yB7_hB6_EB5_EB4_EB3_E"),
192     T_ERR("_RMC0TTTTTTpB8_yB7_llvmEB5_EB4_EB3_E"),
193     T_ERR("_RMC0TTTTTTpB1_yB7_eB6_EB5_EB4_EB3_E"),
194     T_ERR("_RMC0TTTTTTpB1_tB7_fB6_EB5_EB4_EB3_E"),
195     T_ERR("_RMC0TTTC0TTTTTPpB0_SB7_llvmTPpB8_SB7_EB6_EB5_EB4_EB3_E"),
196     T_ERR("_RMC3TTTTTtpB_yB7_EB6_EB5_EB4_EB3_E"),
197     T_ERR("_RMC0TTTTRLpB8_llvB_vmEB_EB5FEB4EB5FEB4_EB3_E"),
198     T_ERR("_RMC0TTTTQLp.B_llvmEB6_EB5_EB4_EB3_E"),
199     T_ERR("_RMC0TRMC0TTTTQLp.B_YBTTTQLp.B_YB7_EBd_EB5_EB4_EB3_E"),
200     T_ERR("_RMC0TTTTQLp.B_llvmEB6_EB5_EB4_E!3_E"),
201     T_ERR("_RMC0TRMC0TTTTQLp.B_bB7_EB6_EB5_EB4_E"),
202     T_ERR("_RMC0TTTTRLp.B_llvmEB6_EB5_EB4_EB3_E"),
203     T_ERR("_RMC0TTTTQLpC0TTTfQLp.B_B_EB84_EB3_E"),
204     T_ERR("_RMC0TTTTQLp.TfQLp.B_jC0TTTfQLp.B_llvT_EB3_E"),
205     T_ERR("_RMC0TTTTQLpB8_TTTTTQLp_B_llvmEB6_E3_E"),
206     T_ERR("_RIC0TRLpB8B8_B8_llvmEB6_EB5_llvmEB6_EB5_EB4_EL3_E"),
207     T_ERR("_RNCINkXs25NNNNNNNNNNNNNNNNNNNNNNNN_INyB9_4IterhENuNgNoBb_4iter8iteraionNCN1_6hr7m0E0Bb_"),
208     T_ERR("_RNCXNkXs25_NgCsbmNqQUJIY6D_4core5sliceINyB4_4IterhENuNgNoBb_4iter8iterator8Iterator9rpositionNCNgNpB2_6hr7m0E0Bb_"),
209     T_ERR("_RNCXNkXs25_NgCsbmNqQUJIY6D_4core5sliceINyB9_4IterhENuNgNoBZ_4iter8iterator8Iterator9rpositionNCNgNpB2_6hr7m0E0Bb_"),
210     T_ERR("_RYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY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YYYYYYYYYYNfYB_"),
211     T_ERR("_RNCXNkXs25_NSCsbmNqQUJIY6D_4core5sliceINyB2_4IterhENuNgNoBb_4iter8iterator8Iterator9rpositionNCNgNpB2_6D_4core5sliReINyB1_4IterhENu6D_4core5sliceINyB1_4IterhENuNgNoBb_4iter8iterator8Iterator9rpositionNCNgNpBNgNoBb_4iter8iterr9rpo25_NgCsbmNqQUJIY6D_4core5sliceIN4IterhENuNgNoBb_4iter8iterator8Iterator9rpositionNCNgNpB2_6NqQUJIY6D_4core5sliReINyB1_4IterhENu6D_4core5sliceINyB1_4IterhENuNgNoBb_4iter8iterator8Iterator9rpositionNCNgNpBNgNoBb_4iter8iterr9rpositionNCNgNpB2_6NqQUJIY6B2_6hr7m0E7m0EsitionNCNgNpB2_6NqQUJIY6B2_6hr7m0E7m0E0Bb_"),
212     T_ERR("_RNCXNkXs25_NCCsbmNqQUJIY6D_4core5sliceINyB2_4IterhENuNgNoBb_4iter8iterator8Iterator9rpositionNCNgNpB2_6D_4core5sliReINyB1_4IterhENu6D_4core5sliceINyB1_4IterhENuNgNoBb_4iter8iterator8Iterator9rpositionNCNgNpBNgNoBb_4iter8iterr9rpo25_NgCsbmNqQUJIY6D_4core5sliceIN4IterhENuNgNoBb_4iter8iterator8Iterator9rpositionNCNgNpB2_6NqQUJIY6D_4core5sliReINyB1_4IterhENu6D_4core5sliceINyB1_4IterhENuNgNoBb_4iter8iterator8Iterator9rpositionNCNgNpBNgNoBb_4iter8iterr9rpositionNCNgNpB2_6NqQUJIY6B2_6hr7m0E7m0EsitionNCNgNpB2_6NqQUJIY6B2_6hr7m0E7m0E0Bb_"),
213     T_ERR("_RMC0TTTTRL_B4_llvmEB6_EB5_EB4_EB3_E"),
214     T_ERR("_RMC0TTTTRRMC0TB7_llvmEB6_EB5_EB4_EB3_EL_B7_llvmEB6_EB5_EB4_EB3_E"),
215     T_ERR("_RIC0TTTTQIC0L_B7_llvmEB6_E75_EB4_EB3_E"),
216     T_ERR("_RNCINkXs25_NSCsbmNqQUJIY6D_4core53liceINyBK_4IterhDNCINkXs25_NSCsbmD_4core5sRNCINkXs25_NSCsbmNqQUJIY6D_4core5sliceINyB9_4IterhDNCINkXs25_NSCsbmJIY6D_4core5sliceINyB9_4IterhENuNgNoBN_4iter8iterator8Iterato29rposillvmtionNCXs25_NSCsbUJIY6D_4core5sliceINyB9_4IterhDNuNgNCINkXs25_NSCsbmJIY6D_4core5sliceINyB9_4IterhDNuNgNoBN_4iter8iterator8IliceINyB1_4IterhENuNgNoBN_4iter8iterator8Iterator9rposillvmtionNCXs25_NSCsbUJIY6D_4core5sliceINyB9_4IterhDNuNgNCINkXs25_NSCsbmJIY6D_4core5sliceINyB9_4IterhDNuNgNoBN_4iter8iterator8Iter9rposillvmtionNCNgNpB1_Bb_"),
217     T_ERR("_RNCINkXs25_NSCsbmNqQUJIY6D_4core93liceINyBK_4IterhDNCINkXs25_NSCsbmD_4core5sRNCINkXs25_NSCsbmNqQUJIY6D_4core5sliceINyB9_4IterhDNCINkXs25_NSCsbmJIY6D_4core5sliceINyB9_4IterhENuNgNoBN_4iter8iterator8Iterato29rposillvmtionNCXs25_NSCsbUJIY6D_4core5sliceINyB9_4IterhDNuNgNCINkXs25_NSCsbmJIY6D_4core5sliceINyB9_4IterhDNuNgNoBN_4iter8iterator8IliceINyB1_4IterhENuNgNoBN_4iter8iterator8Iterator9rposillvmtionNCXs25_NSCsbUJIY6D_4core5sliceINyB9_4IterhDNuNgNCINkXs25_NSCsbmJIY6D_4core5sliceINyB9_4IterhDNuNgNoBN_4iter8iterator8Iter9rposillvmtionNCNgNpB1_Bb_"),
218     T_ERR("_RNCINkXs25_NSCsbmNqQUJIY6D_4core5sliceINyB9_4IterhDNCINkXs25_NSCsbmD_4core5sRNCINkXs25_NSCsbmNqQUJIY6D_4core5sliceINyB9_4IterhDNCINkXs25_NSCsbmJIY6D_4core5sliceINyB9_4IterhENuNgNoBN_4iter8iterator8Iterato29rposillvmtiB_NCXs25_NSCsbUJIY6D_4core5sliceINyB9_4IterhDNuNgNCINkXs25_NSCsbmJIY6D_4core5sliceINyB9_4IterhDNuNgNoBN_4iter8iterator8IliceINyB1_4IterhENuNgNoBN_4iter8iterator8Iterator9rposillvmtionNCXs25_NSCsbUJIY6D_4core5sliceINyB9_4IterhDNuNgNCINkXs25_NSCsbmJIY6D_4core5sliceINyB9_4IterhDNuNgNoBN_4iter8iterator8Iter9rposillvmtionNCNgNpB1_Bb_"),
219     T_ERR("_RNCINkXs25_NSCsbmNqQUJIY6D_4coreu425_NSNgNoBN_4iter8iteratotliceINyB9_4IterhDNCINkXs25_NSCsbmD_4core5sRNCINkXs25_NSCsbeNqQUJIY6D_4core5sliceINyB9_4IterhLNCINkXs25_NSCsbmJIY6D_4core5sliceINyB9_48888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888eeeeeeeeeeeeeee88888888888888888888888888888888888888G88888888888888888888888888888888888888888888888888888888888888888888888888888888888888888NSCsbmJIY6D_4core5sliceINyB9_4IterhDNuNgNoBN_4iter8iteravmtionNCNgNpB1_Bb_"),
220     T_ERR("_ZN9EB0_EB3_E"),
221     T_ERR("_ZN9INTTB7_$B6_SB5_E"),
222     T_ERR("_ZN9INTTB7 E.6_SBEEEEEEEEEEEEEEEEB7_EB6_EB5_EB0EB6_EB5_EB0_EB3_EEB0_EB3_E"),
223     T_ERR("_ZN9I3TTB7_$B8_C0TTT9I3TTB7_$B8_$$5$B_E"),
224     T_ERR("_ZN9$C$TB7_$B8_C0TTT9I3TB7_$B8_$$5$B_E"),
225     T_ERR("_ZN9......=E"),
226     T_ERR("_RMC0TTTTQLpfQNp.B_aaaaaTOTfQL_aaaaaB_"),
227     T_ERR("_RMC0TTTTRLpB8_lRMC0B_aaB5_EB4_B5_EEB3_E"),
228     T_ERR("_RMC0TTTTRLp_aalRMC0B_aaB5_EB4_B5_EEB3_E"),
229     T_ERR("_RMC0TTTTRLp_C0TaalRMC0B6_EB_aaB4_B5_EEB3_E"),
230     T_ERR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A$TT9I3TB7m$8_$A$TT9I3TB7m$__ZN2UE"),
236     T_ERR("__ZN9?@EEEEEJE"),
237     T_ERR("_RMC0TTTATjpB8_EB7_TB_aaB5_EB4_EB3_E"),
238     T_ERR("_ZN949$TE7_llv4C$TE$C$7_llvm$C$TT9'3TB_$__................................................................................................................................................................................................................................................................................................................................................................................................$B$.E..........................................:.........................................................................................................................................P...............................................@..................................................................................................................................................................................................................................................................TTB7_E.6_SB_E.6_S65__ZQCI<_EB=E"),
239     T_ERR("_RMC6aEB8_XB4_YYYYYYYYYYYYYYYYYYYYYYYYNSCsbmJIY6D_4core0MC6aEB8_XB4_YYYYYYYYYYYYYYYYYYsliceINyB9_rhDNuNgNoBN_4iter8iteravmt}ore5sliceINyB9_4IterhDNuNgNCINOXs25_NSCsbmJIY6D_4core5sliceI_yB9_4IterhDNuNgNoB__4llvmwionNB9_4INkXs25_NSCrhDYYYYYYYYYYYYYYYYYYYYYYYYYYYaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)))))_aa)))))))))))))))))))))"),
240     T_ERR("_ZN9A7$TB7_$B8_$B$TT9I3TB7m$__ZN98C$T_aa$B8_$C$TT9I3_ZN9$C$TB7_$B8_$B$TT9I3TB7m$__ZN9$C$TB_$BZN9A7$TB7_$B8_$B$TT6$C$$B$$B$$__ZN98C$T_aa$B8_$K$TT9I7_ZN9$C$TB7_$B8T_aa$B8_$C$TT9I3_ZN9$C$TB7_$LP$B$TT9I3TB7m$__ZN9$ $TB_$B8_$A$TT9I3TB7m$8_$A$TT9I3TB7m$__ZN2UE"),
241     T_ERR("_ZN9A7$TB7_$B8_$B$TT9I3TB7m$__ZN98C$T_aa$B8_$C$TT9I3_ZN9$C$TB7_$B8_$B$TT9I3TB7m$__ZN9$C$TB_$BZN9A7$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terator8Iterator9rpositionNCNgNpB2_6D_4core5sliReINyB1_4IterhENu6D_4core5sliceINyB1_4IterhENuNgNoBb_4iter8iterator8Iterator9rpositionNCNgNpBNgNoBb_4iter8iterr9rpo25_NgCsbmNqQUJIY6D_4core5sliceIN4IterhENuNgNoBb_4iter8iterator8Iterator9rpositionNCNgNpB2_6NqQUJIY6D_4core5sliReINyB1_4IterhENu6D_4core5sliceINyB1_4IterhENuNgNoBb_4iter8iterator8Iterator9rpositionNCNgNpBNgNoBb_4iter8iterr9rpositionNCNgNpB2_6NqQUJIY6B2_6hr7m0E7m0EsitionNCNgNpB2_6NqQUJIY6B2_6hr7m0E7m0E0Bb_"),
246     T_ERR("_RIC6kIIIIIB4_lB5_EB4NEB3_A"),
247     T_ERR("_ZN9I3TTB7_$B8_$B$TT9I398C$T$B8_$B$TT9I398C$T_aa$B8_$C$TT9I3_ZN9$C$TB7_$B8_$B$TB$$B$$__ZN98C$T_aa$B8_$K$TT9I7_ZN9$C$TB7_$B8T_aa$B8_$C$TT9ITB7$LT$B$TT9I3TB7m$__ZB8T_aa$B8K$C$TT9I3_ZN9$C$TB7_$LT$B$TT9I3TB7m$__ZN9$ $TB7m$__ZN98C$T_aa$B8_$C$TT9I3_ZN:$C$TB7_$B8_$B$TT9I3TB7m$__ZN$RF$9$C$TB_$BZN9A7$TB7_8B8_$B$TT6$C$$B$%B$$__ZN98C$T_aa$B8_$K$TT9I7_ZN9$C$TB7_$B8T_aa$B8_$C$TT9I3_ZN9$C$TB7_$LT$B$TT9I3TB7m$__ZN9$ UE"),
248     T_ERR("_RIC6aOB_aaB4_RIC6aOB_aaB8_gB._NaEB5_gB8_gB4_NaEB5_))))))))))))))))))))))da)))))))C6aEB8_XB4_DC6aXB4_DC6aEJ8_gB_NaEB5_gB8_gB4_NaEB5_))))))))))))))))))))))_a))))))))sitUonNCNgNpB1_6hr7m0E0Bb_)))sitionNCNgNpB1_6hr7m0E0Bb_"));
249 
250 /* END CSTYLED */
251 
252 static rust_test_grp_t *rust_tests[] = {
253 	&demangle,
254 	&demangle_dollars,
255 	&demangle_many_dollars,
256 	&demangle_osx,
257 	&demangle_elements_beginning_with_underscore,
258 	&demangle_trait_impls,
259 	&invalid_no_chop,
260 	&handle_assoc_types,
261 	&cplusplus_as_rust,
262 	&v0_crate_with_leading_digit,
263 	&v0_utf8_idents,
264 	&v0_closure,
265 	&v0_dyn_trait,
266 	&v0_const_generics,
267 	&v0_exponential_explosion,
268 	&v0_thinlto,
269 	&v0_demangle_extra_suffix,
270 	&v0_generic_func,
271 	&v0_eddyb,
272 	&v0_afl_fast,
273 };
274 static const size_t n_rust_tests = ARRAY_SIZE(rust_tests);
275 
276 static boolean_t
277 check_failure(size_t i, rust_test_case_t *tc, const char *dem, boolean_t res)
278 {
279 	int savederr = errno;
280 
281 	if (dem == NULL && savederr == EINVAL)
282 		return (B_TRUE);
283 
284 	if (res)
285 		(void) printf("FAILURE\n");
286 
287 	if (dem != NULL) {
288 		(void) printf("  [%zu] Successfully demanged an invalid "
289 		    "name\n", i);
290 		(void) printf("         Name: '%s'\n", tc->mangled);
291 		(void) printf("    Demangled: '%s'\n", dem);
292 		return (B_FALSE);
293 	}
294 
295 	(void) printf("  [%zu] demangle() returned an unexpected error\n", i);
296 	(void) printf("    Errno: %d\n", savederr);
297 	return (B_FALSE);
298 }
299 
300 static boolean_t
301 check_success(size_t i, rust_test_case_t *tc, const char *dem, boolean_t res)
302 {
303 	if (dem != NULL && strcmp(tc->demangled, dem) == 0)
304 		return (B_TRUE);
305 
306 	if (res)
307 		(void) printf("FAILURE\n");
308 
309 	if (dem == NULL) {
310 		(void) printf("  [%zu] Failed to demangle '%s'\n", i,
311 		    tc->mangled);
312 		return (B_FALSE);
313 	}
314 
315 	(void) printf("  [%zu] Demangled results do not match.\n", i);
316 	(void) printf("       Mangled: %s\n", tc->mangled);
317 	(void) printf("      Expected: %s\n", tc->demangled);
318 	(void) printf("        Actual: %s\n", dem);
319 	return (B_FALSE);
320 }
321 
322 static boolean_t
323 run_test(rust_test_grp_t *test)
324 {
325 	boolean_t res = B_TRUE;
326 
327 	(void) printf("Test %s: ", test->name);
328 
329 	for (size_t i = 0; test->tests[i].mangled != NULL; i++) {
330 		char *dem;
331 
332 		dem = sysdemangle(test->tests[i].mangled, SYSDEM_LANG_RUST,
333 		    NULL);
334 		if (test->tests[i].demangled == NULL)
335 			res &= check_failure(i, &test->tests[i], dem, res);
336 		else
337 			res &= check_success(i, &test->tests[i], dem, res);
338 
339 		free(dem);
340 	}
341 
342 	if (res)
343 		(void) printf("SUCCESS\n");
344 
345 	return (res);
346 }
347 
348 int
349 main(int argc, char **argv)
350 {
351 	const char *l;
352 	boolean_t ok = B_TRUE;
353 
354 	l = setlocale(LC_CTYPE, TEST_LOCALE);
355 	if (l == NULL || strcmp(l, TEST_LOCALE) != 0)
356 		errx(EXIT_FAILURE, "failed to set locale to %s", TEST_LOCALE);
357 
358 	for (size_t i = 0; i < n_rust_tests; i++)
359 		ok &= run_test(rust_tests[i]);
360 
361 	return (ok ? 0 : 1);
362 }
363 
364 const char *
365 _umem_debug_init(void)
366 {
367 	return ("default,verbose");
368 }
369 
370 const char *
371 _umem_logging_init(void)
372 {
373 	return ("fail,contents");
374 }
375