[llvm] [Support] Fix ULEB128 test when building with MSVC (PR #93184)
Alexandre Ganea via llvm-commits
llvm-commits at lists.llvm.org
Thu May 23 05:44:50 PDT 2024
https://github.com/aganea created https://github.com/llvm/llvm-project/pull/93184
The VALUE expansion might be compiled in the different ways, because of string pooling which isn't always enabled/guaranteed. When building with MSVC, previously I was seeing empty strings `""` pointing to different addresses.
Previous test log:
```
Note: Google Test filter = LEB128Test.DecodeInvalidULEB128
[==========] Running 1 test from 1 test suite.
[----------] Global test environment set-up.
[----------] 1 test from LEB128Test
[ RUN ] LEB128Test.DecodeInvalidULEB128
C:\src\git\llvm-project\llvm\unittests\Support\LEB128Test.cpp(167): error: Expected equality of these values:
0u
Which is: 0
Value - reinterpret_cast<const uint8_t *>("")
Which is: -5
C:\src\git\llvm-project\llvm\unittests\Support\LEB128Test.cpp(168): error: Expected equality of these values:
1u
Which is: 1
Value - reinterpret_cast<const uint8_t *>("\x80")
Which is: -167
C:\src\git\llvm-project\llvm\unittests\Support\LEB128Test.cpp(171): error: Expected equality of these values:
9u
Which is: 9
Value - reinterpret_cast<const uint8_t *>("\x80\x80\x80\x80\x80\x80\x80\x80\x80\x02")
Which is: -167
C:\src\git\llvm-project\llvm\unittests\Support\LEB128Test.cpp(172): error: Expected equality of these values:
10u
Which is: 10
Value - reinterpret_cast<const uint8_t *>("\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x02")
Which is: -166
[ FAILED ] LEB128Test.DecodeInvalidULEB128 (2 ms)
[----------] 1 test from LEB128Test (2 ms total)
[----------] Global test environment tear-down
[==========] 1 test from 1 test suite ran. (4 ms total)
[ PASSED ] 0 tests.
[ FAILED ] 1 test, listed below:
[ FAILED ] LEB128Test.DecodeInvalidULEB128
1 FAILED TEST
```
>From 5d4ad628e12454aa9e88e58f5e8a3b20aacb2f33 Mon Sep 17 00:00:00 2001
From: Alexandre Ganea <aganea at havenstudios.com>
Date: Thu, 23 May 2024 08:39:46 -0400
Subject: [PATCH] [Support] Fix ULEB128 test when building with MSVC
---
llvm/unittests/Support/LEB128Test.cpp | 20 +++++++++++++-------
1 file changed, 13 insertions(+), 7 deletions(-)
diff --git a/llvm/unittests/Support/LEB128Test.cpp b/llvm/unittests/Support/LEB128Test.cpp
index 60f5ddd568cad..5aa7139c45a7a 100644
--- a/llvm/unittests/Support/LEB128Test.cpp
+++ b/llvm/unittests/Support/LEB128Test.cpp
@@ -147,7 +147,8 @@ TEST(LEB128Test, DecodeULEB128) {
TEST(LEB128Test, DecodeInvalidULEB128) {
#define EXPECT_INVALID_ULEB128(VALUE, ERROR_OFFSET) \
do { \
- const uint8_t *Value = reinterpret_cast<const uint8_t *>(VALUE); \
+ const char *DefaultValue = VALUE; \
+ const uint8_t *Value = reinterpret_cast<const uint8_t *>(DefaultValue); \
const char *Error = nullptr; \
unsigned ErrorOffset = 0; \
uint64_t Actual = \
@@ -155,12 +156,13 @@ TEST(LEB128Test, DecodeInvalidULEB128) {
EXPECT_NE(Error, nullptr); \
EXPECT_EQ(0ul, Actual); \
EXPECT_EQ(ERROR_OFFSET, ErrorOffset); \
- Value = reinterpret_cast<const uint8_t *>(VALUE); \
+ Value = reinterpret_cast<const uint8_t *>(DefaultValue); \
Error = nullptr; \
Actual = decodeULEB128AndInc(Value, Value + strlen(VALUE), &Error); \
EXPECT_NE(Error, nullptr); \
EXPECT_EQ(0ul, Actual); \
- EXPECT_EQ(ERROR_OFFSET, Value - reinterpret_cast<const uint8_t *>(VALUE)); \
+ EXPECT_EQ(ERROR_OFFSET, \
+ Value - reinterpret_cast<const uint8_t *>(DefaultValue)); \
} while (0)
// Buffer overflow.
@@ -222,7 +224,8 @@ TEST(LEB128Test, DecodeSLEB128) {
TEST(LEB128Test, DecodeInvalidSLEB128) {
#define EXPECT_INVALID_SLEB128(VALUE, ERROR_OFFSET) \
do { \
- const uint8_t *Value = reinterpret_cast<const uint8_t *>(VALUE); \
+ const char *DefaultValue = VALUE; \
+ const uint8_t *Value = reinterpret_cast<const uint8_t *>(DefaultValue); \
const char *Error = nullptr; \
unsigned ErrorOffset = 0; \
uint64_t Actual = \
@@ -230,12 +233,13 @@ TEST(LEB128Test, DecodeInvalidSLEB128) {
EXPECT_NE(Error, nullptr); \
EXPECT_EQ(0ul, Actual); \
EXPECT_EQ(ERROR_OFFSET, ErrorOffset); \
- Value = reinterpret_cast<const uint8_t *>(VALUE); \
+ Value = reinterpret_cast<const uint8_t *>(DefaultValue); \
Error = nullptr; \
Actual = decodeSLEB128AndInc(Value, Value + strlen(VALUE), &Error); \
EXPECT_NE(Error, nullptr); \
EXPECT_EQ(0ul, Actual); \
- EXPECT_EQ(ERROR_OFFSET, Value - reinterpret_cast<const uint8_t *>(VALUE)); \
+ EXPECT_EQ(ERROR_OFFSET, \
+ Value - reinterpret_cast<const uint8_t *>(DefaultValue)); \
} while (0)
// Buffer overflow.
@@ -257,7 +261,9 @@ TEST(LEB128Test, DecodeInvalidSLEB128) {
TEST(LEB128Test, DecodeAndInc) {
#define EXPECT_LEB128(FUN, VALUE, SIZE) \
do { \
- const uint8_t *V = reinterpret_cast<const uint8_t *>(VALUE), *P = V; \
+ const char *DefaultValue = VALUE; \
+ const uint8_t *V = reinterpret_cast<const uint8_t *>(DefaultValue), \
+ *P = V; \
auto Expected = FUN(P), Actual = FUN##AndInc(P, P + strlen(VALUE)); \
EXPECT_EQ(Actual, Expected); \
EXPECT_EQ(P - V, SIZE); \
More information about the llvm-commits
mailing list