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(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/Makefile =================================================================== --- /dev/null +++ lldb/test/API/lang/cpp/null_references/Makefile @@ -0,0 +1,3 @@ +CXX_SOURCES := main.cpp + +include Makefile.rules 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/main.cpp =================================================================== --- /dev/null +++ lldb/test/API/lang/cpp/null_references/main.cpp @@ -0,0 +1,12 @@ +#include + +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); +}