Skip to content

Commit d33bf2e

Browse files
NFC: clang-format test_demangle.pass.cpp but keep test "lines"
Add clang-format on/off around test "lines" Run clang-format without breaking string literals: clang-format --style='{BasedOnStyle: llvm, BreakStringLiterals: false}' -i test_demangle.pass.cpp Add clang-format on/off on fp_literal_cases Fixups: Split UNSUPPORTED to next line; xfail_cases trailing comma Replace physical tab
1 parent 99354f9 commit d33bf2e

File tree

1 file changed

+104
-115
lines changed

1 file changed

+104
-115
lines changed

libcxxabi/test/test_demangle.pass.cpp

Lines changed: 104 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
// This test is too big for most embedded devices.
1010
// XFAIL: LIBCXX-PICOLIBC-FIXME
1111

12-
// This test exercises support for char array initializer lists added in dd8b266ef.
12+
// This test exercises support for char array initializer lists added in
13+
// dd8b266ef.
1314
// UNSUPPORTED: using-built-library-before-llvm-20
1415

1516
// Android's long double on x86[-64] is (64/128)-bits instead of Linux's usual
@@ -32,9 +33,8 @@
3233
// Is long double fp128?
3334
#define LDBL_FP128 (__LDBL_MANT_DIG__ == 113)
3435

35-
// clang-format off
36-
const char* cases[][2] =
37-
{
36+
const char *cases[][2] = {
37+
// clang-format off
3838
{"_Z1A", "A"},
3939
{"_Z1Av", "A()"},
4040
{"_Z1A1B1C", "A(B, C)"},
@@ -30245,16 +30245,17 @@ const char* cases[][2] =
3024530245
{"_Z1fDSDRj", "f(_Sat unsigned _Fract)"},
3024630246
{"_Z1fDSDRl", "f(_Sat long _Fract)"},
3024730247
{"_Z1fDSDRm", "f(_Sat unsigned long _Fract)"},
30248+
// clang-format on
3024830249
};
30249-
// clang-format on
3025030250

3025130251
const unsigned N = sizeof(cases) / sizeof(cases[0]);
3025230252

3025330253
struct FPLiteralCase {
30254-
const char* mangled;
30254+
const char *mangled;
3025530255
// There are four possible demanglings of a given float.
3025630256
std::string expecting[4];
3025730257
} fp_literal_cases[] = {
30258+
// clang-format off
3025830259
{"_ZN5test01gIfEEvRAszplcvT__ELf40a00000E_c",
3025930260
{
3026030261
"void test0::g<float>(char (&) [sizeof ((float)() + 0x1.4p+2f)])",
@@ -30280,15 +30281,17 @@ struct FPLiteralCase {
3028030281
#endif
3028130282
#if LDBL_FP128
3028230283
// A 32-character FP literal of long double type
30283-
{"3FooILeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeEE", {"Foo<-0x1.eeeeeeeeeeeeeeeeeeeeeeeeeeeep+12015L>"}},
30284+
{"3FooILeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeEE",
30285+
{"Foo<-0x1.eeeeeeeeeeeeeeeeeeeeeeeeeeeep+12015L>"}},
3028430286
#endif
30287+
// clang-format on
3028530288
};
3028630289
const unsigned NF = sizeof(fp_literal_cases) / sizeof(fp_literal_cases[0]);
30287-
const unsigned NEF = sizeof(fp_literal_cases[0].expecting) / sizeof(fp_literal_cases[0].expecting[0]);
30290+
const unsigned NEF = sizeof(fp_literal_cases[0].expecting) /
30291+
sizeof(fp_literal_cases[0].expecting[0]);
3028830292

30289-
30290-
const char* invalid_cases[] =
30291-
{
30293+
const char *invalid_cases[] = {
30294+
// clang-format off
3029230295
"_ZIPPreEncode",
3029330296
"Agentt",
3029430297
"NSoERj5E=Y1[uM:ga",
@@ -30299,7 +30302,7 @@ const char* invalid_cases[] =
3029930302
#if !LDBL_FP80
3030030303
"_ZN5test01hIfEEvRAcvjplstT_Le4001a000000000000000E_c",
3030130304
#endif
30302-
// The following test cases were found by libFuzzer+ASAN
30305+
// The following test cases were found by libFuzzer+ASAN
3030330306
"\x44\x74\x70\x74\x71\x75\x34\x43\x41\x72\x4D\x6E\x65\x34\x9F\xC1\x43\x41\x72\x4D\x6E\x77\x38\x9A\x8E\x44\x6F\x64\x6C\x53\xF9\x5F\x70\x74\x70\x69\x45\x34\xD3\x73\x9E\x2A\x37",
3030430307
"\x4D\x41\x72\x63\x4E\x39\x44\x76\x72\x4D\x34\x44\x53\x4B\x6F\x44\x54\x6E\x61\x37\x47\x77\x78\x38\x43\x27\x41\x5F\x73\x70\x69\x45*",
3030530308
"\x41\x64\x6E\x32*",
@@ -30345,128 +30348,114 @@ const char* invalid_cases[] =
3034530348
"_ZGI3Foo",
3034630349
"_ZGIW3Foov",
3034730350
"W1x",
30351+
// clang-format on
3034830352
};
3034930353

3035030354
const unsigned NI = sizeof(invalid_cases) / sizeof(invalid_cases[0]);
3035130355

30352-
void test()
30353-
{
30354-
std::size_t len = 0;
30355-
char* buf = nullptr;
30356-
bool failed = false;
30357-
for (unsigned i = 0; i < N; ++i)
30358-
{
30359-
int status;
30360-
char* demang =
30361-
__cxxabiv1::__cxa_demangle(cases[i][0], buf, &len, &status);
30362-
if (!demang || std::strcmp(demang, cases[i][1]) != 0)
30363-
{
30364-
std::fprintf(stderr, "ERROR demangling %s\n"
30365-
"expected: %s\n"
30366-
"got: %d, %s\n",
30367-
cases[i][0], cases[i][1], status,
30368-
demang ? demang : "(null)");
30369-
failed = true;
30370-
}
30371-
if (demang)
30372-
buf = demang;
30356+
void test() {
30357+
std::size_t len = 0;
30358+
char *buf = nullptr;
30359+
bool failed = false;
30360+
for (unsigned i = 0; i < N; ++i) {
30361+
int status;
30362+
char *demang = __cxxabiv1::__cxa_demangle(cases[i][0], buf, &len, &status);
30363+
if (!demang || std::strcmp(demang, cases[i][1]) != 0) {
30364+
std::fprintf(stderr,
30365+
"ERROR demangling %s\n"
30366+
"expected: %s\n"
30367+
"got: %d, %s\n",
30368+
cases[i][0], cases[i][1], status,
30369+
demang ? demang : "(null)");
30370+
failed = true;
3037330371
}
30374-
free(buf);
30375-
assert(!failed && "demangle failed");
30372+
if (demang)
30373+
buf = demang;
30374+
}
30375+
free(buf);
30376+
assert(!failed && "demangle failed");
3037630377
}
3037730378

30378-
void test_invalid_cases()
30379-
{
30380-
std::size_t len = 0;
30381-
char* buf = nullptr;
30382-
bool passed = false;
30383-
for (unsigned i = 0; i < NI; ++i)
30384-
{
30385-
int status;
30386-
char* demang =
30387-
__cxxabiv1::__cxa_demangle(invalid_cases[i], buf, &len, &status);
30388-
if (status != -2)
30389-
{
30390-
std::printf("%s should be invalid but is not\n", invalid_cases[i]);
30391-
std::printf("Got: %d, %s\n", status, demang ? demang : "(null)");
30392-
passed = true;
30393-
}
30394-
if (demang)
30395-
buf = demang;
30379+
void test_invalid_cases() {
30380+
std::size_t len = 0;
30381+
char *buf = nullptr;
30382+
bool passed = false;
30383+
for (unsigned i = 0; i < NI; ++i) {
30384+
int status;
30385+
char *demang =
30386+
__cxxabiv1::__cxa_demangle(invalid_cases[i], buf, &len, &status);
30387+
if (status != -2) {
30388+
std::printf("%s should be invalid but is not\n", invalid_cases[i]);
30389+
std::printf("Got: %d, %s\n", status, demang ? demang : "(null)");
30390+
passed = true;
3039630391
}
30397-
free(buf);
30398-
assert(!passed && "demangle did not fail");
30392+
if (demang)
30393+
buf = demang;
30394+
}
30395+
free(buf);
30396+
assert(!passed && "demangle did not fail");
3039930397
}
3040030398

3040130399
const char *const xfail_cases[] = {
3040230400
// Sentinel value
30403-
nullptr
30401+
nullptr,
3040430402
};
3040530403

30406-
void test_xfail_cases()
30407-
{
30408-
std::size_t len = 0;
30409-
char* buf = nullptr;
30410-
for (const char *c_str : xfail_cases)
30411-
{
30412-
if (!c_str)
30413-
break;
30414-
int status;
30415-
char* demang = __cxxabiv1::__cxa_demangle(c_str, buf, &len, &status);
30416-
if (status != -2)
30417-
{
30418-
std::printf("%s was documented as xfail but passed\n", c_str);
30419-
std::printf("Got status = %d\n", status);
30420-
assert(status == -2);
30421-
}
30422-
else
30423-
{
30424-
buf = demang;
30425-
}
30404+
void test_xfail_cases() {
30405+
std::size_t len = 0;
30406+
char *buf = nullptr;
30407+
for (const char *c_str : xfail_cases) {
30408+
if (!c_str)
30409+
break;
30410+
int status;
30411+
char *demang = __cxxabiv1::__cxa_demangle(c_str, buf, &len, &status);
30412+
if (status != -2) {
30413+
std::printf("%s was documented as xfail but passed\n", c_str);
30414+
std::printf("Got status = %d\n", status);
30415+
assert(status == -2);
30416+
} else {
30417+
buf = demang;
3042630418
}
30427-
free(buf);
30419+
}
30420+
free(buf);
3042830421
}
3042930422

30430-
void testFPLiterals()
30431-
{
30432-
std::size_t len = 0;
30433-
char* buf = nullptr;
30434-
for (unsigned i = 0; i < NF; ++i)
30435-
{
30436-
FPLiteralCase *fpCase = fp_literal_cases+i;
30437-
int status;
30438-
char* demang = __cxxabiv1::__cxa_demangle(fpCase->mangled, buf, &len, &status);
30439-
if (demang == 0)
30440-
{
30441-
std::printf("%s -> %s\n", fpCase->mangled, fpCase->expecting[0].c_str());
30442-
std::printf("Got instead: NULL, %d\n", status);
30443-
assert(false);
30444-
continue;
30445-
}
30446-
std::string *e_beg = fpCase->expecting;
30447-
std::string *e_end = fpCase->expecting + NEF;
30448-
if (std::find(e_beg, e_end, demang) == e_end)
30449-
{
30450-
std::printf("%s -> %s\n", fpCase->mangled, fpCase->expecting[0].c_str());
30451-
std::printf("Got instead: %s\n", demang);
30452-
assert(false);
30453-
continue;
30454-
}
30455-
buf = demang;
30423+
void testFPLiterals() {
30424+
std::size_t len = 0;
30425+
char *buf = nullptr;
30426+
for (unsigned i = 0; i < NF; ++i) {
30427+
FPLiteralCase *fpCase = fp_literal_cases + i;
30428+
int status;
30429+
char *demang =
30430+
__cxxabiv1::__cxa_demangle(fpCase->mangled, buf, &len, &status);
30431+
if (demang == 0) {
30432+
std::printf("%s -> %s\n", fpCase->mangled, fpCase->expecting[0].c_str());
30433+
std::printf("Got instead: NULL, %d\n", status);
30434+
assert(false);
30435+
continue;
3045630436
}
30457-
free(buf);
30437+
std::string *e_beg = fpCase->expecting;
30438+
std::string *e_end = fpCase->expecting + NEF;
30439+
if (std::find(e_beg, e_end, demang) == e_end) {
30440+
std::printf("%s -> %s\n", fpCase->mangled, fpCase->expecting[0].c_str());
30441+
std::printf("Got instead: %s\n", demang);
30442+
assert(false);
30443+
continue;
30444+
}
30445+
buf = demang;
30446+
}
30447+
free(buf);
3045830448
}
3045930449

30460-
int main(int, char**)
30461-
{
30462-
std::printf("Testing %d symbols.\n", N);
30463-
{
30464-
timer t;
30465-
test();
30466-
test_invalid_cases();
30467-
test_xfail_cases();
30468-
testFPLiterals();
30469-
}
30450+
int main(int, char **) {
30451+
std::printf("Testing %d symbols.\n", N);
30452+
{
30453+
timer t;
30454+
test();
30455+
test_invalid_cases();
30456+
test_xfail_cases();
30457+
testFPLiterals();
30458+
}
3047030459
#if 0
3047130460
std::string input;
3047230461
while (std::cin)
@@ -30502,5 +30491,5 @@ int main(int, char**)
3050230491
}
3050330492
#endif
3050430493

30505-
return 0;
30494+
return 0;
3050630495
}

0 commit comments

Comments
 (0)