Commit 2a042b08 by Abseil Team Committed by vslashg

Export of internal Abseil changes

--
389189dbb322df0d0468ab13edf7dc185dc63833 by Abseil Team <absl-team@google.com>:

absl str_format.h can compile with -Wconversion and -Wsign-compare

PiperOrigin-RevId: 420799960

--
762e5adc429fc143756c42fe92fe8073c87c075f by Abseil Team <absl-team@google.com>:

GetStackTraceWithContext: Fix min_dropped_frames when no frames are recorded

Previously, if there were still frames to skip, they would be included
in min_dropped_frames.

PiperOrigin-RevId: 420766341

--
7d4374b8eaa410f4f98ec03d6a8997dccadfb271 by Abseil Team <absl-team@google.com>:

absl::flags compiles with -Wconversion and -Wsign-compare

PiperOrigin-RevId: 420476807

--
5f00f7805419d725fa1ff57b388e4c0750d1d6b0 by Derek Mauro <dmauro@google.com>:

Internal change

PiperOrigin-RevId: 420282152

--
bd5471fc34956acf3888bf90287b2aee4415c96d by Derek Mauro <dmauro@google.com>:

Internal change

PiperOrigin-RevId: 420282033

--
61c78020804e4290e9b2fe151aeaf99b198716ee by Derek Mauro <dmauro@google.com>:

Internal change

PiperOrigin-RevId: 420281867

--
dbe3aad24b65ea11664401a307ea3d2f28e8a7b9 by Derek Mauro <dmauro@google.com>:

Remove the incorrect test for the availability of [[nodiscard]]

It should have been ABSL_HAVE_CPP_ATTRIBUTE(nodiscard) instead of
ABSL_HAVE_ATTRIBUTE(nodiscard). As a result, some code is not
compliant with [[nodiscard]], so we cannot simply correct the availability
test.

Recommend that C++17-only code use the standard [[nodiscard] directly.

PiperOrigin-RevId: 420150702
GitOrigin-RevId: 389189dbb322df0d0468ab13edf7dc185dc63833
Change-Id: Idf6ebae3c4edd945c9032c7db3d0ab32d16e8078
parent 78f96802
...@@ -401,6 +401,9 @@ ...@@ -401,6 +401,9 @@
// //
// Tells the compiler to warn about unused results. // Tells the compiler to warn about unused results.
// //
// For code or headers that are assured to only build with C++17 and up, prefer
// just using the standard `[[nodiscard]]` directly over this macro.
//
// When annotating a function, it must appear as the first part of the // When annotating a function, it must appear as the first part of the
// declaration or definition. The compiler will warn if the return value from // declaration or definition. The compiler will warn if the return value from
// such a function is unused: // such a function is unused:
...@@ -427,9 +430,10 @@ ...@@ -427,9 +430,10 @@
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66425 // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66425
// //
// Note: past advice was to place the macro after the argument list. // Note: past advice was to place the macro after the argument list.
#if ABSL_HAVE_ATTRIBUTE(nodiscard) //
#define ABSL_MUST_USE_RESULT [[nodiscard]] // TODO(b/176172494): Use ABSL_HAVE_CPP_ATTRIBUTE(nodiscard) when all code is
#elif defined(__clang__) && ABSL_HAVE_ATTRIBUTE(warn_unused_result) // compliant with the stricter [[nodiscard]].
#if defined(__clang__) && ABSL_HAVE_ATTRIBUTE(warn_unused_result)
#define ABSL_MUST_USE_RESULT __attribute__((warn_unused_result)) #define ABSL_MUST_USE_RESULT __attribute__((warn_unused_result))
#else #else
#define ABSL_MUST_USE_RESULT #define ABSL_MUST_USE_RESULT
......
...@@ -176,12 +176,17 @@ static int UnwindImpl(void** result, int* sizes, int max_depth, int skip_count, ...@@ -176,12 +176,17 @@ static int UnwindImpl(void** result, int* sizes, int max_depth, int skip_count,
// Implementation detail: we clamp the max of frames we are willing to // Implementation detail: we clamp the max of frames we are willing to
// count, so as not to spend too much time in the loop below. // count, so as not to spend too much time in the loop below.
const int kMaxUnwind = 200; const int kMaxUnwind = 200;
int j = 0; int num_dropped_frames = 0;
for (; frame_pointer != nullptr && j < kMaxUnwind; j++) { for (int j = 0; frame_pointer != nullptr && j < kMaxUnwind; j++) {
if (skip_count > 0) {
skip_count--;
} else {
num_dropped_frames++;
}
frame_pointer = frame_pointer =
NextStackFrame<!IS_STACK_FRAMES, IS_WITH_CONTEXT>(frame_pointer, ucp); NextStackFrame<!IS_STACK_FRAMES, IS_WITH_CONTEXT>(frame_pointer, ucp);
} }
*min_dropped_frames = j; *min_dropped_frames = num_dropped_frames;
} }
return n; return n;
} }
......
...@@ -112,11 +112,16 @@ static int UnwindImpl(void** result, int* sizes, int max_depth, int skip_count, ...@@ -112,11 +112,16 @@ static int UnwindImpl(void** result, int* sizes, int max_depth, int skip_count,
// Implementation detail: we clamp the max of frames we are willing to // Implementation detail: we clamp the max of frames we are willing to
// count, so as not to spend too much time in the loop below. // count, so as not to spend too much time in the loop below.
const int kMaxUnwind = 200; const int kMaxUnwind = 200;
int j = 0; int num_dropped_frames = 0;
for (; sp != nullptr && j < kMaxUnwind; j++) { for (int j = 0; sp != nullptr && j < kMaxUnwind; j++) {
if (skip_count > 0) {
skip_count--;
} else {
num_dropped_frames++;
}
sp = NextStackFrame<!IS_STACK_FRAMES>(sp); sp = NextStackFrame<!IS_STACK_FRAMES>(sp);
} }
*min_dropped_frames = j; *min_dropped_frames = num_dropped_frames;
} }
return n; return n;
} }
......
...@@ -231,11 +231,16 @@ static int UnwindImpl(void** result, int* sizes, int max_depth, int skip_count, ...@@ -231,11 +231,16 @@ static int UnwindImpl(void** result, int* sizes, int max_depth, int skip_count,
// Implementation detail: we clamp the max of frames we are willing to // Implementation detail: we clamp the max of frames we are willing to
// count, so as not to spend too much time in the loop below. // count, so as not to spend too much time in the loop below.
const int kMaxUnwind = 1000; const int kMaxUnwind = 1000;
int j = 0; int num_dropped_frames = 0;
for (; next_sp != nullptr && j < kMaxUnwind; j++) { for (int j = 0; next_sp != nullptr && j < kMaxUnwind; j++) {
if (skip_count > 0) {
skip_count--;
} else {
num_dropped_frames++;
}
next_sp = NextStackFrame<!IS_STACK_FRAMES, IS_WITH_CONTEXT>(next_sp, ucp); next_sp = NextStackFrame<!IS_STACK_FRAMES, IS_WITH_CONTEXT>(next_sp, ucp);
} }
*min_dropped_frames = j; *min_dropped_frames = num_dropped_frames;
} }
return n; return n;
} }
......
...@@ -213,12 +213,17 @@ static int UnwindImpl(void **result, int *sizes, int max_depth, int skip_count, ...@@ -213,12 +213,17 @@ static int UnwindImpl(void **result, int *sizes, int max_depth, int skip_count,
// Implementation detail: we clamp the max of frames we are willing to // Implementation detail: we clamp the max of frames we are willing to
// count, so as not to spend too much time in the loop below. // count, so as not to spend too much time in the loop below.
const int kMaxUnwind = 200; const int kMaxUnwind = 200;
int j = 0; int num_dropped_frames = 0;
for (; frame_pointer != nullptr && j < kMaxUnwind; j++) { for (int j = 0; frame_pointer != nullptr && j < kMaxUnwind; j++) {
if (skip_count > 0) {
skip_count--;
} else {
num_dropped_frames++;
}
frame_pointer = frame_pointer =
NextStackFrame<!IS_STACK_FRAMES, IS_WITH_CONTEXT>(frame_pointer, ucp); NextStackFrame<!IS_STACK_FRAMES, IS_WITH_CONTEXT>(frame_pointer, ucp);
} }
*min_dropped_frames = j; *min_dropped_frames = num_dropped_frames;
} }
return n; return n;
} }
......
...@@ -341,12 +341,17 @@ static int UnwindImpl(void **result, int *sizes, int max_depth, int skip_count, ...@@ -341,12 +341,17 @@ static int UnwindImpl(void **result, int *sizes, int max_depth, int skip_count,
// Implementation detail: we clamp the max of frames we are willing to // Implementation detail: we clamp the max of frames we are willing to
// count, so as not to spend too much time in the loop below. // count, so as not to spend too much time in the loop below.
const int kMaxUnwind = 1000; const int kMaxUnwind = 1000;
int j = 0; int num_dropped_frames = 0;
for (; fp != nullptr && j < kMaxUnwind; j++) { for (int j = 0; fp != nullptr && j < kMaxUnwind; j++) {
if (skip_count > 0) {
skip_count--;
} else {
num_dropped_frames++;
}
fp = NextStackFrame<!IS_STACK_FRAMES, IS_WITH_CONTEXT>(fp, ucp, stack_low, fp = NextStackFrame<!IS_STACK_FRAMES, IS_WITH_CONTEXT>(fp, ucp, stack_low,
stack_high); stack_high);
} }
*min_dropped_frames = j; *min_dropped_frames = num_dropped_frames;
} }
return n; return n;
} }
......
...@@ -303,7 +303,9 @@ constexpr FlagDefaultArg DefaultArg(char) { ...@@ -303,7 +303,9 @@ constexpr FlagDefaultArg DefaultArg(char) {
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// Flag current value auxiliary structs. // Flag current value auxiliary structs.
constexpr int64_t UninitializedFlagValue() { return 0xababababababababll; } constexpr int64_t UninitializedFlagValue() {
return static_cast<int64_t>(0xababababababababll);
}
template <typename T> template <typename T>
using FlagUseValueAndInitBitStorage = std::integral_constant< using FlagUseValueAndInitBitStorage = std::integral_constant<
...@@ -755,8 +757,8 @@ void* FlagOps(FlagOp op, const void* v1, void* v2, void* v3) { ...@@ -755,8 +757,8 @@ void* FlagOps(FlagOp op, const void* v1, void* v2, void* v3) {
case FlagOp::kValueOffset: { case FlagOp::kValueOffset: {
// Round sizeof(FlagImp) to a multiple of alignof(FlagValue<T>) to get the // Round sizeof(FlagImp) to a multiple of alignof(FlagValue<T>) to get the
// offset of the data. // offset of the data.
ptrdiff_t round_to = alignof(FlagValue<T>); size_t round_to = alignof(FlagValue<T>);
ptrdiff_t offset = size_t offset =
(sizeof(FlagImpl) + round_to - 1) / round_to * round_to; (sizeof(FlagImpl) + round_to - 1) / round_to * round_to;
return reinterpret_cast<void*>(offset); return reinterpret_cast<void*>(offset);
} }
......
...@@ -144,7 +144,7 @@ StringConvertResult FormatConvertImpl(const AbslCord& value, ...@@ -144,7 +144,7 @@ StringConvertResult FormatConvertImpl(const AbslCord& value,
size_t space_remaining = 0; size_t space_remaining = 0;
int width = conv.width(); int width = conv.width();
if (width >= 0) space_remaining = width; if (width >= 0) space_remaining = static_cast<size_t>(width);
size_t to_write = value.size(); size_t to_write = value.size();
......
...@@ -70,7 +70,7 @@ class FormatSinkImpl { ...@@ -70,7 +70,7 @@ class FormatSinkImpl {
~FormatSinkImpl() { Flush(); } ~FormatSinkImpl() { Flush(); }
void Flush() { void Flush() {
raw_.Write(string_view(buf_, pos_ - buf_)); raw_.Write(string_view(buf_, static_cast<size_t>(pos_ - buf_)));
pos_ = buf_; pos_ = buf_;
} }
...@@ -120,7 +120,9 @@ class FormatSinkImpl { ...@@ -120,7 +120,9 @@ class FormatSinkImpl {
} }
private: private:
size_t Avail() const { return buf_ + sizeof(buf_) - pos_; } size_t Avail() const {
return static_cast<size_t>(buf_ + sizeof(buf_) - pos_);
}
FormatRawSinkImpl raw_; FormatRawSinkImpl raw_;
size_t size_ = 0; size_t size_ = 0;
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#define ABSL_STRINGS_INTERNAL_STR_FORMAT_OUTPUT_H_ #define ABSL_STRINGS_INTERNAL_STR_FORMAT_OUTPUT_H_
#include <cstdio> #include <cstdio>
#include <ios>
#include <ostream> #include <ostream>
#include <string> #include <string>
...@@ -71,7 +72,7 @@ inline void AbslFormatFlush(std::string* out, string_view s) { ...@@ -71,7 +72,7 @@ inline void AbslFormatFlush(std::string* out, string_view s) {
out->append(s.data(), s.size()); out->append(s.data(), s.size());
} }
inline void AbslFormatFlush(std::ostream* out, string_view s) { inline void AbslFormatFlush(std::ostream* out, string_view s) {
out->write(s.data(), s.size()); out->write(s.data(), static_cast<std::streamsize>(s.size()));
} }
inline void AbslFormatFlush(FILERawSink* sink, string_view v) { inline void AbslFormatFlush(FILERawSink* sink, string_view v) {
......
...@@ -151,7 +151,8 @@ bool ParseFormatString(string_view src, Consumer consumer) { ...@@ -151,7 +151,8 @@ bool ParseFormatString(string_view src, Consumer consumer) {
const char* p = src.data(); const char* p = src.data();
const char* const end = p + src.size(); const char* const end = p + src.size();
while (p != end) { while (p != end) {
const char* percent = static_cast<const char*>(memchr(p, '%', end - p)); const char* percent =
static_cast<const char*>(memchr(p, '%', static_cast<size_t>(end - p)));
if (!percent) { if (!percent) {
// We found the last substring. // We found the last substring.
return consumer.Append(string_view(p, end - p)); return consumer.Append(string_view(p, end - p));
...@@ -242,7 +243,8 @@ class ParsedFormatBase { ...@@ -242,7 +243,8 @@ class ParsedFormatBase {
string_view text(base, 0); string_view text(base, 0);
for (const auto& item : items_) { for (const auto& item : items_) {
const char* const end = text.data() + text.size(); const char* const end = text.data() + text.size();
text = string_view(end, (base + item.text_end) - end); text =
string_view(end, static_cast<size_t>((base + item.text_end) - end));
if (item.is_conversion) { if (item.is_conversion) {
if (!consumer.ConvertOne(item.conv, text)) return false; if (!consumer.ConvertOne(item.conv, text)) return false;
} else { } else {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment