[Lldb-commits] [lldb] r361458 - [Utility] Modernize C-style cats
Jonas Devlieghere via lldb-commits
lldb-commits at lists.llvm.org
Wed May 22 22:12:11 PDT 2019
Author: jdevlieghere
Date: Wed May 22 22:12:11 2019
New Revision: 361458
URL: http://llvm.org/viewvc/llvm-project?rev=361458&view=rev
Log:
[Utility] Modernize C-style cats
Replaces the remaining C-style casts with explicit casts in Utility. The
motivation is that they are (1) easier to spot and (2) don't have
multiple meanings.
Modified:
lldb/trunk/include/lldb/Utility/Args.h
lldb/trunk/include/lldb/Utility/Endian.h
lldb/trunk/include/lldb/Utility/Flags.h
lldb/trunk/include/lldb/Utility/RegisterValue.h
lldb/trunk/include/lldb/Utility/Scalar.h
lldb/trunk/source/Utility/Args.cpp
lldb/trunk/source/Utility/DataBufferHeap.cpp
lldb/trunk/source/Utility/DataEncoder.cpp
lldb/trunk/source/Utility/DataExtractor.cpp
lldb/trunk/source/Utility/Event.cpp
lldb/trunk/source/Utility/JSON.cpp
lldb/trunk/source/Utility/RegisterValue.cpp
lldb/trunk/source/Utility/Scalar.cpp
lldb/trunk/source/Utility/Stream.cpp
lldb/trunk/source/Utility/StreamGDBRemote.cpp
lldb/trunk/source/Utility/StringExtractor.cpp
Modified: lldb/trunk/include/lldb/Utility/Args.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Utility/Args.h?rev=361458&r1=361457&r2=361458&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Utility/Args.h (original)
+++ lldb/trunk/include/lldb/Utility/Args.h Wed May 22 22:12:11 2019
@@ -267,7 +267,9 @@ public:
if (total_byte_size == 8)
return true;
- const uint64_t max = ((uint64_t)1 << (uint64_t)(total_byte_size * 8)) - 1;
+ const uint64_t max = (static_cast<uint64_t>(1)
+ << static_cast<uint64_t>(total_byte_size * 8)) -
+ 1;
return uval64 <= max;
}
@@ -279,7 +281,9 @@ public:
if (total_byte_size == 8)
return true;
- const int64_t max = ((int64_t)1 << (uint64_t)(total_byte_size * 8 - 1)) - 1;
+ const int64_t max = (static_cast<int64_t>(1)
+ << static_cast<uint64_t>(total_byte_size * 8 - 1)) -
+ 1;
const int64_t min = ~(max);
return min <= sval64 && sval64 <= max;
}
Modified: lldb/trunk/include/lldb/Utility/Endian.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Utility/Endian.h?rev=361458&r1=361457&r2=361458&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Utility/Endian.h (original)
+++ lldb/trunk/include/lldb/Utility/Endian.h Wed May 22 22:12:11 2019
@@ -23,7 +23,7 @@ static union EndianTest {
} const endianTest = {0x01020304};
inline lldb::ByteOrder InlHostByteOrder() {
- return (lldb::ByteOrder)endianTest.bytes[0];
+ return static_cast<lldb::ByteOrder>(endianTest.bytes[0]);
}
// ByteOrder const InlHostByteOrder = (ByteOrder)endianTest.bytes[0];
Modified: lldb/trunk/include/lldb/Utility/Flags.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Utility/Flags.h?rev=361458&r1=361457&r2=361458&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Utility/Flags.h (original)
+++ lldb/trunk/include/lldb/Utility/Flags.h Wed May 22 22:12:11 2019
@@ -69,7 +69,7 @@ public:
///
/// \return
/// The new flags after clearing all bits from \a mask.
- ValueType Clear(ValueType mask = ~(ValueType)0) {
+ ValueType Clear(ValueType mask = ~static_cast<ValueType>(0)) {
m_flags &= ~mask;
return m_flags;
}
Modified: lldb/trunk/include/lldb/Utility/RegisterValue.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Utility/RegisterValue.h?rev=361458&r1=361457&r2=361458&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Utility/RegisterValue.h (original)
+++ lldb/trunk/include/lldb/Utility/RegisterValue.h Wed May 22 22:12:11 2019
@@ -41,7 +41,8 @@ public:
eTypeBytes
};
- RegisterValue() : m_type(eTypeInvalid), m_scalar((unsigned long)0) {}
+ RegisterValue()
+ : m_type(eTypeInvalid), m_scalar(static_cast<unsigned long>(0)) {}
explicit RegisterValue(uint8_t inst) : m_type(eTypeUInt8) { m_scalar = inst; }
Modified: lldb/trunk/include/lldb/Utility/Scalar.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Utility/Scalar.h?rev=361458&r1=361457&r2=361458&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Utility/Scalar.h (original)
+++ lldb/trunk/include/lldb/Utility/Scalar.h Wed May 22 22:12:11 2019
@@ -59,22 +59,23 @@ public:
// Constructors and Destructors
Scalar();
- Scalar(int v) : m_type(e_sint), m_float((float)0) {
+ Scalar(int v) : m_type(e_sint), m_float(static_cast<float>(0)) {
m_integer = llvm::APInt(sizeof(int) * 8, v, true);
}
- Scalar(unsigned int v) : m_type(e_uint), m_float((float)0) {
+ Scalar(unsigned int v) : m_type(e_uint), m_float(static_cast<float>(0)) {
m_integer = llvm::APInt(sizeof(int) * 8, v);
}
- Scalar(long v) : m_type(e_slong), m_float((float)0) {
+ Scalar(long v) : m_type(e_slong), m_float(static_cast<float>(0)) {
m_integer = llvm::APInt(sizeof(long) * 8, v, true);
}
- Scalar(unsigned long v) : m_type(e_ulong), m_float((float)0) {
+ Scalar(unsigned long v) : m_type(e_ulong), m_float(static_cast<float>(0)) {
m_integer = llvm::APInt(sizeof(long) * 8, v);
}
- Scalar(long long v) : m_type(e_slonglong), m_float((float)0) {
+ Scalar(long long v) : m_type(e_slonglong), m_float(static_cast<float>(0)) {
m_integer = llvm::APInt(sizeof(long long) * 8, v, true);
}
- Scalar(unsigned long long v) : m_type(e_ulonglong), m_float((float)0) {
+ Scalar(unsigned long long v)
+ : m_type(e_ulonglong), m_float(static_cast<float>(0)) {
m_integer = llvm::APInt(sizeof(long long) * 8, v);
}
Scalar(float v) : m_type(e_float), m_float(v) { m_float = llvm::APFloat(v); }
@@ -82,17 +83,20 @@ public:
m_float = llvm::APFloat(v);
}
Scalar(long double v, bool ieee_quad)
- : m_type(e_long_double), m_float((float)0), m_ieee_quad(ieee_quad) {
+ : m_type(e_long_double), m_float(static_cast<float>(0)),
+ m_ieee_quad(ieee_quad) {
if (ieee_quad)
- m_float = llvm::APFloat(llvm::APFloat::IEEEquad(),
- llvm::APInt(BITWIDTH_INT128, NUM_OF_WORDS_INT128,
- ((type128 *)&v)->x));
+ m_float =
+ llvm::APFloat(llvm::APFloat::IEEEquad(),
+ llvm::APInt(BITWIDTH_INT128, NUM_OF_WORDS_INT128,
+ (reinterpret_cast<type128 *>(&v))->x));
else
- m_float = llvm::APFloat(llvm::APFloat::x87DoubleExtended(),
- llvm::APInt(BITWIDTH_INT128, NUM_OF_WORDS_INT128,
- ((type128 *)&v)->x));
+ m_float =
+ llvm::APFloat(llvm::APFloat::x87DoubleExtended(),
+ llvm::APInt(BITWIDTH_INT128, NUM_OF_WORDS_INT128,
+ (reinterpret_cast<type128 *>(&v))->x));
}
- Scalar(llvm::APInt v) : m_type(), m_float((float)0) {
+ Scalar(llvm::APInt v) : m_type(), m_float(static_cast<float>(0)) {
m_integer = llvm::APInt(v);
switch (m_integer.getBitWidth()) {
case 8:
@@ -252,7 +256,9 @@ public:
if (total_byte_size == 8)
return true;
- const uint64_t max = ((uint64_t)1 << (uint64_t)(total_byte_size * 8)) - 1;
+ const uint64_t max = (static_cast<uint64_t>(1)
+ << static_cast<uint64_t>(total_byte_size * 8)) -
+ 1;
return uval64 <= max;
}
@@ -263,7 +269,9 @@ public:
if (total_byte_size == 8)
return true;
- const int64_t max = ((int64_t)1 << (uint64_t)(total_byte_size * 8 - 1)) - 1;
+ const int64_t max = (static_cast<int64_t>(1)
+ << static_cast<uint64_t>(total_byte_size * 8 - 1)) -
+ 1;
const int64_t min = ~(max);
return min <= sval64 && sval64 <= max;
}
Modified: lldb/trunk/source/Utility/Args.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Utility/Args.cpp?rev=361458&r1=361457&r2=361458&view=diff
==============================================================================
--- lldb/trunk/source/Utility/Args.cpp (original)
+++ lldb/trunk/source/Utility/Args.cpp Wed May 22 22:12:11 2019
@@ -541,7 +541,7 @@ void Args::EncodeEscapeSequences(const c
p += i - 1;
unsigned long octal_value = ::strtoul(oct_str, nullptr, 8);
if (octal_value <= UINT8_MAX) {
- dst.append(1, (char)octal_value);
+ dst.append(1, static_cast<char>(octal_value));
}
}
break;
@@ -561,7 +561,7 @@ void Args::EncodeEscapeSequences(const c
unsigned long hex_value = strtoul(hex_str, nullptr, 16);
if (hex_value <= UINT8_MAX)
- dst.append(1, (char)hex_value);
+ dst.append(1, static_cast<char>(hex_value));
} else {
dst.append(1, 'x');
}
Modified: lldb/trunk/source/Utility/DataBufferHeap.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Utility/DataBufferHeap.cpp?rev=361458&r1=361457&r2=361458&view=diff
==============================================================================
--- lldb/trunk/source/Utility/DataBufferHeap.cpp (original)
+++ lldb/trunk/source/Utility/DataBufferHeap.cpp Wed May 22 22:12:11 2019
@@ -52,7 +52,7 @@ uint64_t DataBufferHeap::SetByteSize(uin
}
void DataBufferHeap::CopyData(const void *src, uint64_t src_len) {
- const uint8_t *src_u8 = (const uint8_t *)src;
+ const uint8_t *src_u8 = static_cast<const uint8_t *>(src);
if (src && src_len > 0)
m_data.assign(src_u8, src_u8 + src_len);
else
@@ -60,8 +60,8 @@ void DataBufferHeap::CopyData(const void
}
void DataBufferHeap::AppendData(const void *src, uint64_t src_len) {
- m_data.insert(m_data.end(), (const uint8_t *)src,
- (const uint8_t *)src + src_len);
+ m_data.insert(m_data.end(), static_cast<const uint8_t *>(src),
+ static_cast<const uint8_t *>(src) + src_len);
}
void DataBufferHeap::Clear() {
Modified: lldb/trunk/source/Utility/DataEncoder.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Utility/DataEncoder.cpp?rev=361458&r1=361457&r2=361458&view=diff
==============================================================================
--- lldb/trunk/source/Utility/DataEncoder.cpp (original)
+++ lldb/trunk/source/Utility/DataEncoder.cpp Wed May 22 22:12:11 2019
@@ -34,8 +34,9 @@ DataEncoder::DataEncoder()
// data must stay around as long as this object is valid.
DataEncoder::DataEncoder(void *data, uint32_t length, ByteOrder endian,
uint8_t addr_size)
- : m_start((uint8_t *)data), m_end((uint8_t *)data + length),
- m_byte_order(endian), m_addr_size(addr_size), m_data_sp() {}
+ : m_start(static_cast<uint8_t *>(data)),
+ m_end(static_cast<uint8_t *>(data) + length), m_byte_order(endian),
+ m_addr_size(addr_size), m_data_sp() {}
// Make a shared pointer reference to the shared data in "data_sp" and set the
// endian swapping setting to "swap", and the address size to "addr_size". The
@@ -90,7 +91,7 @@ uint32_t DataEncoder::SetData(void *byte
m_start = nullptr;
m_end = nullptr;
} else {
- m_start = (uint8_t *)bytes;
+ m_start = static_cast<uint8_t *>(bytes);
m_end = m_start + length;
}
return GetByteSize();
Modified: lldb/trunk/source/Utility/DataExtractor.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Utility/DataExtractor.cpp?rev=361458&r1=361457&r2=361458&view=diff
==============================================================================
--- lldb/trunk/source/Utility/DataExtractor.cpp (original)
+++ lldb/trunk/source/Utility/DataExtractor.cpp Wed May 22 22:12:11 2019
@@ -318,7 +318,7 @@ lldb::offset_t DataExtractor::SetData(co
//
// RETURNS the byte that was extracted, or zero on failure.
uint8_t DataExtractor::GetU8(offset_t *offset_ptr) const {
- const uint8_t *data = (const uint8_t *)GetData(offset_ptr, 1);
+ const uint8_t *data = static_cast<const uint8_t *>(GetData(offset_ptr, 1));
if (data)
return *data;
return 0;
@@ -332,7 +332,8 @@ uint8_t DataExtractor::GetU8(offset_t *o
// buffer due to being out of bounds, or insufficient data.
void *DataExtractor::GetU8(offset_t *offset_ptr, void *dst,
uint32_t count) const {
- const uint8_t *data = (const uint8_t *)GetData(offset_ptr, count);
+ const uint8_t *data =
+ static_cast<const uint8_t *>(GetData(offset_ptr, count));
if (data) {
// Copy the data into the buffer
memcpy(dst, data, count);
@@ -349,7 +350,8 @@ void *DataExtractor::GetU8(offset_t *off
// RETURNS the uint16_t that was extracted, or zero on failure.
uint16_t DataExtractor::GetU16(offset_t *offset_ptr) const {
uint16_t val = 0;
- const uint8_t *data = (const uint8_t *)GetData(offset_ptr, sizeof(val));
+ const uint8_t *data =
+ static_cast<const uint8_t *>(GetData(offset_ptr, sizeof(val)));
if (data) {
if (m_byte_order != endian::InlHostByteOrder())
val = ReadSwapInt16(data);
@@ -398,10 +400,11 @@ uint64_t DataExtractor::GetU64_unchecked
void *DataExtractor::GetU16(offset_t *offset_ptr, void *void_dst,
uint32_t count) const {
const size_t src_size = sizeof(uint16_t) * count;
- const uint16_t *src = (const uint16_t *)GetData(offset_ptr, src_size);
+ const uint16_t *src =
+ static_cast<const uint16_t *>(GetData(offset_ptr, src_size));
if (src) {
if (m_byte_order != endian::InlHostByteOrder()) {
- uint16_t *dst_pos = (uint16_t *)void_dst;
+ uint16_t *dst_pos = static_cast<uint16_t *>(void_dst);
uint16_t *dst_end = dst_pos + count;
const uint16_t *src_pos = src;
while (dst_pos < dst_end) {
@@ -425,7 +428,8 @@ void *DataExtractor::GetU16(offset_t *of
// RETURNS the uint32_t that was extracted, or zero on failure.
uint32_t DataExtractor::GetU32(offset_t *offset_ptr) const {
uint32_t val = 0;
- const uint8_t *data = (const uint8_t *)GetData(offset_ptr, sizeof(val));
+ const uint8_t *data =
+ static_cast<const uint8_t *>(GetData(offset_ptr, sizeof(val)));
if (data) {
if (m_byte_order != endian::InlHostByteOrder()) {
val = ReadSwapInt32(data);
@@ -445,10 +449,11 @@ uint32_t DataExtractor::GetU32(offset_t
void *DataExtractor::GetU32(offset_t *offset_ptr, void *void_dst,
uint32_t count) const {
const size_t src_size = sizeof(uint32_t) * count;
- const uint32_t *src = (const uint32_t *)GetData(offset_ptr, src_size);
+ const uint32_t *src =
+ static_cast<const uint32_t *>(GetData(offset_ptr, src_size));
if (src) {
if (m_byte_order != endian::InlHostByteOrder()) {
- uint32_t *dst_pos = (uint32_t *)void_dst;
+ uint32_t *dst_pos = static_cast<uint32_t *>(void_dst);
uint32_t *dst_end = dst_pos + count;
const uint32_t *src_pos = src;
while (dst_pos < dst_end) {
@@ -472,7 +477,8 @@ void *DataExtractor::GetU32(offset_t *of
// RETURNS the uint64_t that was extracted, or zero on failure.
uint64_t DataExtractor::GetU64(offset_t *offset_ptr) const {
uint64_t val = 0;
- const uint8_t *data = (const uint8_t *)GetData(offset_ptr, sizeof(val));
+ const uint8_t *data =
+ static_cast<const uint8_t *>(GetData(offset_ptr, sizeof(val)));
if (data) {
if (m_byte_order != endian::InlHostByteOrder()) {
val = ReadSwapInt64(data);
@@ -491,10 +497,11 @@ uint64_t DataExtractor::GetU64(offset_t
void *DataExtractor::GetU64(offset_t *offset_ptr, void *void_dst,
uint32_t count) const {
const size_t src_size = sizeof(uint64_t) * count;
- const uint64_t *src = (const uint64_t *)GetData(offset_ptr, src_size);
+ const uint64_t *src =
+ static_cast<const uint64_t *>(GetData(offset_ptr, src_size));
if (src) {
if (m_byte_order != endian::InlHostByteOrder()) {
- uint64_t *dst_pos = (uint64_t *)void_dst;
+ uint64_t *dst_pos = static_cast<uint64_t *>(void_dst);
uint64_t *dst_end = dst_pos + count;
const uint64_t *src_pos = src;
while (dst_pos < dst_end) {
@@ -595,10 +602,11 @@ int64_t DataExtractor::GetMaxS64Bitfield
lsbcount = size * 8 - bitfield_bit_offset - bitfield_bit_size;
if (lsbcount > 0)
sval64 >>= lsbcount;
- uint64_t bitfield_mask = (((uint64_t)1) << bitfield_bit_size) - 1;
+ uint64_t bitfield_mask =
+ ((static_cast<uint64_t>(1)) << bitfield_bit_size) - 1;
sval64 &= bitfield_mask;
// sign extend if needed
- if (sval64 & (((uint64_t)1) << (bitfield_bit_size - 1)))
+ if (sval64 & ((static_cast<uint64_t>(1)) << (bitfield_bit_size - 1)))
sval64 |= ~bitfield_mask;
}
return sval64;
@@ -608,11 +616,12 @@ float DataExtractor::GetFloat(offset_t *
typedef float float_type;
float_type val = 0.0;
const size_t src_size = sizeof(float_type);
- const float_type *src = (const float_type *)GetData(offset_ptr, src_size);
+ const float_type *src =
+ static_cast<const float_type *>(GetData(offset_ptr, src_size));
if (src) {
if (m_byte_order != endian::InlHostByteOrder()) {
- const uint8_t *src_data = (const uint8_t *)src;
- uint8_t *dst_data = (uint8_t *)&val;
+ const uint8_t *src_data = reinterpret_cast<const uint8_t *>(src);
+ uint8_t *dst_data = reinterpret_cast<uint8_t *>(&val);
for (size_t i = 0; i < sizeof(float_type); ++i)
dst_data[sizeof(float_type) - 1 - i] = src_data[i];
} else {
@@ -626,11 +635,12 @@ double DataExtractor::GetDouble(offset_t
typedef double float_type;
float_type val = 0.0;
const size_t src_size = sizeof(float_type);
- const float_type *src = (const float_type *)GetData(offset_ptr, src_size);
+ const float_type *src =
+ static_cast<const float_type *>(GetData(offset_ptr, src_size));
if (src) {
if (m_byte_order != endian::InlHostByteOrder()) {
- const uint8_t *src_data = (const uint8_t *)src;
- uint8_t *dst_data = (uint8_t *)&val;
+ const uint8_t *src_data = reinterpret_cast<const uint8_t *>(src);
+ uint8_t *dst_data = reinterpret_cast<uint8_t *>(&val);
for (size_t i = 0; i < sizeof(float_type); ++i)
dst_data[sizeof(float_type) - 1 - i] = src_data[i];
} else {
@@ -690,7 +700,7 @@ size_t DataExtractor::ExtractBytes(offse
length == 10 || length == 16 || length == 32);
for (uint32_t i = 0; i < length; ++i)
- ((uint8_t *)dst)[i] = src[length - i - 1];
+ (static_cast<uint8_t *>(dst))[i] = src[length - i - 1];
} else
::memcpy(dst, src, length);
return length;
@@ -736,8 +746,8 @@ DataExtractor::CopyByteOrderedData(offse
!(m_byte_order == eByteOrderBig || m_byte_order == eByteOrderLittle))
return 0;
- uint8_t *dst = (uint8_t *)dst_void_ptr;
- const uint8_t *src = (const uint8_t *)PeekData(src_offset, src_len);
+ uint8_t *dst = static_cast<uint8_t *>(dst_void_ptr);
+ const uint8_t *src = PeekData(src_offset, src_len);
if (src) {
if (dst_len >= src_len) {
// We are copying the entire value from src into dst. Calculate how many,
@@ -806,10 +816,10 @@ DataExtractor::CopyByteOrderedData(offse
// non-zero and there aren't enough available bytes, nullptr will be returned
// and "offset_ptr" will not be updated.
const char *DataExtractor::GetCStr(offset_t *offset_ptr) const {
- const char *cstr = (const char *)PeekData(*offset_ptr, 1);
+ const char *cstr = reinterpret_cast<const char *>(PeekData(*offset_ptr, 1));
if (cstr) {
const char *cstr_end = cstr;
- const char *end = (const char *)m_end;
+ const char *end = reinterpret_cast<const char *>(m_end);
while (cstr_end < end && *cstr_end)
++cstr_end;
@@ -837,7 +847,7 @@ const char *DataExtractor::GetCStr(offse
// contain a NULL terminator byte, nullptr will be returned and "offset_ptr"
// will not be updated.
const char *DataExtractor::GetCStr(offset_t *offset_ptr, offset_t len) const {
- const char *cstr = (const char *)PeekData(*offset_ptr, len);
+ const char *cstr = reinterpret_cast<const char *>(PeekData(*offset_ptr, len));
if (cstr != nullptr) {
if (memchr(cstr, '\0', len) == nullptr) {
return nullptr;
@@ -855,7 +865,7 @@ const char *DataExtractor::GetCStr(offse
// Returns a valid C string pointer if "offset" is a valid offset in this
// object's data, else nullptr is returned.
const char *DataExtractor::PeekCStr(offset_t offset) const {
- return (const char *)PeekData(offset, 1);
+ return reinterpret_cast<const char *>(PeekData(offset, 1));
}
// Extracts an unsigned LEB128 number from this object's data starting at the
@@ -865,7 +875,7 @@ const char *DataExtractor::PeekCStr(offs
//
// Returned the extracted integer value.
uint64_t DataExtractor::GetULEB128(offset_t *offset_ptr) const {
- const uint8_t *src = (const uint8_t *)PeekData(*offset_ptr, 1);
+ const uint8_t *src = PeekData(*offset_ptr, 1);
if (src == nullptr)
return 0;
@@ -878,7 +888,7 @@ uint64_t DataExtractor::GetULEB128(offse
int shift = 7;
while (src < end) {
uint8_t byte = *src++;
- result |= (uint64_t)(byte & 0x7f) << shift;
+ result |= static_cast<uint64_t>(byte & 0x7f) << shift;
if ((byte & 0x80) == 0)
break;
shift += 7;
@@ -898,7 +908,7 @@ uint64_t DataExtractor::GetULEB128(offse
//
// Returned the extracted integer value.
int64_t DataExtractor::GetSLEB128(offset_t *offset_ptr) const {
- const uint8_t *src = (const uint8_t *)PeekData(*offset_ptr, 1);
+ const uint8_t *src = PeekData(*offset_ptr, 1);
if (src == nullptr)
return 0;
@@ -915,7 +925,7 @@ int64_t DataExtractor::GetSLEB128(offset
while (src < end) {
bytecount++;
byte = *src++;
- result |= (int64_t)(byte & 0x7f) << shift;
+ result |= static_cast<int64_t>(byte & 0x7f) << shift;
shift += 7;
if ((byte & 0x80) == 0)
break;
@@ -939,7 +949,7 @@ int64_t DataExtractor::GetSLEB128(offset
// Returns the number of bytes consumed during the extraction.
uint32_t DataExtractor::Skip_LEB128(offset_t *offset_ptr) const {
uint32_t bytes_consumed = 0;
- const uint8_t *src = (const uint8_t *)PeekData(*offset_ptr, 1);
+ const uint8_t *src = PeekData(*offset_ptr, 1);
if (src == nullptr)
return 0;
@@ -986,7 +996,7 @@ lldb::offset_t DataExtractor::PutToLog(L
// Reset string offset and fill the current line string with address:
if (base_addr != LLDB_INVALID_ADDRESS)
sstr.Printf("0x%8.8" PRIx64 ":",
- (uint64_t)(base_addr + (offset - start_offset)));
+ static_cast<uint64_t>(base_addr + (offset - start_offset)));
}
switch (type) {
Modified: lldb/trunk/source/Utility/Event.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Utility/Event.cpp?rev=361458&r1=361457&r2=361458&view=diff
==============================================================================
--- lldb/trunk/source/Utility/Event.cpp (original)
+++ lldb/trunk/source/Utility/Event.cpp Wed May 22 22:12:11 2019
@@ -143,7 +143,7 @@ size_t EventDataBytes::GetByteSize() con
void EventDataBytes::SetBytes(const void *src, size_t src_len) {
if (src != nullptr && src_len > 0)
- m_bytes.assign((const char *)src, src_len);
+ m_bytes.assign(static_cast<const char *>(src), src_len);
else
m_bytes.clear();
}
Modified: lldb/trunk/source/Utility/JSON.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Utility/JSON.cpp?rev=361458&r1=361457&r2=361458&view=diff
==============================================================================
--- lldb/trunk/source/Utility/JSON.cpp (original)
+++ lldb/trunk/source/Utility/JSON.cpp Wed May 22 22:12:11 2019
@@ -55,9 +55,9 @@ uint64_t JSONNumber::GetAsUnsigned() con
case DataType::Unsigned:
return m_data.m_unsigned;
case DataType::Signed:
- return (uint64_t)m_data.m_signed;
+ return static_cast<uint64_t>(m_data.m_signed);
case DataType::Double:
- return (uint64_t)m_data.m_double;
+ return static_cast<uint64_t>(m_data.m_double);
}
llvm_unreachable("Unhandled data type");
}
@@ -65,11 +65,11 @@ uint64_t JSONNumber::GetAsUnsigned() con
int64_t JSONNumber::GetAsSigned() const {
switch (m_data_type) {
case DataType::Unsigned:
- return (int64_t)m_data.m_unsigned;
+ return static_cast<int64_t>(m_data.m_unsigned);
case DataType::Signed:
return m_data.m_signed;
case DataType::Double:
- return (int64_t)m_data.m_double;
+ return static_cast<int64_t>(m_data.m_double);
}
llvm_unreachable("Unhandled data type");
}
@@ -77,9 +77,9 @@ int64_t JSONNumber::GetAsSigned() const
double JSONNumber::GetAsDouble() const {
switch (m_data_type) {
case DataType::Unsigned:
- return (double)m_data.m_unsigned;
+ return static_cast<double>(m_data.m_unsigned);
case DataType::Signed:
- return (double)m_data.m_signed;
+ return static_cast<double>(m_data.m_signed);
case DataType::Double:
return m_data.m_double;
}
@@ -253,7 +253,7 @@ JSONParser::Token JSONParser::GetToken(s
const bool is_null = escaped_ch == 0;
if (was_escaped || (!is_end_quote && !is_null)) {
if (CHAR_MIN <= escaped_ch && escaped_ch <= CHAR_MAX) {
- value.append(1, (char)escaped_ch);
+ value.append(1, static_cast<char>(escaped_ch));
} else {
error.Printf("error: wide character support is needed for unicode "
"character 0x%4.4x at offset %" PRIu64,
Modified: lldb/trunk/source/Utility/RegisterValue.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Utility/RegisterValue.cpp?rev=361458&r1=361457&r2=361458&view=diff
==============================================================================
--- lldb/trunk/source/Utility/RegisterValue.cpp (original)
+++ lldb/trunk/source/Utility/RegisterValue.cpp Wed May 22 22:12:11 2019
@@ -146,13 +146,13 @@ bool RegisterValue::GetScalarValue(Scala
scalar = *(const uint8_t *)buffer.bytes;
return true;
case 2:
- scalar = *(const uint16_t *)buffer.bytes;
+ scalar = *reinterpret_cast<const uint16_t *>(buffer.bytes);
return true;
case 4:
- scalar = *(const uint32_t *)buffer.bytes;
+ scalar = *reinterpret_cast<const uint32_t *>(buffer.bytes);
return true;
case 8:
- scalar = *(const uint64_t *)buffer.bytes;
+ scalar = *reinterpret_cast<const uint64_t *>(buffer.bytes);
return true;
case 16:
case 32:
@@ -162,8 +162,9 @@ bool RegisterValue::GetScalarValue(Scala
const auto length_in_uint64 = buffer.length / sizeof(uint64_t);
scalar =
llvm::APInt(length_in_bits,
- llvm::ArrayRef<uint64_t>((const uint64_t *)buffer.bytes,
- length_in_uint64));
+ llvm::ArrayRef<uint64_t>(
+ reinterpret_cast<const uint64_t *>(buffer.bytes),
+ length_in_uint64));
return true;
}
break;
@@ -518,7 +519,7 @@ uint16_t RegisterValue::GetAsUInt16(uint
break;
case 1:
case 2:
- return *(const uint16_t *)buffer.bytes;
+ return *reinterpret_cast<const uint16_t *>(buffer.bytes);
}
} break;
}
@@ -548,7 +549,7 @@ uint32_t RegisterValue::GetAsUInt32(uint
case 1:
case 2:
case 4:
- return *(const uint32_t *)buffer.bytes;
+ return *reinterpret_cast<const uint32_t *>(buffer.bytes);
}
} break;
}
@@ -579,11 +580,11 @@ uint64_t RegisterValue::GetAsUInt64(uint
case 1:
return *(const uint8_t *)buffer.bytes;
case 2:
- return *(const uint16_t *)buffer.bytes;
+ return *reinterpret_cast<const uint16_t *>(buffer.bytes);
case 4:
- return *(const uint32_t *)buffer.bytes;
+ return *reinterpret_cast<const uint32_t *>(buffer.bytes);
case 8:
- return *(const uint64_t *)buffer.bytes;
+ return *reinterpret_cast<const uint64_t *>(buffer.bytes);
}
} break;
}
@@ -618,7 +619,7 @@ llvm::APInt RegisterValue::GetAsUInt128(
case 8:
case 16:
return llvm::APInt(BITWIDTH_INT128, NUM_OF_WORDS_INT128,
- ((const type128 *)buffer.bytes)->x);
+ (reinterpret_cast<const type128 *>(buffer.bytes))->x);
}
} break;
}
Modified: lldb/trunk/source/Utility/Scalar.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Utility/Scalar.cpp?rev=361458&r1=361457&r2=361458&view=diff
==============================================================================
--- lldb/trunk/source/Utility/Scalar.cpp (original)
+++ lldb/trunk/source/Utility/Scalar.cpp Wed May 22 22:12:11 2019
@@ -69,7 +69,7 @@ static Scalar::Type PromoteToMaxType(
return Scalar::e_void;
}
-Scalar::Scalar() : m_type(e_void), m_float((float)0) {}
+Scalar::Scalar() : m_type(e_void), m_float(static_cast<float>(0)) {}
bool Scalar::GetData(DataExtractor &data, size_t limit_byte_size) const {
size_t byte_size = GetByteSize();
@@ -365,13 +365,13 @@ Scalar &Scalar::operator=(double v) {
Scalar &Scalar::operator=(long double v) {
m_type = e_long_double;
if (m_ieee_quad)
- m_float = llvm::APFloat(
- llvm::APFloat::IEEEquad(),
- llvm::APInt(BITWIDTH_INT128, NUM_OF_WORDS_INT128, ((type128 *)&v)->x));
+ m_float = llvm::APFloat(llvm::APFloat::IEEEquad(),
+ llvm::APInt(BITWIDTH_INT128, NUM_OF_WORDS_INT128,
+ (reinterpret_cast<type128 *>(&v))->x));
else
- m_float = llvm::APFloat(
- llvm::APFloat::x87DoubleExtended(),
- llvm::APInt(BITWIDTH_INT128, NUM_OF_WORDS_INT128, ((type128 *)&v)->x));
+ m_float = llvm::APFloat(llvm::APFloat::x87DoubleExtended(),
+ llvm::APInt(BITWIDTH_INT128, NUM_OF_WORDS_INT128,
+ (reinterpret_cast<type128 *>(&v))->x));
return *this;
}
@@ -1032,7 +1032,7 @@ bool Scalar::Promote(Scalar::Type type)
success = true;
break;
case e_double:
- m_float = llvm::APFloat((double_t)m_float.convertToFloat());
+ m_float = llvm::APFloat(static_cast<double_t>(m_float.convertToFloat()));
success = true;
break;
@@ -1318,14 +1318,16 @@ signed char Scalar::SChar(char fail_valu
case e_uint256:
case e_sint512:
case e_uint512:
- return (schar_t)(m_integer.sextOrTrunc(sizeof(schar_t) * 8)).getSExtValue();
+ return static_cast<schar_t>(
+ (m_integer.sextOrTrunc(sizeof(schar_t) * 8)).getSExtValue());
case e_float:
- return (schar_t)m_float.convertToFloat();
+ return static_cast<schar_t>(m_float.convertToFloat());
case e_double:
- return (schar_t)m_float.convertToDouble();
+ return static_cast<schar_t>(m_float.convertToDouble());
case e_long_double:
llvm::APInt ldbl_val = m_float.bitcastToAPInt();
- return (schar_t)(ldbl_val.sextOrTrunc(sizeof(schar_t) * 8)).getSExtValue();
+ return static_cast<schar_t>(
+ (ldbl_val.sextOrTrunc(sizeof(schar_t) * 8)).getSExtValue());
}
return fail_value;
}
@@ -1346,14 +1348,16 @@ unsigned char Scalar::UChar(unsigned cha
case e_uint256:
case e_sint512:
case e_uint512:
- return (uchar_t)(m_integer.zextOrTrunc(sizeof(uchar_t) * 8)).getZExtValue();
+ return static_cast<uchar_t>(
+ (m_integer.zextOrTrunc(sizeof(uchar_t) * 8)).getZExtValue());
case e_float:
- return (uchar_t)m_float.convertToFloat();
+ return static_cast<uchar_t>(m_float.convertToFloat());
case e_double:
- return (uchar_t)m_float.convertToDouble();
+ return static_cast<uchar_t>(m_float.convertToDouble());
case e_long_double:
llvm::APInt ldbl_val = m_float.bitcastToAPInt();
- return (uchar_t)(ldbl_val.zextOrTrunc(sizeof(uchar_t) * 8)).getZExtValue();
+ return static_cast<uchar_t>(
+ (ldbl_val.zextOrTrunc(sizeof(uchar_t) * 8)).getZExtValue());
}
return fail_value;
}
@@ -1374,16 +1378,16 @@ short Scalar::SShort(short fail_value) c
case e_uint256:
case e_sint512:
case e_uint512:
- return (sshort_t)(m_integer.sextOrTrunc(sizeof(sshort_t) * 8))
- .getSExtValue();
+ return static_cast<sshort_t>(
+ (m_integer.sextOrTrunc(sizeof(sshort_t) * 8)).getSExtValue());
case e_float:
- return (sshort_t)m_float.convertToFloat();
+ return static_cast<sshort_t>(m_float.convertToFloat());
case e_double:
- return (sshort_t)m_float.convertToDouble();
+ return static_cast<sshort_t>(m_float.convertToDouble());
case e_long_double:
llvm::APInt ldbl_val = m_float.bitcastToAPInt();
- return (sshort_t)(ldbl_val.sextOrTrunc(sizeof(sshort_t) * 8))
- .getSExtValue();
+ return static_cast<sshort_t>(
+ (ldbl_val.sextOrTrunc(sizeof(sshort_t) * 8)).getSExtValue());
}
return fail_value;
}
@@ -1404,16 +1408,16 @@ unsigned short Scalar::UShort(unsigned s
case e_uint256:
case e_sint512:
case e_uint512:
- return (ushort_t)(m_integer.zextOrTrunc(sizeof(ushort_t) * 8))
- .getZExtValue();
+ return static_cast<ushort_t>(
+ (m_integer.zextOrTrunc(sizeof(ushort_t) * 8)).getZExtValue());
case e_float:
- return (ushort_t)m_float.convertToFloat();
+ return static_cast<ushort_t>(m_float.convertToFloat());
case e_double:
- return (ushort_t)m_float.convertToDouble();
+ return static_cast<ushort_t>(m_float.convertToDouble());
case e_long_double:
llvm::APInt ldbl_val = m_float.bitcastToAPInt();
- return (ushort_t)(ldbl_val.zextOrTrunc(sizeof(ushort_t) * 8))
- .getZExtValue();
+ return static_cast<ushort_t>(
+ (ldbl_val.zextOrTrunc(sizeof(ushort_t) * 8)).getZExtValue());
}
return fail_value;
}
@@ -1434,14 +1438,16 @@ int Scalar::SInt(int fail_value) const {
case e_uint256:
case e_sint512:
case e_uint512:
- return (sint_t)(m_integer.sextOrTrunc(sizeof(sint_t) * 8)).getSExtValue();
+ return static_cast<sint_t>(
+ (m_integer.sextOrTrunc(sizeof(sint_t) * 8)).getSExtValue());
case e_float:
- return (sint_t)m_float.convertToFloat();
+ return static_cast<sint_t>(m_float.convertToFloat());
case e_double:
- return (sint_t)m_float.convertToDouble();
+ return static_cast<sint_t>(m_float.convertToDouble());
case e_long_double:
llvm::APInt ldbl_val = m_float.bitcastToAPInt();
- return (sint_t)(ldbl_val.sextOrTrunc(sizeof(sint_t) * 8)).getSExtValue();
+ return static_cast<sint_t>(
+ (ldbl_val.sextOrTrunc(sizeof(sint_t) * 8)).getSExtValue());
}
return fail_value;
}
@@ -1462,14 +1468,16 @@ unsigned int Scalar::UInt(unsigned int f
case e_uint256:
case e_sint512:
case e_uint512:
- return (uint_t)(m_integer.zextOrTrunc(sizeof(uint_t) * 8)).getZExtValue();
+ return static_cast<uint_t>(
+ (m_integer.zextOrTrunc(sizeof(uint_t) * 8)).getZExtValue());
case e_float:
- return (uint_t)m_float.convertToFloat();
+ return static_cast<uint_t>(m_float.convertToFloat());
case e_double:
- return (uint_t)m_float.convertToDouble();
+ return static_cast<uint_t>(m_float.convertToDouble());
case e_long_double:
llvm::APInt ldbl_val = m_float.bitcastToAPInt();
- return (uint_t)(ldbl_val.zextOrTrunc(sizeof(uint_t) * 8)).getZExtValue();
+ return static_cast<uint_t>(
+ (ldbl_val.zextOrTrunc(sizeof(uint_t) * 8)).getZExtValue());
}
return fail_value;
}
@@ -1490,14 +1498,16 @@ long Scalar::SLong(long fail_value) cons
case e_uint256:
case e_sint512:
case e_uint512:
- return (slong_t)(m_integer.sextOrTrunc(sizeof(slong_t) * 8)).getSExtValue();
+ return static_cast<slong_t>(
+ (m_integer.sextOrTrunc(sizeof(slong_t) * 8)).getSExtValue());
case e_float:
- return (slong_t)m_float.convertToFloat();
+ return static_cast<slong_t>(m_float.convertToFloat());
case e_double:
- return (slong_t)m_float.convertToDouble();
+ return static_cast<slong_t>(m_float.convertToDouble());
case e_long_double:
llvm::APInt ldbl_val = m_float.bitcastToAPInt();
- return (slong_t)(ldbl_val.sextOrTrunc(sizeof(slong_t) * 8)).getSExtValue();
+ return static_cast<slong_t>(
+ (ldbl_val.sextOrTrunc(sizeof(slong_t) * 8)).getSExtValue());
}
return fail_value;
}
@@ -1518,14 +1528,16 @@ unsigned long Scalar::ULong(unsigned lon
case e_uint256:
case e_sint512:
case e_uint512:
- return (ulong_t)(m_integer.zextOrTrunc(sizeof(ulong_t) * 8)).getZExtValue();
+ return static_cast<ulong_t>(
+ (m_integer.zextOrTrunc(sizeof(ulong_t) * 8)).getZExtValue());
case e_float:
- return (ulong_t)m_float.convertToFloat();
+ return static_cast<ulong_t>(m_float.convertToFloat());
case e_double:
- return (ulong_t)m_float.convertToDouble();
+ return static_cast<ulong_t>(m_float.convertToDouble());
case e_long_double:
llvm::APInt ldbl_val = m_float.bitcastToAPInt();
- return (ulong_t)(ldbl_val.zextOrTrunc(sizeof(ulong_t) * 8)).getZExtValue();
+ return static_cast<ulong_t>(
+ (ldbl_val.zextOrTrunc(sizeof(ulong_t) * 8)).getZExtValue());
}
return fail_value;
}
@@ -1546,16 +1558,16 @@ long long Scalar::SLongLong(long long fa
case e_uint256:
case e_sint512:
case e_uint512:
- return (slonglong_t)(m_integer.sextOrTrunc(sizeof(slonglong_t) * 8))
- .getSExtValue();
+ return static_cast<slonglong_t>(
+ (m_integer.sextOrTrunc(sizeof(slonglong_t) * 8)).getSExtValue());
case e_float:
- return (slonglong_t)m_float.convertToFloat();
+ return static_cast<slonglong_t>(m_float.convertToFloat());
case e_double:
- return (slonglong_t)m_float.convertToDouble();
+ return static_cast<slonglong_t>(m_float.convertToDouble());
case e_long_double:
llvm::APInt ldbl_val = m_float.bitcastToAPInt();
- return (slonglong_t)(ldbl_val.sextOrTrunc(sizeof(slonglong_t) * 8))
- .getSExtValue();
+ return static_cast<slonglong_t>(
+ (ldbl_val.sextOrTrunc(sizeof(slonglong_t) * 8)).getSExtValue());
}
return fail_value;
}
@@ -1576,21 +1588,21 @@ unsigned long long Scalar::ULongLong(uns
case e_uint256:
case e_sint512:
case e_uint512:
- return (ulonglong_t)(m_integer.zextOrTrunc(sizeof(ulonglong_t) * 8))
- .getZExtValue();
+ return static_cast<ulonglong_t>(
+ (m_integer.zextOrTrunc(sizeof(ulonglong_t) * 8)).getZExtValue());
case e_float:
- return (ulonglong_t)m_float.convertToFloat();
+ return static_cast<ulonglong_t>(m_float.convertToFloat());
case e_double: {
double d_val = m_float.convertToDouble();
llvm::APInt rounded_double =
llvm::APIntOps::RoundDoubleToAPInt(d_val, sizeof(ulonglong_t) * 8);
- return (ulonglong_t)(rounded_double.zextOrTrunc(sizeof(ulonglong_t) * 8))
- .getZExtValue();
+ return static_cast<ulonglong_t>(
+ (rounded_double.zextOrTrunc(sizeof(ulonglong_t) * 8)).getZExtValue());
}
case e_long_double:
llvm::APInt ldbl_val = m_float.bitcastToAPInt();
- return (ulonglong_t)(ldbl_val.zextOrTrunc(sizeof(ulonglong_t) * 8))
- .getZExtValue();
+ return static_cast<ulonglong_t>(
+ (ldbl_val.zextOrTrunc(sizeof(ulonglong_t) * 8)).getZExtValue());
}
return fail_value;
}
@@ -1665,7 +1677,7 @@ float Scalar::Float(float fail_value) co
case e_float:
return m_float.convertToFloat();
case e_double:
- return (float_t)m_float.convertToDouble();
+ return static_cast<float_t>(m_float.convertToDouble());
case e_long_double:
llvm::APInt ldbl_val = m_float.bitcastToAPInt();
return ldbl_val.bitsToFloat();
@@ -1691,7 +1703,7 @@ double Scalar::Double(double fail_value)
case e_uint512:
return llvm::APIntOps::RoundAPIntToDouble(m_integer);
case e_float:
- return (double_t)m_float.convertToFloat();
+ return static_cast<double_t>(m_float.convertToFloat());
case e_double:
return m_float.convertToDouble();
case e_long_double:
@@ -1717,14 +1729,15 @@ long double Scalar::LongDouble(long doub
case e_uint256:
case e_sint512:
case e_uint512:
- return (long_double_t)llvm::APIntOps::RoundAPIntToDouble(m_integer);
+ return static_cast<long_double_t>(
+ llvm::APIntOps::RoundAPIntToDouble(m_integer));
case e_float:
- return (long_double_t)m_float.convertToFloat();
+ return static_cast<long_double_t>(m_float.convertToFloat());
case e_double:
- return (long_double_t)m_float.convertToDouble();
+ return static_cast<long_double_t>(m_float.convertToDouble());
case e_long_double:
llvm::APInt ldbl_val = m_float.bitcastToAPInt();
- return (long_double_t)ldbl_val.bitsToDouble();
+ return static_cast<long_double_t>(ldbl_val.bitsToDouble());
}
return fail_value;
}
@@ -2364,10 +2377,10 @@ Status Scalar::SetValueFromCString(const
error.SetErrorStringWithFormat(
"'%s' is not a valid unsigned integer string value", value_str);
else if (!UIntValueIsValidForSize(uval64, byte_size))
- error.SetErrorStringWithFormat("value 0x%" PRIx64
- " is too large to fit in a %" PRIu64
- " byte unsigned integer value",
- uval64, (uint64_t)byte_size);
+ error.SetErrorStringWithFormat(
+ "value 0x%" PRIx64 " is too large to fit in a %" PRIu64
+ " byte unsigned integer value",
+ uval64, static_cast<uint64_t>(byte_size));
else {
m_type = Scalar::GetValueTypeForUnsignedIntegerWithByteSize(byte_size);
switch (m_type) {
@@ -2383,14 +2396,14 @@ Status Scalar::SetValueFromCString(const
default:
error.SetErrorStringWithFormat(
"unsupported unsigned integer byte size: %" PRIu64 "",
- (uint64_t)byte_size);
+ static_cast<uint64_t>(byte_size));
break;
}
}
} else {
error.SetErrorStringWithFormat(
"unsupported unsigned integer byte size: %" PRIu64 "",
- (uint64_t)byte_size);
+ static_cast<uint64_t>(byte_size));
return error;
}
break;
@@ -2402,10 +2415,10 @@ Status Scalar::SetValueFromCString(const
error.SetErrorStringWithFormat(
"'%s' is not a valid signed integer string value", value_str);
else if (!SIntValueIsValidForSize(sval64, byte_size))
- error.SetErrorStringWithFormat("value 0x%" PRIx64
- " is too large to fit in a %" PRIu64
- " byte signed integer value",
- sval64, (uint64_t)byte_size);
+ error.SetErrorStringWithFormat(
+ "value 0x%" PRIx64 " is too large to fit in a %" PRIu64
+ " byte signed integer value",
+ sval64, static_cast<uint64_t>(byte_size));
else {
m_type = Scalar::GetValueTypeForSignedIntegerWithByteSize(byte_size);
switch (m_type) {
@@ -2421,14 +2434,14 @@ Status Scalar::SetValueFromCString(const
default:
error.SetErrorStringWithFormat(
"unsupported signed integer byte size: %" PRIu64 "",
- (uint64_t)byte_size);
+ static_cast<uint64_t>(byte_size));
break;
}
}
} else {
error.SetErrorStringWithFormat(
"unsupported signed integer byte size: %" PRIu64 "",
- (uint64_t)byte_size);
+ static_cast<uint64_t>(byte_size));
return error;
}
break;
@@ -2453,17 +2466,17 @@ Status Scalar::SetValueFromCString(const
value_str);
} else if (byte_size == sizeof(long double)) {
if (::sscanf(value_str, "%Lf", &l_val) == 1) {
- m_float =
- llvm::APFloat(llvm::APFloat::x87DoubleExtended(),
- llvm::APInt(BITWIDTH_INT128, NUM_OF_WORDS_INT128,
- ((type128 *)&l_val)->x));
+ m_float = llvm::APFloat(
+ llvm::APFloat::x87DoubleExtended(),
+ llvm::APInt(BITWIDTH_INT128, NUM_OF_WORDS_INT128,
+ (reinterpret_cast<type128 *>(&l_val))->x));
m_type = e_long_double;
} else
error.SetErrorStringWithFormat("'%s' is not a valid float string value",
value_str);
} else {
error.SetErrorStringWithFormat("unsupported float byte size: %" PRIu64 "",
- (uint64_t)byte_size);
+ static_cast<uint64_t>(byte_size));
return error;
}
break;
@@ -2496,45 +2509,45 @@ Status Scalar::SetValueFromData(DataExtr
switch (byte_size) {
case 1:
- operator=((uint8_t)data.GetU8(&offset));
+ operator=(data.GetU8(&offset));
break;
case 2:
- operator=((uint16_t)data.GetU16(&offset));
+ operator=(data.GetU16(&offset));
break;
case 4:
- operator=((uint32_t)data.GetU32(&offset));
+ operator=(data.GetU32(&offset));
break;
case 8:
- operator=((uint64_t)data.GetU64(&offset));
+ operator=(data.GetU64(&offset));
break;
case 16:
if (data.GetByteOrder() == eByteOrderBig) {
- int128.x[1] = (uint64_t)data.GetU64(&offset);
- int128.x[0] = (uint64_t)data.GetU64(&offset);
+ int128.x[1] = data.GetU64(&offset);
+ int128.x[0] = data.GetU64(&offset);
} else {
- int128.x[0] = (uint64_t)data.GetU64(&offset);
- int128.x[1] = (uint64_t)data.GetU64(&offset);
+ int128.x[0] = data.GetU64(&offset);
+ int128.x[1] = data.GetU64(&offset);
}
operator=(llvm::APInt(BITWIDTH_INT128, NUM_OF_WORDS_INT128, int128.x));
break;
case 32:
if (data.GetByteOrder() == eByteOrderBig) {
- int256.x[3] = (uint64_t)data.GetU64(&offset);
- int256.x[2] = (uint64_t)data.GetU64(&offset);
- int256.x[1] = (uint64_t)data.GetU64(&offset);
- int256.x[0] = (uint64_t)data.GetU64(&offset);
+ int256.x[3] = data.GetU64(&offset);
+ int256.x[2] = data.GetU64(&offset);
+ int256.x[1] = data.GetU64(&offset);
+ int256.x[0] = data.GetU64(&offset);
} else {
- int256.x[0] = (uint64_t)data.GetU64(&offset);
- int256.x[1] = (uint64_t)data.GetU64(&offset);
- int256.x[2] = (uint64_t)data.GetU64(&offset);
- int256.x[3] = (uint64_t)data.GetU64(&offset);
+ int256.x[0] = data.GetU64(&offset);
+ int256.x[1] = data.GetU64(&offset);
+ int256.x[2] = data.GetU64(&offset);
+ int256.x[3] = data.GetU64(&offset);
}
operator=(llvm::APInt(BITWIDTH_INT256, NUM_OF_WORDS_INT256, int256.x));
break;
default:
error.SetErrorStringWithFormat(
"unsupported unsigned integer byte size: %" PRIu64 "",
- (uint64_t)byte_size);
+ static_cast<uint64_t>(byte_size));
break;
}
} break;
@@ -2543,45 +2556,45 @@ Status Scalar::SetValueFromData(DataExtr
switch (byte_size) {
case 1:
- operator=((int8_t)data.GetU8(&offset));
+ operator=(static_cast<int8_t>(data.GetU8(&offset)));
break;
case 2:
- operator=((int16_t)data.GetU16(&offset));
+ operator=(static_cast<int16_t>(data.GetU16(&offset)));
break;
case 4:
- operator=((int32_t)data.GetU32(&offset));
+ operator=(static_cast<int32_t>(data.GetU32(&offset)));
break;
case 8:
- operator=((int64_t)data.GetU64(&offset));
+ operator=(static_cast<int64_t>(data.GetU64(&offset)));
break;
case 16:
if (data.GetByteOrder() == eByteOrderBig) {
- int128.x[1] = (uint64_t)data.GetU64(&offset);
- int128.x[0] = (uint64_t)data.GetU64(&offset);
+ int128.x[1] = data.GetU64(&offset);
+ int128.x[0] = data.GetU64(&offset);
} else {
- int128.x[0] = (uint64_t)data.GetU64(&offset);
- int128.x[1] = (uint64_t)data.GetU64(&offset);
+ int128.x[0] = data.GetU64(&offset);
+ int128.x[1] = data.GetU64(&offset);
}
operator=(llvm::APInt(BITWIDTH_INT128, NUM_OF_WORDS_INT128, int128.x));
break;
case 32:
if (data.GetByteOrder() == eByteOrderBig) {
- int256.x[3] = (uint64_t)data.GetU64(&offset);
- int256.x[2] = (uint64_t)data.GetU64(&offset);
- int256.x[1] = (uint64_t)data.GetU64(&offset);
- int256.x[0] = (uint64_t)data.GetU64(&offset);
+ int256.x[3] = data.GetU64(&offset);
+ int256.x[2] = data.GetU64(&offset);
+ int256.x[1] = data.GetU64(&offset);
+ int256.x[0] = data.GetU64(&offset);
} else {
- int256.x[0] = (uint64_t)data.GetU64(&offset);
- int256.x[1] = (uint64_t)data.GetU64(&offset);
- int256.x[2] = (uint64_t)data.GetU64(&offset);
- int256.x[3] = (uint64_t)data.GetU64(&offset);
+ int256.x[0] = data.GetU64(&offset);
+ int256.x[1] = data.GetU64(&offset);
+ int256.x[2] = data.GetU64(&offset);
+ int256.x[3] = data.GetU64(&offset);
}
operator=(llvm::APInt(BITWIDTH_INT256, NUM_OF_WORDS_INT256, int256.x));
break;
default:
error.SetErrorStringWithFormat(
"unsupported signed integer byte size: %" PRIu64 "",
- (uint64_t)byte_size);
+ static_cast<uint64_t>(byte_size));
break;
}
} break;
@@ -2589,14 +2602,14 @@ Status Scalar::SetValueFromData(DataExtr
lldb::offset_t offset = 0;
if (byte_size == sizeof(float))
- operator=((float)data.GetFloat(&offset));
+ operator=(data.GetFloat(&offset));
else if (byte_size == sizeof(double))
- operator=((double)data.GetDouble(&offset));
+ operator=(data.GetDouble(&offset));
else if (byte_size == sizeof(long double))
- operator=((long double)data.GetLongDouble(&offset));
+ operator=(data.GetLongDouble(&offset));
else
error.SetErrorStringWithFormat("unsupported float byte size: %" PRIu64 "",
- (uint64_t)byte_size);
+ static_cast<uint64_t>(byte_size));
} break;
}
Modified: lldb/trunk/source/Utility/Stream.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Utility/Stream.cpp?rev=361458&r1=361457&r2=361458&view=diff
==============================================================================
--- lldb/trunk/source/Utility/Stream.cpp (original)
+++ lldb/trunk/source/Utility/Stream.cpp Wed May 22 22:12:11 2019
@@ -84,7 +84,7 @@ void Stream::Address(uint64_t addr, uint
suffix = "";
// int addr_width = m_addr_size << 1;
// Printf ("%s0x%0*" PRIx64 "%s", prefix, addr_width, addr, suffix);
- Printf("%s0x%0*" PRIx64 "%s", prefix, addr_size * 2, (uint64_t)addr, suffix);
+ Printf("%s0x%0*" PRIx64 "%s", prefix, addr_size * 2, addr, suffix);
}
// Put an address range out to the stream with optional prefix and suffix
@@ -156,7 +156,7 @@ Stream &Stream::operator<<(llvm::StringR
// Stream the pointer value out to this stream.
Stream &Stream::operator<<(const void *p) {
- Printf("0x%.*tx", (int)sizeof(const void *) * 2, (ptrdiff_t)p);
+ Printf("0x%.*tx", static_cast<int>(sizeof(const void *)) * 2, (ptrdiff_t)p);
return *this;
}
@@ -186,19 +186,19 @@ Stream &Stream::operator<<(uint64_t uval
// Stream a int8_t "sval" out to this stream.
Stream &Stream::operator<<(int8_t sval) {
- Printf("%i", (int)sval);
+ Printf("%i", static_cast<int>(sval));
return *this;
}
// Stream a int16_t "sval" out to this stream.
Stream &Stream::operator<<(int16_t sval) {
- Printf("%i", (int)sval);
+ Printf("%i", static_cast<int>(sval));
return *this;
}
// Stream a int32_t "sval" out to this stream.
Stream &Stream::operator<<(int32_t sval) {
- Printf("%i", (int)sval);
+ Printf("%i", static_cast<int>(sval));
return *this;
}
@@ -295,10 +295,10 @@ size_t Stream::PutHex16(uint16_t uvalue,
if (byte_order == eByteOrderLittle) {
for (size_t byte = 0; byte < sizeof(uvalue); ++byte)
- _PutHex8((uint8_t)(uvalue >> (byte * 8)), false);
+ _PutHex8(static_cast<uint8_t>(uvalue >> (byte * 8)), false);
} else {
for (size_t byte = sizeof(uvalue) - 1; byte < sizeof(uvalue); --byte)
- _PutHex8((uint8_t)(uvalue >> (byte * 8)), false);
+ _PutHex8(static_cast<uint8_t>(uvalue >> (byte * 8)), false);
}
return *delta;
}
@@ -311,10 +311,10 @@ size_t Stream::PutHex32(uint32_t uvalue,
if (byte_order == eByteOrderLittle) {
for (size_t byte = 0; byte < sizeof(uvalue); ++byte)
- _PutHex8((uint8_t)(uvalue >> (byte * 8)), false);
+ _PutHex8(static_cast<uint8_t>(uvalue >> (byte * 8)), false);
} else {
for (size_t byte = sizeof(uvalue) - 1; byte < sizeof(uvalue); --byte)
- _PutHex8((uint8_t)(uvalue >> (byte * 8)), false);
+ _PutHex8(static_cast<uint8_t>(uvalue >> (byte * 8)), false);
}
return *delta;
}
@@ -327,10 +327,10 @@ size_t Stream::PutHex64(uint64_t uvalue,
if (byte_order == eByteOrderLittle) {
for (size_t byte = 0; byte < sizeof(uvalue); ++byte)
- _PutHex8((uint8_t)(uvalue >> (byte * 8)), false);
+ _PutHex8(static_cast<uint8_t>(uvalue >> (byte * 8)), false);
} else {
for (size_t byte = sizeof(uvalue) - 1; byte < sizeof(uvalue); --byte)
- _PutHex8((uint8_t)(uvalue >> (byte * 8)), false);
+ _PutHex8(static_cast<uint8_t>(uvalue >> (byte * 8)), false);
}
return *delta;
}
@@ -339,11 +339,11 @@ size_t Stream::PutMaxHex64(uint64_t uval
lldb::ByteOrder byte_order) {
switch (byte_size) {
case 1:
- return PutHex8((uint8_t)uvalue);
+ return PutHex8(static_cast<uint8_t>(uvalue));
case 2:
- return PutHex16((uint16_t)uvalue, byte_order);
+ return PutHex16(static_cast<uint16_t>(uvalue), byte_order);
case 4:
- return PutHex32((uint32_t)uvalue, byte_order);
+ return PutHex32(static_cast<uint32_t>(uvalue), byte_order);
case 8:
return PutHex64(uvalue, byte_order);
}
@@ -386,7 +386,7 @@ size_t Stream::PutRawBytes(const void *s
if (dst_byte_order == eByteOrderInvalid)
dst_byte_order = m_byte_order;
- const uint8_t *src = (const uint8_t *)s;
+ const uint8_t *src = static_cast<const uint8_t *>(s);
bool binary_was_set = m_flags.Test(eBinary);
if (!binary_was_set)
m_flags.Set(eBinary);
@@ -413,7 +413,7 @@ size_t Stream::PutBytesAsRawHex8(const v
if (dst_byte_order == eByteOrderInvalid)
dst_byte_order = m_byte_order;
- const uint8_t *src = (const uint8_t *)s;
+ const uint8_t *src = static_cast<const uint8_t *>(s);
bool binary_is_set = m_flags.Test(eBinary);
m_flags.Clear(eBinary);
if (src_byte_order == dst_byte_order) {
Modified: lldb/trunk/source/Utility/StreamGDBRemote.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Utility/StreamGDBRemote.cpp?rev=361458&r1=361457&r2=361458&view=diff
==============================================================================
--- lldb/trunk/source/Utility/StreamGDBRemote.cpp (original)
+++ lldb/trunk/source/Utility/StreamGDBRemote.cpp Wed May 22 22:12:11 2019
@@ -26,7 +26,7 @@ StreamGDBRemote::~StreamGDBRemote() {}
int StreamGDBRemote::PutEscapedBytes(const void *s, size_t src_len) {
int bytes_written = 0;
- const uint8_t *src = (const uint8_t *)s;
+ const uint8_t *src = static_cast<const uint8_t *>(s);
bool binary_is_set = m_flags.Test(eBinary);
m_flags.Clear(eBinary);
while (src_len) {
Modified: lldb/trunk/source/Utility/StringExtractor.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Utility/StringExtractor.cpp?rev=361458&r1=361457&r2=361458&view=diff
==============================================================================
--- lldb/trunk/source/Utility/StringExtractor.cpp (original)
+++ lldb/trunk/source/Utility/StringExtractor.cpp Wed May 22 22:12:11 2019
@@ -67,7 +67,7 @@ int StringExtractor::DecodeHexU8() {
return -1;
}
m_index += 2;
- return (uint8_t)((hi_nibble << 4) + lo_nibble);
+ return static_cast<uint8_t>((hi_nibble << 4) + lo_nibble);
}
// Extract an unsigned character from two hex ASCII chars in the packet string,
@@ -87,7 +87,7 @@ bool StringExtractor::GetHexU8Ex(uint8_t
// ch should not be changed in case of failure
return false;
}
- ch = (uint8_t)byte;
+ ch = static_cast<uint8_t>(byte);
return true;
}
@@ -172,12 +172,12 @@ uint32_t StringExtractor::GetHexMaxU32(b
if (m_index < m_packet.size() && ::isxdigit(m_packet[m_index])) {
nibble_lo = xdigit_to_sint(m_packet[m_index]);
++m_index;
- result |= ((uint32_t)nibble_hi << (shift_amount + 4));
- result |= ((uint32_t)nibble_lo << shift_amount);
+ result |= (static_cast<uint32_t>(nibble_hi) << (shift_amount + 4));
+ result |= (static_cast<uint32_t>(nibble_lo) << shift_amount);
nibble_count += 2;
shift_amount += 8;
} else {
- result |= ((uint32_t)nibble_hi << shift_amount);
+ result |= (static_cast<uint32_t>(nibble_hi) << shift_amount);
nibble_count += 1;
shift_amount += 4;
}
@@ -223,12 +223,12 @@ uint64_t StringExtractor::GetHexMaxU64(b
if (m_index < m_packet.size() && ::isxdigit(m_packet[m_index])) {
nibble_lo = xdigit_to_sint(m_packet[m_index]);
++m_index;
- result |= ((uint64_t)nibble_hi << (shift_amount + 4));
- result |= ((uint64_t)nibble_lo << shift_amount);
+ result |= (static_cast<uint64_t>(nibble_hi) << (shift_amount + 4));
+ result |= (static_cast<uint64_t>(nibble_lo) << shift_amount);
nibble_count += 2;
shift_amount += 8;
} else {
- result |= ((uint64_t)nibble_hi << shift_amount);
+ result |= (static_cast<uint64_t>(nibble_hi) << shift_amount);
nibble_count += 1;
shift_amount += 4;
}
@@ -289,7 +289,7 @@ size_t StringExtractor::GetHexBytesAvail
int decode = DecodeHexU8();
if (decode == -1)
break;
- dest[0] = (uint8_t)decode;
+ dest[0] = static_cast<uint8_t>(decode);
dest = dest.drop_front();
++bytes_extracted;
}
@@ -310,7 +310,7 @@ uint64_t StringExtractor::GetHexWithFixe
uint32_t shift_amount;
for (i = 0, shift_amount = 0; i < byte_size && IsGood();
++i, shift_amount += 8) {
- result |= ((uint64_t)GetHexU8() << shift_amount);
+ result |= (static_cast<uint64_t>(GetHexU8()) << shift_amount);
}
} else {
// Big Endian
More information about the lldb-commits
mailing list