forked from OSchip/llvm-project
[sanitizer] Fix VSNPrintf %V on Windows
This commit is contained in:
parent
2a399e60b6
commit
2bc07083a2
|
@ -990,7 +990,7 @@ struct SignalContext {
|
|||
};
|
||||
|
||||
void InitializePlatformEarly();
|
||||
void MaybeReexec();
|
||||
void MaybeReexec();
|
||||
|
||||
template <typename Fn>
|
||||
class RunOnDestruction {
|
||||
|
@ -1057,6 +1057,13 @@ class ArrayRef {
|
|||
T *end_ = nullptr;
|
||||
};
|
||||
|
||||
#define PRINTF_128(v) \
|
||||
(*((u8 *)&v + 0)), (*((u8 *)&v + 1)), (*((u8 *)&v + 2)), (*((u8 *)&v + 3)), \
|
||||
(*((u8 *)&v + 4)), (*((u8 *)&v + 5)), (*((u8 *)&v + 6)), \
|
||||
(*((u8 *)&v + 7)), (*((u8 *)&v + 8)), (*((u8 *)&v + 9)), \
|
||||
(*((u8 *)&v + 10)), (*((u8 *)&v + 11)), (*((u8 *)&v + 12)), \
|
||||
(*((u8 *)&v + 13)), (*((u8 *)&v + 14)), (*((u8 *)&v + 15))
|
||||
|
||||
} // namespace __sanitizer
|
||||
|
||||
inline void *operator new(__sanitizer::operator_new_size_type size,
|
||||
|
|
|
@ -132,7 +132,7 @@ static int AppendPointer(char **buff, const char *buff_end, u64 ptr_value) {
|
|||
int VSNPrintf(char *buff, int buff_length,
|
||||
const char *format, va_list args) {
|
||||
static const char *kPrintfFormatsHelp =
|
||||
"Supported Printf formats: %([0-9]*)?(z|ll)?{d,u,x,X}; %p; "
|
||||
"Supported Printf formats: %([0-9]*)?(z|ll)?{d,u,x,X,V}; %p; "
|
||||
"%[-]([0-9]*)?(\\.\\*)?s; %c\n";
|
||||
RAW_CHECK(format);
|
||||
RAW_CHECK(buff_length > 0);
|
||||
|
@ -190,16 +190,13 @@ int VSNPrintf(char *buff, int buff_length,
|
|||
width, pad_with_zero, uppercase);
|
||||
break;
|
||||
}
|
||||
#if defined(__x86_64__)
|
||||
case 'V': {
|
||||
__m128i v = va_arg(args, __m128i);
|
||||
u8 x[sizeof(v)];
|
||||
internal_memcpy(x, &v, sizeof(x));
|
||||
for (uptr i = 0; i < sizeof(x); i++)
|
||||
result += AppendUnsigned(&buff, buff_end, x[i], 16, 2, true, false);
|
||||
for (uptr i = 0; i < 16; i++) {
|
||||
unsigned x = va_arg(args, unsigned);
|
||||
result += AppendUnsigned(&buff, buff_end, x, 16, 2, true, false);
|
||||
}
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
case 'p': {
|
||||
RAW_CHECK_MSG(!have_flags, kPrintfFormatsHelp);
|
||||
result += AppendPointer(&buff, buff_end, va_arg(args, uptr));
|
||||
|
|
|
@ -162,12 +162,12 @@ TEST(Printf, Precision) {
|
|||
TEST(Printf, M128) {
|
||||
__m128i v = _mm_set_epi32(0x12345678, 0x0a0a0a0a, 0xb0b0b0b0, 0xaabbccdd);
|
||||
char buf[128];
|
||||
internal_snprintf(buf, sizeof(buf), "%V", v);
|
||||
internal_snprintf(buf, sizeof(buf), "%V", PRINTF_128(v));
|
||||
EXPECT_STREQ("ddccbbaab0b0b0b00a0a0a0a78563412", buf);
|
||||
v = _mm_cvtsi32_si128(0x12345678);
|
||||
internal_snprintf(buf, sizeof(buf), "%V", v);
|
||||
internal_snprintf(buf, sizeof(buf), "%V", PRINTF_128(v));
|
||||
EXPECT_STREQ("78563412000000000000000000000000", buf);
|
||||
internal_snprintf(buf, sizeof(buf), "%d %V", 0, v);
|
||||
internal_snprintf(buf, sizeof(buf), "%d %V", 0, PRINTF_128(v));
|
||||
EXPECT_STREQ("0 78563412000000000000000000000000", buf);
|
||||
}
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue