[compiler-rt] 2bc0708 - [sanitizer] Fix VSNPrintf %V on Windows
Vitaly Buka via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 13 10:56:31 PDT 2021
Author: Vitaly Buka
Date: 2021-07-13T10:56:17-07:00
New Revision: 2bc07083a258fdbbafc9c0381e936f441f93af70
URL: https://github.com/llvm/llvm-project/commit/2bc07083a258fdbbafc9c0381e936f441f93af70
DIFF: https://github.com/llvm/llvm-project/commit/2bc07083a258fdbbafc9c0381e936f441f93af70.diff
LOG: [sanitizer] Fix VSNPrintf %V on Windows
Added:
Modified:
compiler-rt/lib/sanitizer_common/sanitizer_common.h
compiler-rt/lib/sanitizer_common/sanitizer_printf.cpp
compiler-rt/lib/sanitizer_common/tests/sanitizer_printf_test.cpp
Removed:
################################################################################
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common.h b/compiler-rt/lib/sanitizer_common/sanitizer_common.h
index 64c15f1ec64e..4336fd63db5d 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_common.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_common.h
@@ -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,
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_printf.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_printf.cpp
index cf454811b6ec..b913c92e16f1 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_printf.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_printf.cpp
@@ -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));
diff --git a/compiler-rt/lib/sanitizer_common/tests/sanitizer_printf_test.cpp b/compiler-rt/lib/sanitizer_common/tests/sanitizer_printf_test.cpp
index c47dff18590b..7a3724c3ab39 100644
--- a/compiler-rt/lib/sanitizer_common/tests/sanitizer_printf_test.cpp
+++ b/compiler-rt/lib/sanitizer_common/tests/sanitizer_printf_test.cpp
@@ -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
More information about the llvm-commits
mailing list