[PATCH] D28849: [compiler-rt] [test] Fix page address logic in clear_cache_test to use binary negation

Michał Górny via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Jan 18 00:56:29 PST 2017

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.




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;

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D28849.84806.patch
Type: text/x-patch
Size: 662 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170118/6cc93f27/attachment.bin>

More information about the cfe-commits mailing list