Skip to content

Commit b8be76c

Browse files
committed
🍒 [lldb][CPlusPlusLanguage] Avoid redundant const char* -> StringRef roundtrip (llvm#161499)
We've been seen (very sporadic) lifetime issues around this area. Here's an example backtrace: ``` [ 8] 0x0000000188e56743 libsystem_platform.dylib`_sigtramp + 55 [ 9] 0x00000001181e041f LLDB`lldb_private::CPlusPlusLanguage::SymbolNameFitsToLanguage(lldb_private::Mangled) const [inlined] unsigned long std::1::constexpr_strlen[abi:nn200100]<char>(char const*) + 7 at constexpr_c_functions.h:63:10 [ 9] 0x00000001181e0418 LLDB`lldb_private::CPlusPlusLanguage::SymbolNameFitsToLanguage(lldb_private::Mangled) const [inlined] std::__1::char_traits<char>::length[abi:nn200100](char const*) at char_traits.h:232:12 [ 9] 0x00000001181e0418 LLDB`lldb_private::CPlusPlusLanguage::SymbolNameFitsToLanguage(lldb_private::Mangled) const [inlined] llvm::StringRef::StringRef(char const*) at StringRef.h:90:33 [ 9] 0x00000001181e0418 LLDB`lldb_private::CPlusPlusLanguage::SymbolNameFitsToLanguage(lldb_private::Mangled) const [inlined] llvm::StringRef::StringRef(char const*) at StringRef.h:92:38 [ 9] 0x00000001181e0418 LLDB`lldb_private::CPlusPlusLanguage::SymbolNameFitsToLanguage(lldb_private::Mangled) const + 20 at CPlusPlusLanguage.cpp:68:62 ``` Looks like we're calling `strlen` on a nullptr. I stared at this codepath for a while but am still not sure how that could happen unless the underlying `ConstString` somehow pointed to corrupted data. But `SymbolNameFitsToLanguage` does some roundtripping through a `const char*` before calling `GetManglingScheme`. No other callsite does this and it just seems redundant. This patch cleans this up. rdar://161128180 (cherry picked from commit 2a96d19)
1 parent bb6916c commit b8be76c

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

‎lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,10 @@ CPlusPlusLanguage::GetFunctionNameInfo(ConstString name) const {
103103
}
104104

105105
bool CPlusPlusLanguage::SymbolNameFitsToLanguage(Mangled mangled) const {
106-
const char *mangled_name = mangled.GetMangledName().GetCString();
107-
auto mangling_scheme = Mangled::GetManglingScheme(mangled_name);
108-
return mangled_name && (mangling_scheme == Mangled::eManglingSchemeItanium ||
109-
mangling_scheme == Mangled::eManglingSchemeMSVC);
106+
auto mangling_scheme =
107+
Mangled::GetManglingScheme(mangled.GetMangledName().GetStringRef());
108+
return mangling_scheme == Mangled::eManglingSchemeItanium ||
109+
mangling_scheme == Mangled::eManglingSchemeMSVC;
110110
}
111111

112112
ConstString CPlusPlusLanguage::GetDemangledFunctionNameWithoutArguments(

0 commit comments

Comments
 (0)