shafik created this revision. shafik added reviewers: aprantl, teemperor, werat. Herald added a subscriber: arphaman. shafik requested review of this revision.
D103532 <https://reviews.llvm.org/D103532> modified this case to preserve type sugar but we can end up with cases where the cast is not valid. I modified the code to use `GetLValueReferenceType(type)`/`GetRValueReferenceType(type)` respectively. In the case being tested in the test case we end with the following type: TypedefType 0x7f8a710202f0 'std::__compressed_pair_elem<struct std::basic_string<char, struct std::char_traits<char>, class std::allocator<char> >::__rep, 0, false>::const_reference' sugar |-Typedef 0x7f8a71020280 'const_reference' `-LValueReferenceType 0x7f8a71020250 'const struct std::basic_string<char, struct std::char_traits<char>, class std::allocator<char> >::__rep &' ... which can't be cast to `ReferenceType`. https://reviews.llvm.org/D108717 Files: lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp lldb/test/API/lang/cpp/null_references/Makefile lldb/test/API/lang/cpp/null_references/TestNullReferences.py lldb/test/API/lang/cpp/null_references/main.cpp Index: lldb/test/API/lang/cpp/null_references/main.cpp =================================================================== --- /dev/null +++ lldb/test/API/lang/cpp/null_references/main.cpp @@ -0,0 +1,12 @@ +#include <string> + +int f(std::string &instr) { + return instr.size(); // break here +} + +int main() { + std::string *bad_str = (std::string *)nullptr; + // This is undefined behavior. We are purposefully trying to hit + // GetCrashingDereference(...) + return f(*bad_str); +} Index: lldb/test/API/lang/cpp/null_references/TestNullReferences.py =================================================================== --- /dev/null +++ lldb/test/API/lang/cpp/null_references/TestNullReferences.py @@ -0,0 +1,14 @@ +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + +class TestNullReferences(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + def test(self): + self.build() + lldbutil.run_to_source_breakpoint(self, "// break here", lldb.SBFileSpec("main.cpp")) + + self.runCmd("continue") Index: lldb/test/API/lang/cpp/null_references/Makefile =================================================================== --- /dev/null +++ lldb/test/API/lang/cpp/null_references/Makefile @@ -0,0 +1,3 @@ +CXX_SOURCES := main.cpp + +include Makefile.rules Index: lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp =================================================================== --- lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp +++ lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp @@ -6502,10 +6502,13 @@ case clang::Type::LValueReference: case clang::Type::RValueReference: if (idx_is_valid) { - const clang::ReferenceType *reference_type = - llvm::cast<clang::ReferenceType>(GetQualType(type).getTypePtr()); - CompilerType pointee_clang_type = - GetType(reference_type->getPointeeType()); + CompilerType pointee_clang_type; + + if (parent_type_class == clang::Type::LValueReference) + pointee_clang_type = GetLValueReferenceType(type).GetPointeeType(); + else + pointee_clang_type = GetRValueReferenceType(type).GetPointeeType(); + if (transparent_pointers && pointee_clang_type.IsAggregateType()) { child_is_deref_of_parent = false; bool tmp_child_is_deref_of_parent = false;
Index: lldb/test/API/lang/cpp/null_references/main.cpp =================================================================== --- /dev/null +++ lldb/test/API/lang/cpp/null_references/main.cpp @@ -0,0 +1,12 @@ +#include <string> + +int f(std::string &instr) { + return instr.size(); // break here +} + +int main() { + std::string *bad_str = (std::string *)nullptr; + // This is undefined behavior. We are purposefully trying to hit + // GetCrashingDereference(...) + return f(*bad_str); +} Index: lldb/test/API/lang/cpp/null_references/TestNullReferences.py =================================================================== --- /dev/null +++ lldb/test/API/lang/cpp/null_references/TestNullReferences.py @@ -0,0 +1,14 @@ +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + +class TestNullReferences(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + def test(self): + self.build() + lldbutil.run_to_source_breakpoint(self, "// break here", lldb.SBFileSpec("main.cpp")) + + self.runCmd("continue") Index: lldb/test/API/lang/cpp/null_references/Makefile =================================================================== --- /dev/null +++ lldb/test/API/lang/cpp/null_references/Makefile @@ -0,0 +1,3 @@ +CXX_SOURCES := main.cpp + +include Makefile.rules Index: lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp =================================================================== --- lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp +++ lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp @@ -6502,10 +6502,13 @@ case clang::Type::LValueReference: case clang::Type::RValueReference: if (idx_is_valid) { - const clang::ReferenceType *reference_type = - llvm::cast<clang::ReferenceType>(GetQualType(type).getTypePtr()); - CompilerType pointee_clang_type = - GetType(reference_type->getPointeeType()); + CompilerType pointee_clang_type; + + if (parent_type_class == clang::Type::LValueReference) + pointee_clang_type = GetLValueReferenceType(type).GetPointeeType(); + else + pointee_clang_type = GetRValueReferenceType(type).GetPointeeType(); + if (transparent_pointers && pointee_clang_type.IsAggregateType()) { child_is_deref_of_parent = false; bool tmp_child_is_deref_of_parent = false;
_______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits