[Lldb-commits] [lldb] r339014 - Add ConstString::IsNull() to tell between null vs. empty strings and fix usage in Mangled::GetDemangledName()
Stefan Granitz via lldb-commits
lldb-commits at lists.llvm.org
Mon Aug 6 07:15:18 PDT 2018
Author: stefan.graenitz
Date: Mon Aug 6 07:15:17 2018
New Revision: 339014
URL: http://llvm.org/viewvc/llvm-project?rev=339014&view=rev
Log:
Add ConstString::IsNull() to tell between null vs. empty strings and fix usage in Mangled::GetDemangledName()
Summary: `IsEmpty()` and `operator bool() == false` have equal semantics. Usage in Mangled::GetDemangledName() was incorrect. What it actually wants is a check for null-string. Split this off of D50071 and added a test to clarify usage.
Reviewers: labath, jingham
Subscribers: erik.pilkington, lldb-commits
Differential Revision: https://reviews.llvm.org/D50327
Modified:
lldb/trunk/include/lldb/Utility/ConstString.h
lldb/trunk/source/Core/Mangled.cpp
lldb/trunk/unittests/Utility/ConstStringTest.cpp
Modified: lldb/trunk/include/lldb/Utility/ConstString.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Utility/ConstString.h?rev=339014&r1=339013&r2=339014&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Utility/ConstString.h (original)
+++ lldb/trunk/include/lldb/Utility/ConstString.h Mon Aug 6 07:15:17 2018
@@ -346,6 +346,15 @@ public:
bool IsEmpty() const { return m_string == nullptr || m_string[0] == '\0'; }
//------------------------------------------------------------------
+ /// Test for null string.
+ ///
+ /// @return
+ /// @li \b true if there is no string associated with this instance.
+ /// @li \b false if there is a string associated with this instance.
+ //------------------------------------------------------------------
+ bool IsNull() const { return m_string == nullptr; }
+
+ //------------------------------------------------------------------
/// Set the C string value.
///
/// Set the string value in the object by uniquing the \a cstr string value
Modified: lldb/trunk/source/Core/Mangled.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Mangled.cpp?rev=339014&r1=339013&r2=339014&view=diff
==============================================================================
--- lldb/trunk/source/Core/Mangled.cpp (original)
+++ lldb/trunk/source/Core/Mangled.cpp Mon Aug 6 07:15:17 2018
@@ -242,7 +242,7 @@ const ConstString &
Mangled::GetDemangledName(lldb::LanguageType language) const {
// Check to make sure we have a valid mangled name and that we haven't
// already decoded our mangled name.
- if (m_mangled && !m_demangled) {
+ if (m_mangled && m_demangled.IsNull()) {
// We need to generate and cache the demangled name.
static Timer::Category func_cat(LLVM_PRETTY_FUNCTION);
Timer scoped_timer(func_cat, "Mangled::GetDemangledName (m_mangled = %s)",
@@ -312,7 +312,7 @@ Mangled::GetDemangledName(lldb::Language
free(demangled_name);
}
}
- if (!m_demangled) {
+ if (m_demangled.IsNull()) {
// Set the demangled string to the empty string to indicate we tried to
// parse it once and failed.
m_demangled.SetCString("");
Modified: lldb/trunk/unittests/Utility/ConstStringTest.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/Utility/ConstStringTest.cpp?rev=339014&r1=339013&r2=339014&view=diff
==============================================================================
--- lldb/trunk/unittests/Utility/ConstStringTest.cpp (original)
+++ lldb/trunk/unittests/Utility/ConstStringTest.cpp Mon Aug 6 07:15:17 2018
@@ -33,3 +33,20 @@ TEST(ConstStringTest, MangledCounterpart
EXPECT_TRUE(foo.GetMangledCounterpart(counterpart));
EXPECT_EQ("bar", counterpart.GetStringRef());
}
+
+TEST(ConstStringTest, NullAndEmptyStates) {
+ ConstString foo("foo");
+ EXPECT_FALSE(!foo);
+ EXPECT_FALSE(foo.IsEmpty());
+ EXPECT_FALSE(foo.IsNull());
+
+ ConstString empty("");
+ EXPECT_TRUE(!empty);
+ EXPECT_TRUE(empty.IsEmpty());
+ EXPECT_FALSE(empty.IsNull());
+
+ ConstString null;
+ EXPECT_TRUE(!null);
+ EXPECT_TRUE(null.IsEmpty());
+ EXPECT_TRUE(null.IsNull());
+}
More information about the lldb-commits
mailing list