[llvm-commits] [PATCH] Try to figure out <size> argument in llvm.lifetime intrinsics

Alexey Samsonov samsonov at google.com
Sun Nov 11 10:17:18 PST 2012


On Sun, Nov 11, 2012 at 10:10 PM, Dmitri Gribenko <gribozavr at gmail.com>wrote:

> On Sun, Nov 11, 2012 at 7:32 PM, Dmitry N. Mikushin <maemarcus at gmail.com>
> wrote:
> > In case of stack reuse there should be another llvm.livetime start/end
> > region, isn't it?
>
> I was thinking about something like this:
>
> $ cat a.c
> #include <stdio.h>
>
> void store_ptr(int *);
> int *load_ptr(void);
> int ret_int(void);
> void use_ptr(int *);
> extern int global;
>
> int main()
> {
>   {
>     int i[8];
>     store_ptr(i);
>   }
>   {
>     int j[8];
>     j[0] = ret_int();
>     use_ptr(j);
>     int *k = load_ptr();
>     *k = 42;
>     use_ptr(j);
>     printf("%d\n", global);
>   }
> }
>
> $ cat b.c
> static int *ptr;
>
> void store_ptr(int *p) { ptr = p; }
> int *load_ptr(void) { return ptr; }
> int ret_int() { return 7; }
> int global;
> void use_ptr(int *p) { global = *p; }
>
> Currently ASan does not catch an issue in this code, but with lifetime
> markers emitted by Clang, it should.
>
> Here 'i' and 'j' would occupy different addresses without stack reuse.
>  In this case, 'i' would be still allocated while 'j' is alive, but
> 'i' would be poisoned.  With stack reuse, 'i' and 'j' will most likely
> occupy the same block of memory.
>

I see. But we can explicitly turn off stack reuse optimization in ASan mode.


>
> Dmitri
>
> --
> main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if
> (j){printf("%d\n",i);}}} /*Dmitri Gribenko <gribozavr at gmail.com>*/
>



-- 
Alexey Samsonov, MSK
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20121111/9e6d33fc/attachment.html>


More information about the llvm-commits mailing list