Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,9 @@ CPlusPlusLanguage::GetFunctionNameInfo(ConstString name) const {

bool CPlusPlusLanguage::SymbolNameFitsToLanguage(Mangled mangled) const {
const char *mangled_name = mangled.GetMangledName().GetCString();
return mangled_name && Mangled::IsMangledName(mangled_name);
auto mangling_scheme = Mangled::GetManglingScheme(mangled_name);
return mangled_name && (mangling_scheme == Mangled::eManglingSchemeItanium ||
mangling_scheme == Mangled::eManglingSchemeMSVC);
}

ConstString CPlusPlusLanguage::GetDemangledFunctionNameWithoutArguments(
Expand Down
30 changes: 30 additions & 0 deletions lldb/unittests/Language/CPlusPlus/CPlusPlusLanguageTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -397,3 +397,33 @@ TEST(CPlusPlusLanguage, CPlusPlusNameParser) {
// Don't crash.
CPlusPlusNameParser((const char *)nullptr);
}

TEST(CPlusPlusLanguage, DoesNotMatchCxx) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you're adding this here, can you add a case where we do match C++? Using Itanium and MS ABI examples?

// Test that a symbol name that is NOT C++ does not match C++.

SubsystemRAII<CPlusPlusLanguage> lang;
Language *CPlusPlusLang =
Language::FindPlugin(lldb::eLanguageTypeC_plus_plus);

EXPECT_TRUE(CPlusPlusLang != nullptr);

Mangled swiftSymbol("$sS");
EXPECT_FALSE(CPlusPlusLang->SymbolNameFitsToLanguage(swiftSymbol));
}

TEST(CPlusPlusLanguage, MatchesCxx) {
// Test that a symbol name that is C++ does match C++ (both Itanium and MSVC).

SubsystemRAII<CPlusPlusLanguage> lang;
Language *CPlusPlusLang =
Language::FindPlugin(lldb::eLanguageTypeC_plus_plus);

EXPECT_TRUE(CPlusPlusLang != nullptr);

Mangled itaniumSymbol("_ZFoo");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not that it matters much, but should we make these actually demangle-able symbols?

Some minimal ones are:

_Z3Foo
___Z3Bar_block_invoke
?x@@3AH

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah only saw your comment after merging. I'll make them real symbols.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here #153857

EXPECT_TRUE(CPlusPlusLang->SymbolNameFitsToLanguage(itaniumSymbol));
Mangled itaniumExtensionSymbol("___ZBar");
EXPECT_TRUE(CPlusPlusLang->SymbolNameFitsToLanguage(itaniumExtensionSymbol));
Mangled msvcSymbol("?Baz");
EXPECT_TRUE(CPlusPlusLang->SymbolNameFitsToLanguage(msvcSymbol));
}
Loading