Index: lldb/source/Core/Value.cpp =================================================================== --- lldb/source/Core/Value.cpp +++ lldb/source/Core/Value.cpp @@ -222,6 +222,11 @@ case eContextTypeLLDBType: // Type * case eContextTypeVariable: // Variable * { + // The size of this Value may be less than the size of the type of its + // source variable due to truncating operations such as DW_OP_piece. + if (m_value_type == eValueTypeHostAddress) + return GetBuffer().GetByteSize(); + auto *scope = exe_ctx ? exe_ctx->GetBestExecutionContextScope() : nullptr; if (llvm::Optional size = GetCompilerType().GetByteSize(scope)) { if (error_ptr) Index: lldb/unittests/Expression/DWARFExpressionTest.cpp =================================================================== --- lldb/unittests/Expression/DWARFExpressionTest.cpp +++ lldb/unittests/Expression/DWARFExpressionTest.cpp @@ -360,4 +360,16 @@ // Note that the "00" should really be "undef", but we can't // represent that yet. llvm::HasValue(GetScalar(16, 0xff00, true))); + + for (unsigned char ByteSize = 1; ByteSize <= 8; ++ByteSize) { + llvm::Expected empty = Evaluate({DW_OP_piece, ByteSize}); + // Note that the "00" should really be "undef", but we can't + // represent that yet. + EXPECT_THAT_EXPECTED(empty, + llvm::HasValue(GetScalar(ByteSize * 8, 0, true))); + + Value pieces; + ASSERT_EQ(pieces.AppendDataToHostBuffer(empty.get()), ByteSize); + ASSERT_EQ(pieces.GetValueByteSize(nullptr, nullptr), ByteSize); + } }