[llvm-dev] Added AllocaInsts are relocated in stack

Tim Northover via llvm-dev llvm-dev at lists.llvm.org
Fri Sep 21 06:36:24 PDT 2018


Hi Sam,

On Fri, 21 Sep 2018 at 14:05, sam djafari <sami.djafari at gmail.com> wrote:
> Thanks for your reply. However, I have seen that addressSanitizer has done this by placing redzones around each local variable.

Maybe conceptually, but as far as I can see from the IR ASAN maintains
a completely separate stack via calls to runtime support (like
__asan_stack_malloc).

> By doing so, LLVM would place them in the expected order I guess.

I doubt it. Allocating objects on the stack involves a reasonably
sophisticated algorithm to try and minimize space consumed. Some of
that involves reordering variables with different sizes so that
they're contiguous. Some involves lifetime tracking to try and share
slots if two variables are live at different points.

Combined, it means LLVM isn't going to make any guarantees that the
order you write your allocas (or anything else you have access to)
dictates the order they get laid out in memory.

Why do you think the single-allocation approach isn't appropriate?
It's really the only way to guarantee you get a block, whether done
via alloca or via callbacks like ASAN.

Cheers.

Tim.


More information about the llvm-dev mailing list