1 // RUN: %clangxx_msan -O0 %s -o %t && %run %t 2 3 // Check that strlen() and similar intercepted functions can be called on shadow 4 // memory. 5 6 #include <assert.h> 7 #include <stdint.h> 8 #include <stdio.h> 9 #include <string.h> 10 11 const char *mem_to_shadow(const char *p) { 12 #if defined(__x86_64__) 13 return (char *)((uintptr_t)p & ~0x400000000000ULL); 14 #elif defined (__mips64) 15 return (char *)((uintptr_t)p & ~0x4000000000ULL); 16 #endif 17 } 18 19 int main(void) { 20 const char *s = "abcdef"; 21 assert(strlen(s) == 6); 22 assert(strlen(mem_to_shadow(s)) == 0); 23 24 char *t = new char[42]; 25 t[41] = 0; 26 assert(strlen(mem_to_shadow(t)) == 41); 27 return 0; 28 } 29