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
This commit is contained in:
Hubert Tong 2024-12-14 19:37:15 -05:00
parent 99354f968f
commit d33bf2e9df

View File

@ -9,7 +9,8 @@
// This test is too big for most embedded devices.
// XFAIL: LIBCXX-PICOLIBC-FIXME
// This test exercises support for char array initializer lists added in dd8b266ef.
// This test exercises support for char array initializer lists added in
// dd8b266ef.
// UNSUPPORTED: using-built-library-before-llvm-20
// Android's long double on x86[-64] is (64/128)-bits instead of Linux's usual
@ -32,9 +33,8 @@
// Is long double fp128?
#define LDBL_FP128 (__LDBL_MANT_DIG__ == 113)
// clang-format off
const char* cases[][2] =
{
const char *cases[][2] = {
// clang-format off
{"_Z1A", "A"},
{"_Z1Av", "A()"},
{"_Z1A1B1C", "A(B, C)"},
@ -30245,16 +30245,17 @@ const char* cases[][2] =
{"_Z1fDSDRj", "f(_Sat unsigned _Fract)"},
{"_Z1fDSDRl", "f(_Sat long _Fract)"},
{"_Z1fDSDRm", "f(_Sat unsigned long _Fract)"},
// clang-format on
};
// clang-format on
const unsigned N = sizeof(cases) / sizeof(cases[0]);
struct FPLiteralCase {
const char* mangled;
const char *mangled;
// There are four possible demanglings of a given float.
std::string expecting[4];
} fp_literal_cases[] = {
// clang-format off
{"_ZN5test01gIfEEvRAszplcvT__ELf40a00000E_c",
{
"void test0::g<float>(char (&) [sizeof ((float)() + 0x1.4p+2f)])",
@ -30280,15 +30281,17 @@ struct FPLiteralCase {
#endif
#if LDBL_FP128
// A 32-character FP literal of long double type
{"3FooILeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeEE", {"Foo<-0x1.eeeeeeeeeeeeeeeeeeeeeeeeeeeep+12015L>"}},
{"3FooILeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeEE",
{"Foo<-0x1.eeeeeeeeeeeeeeeeeeeeeeeeeeeep+12015L>"}},
#endif
// clang-format on
};
const unsigned NF = sizeof(fp_literal_cases) / sizeof(fp_literal_cases[0]);
const unsigned NEF = sizeof(fp_literal_cases[0].expecting) / sizeof(fp_literal_cases[0].expecting[0]);
const unsigned NEF = sizeof(fp_literal_cases[0].expecting) /
sizeof(fp_literal_cases[0].expecting[0]);
const char* invalid_cases[] =
{
const char *invalid_cases[] = {
// clang-format off
"_ZIPPreEncode",
"Agentt",
"NSoERj5E=Y1[uM:ga",
@ -30299,7 +30302,7 @@ const char* invalid_cases[] =
#if !LDBL_FP80
"_ZN5test01hIfEEvRAcvjplstT_Le4001a000000000000000E_c",
#endif
// The following test cases were found by libFuzzer+ASAN
// The following test cases were found by libFuzzer+ASAN
"\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",
"\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*",
"\x41\x64\x6E\x32*",
@ -30345,128 +30348,114 @@ const char* invalid_cases[] =
"_ZGI3Foo",
"_ZGIW3Foov",
"W1x",
// clang-format on
};
const unsigned NI = sizeof(invalid_cases) / sizeof(invalid_cases[0]);
void test()
{
std::size_t len = 0;
char* buf = nullptr;
bool failed = false;
for (unsigned i = 0; i < N; ++i)
{
int status;
char* demang =
__cxxabiv1::__cxa_demangle(cases[i][0], buf, &len, &status);
if (!demang || std::strcmp(demang, cases[i][1]) != 0)
{
std::fprintf(stderr, "ERROR demangling %s\n"
"expected: %s\n"
"got: %d, %s\n",
cases[i][0], cases[i][1], status,
demang ? demang : "(null)");
failed = true;
}
if (demang)
buf = demang;
void test() {
std::size_t len = 0;
char *buf = nullptr;
bool failed = false;
for (unsigned i = 0; i < N; ++i) {
int status;
char *demang = __cxxabiv1::__cxa_demangle(cases[i][0], buf, &len, &status);
if (!demang || std::strcmp(demang, cases[i][1]) != 0) {
std::fprintf(stderr,
"ERROR demangling %s\n"
"expected: %s\n"
"got: %d, %s\n",
cases[i][0], cases[i][1], status,
demang ? demang : "(null)");
failed = true;
}
free(buf);
assert(!failed && "demangle failed");
if (demang)
buf = demang;
}
free(buf);
assert(!failed && "demangle failed");
}
void test_invalid_cases()
{
std::size_t len = 0;
char* buf = nullptr;
bool passed = false;
for (unsigned i = 0; i < NI; ++i)
{
int status;
char* demang =
__cxxabiv1::__cxa_demangle(invalid_cases[i], buf, &len, &status);
if (status != -2)
{
std::printf("%s should be invalid but is not\n", invalid_cases[i]);
std::printf("Got: %d, %s\n", status, demang ? demang : "(null)");
passed = true;
}
if (demang)
buf = demang;
void test_invalid_cases() {
std::size_t len = 0;
char *buf = nullptr;
bool passed = false;
for (unsigned i = 0; i < NI; ++i) {
int status;
char *demang =
__cxxabiv1::__cxa_demangle(invalid_cases[i], buf, &len, &status);
if (status != -2) {
std::printf("%s should be invalid but is not\n", invalid_cases[i]);
std::printf("Got: %d, %s\n", status, demang ? demang : "(null)");
passed = true;
}
free(buf);
assert(!passed && "demangle did not fail");
if (demang)
buf = demang;
}
free(buf);
assert(!passed && "demangle did not fail");
}
const char *const xfail_cases[] = {
// Sentinel value
nullptr
nullptr,
};
void test_xfail_cases()
{
std::size_t len = 0;
char* buf = nullptr;
for (const char *c_str : xfail_cases)
{
if (!c_str)
break;
int status;
char* demang = __cxxabiv1::__cxa_demangle(c_str, buf, &len, &status);
if (status != -2)
{
std::printf("%s was documented as xfail but passed\n", c_str);
std::printf("Got status = %d\n", status);
assert(status == -2);
}
else
{
buf = demang;
}
void test_xfail_cases() {
std::size_t len = 0;
char *buf = nullptr;
for (const char *c_str : xfail_cases) {
if (!c_str)
break;
int status;
char *demang = __cxxabiv1::__cxa_demangle(c_str, buf, &len, &status);
if (status != -2) {
std::printf("%s was documented as xfail but passed\n", c_str);
std::printf("Got status = %d\n", status);
assert(status == -2);
} else {
buf = demang;
}
free(buf);
}
free(buf);
}
void testFPLiterals()
{
std::size_t len = 0;
char* buf = nullptr;
for (unsigned i = 0; i < NF; ++i)
{
FPLiteralCase *fpCase = fp_literal_cases+i;
int status;
char* demang = __cxxabiv1::__cxa_demangle(fpCase->mangled, buf, &len, &status);
if (demang == 0)
{
std::printf("%s -> %s\n", fpCase->mangled, fpCase->expecting[0].c_str());
std::printf("Got instead: NULL, %d\n", status);
assert(false);
continue;
}
std::string *e_beg = fpCase->expecting;
std::string *e_end = fpCase->expecting + NEF;
if (std::find(e_beg, e_end, demang) == e_end)
{
std::printf("%s -> %s\n", fpCase->mangled, fpCase->expecting[0].c_str());
std::printf("Got instead: %s\n", demang);
assert(false);
continue;
}
buf = demang;
void testFPLiterals() {
std::size_t len = 0;
char *buf = nullptr;
for (unsigned i = 0; i < NF; ++i) {
FPLiteralCase *fpCase = fp_literal_cases + i;
int status;
char *demang =
__cxxabiv1::__cxa_demangle(fpCase->mangled, buf, &len, &status);
if (demang == 0) {
std::printf("%s -> %s\n", fpCase->mangled, fpCase->expecting[0].c_str());
std::printf("Got instead: NULL, %d\n", status);
assert(false);
continue;
}
free(buf);
std::string *e_beg = fpCase->expecting;
std::string *e_end = fpCase->expecting + NEF;
if (std::find(e_beg, e_end, demang) == e_end) {
std::printf("%s -> %s\n", fpCase->mangled, fpCase->expecting[0].c_str());
std::printf("Got instead: %s\n", demang);
assert(false);
continue;
}
buf = demang;
}
free(buf);
}
int main(int, char**)
{
std::printf("Testing %d symbols.\n", N);
{
timer t;
test();
test_invalid_cases();
test_xfail_cases();
testFPLiterals();
}
int main(int, char **) {
std::printf("Testing %d symbols.\n", N);
{
timer t;
test();
test_invalid_cases();
test_xfail_cases();
testFPLiterals();
}
#if 0
std::string input;
while (std::cin)
@ -30502,5 +30491,5 @@ int main(int, char**)
}
#endif
return 0;
return 0;
}