Skip to content

[lldb][test] Test all libcxxabi demangler test-cases against TrackingOutputBuffer #137793

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 31, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions lldb/unittests/Core/MangledTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -612,3 +612,66 @@ TEST_P(DemanglingPartsTestFixture, DemanglingParts) {

INSTANTIATE_TEST_SUITE_P(DemanglingPartsTests, DemanglingPartsTestFixture,
::testing::ValuesIn(g_demangling_parts_test_cases));

struct DemanglingInfoCorrectnessTestCase {
const char *mangled;
const char *demangled;
};

DemanglingInfoCorrectnessTestCase g_demangling_correctness_test_cases[] = {
#include "llvm/Testing/Demangle/DemangleTestCases.inc"
};

struct DemanglingInfoCorrectnessTestFixutre
: public ::testing::TestWithParam<DemanglingInfoCorrectnessTestCase> {};

TEST_P(DemanglingInfoCorrectnessTestFixutre, Correctness) {
auto [mangled, demangled] = GetParam();

llvm::itanium_demangle::ManglingParser<TestAllocator> Parser(
mangled, mangled + ::strlen(mangled));

const auto *Root = Parser.parse();

ASSERT_NE(nullptr, Root);

TrackingOutputBuffer OB;
Root->print(OB);

// Filter out cases which would never show up in frames. We only care about
// function names.
if (Root->getKind() !=
llvm::itanium_demangle::Node::Kind::KFunctionEncoding &&
Root->getKind() != llvm::itanium_demangle::Node::Kind::KDotSuffix)
return;

ASSERT_TRUE(OB.NameInfo.hasBasename());

auto tracked_name = llvm::StringRef(OB);

auto return_left = tracked_name.slice(0, OB.NameInfo.ScopeRange.first);
auto scope = tracked_name.slice(OB.NameInfo.ScopeRange.first,
OB.NameInfo.ScopeRange.second);
auto basename = tracked_name.slice(OB.NameInfo.BasenameRange.first,
OB.NameInfo.BasenameRange.second);
auto template_args = tracked_name.slice(OB.NameInfo.BasenameRange.second,
OB.NameInfo.ArgumentsRange.first);
auto args = tracked_name.slice(OB.NameInfo.ArgumentsRange.first,
OB.NameInfo.ArgumentsRange.second);
auto return_right = tracked_name.slice(OB.NameInfo.ArgumentsRange.second,
OB.NameInfo.QualifiersRange.first);
auto qualifiers = tracked_name.slice(OB.NameInfo.QualifiersRange.first,
OB.NameInfo.QualifiersRange.second);
auto suffix = tracked_name.slice(OB.NameInfo.QualifiersRange.second,
llvm::StringRef::npos);

auto reconstructed_name =
llvm::join_items("", return_left, scope, basename, template_args, args,
return_right, qualifiers, suffix);

EXPECT_EQ(reconstructed_name, demangled);
}

INSTANTIATE_TEST_SUITE_P(
DemanglingInfoCorrectnessTests, DemanglingInfoCorrectnessTestFixutre,
::testing::ValuesIn(g_demangling_correctness_test_cases));
Loading