1 // RUN: %clangxx_msan -O0 %s -o %t && %run %t
3 // Check that strlen() and similar intercepted functions can be called on shadow
5 // The mem_to_shadow's part might need rework
6 // XFAIL: target={{.*freebsd.*}}
15 const char *mem_to_shadow(const char *p
) {
16 #if defined(__x86_64__)
17 return (char *)((uintptr_t)p
^ 0x500000000000ULL
);
18 #elif defined(__loongarch_lp64)
19 return (char *)((uintptr_t)p
^ 0x500000000000ULL
);
20 #elif defined (__mips64)
21 return (char *)((uintptr_t)p
^ 0x8000000000ULL
);
22 #elif defined(__powerpc64__)
23 #define LINEARIZE_MEM(mem) \
24 (((uintptr_t)(mem) & ~0x200000000000ULL) ^ 0x100000000000ULL)
25 return (char *)(LINEARIZE_MEM(p
) + 0x080000000000ULL
);
26 #elif defined(__s390x__)
27 return (char *)(((uintptr_t)p
& ~0xC00000000000ULL
) + 0x080000000000ULL
);
28 #elif defined(__aarch64__)
29 return (char *)((uintptr_t)p
^ 0xB00000000000ULL
);
34 const char *s
= "abcdef";
35 assert(strlen(s
) == 6);
36 assert(strlen(mem_to_shadow(s
)) == 0);
38 char *t
= new char[42];
40 assert(strlen(mem_to_shadow(t
)) == 41);