<div dir="ltr">Thanks.<div>Done: <a href="https://reviews.llvm.org/D23676">https://reviews.llvm.org/D23676</a></div></div><br><div class="gmail_quote"><div dir="ltr">On Thu, Aug 18, 2016 at 5:46 AM Filipe Cabecinhas <<a href="mailto:filcab%2Bllvm.phabricator@gmail.com">filcab+llvm.phabricator@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Vitaly,<br>
<br>
Can you add a test for this?<br>
<br>
Something like this would probably work:<br>
////////////////////////////////////////////<br>
// RUN: %run %t 0x00 | FileCheck %s -check-prefix=X00<br>
// RUN: %run %t 0xf1 | FileCheck %s -check-prefix=XF1<br>
// RUN: %run %t 0xf2 | FileCheck %s -check-prefix=XF2<br>
// RUN: %run %t 0xf3 | FileCheck %s -check-prefix=XF3<br>
// RUN: %run %t 0xf5 | FileCheck %s -check-prefix=XF5<br>
// RUN: %run %t 0xf8 | FileCheck %s -check-prefix=XF8<br>
<br>
#include <assert.h><br>
#include <stdlib.h><br>
#include <stddef.h><br>
#include <sanitizer/asan_interface.h><br>
<br>
size_t shadow_offset;<br>
size_t shadow_scale;<br>
#define MEM_TO_SHADOW(addr) ((addr >> shadow_scale) + shadow_offset)<br>
<br>
extern "C" {<br>
void __asan_set_shadow_00(size_t addr, size_t size);<br>
void __asan_set_shadow_f1(size_t addr, size_t size);<br>
void __asan_set_shadow_f2(size_t addr, size_t size);<br>
void __asan_set_shadow_f3(size_t addr, size_t size);<br>
void __asan_set_shadow_f5(size_t addr, size_t size);<br>
void __asan_set_shadow_f8(size_t addr, size_t size);<br>
}<br>
<br>
char f(char *a) {<br>
return *a;<br>
}<br>
<br>
long g(long arg) {<br>
char arr[1] __attribute__((aligned(8)));<br>
size_t iarr = (size_t)arr;<br>
<br>
switch (arg) {<br>
#define CASE(xx) case 0x##xx: \<br>
__asan_set_shadow_##xx(MEM_TO_SHADOW(iarr), 1); \<br>
return *arr;<br>
// X00-NOT: AddressSanitizer<br>
CASE(00);<br>
// XF1: AddressSanitizer: stack-buffer-underflow<br>
// XF1: [f1]<br>
CASE(f1);<br>
// XF2: AddressSanitizer: stack-buffer-overflow<br>
// XF2: [f2]<br>
CASE(f2);<br>
// XF3: AddressSanitizer: stack-buffer-overflow<br>
// XF3: [f3]<br>
CASE(f3);<br>
// XF5: AddressSanitizer: stack-use-after-return<br>
// XF5: [f5]<br>
CASE(f5);<br>
// XF8: AddressSanitizer: stack-use-after-scope<br>
// XF8: [f8]<br>
CASE(f8);<br>
#undef CASE<br>
}<br>
assert(false);<br>
}<br>
<br>
int main(int argc, char **argv) {<br>
assert(argc > 1);<br>
__asan_get_shadow_mapping(&shadow_scale, &shadow_offset);<br>
<br>
<br>
long arg = strtol(argv[1], nullptr, 16);<br>
g(arg);<br>
puts("Done"); // Otherwise we get: FileCheck error: '-' is empty<br>
return 0;<br>
}<br>
////////////////////////////////////////////<br>
<br>
That way, you end up testing that the shadow address does get<br>
poisoned/unpoisoned with the value you want.<br>
<br>
Thank you,<br>
<br>
Filipe<br>
</blockquote></div>