[compiler-rt] [win/asan] Add a test skeleton for function GetInstructionSize. (PR #116948)

via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 20 05:03:44 PST 2024


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff 47ef5c4b7f85bc1c8a859d721db9fd1dde7b8d8e 47328b1848e34a7477e892af77fe5221eb92ac26 --extensions cpp,h -- compiler-rt/lib/interception/interception_win.cpp compiler-rt/lib/interception/interception_win.h compiler-rt/lib/interception/tests/interception_win_test.cpp
``````````

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/compiler-rt/lib/interception/interception_win.cpp b/compiler-rt/lib/interception/interception_win.cpp
index ac5c5f7da8..d01548088a 100644
--- a/compiler-rt/lib/interception/interception_win.cpp
+++ b/compiler-rt/lib/interception/interception_win.cpp
@@ -544,7 +544,6 @@ static const u8 kPrologueWithShortJump2[] = {
 
 // Returns 0 on error.
 static size_t GetInstructionSize(uptr address, size_t* rel_offset = nullptr) {
-
   if (rel_offset) {
     *rel_offset = 0;
   }
@@ -913,7 +912,7 @@ static size_t GetInstructionSize(uptr address, size_t* rel_offset = nullptr) {
 }
 
 // Unfortunately size_t is not known when compiling asan_allocator.cpp
-SIZE_T TestOnlyGetInstructionSize(uptr address, SIZE_T* rel_offset) {
+SIZE_T TestOnlyGetInstructionSize(uptr address, SIZE_T *rel_offset) {
   return GetInstructionSize(address, rel_offset);
 }
 
diff --git a/compiler-rt/lib/interception/interception_win.h b/compiler-rt/lib/interception/interception_win.h
index 1c66997730..91c7e38bfe 100644
--- a/compiler-rt/lib/interception/interception_win.h
+++ b/compiler-rt/lib/interception/interception_win.h
@@ -64,7 +64,7 @@ bool OverrideFunctionWithTrampoline(
 void TestOnlyReleaseTrampolineRegions();
 
 // Exposed for unittests
-SIZE_T TestOnlyGetInstructionSize(uptr address, SIZE_T* rel_offset);
+SIZE_T TestOnlyGetInstructionSize(uptr address, SIZE_T *rel_offset);
 
 }  // namespace __interception
 
diff --git a/compiler-rt/lib/interception/tests/interception_win_test.cpp b/compiler-rt/lib/interception/tests/interception_win_test.cpp
index 29141438f8..361168e68b 100644
--- a/compiler-rt/lib/interception/tests/interception_win_test.cpp
+++ b/compiler-rt/lib/interception/tests/interception_win_test.cpp
@@ -794,34 +794,40 @@ TEST(Interception, EmptyExportTable) {
 }
 
 const struct InstructionSizeData_t {
-  size_t size;       // hold instruction size or 0 for failure, e.g. on control instructions
+  size_t size;  // hold instruction size or 0 for failure, e.g. on control
+                // instructions
   u8 instr[16];
   size_t rel_offset;
 } data[] = {
-  /* sorted list */
-  {  1, { 0x50 }, 0 },  // 50 : push eax / rax
+    /* sorted list */
+    {1, {0x50}, 0},  // 50 : push eax / rax
 };
 
-std::string dumpInstruction(unsigned int arrayIndex, const InstructionSizeData_t& data) {
-    std::stringstream ret;
-    ret << "  with arrayIndex=" << arrayIndex << " ( ";
-    for (size_t byteIndex = 0; byteIndex < data.size; byteIndex++) {
-        ret << std::setfill('0') << std::setw(2) << std::right << std::hex << (int)data.instr[byteIndex] << " ";
-    }
-    ret << ")";
-    return ret.str();
+std::string dumpInstruction(unsigned int arrayIndex,
+                            const InstructionSizeData_t &data) {
+  std::stringstream ret;
+  ret << "  with arrayIndex=" << arrayIndex << " ( ";
+  for (size_t byteIndex = 0; byteIndex < data.size; byteIndex++) {
+    ret << std::setfill('0') << std::setw(2) << std::right << std::hex
+        << (int)data.instr[byteIndex] << " ";
+  }
+  ret << ")";
+  return ret.str();
 }
 
 TEST(Interception, GetInstructionSize) {
-
   size_t size;
   size_t rel_offset;
 
-  for (unsigned int arrayIndex = 0; arrayIndex < sizeof(data)/sizeof(*data); arrayIndex++) {
+  for (unsigned int arrayIndex = 0; arrayIndex < sizeof(data) / sizeof(*data);
+       arrayIndex++) {
     rel_offset = ~0L;
-    size = __interception::TestOnlyGetInstructionSize((uptr)data[arrayIndex].instr, &rel_offset);
-    EXPECT_EQ(data[arrayIndex].size, size) << dumpInstruction(arrayIndex, data[arrayIndex]);
-    EXPECT_EQ(data[arrayIndex].rel_offset, rel_offset) << dumpInstruction(arrayIndex, data[arrayIndex]);
+    size = __interception::TestOnlyGetInstructionSize(
+        (uptr)data[arrayIndex].instr, &rel_offset);
+    EXPECT_EQ(data[arrayIndex].size, size)
+        << dumpInstruction(arrayIndex, data[arrayIndex]);
+    EXPECT_EQ(data[arrayIndex].rel_offset, rel_offset)
+        << dumpInstruction(arrayIndex, data[arrayIndex]);
   }
 }
 

``````````

</details>


https://github.com/llvm/llvm-project/pull/116948


More information about the llvm-commits mailing list