diff --git a/lldb/include/lldb/Utility/RegisterValue.h b/lldb/include/lldb/Utility/RegisterValue.h --- a/lldb/include/lldb/Utility/RegisterValue.h +++ b/lldb/include/lldb/Utility/RegisterValue.h @@ -110,7 +110,7 @@ if (m_type == eTypeUInt8) { if (success_ptr) *success_ptr = true; - return m_scalar.UChar(fail_value); + return m_scalar.ZExtOrTruncInt(fail_value); } if (success_ptr) *success_ptr = true; diff --git a/lldb/include/lldb/Utility/Scalar.h b/lldb/include/lldb/Utility/Scalar.h --- a/lldb/include/lldb/Utility/Scalar.h +++ b/lldb/include/lldb/Utility/Scalar.h @@ -181,28 +181,17 @@ // Access the type of the current value. Scalar::Type GetType() const { return m_type; } - // Returns a casted value of the current contained data without modifying the - // current value. FAIL_VALUE will be returned if the type of the value is - // void or invalid. - int SInt(int fail_value = 0) const; - - unsigned char UChar(unsigned char fail_value = 0) const; - - signed char SChar(signed char fail_value = 0) const; - - unsigned short UShort(unsigned short fail_value = 0) const; - - short SShort(short fail_value = 0) const; - - unsigned int UInt(unsigned int fail_value = 0) const; - - long SLong(long fail_value = 0) const; - - unsigned long ULong(unsigned long fail_value = 0) const; - - long long SLongLong(long long fail_value = 0) const; - - unsigned long long ULongLong(unsigned long long fail_value = 0) const; + /// Return an unsigned integer representation of this value. Integers values + /// will be zero-extended or truncated. Floating point values will be + /// converted to integers first. In case of a void type, fail_value is + /// returned. + uint64_t ZExtOrTruncInt(uint64_t fail_value = 0) const; + + /// Return an signed integer representation of this value. Integers values + /// will be sign-extended or truncated. Floating point values will be + /// converted to integers first. In case of a void type, fail_value is + /// returned. + int64_t SExtOrTruncInt(int64_t fail_value = 0) const; llvm::APInt SInt128(const llvm::APInt &fail_value) const; @@ -267,9 +256,6 @@ llvm::APInt m_integer; llvm::APFloat m_float; - template T GetAsSigned(T fail_value) const; - template T GetAsUnsigned(T fail_value) const; - private: friend const Scalar operator+(const Scalar &lhs, const Scalar &rhs); friend const Scalar operator-(const Scalar &lhs, const Scalar &rhs); diff --git a/lldb/source/Core/Value.cpp b/lldb/source/Core/Value.cpp --- a/lldb/source/Core/Value.cpp +++ b/lldb/source/Core/Value.cpp @@ -61,7 +61,7 @@ m_value_type(v.m_value_type), m_context_type(v.m_context_type), m_data_buffer() { const uintptr_t rhs_value = - (uintptr_t)v.m_value.ULongLong(LLDB_INVALID_ADDRESS); + (uintptr_t)v.m_value.ZExtOrTruncInt(LLDB_INVALID_ADDRESS); if ((rhs_value != 0) && (rhs_value == (uintptr_t)v.m_data_buffer.GetBytes())) { m_data_buffer.CopyData(v.m_data_buffer.GetBytes(), @@ -80,7 +80,7 @@ m_value_type = rhs.m_value_type; m_context_type = rhs.m_context_type; const uintptr_t rhs_value = - (uintptr_t)rhs.m_value.ULongLong(LLDB_INVALID_ADDRESS); + (uintptr_t)rhs.m_value.ZExtOrTruncInt(LLDB_INVALID_ADDRESS); if ((rhs_value != 0) && (rhs_value == (uintptr_t)rhs.m_data_buffer.GetBytes())) { m_data_buffer.CopyData(rhs.m_data_buffer.GetBytes(), @@ -371,7 +371,7 @@ // execute commands where you can look at types in data sections. const SectionLoadList &target_sections = target->GetSectionLoadList(); if (!target_sections.IsEmpty()) { - address = m_value.ULongLong(LLDB_INVALID_ADDRESS); + address = m_value.ZExtOrTruncInt(LLDB_INVALID_ADDRESS); if (target_sections.ResolveLoadAddress(address, file_so_addr)) { address_type = eAddressTypeLoad; data.SetByteOrder(target->GetArchitecture().GetByteOrder()); @@ -384,7 +384,7 @@ error.SetErrorString("can't read load address (invalid process)"); } } else { - address = m_value.ULongLong(LLDB_INVALID_ADDRESS); + address = m_value.ZExtOrTruncInt(LLDB_INVALID_ADDRESS); address_type = eAddressTypeLoad; data.SetByteOrder( process->GetTarget().GetArchitecture().GetByteOrder()); @@ -400,7 +400,7 @@ } else if (exe_ctx->GetTargetPtr() == nullptr) { error.SetErrorString("can't read file address (invalid target)"); } else { - address = m_value.ULongLong(LLDB_INVALID_ADDRESS); + address = m_value.ZExtOrTruncInt(LLDB_INVALID_ADDRESS); if (address == LLDB_INVALID_ADDRESS) { error.SetErrorString("invalid file address"); } else { @@ -485,7 +485,7 @@ break; case eValueTypeHostAddress: - address = m_value.ULongLong(LLDB_INVALID_ADDRESS); + address = m_value.ZExtOrTruncInt(LLDB_INVALID_ADDRESS); address_type = eAddressTypeHost; if (exe_ctx) { Target *target = exe_ctx->GetTargetPtr(); @@ -600,7 +600,7 @@ // that is using liblldb) { DataExtractor data; - lldb::addr_t addr = m_value.ULongLong(LLDB_INVALID_ADDRESS); + lldb::addr_t addr = m_value.ZExtOrTruncInt(LLDB_INVALID_ADDRESS); Status error(GetValueAsData(exe_ctx, data, nullptr)); if (error.Success()) { Scalar scalar; @@ -676,7 +676,7 @@ if (!module || !target || (GetValueType() != eValueTypeFileAddress)) return; - lldb::addr_t file_addr = GetScalar().ULongLong(LLDB_INVALID_ADDRESS); + lldb::addr_t file_addr = GetScalar().ZExtOrTruncInt(LLDB_INVALID_ADDRESS); if (file_addr == LLDB_INVALID_ADDRESS) return; diff --git a/lldb/source/Core/ValueObject.cpp b/lldb/source/Core/ValueObject.cpp --- a/lldb/source/Core/ValueObject.cpp +++ b/lldb/source/Core/ValueObject.cpp @@ -412,8 +412,8 @@ case Value::eValueTypeFileAddress: case Value::eValueTypeHostAddress: { uint32_t addr_nibble_size = data.GetAddressByteSize() * 2; - sstr.Printf("0x%*.*llx", addr_nibble_size, addr_nibble_size, - value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS)); + sstr.Printf("0x%*.*" PRIx64, addr_nibble_size, addr_nibble_size, + value.GetScalar().ZExtOrTruncInt(LLDB_INVALID_ADDRESS)); m_location_str = std::string(sstr.GetString()); } break; } @@ -464,7 +464,7 @@ } bool ret; - ret = scalar_value.ULongLong(1) != 0; + ret = scalar_value != 0; error.Clear(); return ret; } @@ -860,7 +860,7 @@ GetCompilerType().GetByteSize(exe_ctx.GetBestExecutionContextScope()); if (max_bytes && *max_bytes > offset) { size_t bytes_read = std::min(*max_bytes - offset, bytes); - addr = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS); + addr = m_value.GetScalar().ZExtOrTruncInt(LLDB_INVALID_ADDRESS); if (addr == 0 || addr == LLDB_INVALID_ADDRESS) break; heap_buf_ptr->CopyData((uint8_t *)(addr + offset), bytes_read); @@ -926,7 +926,8 @@ ExecutionContext exe_ctx(GetExecutionContextRef()); Process *process = exe_ctx.GetProcessPtr(); if (process) { - addr_t target_addr = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS); + addr_t target_addr = + m_value.GetScalar().ZExtOrTruncInt(LLDB_INVALID_ADDRESS); size_t bytes_written = process->WriteMemory( target_addr, data.GetDataStart(), byte_size, error); if (!error.Success()) @@ -1203,7 +1204,7 @@ if (ResolveValue(scalar)) { if (success) *success = true; - return scalar.ULongLong(fail_value); + return scalar.ZExtOrTruncInt(fail_value); } // fallthrough, otherwise... } @@ -1220,7 +1221,7 @@ if (ResolveValue(scalar)) { if (success) *success = true; - return scalar.SLongLong(fail_value); + return scalar.SExtOrTruncInt(fail_value); } // fallthrough, otherwise... } @@ -1517,7 +1518,7 @@ if (scalar_is_load_address) { if (address_type) *address_type = eAddressTypeLoad; - return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS); + return m_value.GetScalar().ZExtOrTruncInt(LLDB_INVALID_ADDRESS); } break; @@ -1525,7 +1526,7 @@ case Value::eValueTypeFileAddress: { if (address_type) *address_type = m_value.GetValueAddressType(); - return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS); + return m_value.GetScalar().ZExtOrTruncInt(LLDB_INVALID_ADDRESS); } break; case Value::eValueTypeHostAddress: { if (address_type) @@ -1549,7 +1550,7 @@ switch (m_value.GetValueType()) { case Value::eValueTypeScalar: case Value::eValueTypeVector: - address = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS); + address = m_value.GetScalar().ZExtOrTruncInt(LLDB_INVALID_ADDRESS); break; case Value::eValueTypeHostAddress: @@ -1601,7 +1602,7 @@ Process *process = exe_ctx.GetProcessPtr(); if (process) { addr_t target_addr = - m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS); + m_value.GetScalar().ZExtOrTruncInt(LLDB_INVALID_ADDRESS); size_t bytes_written = process->WriteScalarToMemory( target_addr, new_scalar, byte_size, error); if (!error.Success()) @@ -2051,7 +2052,7 @@ return; } else { uint64_t load_addr = - m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS); + m_value.GetScalar().ZExtOrTruncInt(LLDB_INVALID_ADDRESS); if (load_addr != LLDB_INVALID_ADDRESS) { s.Printf("(*( (%s *)0x%" PRIx64 "))", GetTypeName().AsCString("void"), load_addr); diff --git a/lldb/source/Core/ValueObjectChild.cpp b/lldb/source/Core/ValueObjectChild.cpp --- a/lldb/source/Core/ValueObjectChild.cpp +++ b/lldb/source/Core/ValueObjectChild.cpp @@ -166,7 +166,7 @@ case Value::eValueTypeFileAddress: case Value::eValueTypeHostAddress: { lldb::addr_t addr = - m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS); + m_value.GetScalar().ZExtOrTruncInt(LLDB_INVALID_ADDRESS); if (addr == LLDB_INVALID_ADDRESS) { m_error.SetErrorString("parent address is invalid."); } else if (addr == 0) { diff --git a/lldb/source/Expression/DWARFExpression.cpp b/lldb/source/Expression/DWARFExpression.cpp --- a/lldb/source/Expression/DWARFExpression.cpp +++ b/lldb/source/Expression/DWARFExpression.cpp @@ -1025,15 +1025,15 @@ Value::ValueType value_type = stack.back().GetValueType(); switch (value_type) { case Value::eValueTypeHostAddress: { - void *src = (void *)stack.back().GetScalar().ULongLong(); + void *src = (void *)stack.back().GetScalar().ZExtOrTruncInt(); intptr_t ptr; ::memcpy(&ptr, src, sizeof(void *)); stack.back().GetScalar() = ptr; stack.back().ClearContext(); } break; case Value::eValueTypeFileAddress: { - auto file_addr = stack.back().GetScalar().ULongLong( - LLDB_INVALID_ADDRESS); + auto file_addr = + stack.back().GetScalar().ZExtOrTruncInt(LLDB_INVALID_ADDRESS); if (!module_sp) { if (error_ptr) error_ptr->SetErrorStringWithFormat( @@ -1062,7 +1062,7 @@ if (exe_ctx) { if (process) { lldb::addr_t pointer_addr = - stack.back().GetScalar().ULongLong(LLDB_INVALID_ADDRESS); + stack.back().GetScalar().ZExtOrTruncInt(LLDB_INVALID_ADDRESS); Status error; lldb::addr_t pointer_value = process->ReadPointerFromMemory(pointer_addr, error); @@ -1120,7 +1120,7 @@ Value::ValueType value_type = stack.back().GetValueType(); switch (value_type) { case Value::eValueTypeHostAddress: { - void *src = (void *)stack.back().GetScalar().ULongLong(); + void *src = (void *)stack.back().GetScalar().ZExtOrTruncInt(); intptr_t ptr; ::memcpy(&ptr, src, sizeof(void *)); // I can't decide whether the size operand should apply to the bytes in @@ -1163,7 +1163,7 @@ if (exe_ctx) { if (process) { lldb::addr_t pointer_addr = - stack.back().GetScalar().ULongLong(LLDB_INVALID_ADDRESS); + stack.back().GetScalar().ZExtOrTruncInt(LLDB_INVALID_ADDRESS); uint8_t addr_bytes[sizeof(lldb::addr_t)]; Status error; if (process->ReadMemory(pointer_addr, &addr_bytes, size, error) == @@ -2093,7 +2093,7 @@ if (process) { if (curr_piece.ResizeData(piece_byte_size) == piece_byte_size) { lldb::addr_t load_addr = - curr_piece_source_value.GetScalar().ULongLong( + curr_piece_source_value.GetScalar().ZExtOrTruncInt( LLDB_INVALID_ADDRESS); if (process->ReadMemory( load_addr, curr_piece.GetBuffer().GetBytes(), @@ -2119,8 +2119,9 @@ case Value::eValueTypeFileAddress: case Value::eValueTypeHostAddress: if (error_ptr) { - lldb::addr_t addr = curr_piece_source_value.GetScalar().ULongLong( - LLDB_INVALID_ADDRESS); + lldb::addr_t addr = + curr_piece_source_value.GetScalar().ZExtOrTruncInt( + LLDB_INVALID_ADDRESS); error_ptr->SetErrorStringWithFormat( "failed to read memory DW_OP_piece(%" PRIu64 ") from %s address 0x%" PRIx64, @@ -2464,7 +2465,7 @@ // Lookup the TLS block address for this thread and module. const addr_t tls_file_addr = - stack.back().GetScalar().ULongLong(LLDB_INVALID_ADDRESS); + stack.back().GetScalar().ZExtOrTruncInt(LLDB_INVALID_ADDRESS); const addr_t tls_load_addr = thread->GetThreadLocalData(module_sp, tls_file_addr); diff --git a/lldb/source/Expression/IRInterpreter.cpp b/lldb/source/Expression/IRInterpreter.cpp --- a/lldb/source/Expression/IRInterpreter.cpp +++ b/lldb/source/Expression/IRInterpreter.cpp @@ -205,7 +205,8 @@ lldb_private::Scalar cast_scalar; - if (!AssignToMatchType(cast_scalar, scalar.ULongLong(), value->getType())) + if (!AssignToMatchType(cast_scalar, scalar.ZExtOrTruncInt(), + value->getType())) return false; size_t value_byte_size = m_target_data.getTypeStoreSize(value->getType()); @@ -891,7 +892,7 @@ S.MakeSigned(); - lldb_private::Scalar S_signextend(S.SLongLong()); + lldb_private::Scalar S_signextend(S.SExtOrTruncInt()); frame.AssignValue(inst, S_signextend, module); } break; @@ -994,11 +995,11 @@ return false; } - LLDB_LOGF(log, "Evaluated constant index %s as %llu", - PrintValue(*ii).c_str(), I.ULongLong(LLDB_INVALID_ADDRESS)); + LLDB_LOG(log, "Evaluated constant index {0} as {1}", PrintValue(*ii), + I.ZExtOrTruncInt(LLDB_INVALID_ADDRESS)); constant_index = cast(ConstantInt::get( - (*ii)->getType(), I.ULongLong(LLDB_INVALID_ADDRESS))); + (*ii)->getType(), I.ZExtOrTruncInt(LLDB_INVALID_ADDRESS))); } const_indices.push_back(constant_index); @@ -1374,7 +1375,7 @@ error.SetErrorString("unable to get address of function"); return false; } - lldb_private::Address funcAddr(I.ULongLong(LLDB_INVALID_ADDRESS)); + lldb_private::Address funcAddr(I.ZExtOrTruncInt(LLDB_INVALID_ADDRESS)); lldb_private::DiagnosticManager diagnostics; lldb_private::EvaluateExpressionOptions options; @@ -1430,7 +1431,7 @@ // Check if this is a string literal or constant string pointer if (arg_ty->isPointerTy()) { - lldb::addr_t addr = tmp_op.ULongLong(); + lldb::addr_t addr = tmp_op.ZExtOrTruncInt(); size_t dataSize = 0; bool Success = execution_unit.GetAllocSize(addr, dataSize); @@ -1456,7 +1457,7 @@ // Get argument size in bytes rawArgs[i].size = arg_ty->getIntegerBitWidth() / 8; // Push value into argument list for thread plan - rawArgs[i].value = tmp_op.ULongLong(); + rawArgs[i].value = tmp_op.ZExtOrTruncInt(); } } @@ -1473,9 +1474,9 @@ lldb_private::StreamString ss; if (!call_plan_sp || !call_plan_sp->ValidatePlan(&ss)) { error.SetErrorToGenericError(); - error.SetErrorStringWithFormat( - "unable to make ThreadPlanCallFunctionUsingABI for 0x%llx", - I.ULongLong()); + error.SetErrorStringWithFormatv( + "unable to make ThreadPlanCallFunctionUsingABI for {0:x}", + I.ZExtOrTruncInt()); return false; } diff --git a/lldb/source/Expression/IRMemoryMap.cpp b/lldb/source/Expression/IRMemoryMap.cpp --- a/lldb/source/Expression/IRMemoryMap.cpp +++ b/lldb/source/Expression/IRMemoryMap.cpp @@ -772,7 +772,7 @@ if (!error.Success()) return; - *address = pointer_scalar.ULongLong(); + *address = pointer_scalar.ZExtOrTruncInt(); return; } diff --git a/lldb/source/Expression/Materializer.cpp b/lldb/source/Expression/Materializer.cpp --- a/lldb/source/Expression/Materializer.cpp +++ b/lldb/source/Expression/Materializer.cpp @@ -122,7 +122,7 @@ map.Free((lldb::addr_t)m_persistent_variable_sp->m_live_sp->GetValue() .GetScalar() - .ULongLong(), + .ZExtOrTruncInt(), deallocate_error); m_persistent_variable_sp->m_live_sp.reset(); @@ -255,7 +255,7 @@ lldb::addr_t mem = m_persistent_variable_sp->m_live_sp->GetValue() .GetScalar() - .ULongLong(); + .ZExtOrTruncInt(); if (!m_persistent_variable_sp->m_live_sp) { err.SetErrorStringWithFormat( diff --git a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOS.cpp b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOS.cpp --- a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOS.cpp +++ b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOS.cpp @@ -264,15 +264,16 @@ if (abi->GetArgumentValues(exe_ctx.GetThreadRef(), argument_values)) { uint32_t dyld_mode = - argument_values.GetValueAtIndex(0)->GetScalar().UInt(-1); + argument_values.GetValueAtIndex(0)->GetScalar().ZExtOrTruncInt(-1); if (dyld_mode != static_cast(-1)) { // Okay the mode was right, now get the number of elements, and the // array of new elements... uint32_t image_infos_count = - argument_values.GetValueAtIndex(1)->GetScalar().UInt(-1); + argument_values.GetValueAtIndex(1)->GetScalar().ZExtOrTruncInt(-1); if (image_infos_count != static_cast(-1)) { addr_t header_array = - argument_values.GetValueAtIndex(2)->GetScalar().ULongLong(-1); + argument_values.GetValueAtIndex(2)->GetScalar().ZExtOrTruncInt( + -1); if (header_array != static_cast(-1)) { std::vector image_load_addresses; for (uint64_t i = 0; i < image_infos_count; i++) { diff --git a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp --- a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp +++ b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp @@ -368,12 +368,12 @@ if (abi->GetArgumentValues(exe_ctx.GetThreadRef(), argument_values)) { uint32_t dyld_mode = - argument_values.GetValueAtIndex(0)->GetScalar().UInt(-1); + argument_values.GetValueAtIndex(0)->GetScalar().ZExtOrTruncInt(-1); if (dyld_mode != static_cast(-1)) { // Okay the mode was right, now get the number of elements, and the // array of new elements... uint32_t image_infos_count = - argument_values.GetValueAtIndex(1)->GetScalar().UInt(-1); + argument_values.GetValueAtIndex(1)->GetScalar().ZExtOrTruncInt(-1); if (image_infos_count != static_cast(-1)) { // Got the number added, now go through the array of added elements, // putting out the mach header address, and adding the image. Note, @@ -381,7 +381,7 @@ // RemoveModules functions do all the logging internally. lldb::addr_t image_infos_addr = - argument_values.GetValueAtIndex(2)->GetScalar().ULongLong(); + argument_values.GetValueAtIndex(2)->GetScalar().ZExtOrTruncInt(); if (dyld_mode == 0) { // This is add: dyld_instance->AddModulesUsingImageInfosAddress(image_infos_addr, diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp --- a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp +++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp @@ -472,7 +472,7 @@ ClangExpressionVariable::ParserVars *parser_vars = entity->GetParserVars(GetParserID()); - ptr = parser_vars->m_lldb_value.GetScalar().ULongLong(); + ptr = parser_vars->m_lldb_value.GetScalar().ZExtOrTruncInt(); return true; } @@ -1509,7 +1509,7 @@ if (!var_sc.module_sp) return false; - Address so_addr(var_location.GetScalar().ULongLong(), + Address so_addr(var_location.GetScalar().ZExtOrTruncInt(), var_sc.module_sp->GetSectionList()); lldb::addr_t load_addr = so_addr.GetLoadAddress(target); diff --git a/lldb/source/Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.cpp b/lldb/source/Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.cpp --- a/lldb/source/Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.cpp +++ b/lldb/source/Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.cpp @@ -580,7 +580,7 @@ } size_t ptr_size = m_process->GetAddressByteSize(); - addr_t result_ptr = results.GetScalar().ULongLong(LLDB_INVALID_ADDRESS); + addr_t result_ptr = results.GetScalar().ZExtOrTruncInt(LLDB_INVALID_ADDRESS); addr_t exception_addr = m_process->ReadPointerFromMemory(result_ptr - ptr_size, error); diff --git a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCClassDescriptorV2.cpp b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCClassDescriptorV2.cpp --- a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCClassDescriptorV2.cpp +++ b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCClassDescriptorV2.cpp @@ -536,9 +536,9 @@ offset_ptr, offset_ptr_size, is_signed, offset_scalar, error); if (error.Success() && 4 == read) { LLDB_LOGV(log, "offset_ptr = {0:x} --> {1}", offset_ptr, - offset_scalar.SInt()); - m_ivars.push_back( - {ConstString(name), ivar_type, size, offset_scalar.SInt()}); + offset_scalar.SExtOrTruncInt()); + m_ivars.push_back({ConstString(name), ivar_type, size, + int32_t(offset_scalar.SExtOrTruncInt())}); } else LLDB_LOGV(log, "offset_ptr = {0:x} --> read fail, read = %{1}", offset_ptr, read); diff --git a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp --- a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp +++ b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp @@ -197,7 +197,7 @@ return false; } - addr_t result_ptr = ret.GetScalar().ULongLong(LLDB_INVALID_ADDRESS); + addr_t result_ptr = ret.GetScalar().ZExtOrTruncInt(LLDB_INVALID_ADDRESS); char buf[512]; size_t cstr_len = 0; diff --git a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp --- a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp +++ b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp @@ -1477,7 +1477,7 @@ if (results == eExpressionCompleted) { // The result is the number of ClassInfo structures that were filled in - num_class_infos = return_value.GetScalar().ULong(); + num_class_infos = return_value.GetScalar().ZExtOrTruncInt(); LLDB_LOGF(log, "Discovered %u ObjC classes\n", num_class_infos); if (num_class_infos > 0) { // Read the ClassInfo structures @@ -1773,7 +1773,7 @@ if (results == eExpressionCompleted) { // The result is the number of ClassInfo structures that were filled in - num_class_infos = return_value.GetScalar().ULong(); + num_class_infos = return_value.GetScalar().ZExtOrTruncInt(); LLDB_LOGF(log, "Discovered %u ObjC classes in shared cache\n", num_class_infos); assert(num_class_infos <= num_classes); @@ -2682,7 +2682,8 @@ if (!abi->GetArgumentValues(*thread_sp, args)) return; - addr_t exception_addr = args.GetValueAtIndex(0)->GetScalar().ULongLong(); + addr_t exception_addr = + args.GetValueAtIndex(0)->GetScalar().ZExtOrTruncInt(); Value value(exception_addr); value.SetCompilerType(voidstar); diff --git a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.cpp b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.cpp --- a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.cpp +++ b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.cpp @@ -981,8 +981,9 @@ if (!success) return ret_plan_sp; - lldb::addr_t obj_addr = - argument_values.GetValueAtIndex(obj_index)->GetScalar().ULongLong(); + lldb::addr_t obj_addr = argument_values.GetValueAtIndex(obj_index) + ->GetScalar() + .ZExtOrTruncInt(); if (obj_addr == 0x0) { LLDB_LOGF( log, @@ -998,8 +999,9 @@ // used to look up the class/selector pair in our cache. lldb::addr_t isa_addr = LLDB_INVALID_ADDRESS; - lldb::addr_t sel_addr = - argument_values.GetValueAtIndex(sel_index)->GetScalar().ULongLong(); + lldb::addr_t sel_addr = argument_values.GetValueAtIndex(sel_index) + ->GetScalar() + .ZExtOrTruncInt(); // Figure out the class this is being dispatched to and see if // we've already cached this method call, If so we can push a @@ -1024,7 +1026,7 @@ super_value.GetScalar() += process->GetAddressByteSize(); super_value.ResolveValue(&exe_ctx); if (super_value.GetScalar().IsValid()) - isa_addr = super_value.GetScalar().ULongLong(); + isa_addr = super_value.GetScalar().ZExtOrTruncInt(); else { LLDB_LOGF(log, "Failed to extract the super class value from the " "class in objc_super."); @@ -1044,7 +1046,7 @@ super_value.ResolveValue(&exe_ctx); if (super_value.GetScalar().IsValid()) { - isa_addr = super_value.GetScalar().ULongLong(); + isa_addr = super_value.GetScalar().ZExtOrTruncInt(); } else { LLDB_LOGF(log, "Failed to extract the class value from objc_super."); } @@ -1067,7 +1069,7 @@ isa_value.SetValueType(Value::eValueTypeLoadAddress); isa_value.ResolveValue(&exe_ctx); if (isa_value.GetScalar().IsValid()) { - isa_addr = isa_value.GetScalar().ULongLong(); + isa_addr = isa_value.GetScalar().ZExtOrTruncInt(); } else { LLDB_LOGF(log, "Failed to extract the isa value from object."); } diff --git a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleThreadPlanStepThroughObjCTrampoline.cpp b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleThreadPlanStepThroughObjCTrampoline.cpp --- a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleThreadPlanStepThroughObjCTrampoline.cpp +++ b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleThreadPlanStepThroughObjCTrampoline.cpp @@ -88,9 +88,9 @@ if (level == lldb::eDescriptionLevelBrief) s->Printf("Step through ObjC trampoline"); else { - s->Printf("Stepping to implementation of ObjC method - obj: 0x%llx, isa: " - "0x%" PRIx64 ", sel: 0x%" PRIx64, - m_input_values.GetValueAtIndex(0)->GetScalar().ULongLong(), + s->Format("Stepping to implementation of ObjC method - obj: {0:x}, isa: " + "{1:x}, sel: {2:x}", + m_input_values.GetValueAtIndex(0)->GetScalar().ZExtOrTruncInt(), m_isa_addr, m_sel_addr); } } @@ -135,7 +135,7 @@ m_impl_function->FetchFunctionResults(exc_ctx, m_args_addr, target_addr_value); m_impl_function->DeallocateFunctionResults(exc_ctx, m_args_addr); - lldb::addr_t target_addr = target_addr_value.GetScalar().ULongLong(); + lldb::addr_t target_addr = target_addr_value.GetScalar().ZExtOrTruncInt(); Address target_so_addr; target_so_addr.SetOpcodeLoadAddress(target_addr, exc_ctx.GetTargetPtr()); Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_STEP)); diff --git a/lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp b/lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp --- a/lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp +++ b/lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp @@ -892,7 +892,7 @@ Scalar scalar; if (result_valobj_sp->ResolveValue(scalar)) { - if (scalar.UInt(1)) + if (scalar.ZExtOrTruncInt(1)) return Status("expression failed: \"%s\"", expr.GetData()); process->ResetImageToken(image_token); } diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp @@ -2467,7 +2467,8 @@ DataExtractor(debug_info_data, block_offset, block_length), die.GetCU(), eRegisterKindDWARF, &initialValue, nullptr, memberOffset, nullptr)) { - member_byte_offset = memberOffset.ResolveValue(nullptr).UInt(); + member_byte_offset = + memberOffset.ResolveValue(nullptr).ZExtOrTruncInt(); } } else { // With DWARF 3 and later, if the value is an integer constant, @@ -2902,7 +2903,7 @@ die.GetCU(), eRegisterKindDWARF, &initialValue, nullptr, memberOffset, nullptr)) { member_byte_offset = - memberOffset.ResolveValue(nullptr).UInt(); + memberOffset.ResolveValue(nullptr).ZExtOrTruncInt(); } } else { // With DWARF 3 and later, if the value is an integer constant, diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp --- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp @@ -1785,7 +1785,7 @@ if (location_result.GetValueType() == Value::eValueTypeFileAddress) { lldb::addr_t file_addr = - location_result.GetScalar().ULongLong(); + location_result.GetScalar().ZExtOrTruncInt(); lldb::addr_t byte_size = 1; if (var_sp->GetType()) byte_size = diff --git a/lldb/source/Symbol/Function.cpp b/lldb/source/Symbol/Function.cpp --- a/lldb/source/Symbol/Function.cpp +++ b/lldb/source/Symbol/Function.cpp @@ -204,7 +204,8 @@ return nullptr; } - addr_t raw_addr = callee_addr_val.GetScalar().ULongLong(LLDB_INVALID_ADDRESS); + addr_t raw_addr = + callee_addr_val.GetScalar().ZExtOrTruncInt(LLDB_INVALID_ADDRESS); if (raw_addr == LLDB_INVALID_ADDRESS) { LLDB_LOG(log, "IndirectCallEdge: Could not extract address from scalar"); return nullptr; diff --git a/lldb/source/Target/Process.cpp b/lldb/source/Target/Process.cpp --- a/lldb/source/Target/Process.cpp +++ b/lldb/source/Target/Process.cpp @@ -2209,7 +2209,7 @@ Scalar scalar; if (ReadScalarIntegerFromMemory(vm_addr, integer_byte_size, false, scalar, error)) - return scalar.ULongLong(fail_value); + return scalar.ZExtOrTruncInt(fail_value); return fail_value; } @@ -2220,7 +2220,7 @@ Scalar scalar; if (ReadScalarIntegerFromMemory(vm_addr, integer_byte_size, true, scalar, error)) - return scalar.SLongLong(fail_value); + return scalar.SExtOrTruncInt(fail_value); return fail_value; } @@ -2228,7 +2228,7 @@ Scalar scalar; if (ReadScalarIntegerFromMemory(vm_addr, GetAddressByteSize(), false, scalar, error)) - return scalar.ULongLong(LLDB_INVALID_ADDRESS); + return scalar.ZExtOrTruncInt(LLDB_INVALID_ADDRESS); return LLDB_INVALID_ADDRESS; } diff --git a/lldb/source/Target/RegisterContext.cpp b/lldb/source/Target/RegisterContext.cpp --- a/lldb/source/Target/RegisterContext.cpp +++ b/lldb/source/Target/RegisterContext.cpp @@ -88,7 +88,7 @@ if (dwarf_expr.Evaluate(&exe_ctx, this, opcode_ctx, dwarf_data, nullptr, eRegisterKindDWARF, nullptr, nullptr, result, &error)) { - expr_result = result.GetScalar().SInt(-1); + expr_result = result.GetScalar().SExtOrTruncInt(-1); switch (expr_result) { case 0: return 4; diff --git a/lldb/source/Target/RegisterContextUnwind.cpp b/lldb/source/Target/RegisterContextUnwind.cpp --- a/lldb/source/Target/RegisterContextUnwind.cpp +++ b/lldb/source/Target/RegisterContextUnwind.cpp @@ -1527,7 +1527,7 @@ if (dwarfexpr.Evaluate(&exe_ctx, this, 0, &cfa_val, nullptr, result, &error)) { addr_t val; - val = result.GetScalar().ULongLong(); + val = result.GetScalar().ZExtOrTruncInt(); if (unwindplan_regloc.IsDWARFExpression()) { regloc.type = UnwindLLDB::RegisterLocation::eRegisterValueInferred; regloc.location.inferred_value = val; @@ -1877,7 +1877,7 @@ Status error; if (dwarfexpr.Evaluate(&exe_ctx, this, 0, nullptr, nullptr, result, &error)) { - address = result.GetScalar().ULongLong(); + address = result.GetScalar().ZExtOrTruncInt(); UnwindLogMsg("CFA value set by DWARF expression is 0x%" PRIx64, address); diff --git a/lldb/source/Target/StopInfo.cpp b/lldb/source/Target/StopInfo.cpp --- a/lldb/source/Target/StopInfo.cpp +++ b/lldb/source/Target/StopInfo.cpp @@ -805,7 +805,7 @@ if (result_value_sp) { Scalar scalar_value; if (result_value_sp->ResolveValue(scalar_value)) { - if (scalar_value.ULongLong(1) == 0) { + if (scalar_value.ZExtOrTruncInt(1) == 0) { // We have been vetoed. This takes precedence over querying // the watchpoint whether it should stop (aka ignore count // and friends). See also StopInfoWatchpoint::ShouldStop() diff --git a/lldb/source/Target/Target.cpp b/lldb/source/Target/Target.cpp --- a/lldb/source/Target/Target.cpp +++ b/lldb/source/Target/Target.cpp @@ -1917,7 +1917,7 @@ Scalar scalar; if (ReadScalarIntegerFromMemory(addr, prefer_file_cache, integer_byte_size, false, scalar, error)) - return scalar.ULongLong(fail_value); + return scalar.ZExtOrTruncInt(fail_value); return fail_value; } @@ -1927,7 +1927,7 @@ if (ReadScalarIntegerFromMemory(addr, prefer_file_cache, m_arch.GetSpec().GetAddressByteSize(), false, scalar, error)) { - addr_t pointer_vm_addr = scalar.ULongLong(LLDB_INVALID_ADDRESS); + addr_t pointer_vm_addr = scalar.ZExtOrTruncInt(LLDB_INVALID_ADDRESS); if (pointer_vm_addr != LLDB_INVALID_ADDRESS) { SectionLoadList §ion_load_list = GetSectionLoadList(); if (section_load_list.IsEmpty()) { diff --git a/lldb/source/Target/ThreadPlanTracer.cpp b/lldb/source/Target/ThreadPlanTracer.cpp --- a/lldb/source/Target/ThreadPlanTracer.cpp +++ b/lldb/source/Target/ThreadPlanTracer.cpp @@ -198,9 +198,10 @@ if (abi->GetArgumentValues(GetThread(), value_list)) { for (int arg_index = 0; arg_index < num_args; ++arg_index) { - stream->Printf( - "\n\targ[%d]=%llx", arg_index, - value_list.GetValueAtIndex(arg_index)->GetScalar().ULongLong()); + stream->Format("\n\targ[{0}]={1:x}", arg_index, + value_list.GetValueAtIndex(arg_index) + ->GetScalar() + .ZExtOrTruncInt()); if (arg_index + 1 < num_args) stream->PutCString(", "); diff --git a/lldb/source/Utility/RegisterValue.cpp b/lldb/source/Utility/RegisterValue.cpp --- a/lldb/source/Utility/RegisterValue.cpp +++ b/lldb/source/Utility/RegisterValue.cpp @@ -540,7 +540,7 @@ break; case eTypeUInt8: case eTypeUInt16: - return m_scalar.UShort(fail_value); + return m_scalar.ZExtOrTruncInt(fail_value); case eTypeBytes: { switch (buffer.length) { default: @@ -569,7 +569,7 @@ case eTypeFloat: case eTypeDouble: case eTypeLongDouble: - return m_scalar.UInt(fail_value); + return m_scalar.ZExtOrTruncInt(fail_value); case eTypeBytes: { switch (buffer.length) { default: @@ -600,7 +600,7 @@ case eTypeFloat: case eTypeDouble: case eTypeLongDouble: - return m_scalar.ULongLong(fail_value); + return m_scalar.ZExtOrTruncInt(fail_value); case eTypeBytes: { switch (buffer.length) { default: diff --git a/lldb/source/Utility/Scalar.cpp b/lldb/source/Utility/Scalar.cpp --- a/lldb/source/Utility/Scalar.cpp +++ b/lldb/source/Utility/Scalar.cpp @@ -644,7 +644,7 @@ return success; } -template T Scalar::GetAsSigned(T fail_value) const { +uint64_t Scalar::ZExtOrTruncInt(uint64_t fail_value) const { switch (m_type) { case e_void: break; @@ -660,21 +660,21 @@ case e_uint256: case e_sint512: case e_uint512: - return m_integer.sextOrTrunc(sizeof(T) * 8).getSExtValue(); + return m_integer.zextOrTrunc(sizeof(uint64_t) * 8).getZExtValue(); case e_float: - return static_cast(m_float.convertToFloat()); + return static_cast(m_float.convertToFloat()); case e_double: - return static_cast(m_float.convertToDouble()); + return static_cast(m_float.convertToDouble()); case e_long_double: llvm::APInt ldbl_val = m_float.bitcastToAPInt(); - return static_cast( - (ldbl_val.sextOrTrunc(sizeof(schar_t) * 8)).getSExtValue()); + return static_cast( + ldbl_val.zextOrTrunc(sizeof(uint64_t) * 8).getZExtValue()); } return fail_value; } -template T Scalar::GetAsUnsigned(T fail_value) const { +int64_t Scalar::SExtOrTruncInt(int64_t fail_value) const { switch (m_type) { case e_void: break; @@ -690,55 +690,20 @@ case e_uint256: case e_sint512: case e_uint512: - return m_integer.zextOrTrunc(sizeof(T) * 8).getZExtValue(); + return m_integer.sextOrTrunc(sizeof(int64_t) * 8).getSExtValue(); case e_float: - return static_cast(m_float.convertToFloat()); + return static_cast(m_float.convertToFloat()); case e_double: - return static_cast(m_float.convertToDouble()); + return static_cast(m_float.convertToDouble()); case e_long_double: llvm::APInt ldbl_val = m_float.bitcastToAPInt(); - return static_cast((ldbl_val.zextOrTrunc(sizeof(T) * 8)).getZExtValue()); + return static_cast( + ldbl_val.sextOrTrunc(sizeof(int64_t) * 8).getSExtValue()); } return fail_value; } -signed char Scalar::SChar(signed char fail_value) const { - return GetAsSigned(fail_value); -} - -unsigned char Scalar::UChar(unsigned char fail_value) const { - return GetAsUnsigned(fail_value); -} - -short Scalar::SShort(short fail_value) const { - return GetAsSigned(fail_value); -} - -unsigned short Scalar::UShort(unsigned short fail_value) const { - return GetAsUnsigned(fail_value); -} - -int Scalar::SInt(int fail_value) const { return GetAsSigned(fail_value); } - -unsigned int Scalar::UInt(unsigned int fail_value) const { - return GetAsUnsigned(fail_value); -} - -long Scalar::SLong(long fail_value) const { return GetAsSigned(fail_value); } - -unsigned long Scalar::ULong(unsigned long fail_value) const { - return GetAsUnsigned(fail_value); -} - -long long Scalar::SLongLong(long long fail_value) const { - return GetAsSigned(fail_value); -} - -unsigned long long Scalar::ULongLong(unsigned long long fail_value) const { - return GetAsUnsigned(fail_value); -} - llvm::APInt Scalar::SInt128(const llvm::APInt &fail_value) const { switch (m_type) { case e_void: diff --git a/lldb/unittests/Utility/ScalarTest.cpp b/lldb/unittests/Utility/ScalarTest.cpp --- a/lldb/unittests/Utility/ScalarTest.cpp +++ b/lldb/unittests/Utility/ScalarTest.cpp @@ -20,6 +20,9 @@ using llvm::Failed; using llvm::Succeeded; +template static T (*max)() = std::numeric_limits::max; +template static T (*min)() = std::numeric_limits::min; + template bool checkInequality(T c1, T c2) { return (Scalar(c1) != Scalar(c2)); @@ -116,20 +119,24 @@ ASSERT_EQ(0, memcmp(f, Storage, sizeof(f))); } -TEST(ScalarTest, CastOperations) { - long long a = 0xf1f2f3f4f5f6f7f8LL; - Scalar a_scalar(a); - ASSERT_EQ((signed char)a, a_scalar.SChar()); - ASSERT_EQ((unsigned char)a, a_scalar.UChar()); - ASSERT_EQ((signed short)a, a_scalar.SShort()); - ASSERT_EQ((unsigned short)a, a_scalar.UShort()); - ASSERT_EQ((signed int)a, a_scalar.SInt()); - ASSERT_EQ((unsigned int)a, a_scalar.UInt()); - ASSERT_EQ((signed long)a, a_scalar.SLong()); - ASSERT_EQ((unsigned long)a, a_scalar.ULong()); - ASSERT_EQ((signed long long)a, a_scalar.SLongLong()); - ASSERT_EQ((unsigned long long)a, a_scalar.ULongLong()); +TEST(ScalarTest, ZExtOrTruncInt) { + EXPECT_EQ(uint64_t(max()), Scalar(max()).ZExtOrTruncInt()); + EXPECT_EQ(uint64_t(max()), + Scalar(max()).ZExtOrTruncInt()); + EXPECT_EQ(uint64_t(max()), Scalar(max()).ZExtOrTruncInt()); + EXPECT_EQ(uint64_t(max()), + Scalar(max()).ZExtOrTruncInt()); +} + +TEST(ScalarTest, SExtOrTruncInt) { + EXPECT_EQ(int64_t(max()), Scalar(max()).SExtOrTruncInt()); + EXPECT_EQ(int64_t(max()), Scalar(max()).SExtOrTruncInt()); + EXPECT_EQ(int64_t(max()), Scalar(max()).SExtOrTruncInt()); + EXPECT_EQ(int64_t(max()), + Scalar(max()).SExtOrTruncInt()); +} +TEST(ScalarTest, FloatCasts) { int a2 = 23; Scalar a2_scalar(a2); ASSERT_EQ((float)a2, a2_scalar.Float()); @@ -171,38 +178,38 @@ EXPECT_EQ("12345", ScalarGetValue(12345)); EXPECT_EQ("-12345", ScalarGetValue(-12345)); EXPECT_EQ("12345", ScalarGetValue(12345)); - EXPECT_EQ(std::to_string(std::numeric_limits::max()), - ScalarGetValue(std::numeric_limits::max())); + EXPECT_EQ(std::to_string(max()), + ScalarGetValue(max())); EXPECT_EQ("12345", ScalarGetValue(12345)); EXPECT_EQ("-12345", ScalarGetValue(-12345)); EXPECT_EQ("12345", ScalarGetValue(12345)); - EXPECT_EQ(std::to_string(std::numeric_limits::max()), - ScalarGetValue(std::numeric_limits::max())); + EXPECT_EQ(std::to_string(max()), + ScalarGetValue(max())); EXPECT_EQ("12345678", ScalarGetValue(12345678L)); EXPECT_EQ("-12345678", ScalarGetValue(-12345678L)); EXPECT_EQ("12345678", ScalarGetValue(12345678UL)); - EXPECT_EQ(std::to_string(std::numeric_limits::max()), - ScalarGetValue(std::numeric_limits::max())); + EXPECT_EQ(std::to_string(max()), + ScalarGetValue(max())); EXPECT_EQ("1234567890123", ScalarGetValue(1234567890123LL)); EXPECT_EQ("-1234567890123", ScalarGetValue(-1234567890123LL)); EXPECT_EQ("1234567890123", ScalarGetValue(1234567890123ULL)); - EXPECT_EQ(std::to_string(std::numeric_limits::max()), - ScalarGetValue(std::numeric_limits::max())); + EXPECT_EQ(std::to_string(max()), + ScalarGetValue(max())); } TEST(ScalarTest, LongLongAssigmentOperator) { Scalar ull; - ull = std::numeric_limits::max(); - EXPECT_EQ(std::numeric_limits::max(), ull.ULongLong()); + ull = max(); + EXPECT_EQ(max(), ull); Scalar sll; - sll = std::numeric_limits::max(); - EXPECT_EQ(std::numeric_limits::max(), sll.SLongLong()); + sll = max(); + EXPECT_EQ(max(), sll); } TEST(ScalarTest, Division) { @@ -324,11 +331,11 @@ TEST(ScalarTest, TruncOrExtendTo) { Scalar S(0xffff); S.TruncOrExtendTo(12, true); - EXPECT_EQ(S.ULong(), 0xfffu); + EXPECT_EQ(S.ZExtOrTruncInt(), 0xfffu); S.TruncOrExtendTo(20, true); - EXPECT_EQ(S.ULong(), 0xfffffu); + EXPECT_EQ(S.ZExtOrTruncInt(), 0xfffffu); S.TruncOrExtendTo(24, false); - EXPECT_EQ(S.ULong(), 0x0fffffu); + EXPECT_EQ(S.ZExtOrTruncInt(), 0x0fffffu); S.TruncOrExtendTo(16, false); - EXPECT_EQ(S.ULong(), 0xffffu); + EXPECT_EQ(S.ZExtOrTruncInt(), 0xffffu); }