mgorny created this revision.
Herald added a subscriber: dberris.

Fix the logic used to calculate page address in clear_cache_test to use
the binary negation of 4095 rather than arithmetic. The latter gives
incorrect result since:

  -4095 -> 0xfffff001
  ~4095 -> 0xfffff000

Alternatively, -4096 could be used to obtain the correct result.
However, considering the confusion caused by this so far I think it's
better to use binary negation explicitly.

The issue went unnoticed so far because the array alignment caused
the last bit not to be set. However, on 32-bit x86 no such alignment is
enforced and the wrong page address caused the test to fail.


Repository:
  rL LLVM

https://reviews.llvm.org/D28849

Files:
  test/builtins/Unit/clear_cache_test.c


Index: test/builtins/Unit/clear_cache_test.c
===================================================================
--- test/builtins/Unit/clear_cache_test.c
+++ test/builtins/Unit/clear_cache_test.c
@@ -56,8 +56,8 @@
 int main()
 {
     // make executable the page containing execution_buffer 
-    char* start = (char*)((uintptr_t)execution_buffer & (-4095));
-    char* end = (char*)((uintptr_t)(&execution_buffer[128+4096]) & (-4095));
+    char* start = (char*)((uintptr_t)execution_buffer & (~4095));
+    char* end = (char*)((uintptr_t)(&execution_buffer[128+4096]) & (~4095));
 #if defined(_WIN32)
     DWORD dummy_oldProt;
     MEMORY_BASIC_INFORMATION b;


Index: test/builtins/Unit/clear_cache_test.c
===================================================================
--- test/builtins/Unit/clear_cache_test.c
+++ test/builtins/Unit/clear_cache_test.c
@@ -56,8 +56,8 @@
 int main()
 {
     // make executable the page containing execution_buffer 
-    char* start = (char*)((uintptr_t)execution_buffer & (-4095));
-    char* end = (char*)((uintptr_t)(&execution_buffer[128+4096]) & (-4095));
+    char* start = (char*)((uintptr_t)execution_buffer & (~4095));
+    char* end = (char*)((uintptr_t)(&execution_buffer[128+4096]) & (~4095));
 #if defined(_WIN32)
     DWORD dummy_oldProt;
     MEMORY_BASIC_INFORMATION b;
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to