Changes imported from Abseil "staging" branch:
- 1320147f7597a9490562d439ecea46faa1793a24 Support Hex formatting of pointers without forcing a cast... by Jorg Brown <jorg@google.com> - 13c793d6e14a52063c2d4ee327b6c976631b690e Add support for native WebAssembly llvm backend. by Abseil Team <absl-team@google.com> GitOrigin-RevId: 1320147f7597a9490562d439ecea46faa1793a24 Change-Id: Ibd4dbf288903ab45387932e5b11a28f5accdf166
This commit is contained in:
parent
506fb4b56a
commit
4e2e6c5c00
7 changed files with 45 additions and 15 deletions
|
@ -250,6 +250,7 @@
|
||||||
// Windows _WIN32
|
// Windows _WIN32
|
||||||
// NaCL __native_client__
|
// NaCL __native_client__
|
||||||
// AsmJS __asmjs__
|
// AsmJS __asmjs__
|
||||||
|
// WebAssembly __wasm__
|
||||||
// Fuchsia __Fuchsia__
|
// Fuchsia __Fuchsia__
|
||||||
//
|
//
|
||||||
// Note that since Android defines both __ANDROID__ and __linux__, one
|
// Note that since Android defines both __ANDROID__ and __linux__, one
|
||||||
|
@ -263,7 +264,7 @@
|
||||||
#error ABSL_HAVE_MMAP cannot be directly set
|
#error ABSL_HAVE_MMAP cannot be directly set
|
||||||
#elif defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) || \
|
#elif defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) || \
|
||||||
defined(__ros__) || defined(__native_client__) || defined(__asmjs__) || \
|
defined(__ros__) || defined(__native_client__) || defined(__asmjs__) || \
|
||||||
defined(__Fuchsia__)
|
defined(__wasm__) || defined(__Fuchsia__)
|
||||||
#define ABSL_HAVE_MMAP 1
|
#define ABSL_HAVE_MMAP 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,7 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(__ELF__) && defined(__GLIBC__) && !defined(__native_client__) && \
|
#if defined(__ELF__) && defined(__GLIBC__) && !defined(__native_client__) && \
|
||||||
!defined(__asmjs__)
|
!defined(__asmjs__) && !defined(__wasm__)
|
||||||
#define ABSL_HAVE_ELF_MEM_IMAGE 1
|
#define ABSL_HAVE_ELF_MEM_IMAGE 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
#error ABSL_STACKTRACE_INL_HEADER cannot be directly set
|
#error ABSL_STACKTRACE_INL_HEADER cannot be directly set
|
||||||
#elif defined(__native_client__) || defined(__APPLE__) || \
|
#elif defined(__native_client__) || defined(__APPLE__) || \
|
||||||
defined(__FreeBSD__) || defined(__ANDROID__) || defined(__myriad2__) || \
|
defined(__FreeBSD__) || defined(__ANDROID__) || defined(__myriad2__) || \
|
||||||
defined(__asmjs__) || defined(__Fuchsia__)
|
defined(__asmjs__) || defined(__wasm__) || defined(__Fuchsia__)
|
||||||
#define ABSL_STACKTRACE_INL_HEADER \
|
#define ABSL_STACKTRACE_INL_HEADER \
|
||||||
"absl/debugging/internal/stacktrace_unimplemented-inl.inc"
|
"absl/debugging/internal/stacktrace_unimplemented-inl.inc"
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
#ifdef ABSL_INTERNAL_HAVE_ELF_SYMBOLIZE
|
#ifdef ABSL_INTERNAL_HAVE_ELF_SYMBOLIZE
|
||||||
#error ABSL_INTERNAL_HAVE_ELF_SYMBOLIZE cannot be directly set
|
#error ABSL_INTERNAL_HAVE_ELF_SYMBOLIZE cannot be directly set
|
||||||
#elif defined(__ELF__) && defined(__GLIBC__) && !defined(__native_client__) && \
|
#elif defined(__ELF__) && defined(__GLIBC__) && !defined(__native_client__) && \
|
||||||
!defined(__asmjs__)
|
!defined(__asmjs__) && !defined(__wasm__)
|
||||||
#define ABSL_INTERNAL_HAVE_ELF_SYMBOLIZE 1
|
#define ABSL_INTERNAL_HAVE_ELF_SYMBOLIZE 1
|
||||||
|
|
||||||
#include <elf.h>
|
#include <elf.h>
|
||||||
|
|
|
@ -127,21 +127,32 @@ struct Hex {
|
||||||
char fill;
|
char fill;
|
||||||
|
|
||||||
template <typename Int>
|
template <typename Int>
|
||||||
explicit Hex(Int v, PadSpec spec = absl::kNoPad,
|
explicit Hex(
|
||||||
typename std::enable_if<sizeof(Int) == 1>::type* = nullptr)
|
Int v, PadSpec spec = absl::kNoPad,
|
||||||
|
typename std::enable_if<sizeof(Int) == 1 &&
|
||||||
|
!std::is_pointer<Int>::value>::type* = nullptr)
|
||||||
: Hex(spec, static_cast<uint8_t>(v)) {}
|
: Hex(spec, static_cast<uint8_t>(v)) {}
|
||||||
template <typename Int>
|
template <typename Int>
|
||||||
explicit Hex(Int v, PadSpec spec = absl::kNoPad,
|
explicit Hex(
|
||||||
typename std::enable_if<sizeof(Int) == 2>::type* = nullptr)
|
Int v, PadSpec spec = absl::kNoPad,
|
||||||
|
typename std::enable_if<sizeof(Int) == 2 &&
|
||||||
|
!std::is_pointer<Int>::value>::type* = nullptr)
|
||||||
: Hex(spec, static_cast<uint16_t>(v)) {}
|
: Hex(spec, static_cast<uint16_t>(v)) {}
|
||||||
template <typename Int>
|
template <typename Int>
|
||||||
explicit Hex(Int v, PadSpec spec = absl::kNoPad,
|
explicit Hex(
|
||||||
typename std::enable_if<sizeof(Int) == 4>::type* = nullptr)
|
Int v, PadSpec spec = absl::kNoPad,
|
||||||
|
typename std::enable_if<sizeof(Int) == 4 &&
|
||||||
|
!std::is_pointer<Int>::value>::type* = nullptr)
|
||||||
: Hex(spec, static_cast<uint32_t>(v)) {}
|
: Hex(spec, static_cast<uint32_t>(v)) {}
|
||||||
template <typename Int>
|
template <typename Int>
|
||||||
explicit Hex(Int v, PadSpec spec = absl::kNoPad,
|
explicit Hex(
|
||||||
typename std::enable_if<sizeof(Int) == 8>::type* = nullptr)
|
Int v, PadSpec spec = absl::kNoPad,
|
||||||
|
typename std::enable_if<sizeof(Int) == 8 &&
|
||||||
|
!std::is_pointer<Int>::value>::type* = nullptr)
|
||||||
: Hex(spec, static_cast<uint64_t>(v)) {}
|
: Hex(spec, static_cast<uint64_t>(v)) {}
|
||||||
|
template <typename Pointee>
|
||||||
|
explicit Hex(Pointee* v, PadSpec spec = absl::kNoPad)
|
||||||
|
: Hex(spec, reinterpret_cast<uintptr_t>(v)) {}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Hex(PadSpec spec, uint64_t v)
|
Hex(PadSpec spec, uint64_t v)
|
||||||
|
|
|
@ -234,7 +234,7 @@ TEST(StrCat, CustomAllocator) {
|
||||||
|
|
||||||
TEST(StrCat, MaxArgs) {
|
TEST(StrCat, MaxArgs) {
|
||||||
std::string result;
|
std::string result;
|
||||||
// Test 10 up to 26 arguments, the current maximum
|
// Test 10 up to 26 arguments, the old maximum
|
||||||
result = absl::StrCat(1, 2, 3, 4, 5, 6, 7, 8, 9, "a");
|
result = absl::StrCat(1, 2, 3, 4, 5, 6, 7, 8, 9, "a");
|
||||||
EXPECT_EQ(result, "123456789a");
|
EXPECT_EQ(result, "123456789a");
|
||||||
result = absl::StrCat(1, 2, 3, 4, 5, 6, 7, 8, 9, "a", "b");
|
result = absl::StrCat(1, 2, 3, 4, 5, 6, 7, 8, 9, "a", "b");
|
||||||
|
@ -469,6 +469,12 @@ void CheckHexDec64(uint64_t v) {
|
||||||
|
|
||||||
long long llv = static_cast<long long>(ullv); // NOLINT(runtime/int)
|
long long llv = static_cast<long long>(ullv); // NOLINT(runtime/int)
|
||||||
CheckDec(llv, "%lld", "%0*lld", "%*lld");
|
CheckDec(llv, "%lld", "%0*lld", "%*lld");
|
||||||
|
|
||||||
|
if (sizeof(v) == sizeof(&v)) {
|
||||||
|
auto uintptr = static_cast<uintptr_t>(v);
|
||||||
|
void* ptr = reinterpret_cast<void*>(uintptr);
|
||||||
|
CheckHex(ptr, "%llx", "%0*llx", "%*llx");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CheckHexDec32(uint32_t uv) {
|
void CheckHexDec32(uint32_t uv) {
|
||||||
|
@ -476,6 +482,12 @@ void CheckHexDec32(uint32_t uv) {
|
||||||
CheckDec(uv, "%u", "%0*u", "%*u");
|
CheckDec(uv, "%u", "%0*u", "%*u");
|
||||||
int32_t v = static_cast<int32_t>(uv);
|
int32_t v = static_cast<int32_t>(uv);
|
||||||
CheckDec(v, "%d", "%0*d", "%*d");
|
CheckDec(v, "%d", "%0*d", "%*d");
|
||||||
|
|
||||||
|
if (sizeof(v) == sizeof(&v)) {
|
||||||
|
auto uintptr = static_cast<uintptr_t>(v);
|
||||||
|
void* ptr = reinterpret_cast<void*>(uintptr);
|
||||||
|
CheckHex(ptr, "%llx", "%0*llx", "%*llx");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CheckAll(uint64_t v) {
|
void CheckAll(uint64_t v) {
|
||||||
|
|
|
@ -46,8 +46,14 @@ TEST(SubstituteTest, Substitute) {
|
||||||
// Pointer.
|
// Pointer.
|
||||||
const int* int_p = reinterpret_cast<const int*>(0x12345);
|
const int* int_p = reinterpret_cast<const int*>(0x12345);
|
||||||
std::string str = absl::Substitute("$0", int_p);
|
std::string str = absl::Substitute("$0", int_p);
|
||||||
EXPECT_EQ(absl::StrCat("0x", absl::Hex(reinterpret_cast<intptr_t>(int_p))),
|
EXPECT_EQ(absl::StrCat("0x", absl::Hex(int_p)), str);
|
||||||
str);
|
|
||||||
|
// Volatile Pointer.
|
||||||
|
// Like C++ streamed I/O, such pointers implicitly become bool
|
||||||
|
volatile int vol = 237;
|
||||||
|
volatile int *volatile volptr = &vol;
|
||||||
|
str = absl::Substitute("$0", volptr);
|
||||||
|
EXPECT_EQ("true", str);
|
||||||
|
|
||||||
// null is special. StrCat prints 0x0. Substitute prints NULL.
|
// null is special. StrCat prints 0x0. Substitute prints NULL.
|
||||||
const uint64_t* null_p = nullptr;
|
const uint64_t* null_p = nullptr;
|
||||||
|
|
Loading…
Reference in a new issue