[ASan] Disable dynamic alloca and UAR detection in presence of returns_twice calls.
authorAlexey Samsonov <vonosmas@gmail.com>
Wed, 29 Jul 2015 19:36:08 +0000 (19:36 +0000)
committerAlexey Samsonov <vonosmas@gmail.com>
Wed, 29 Jul 2015 19:36:08 +0000 (19:36 +0000)
commit67e53da671b698a89864d2b6df8904456eb1a8ee
treebd1ef673e63f136e6213d0e5ed0ccf45e13cd31e
parent55e9a41ac8f910814bfe4078e8efe58c55f56679
[ASan] Disable dynamic alloca and UAR detection in presence of returns_twice calls.

Summary:
returns_twice (most importantly, setjmp) functions are
optimization-hostile: if local variable is promoted to register, and is
changed between setjmp() and longjmp() calls, this update will be
undone. This is the reason why "man setjmp" advises to mark all these
locals as "volatile".

This can not be enough for ASan, though: when it replaces static alloca
with dynamic one, optionally called if UAR mode is enabled, it adds a
whole lot of SSA values, and computations of local variable addresses,
that can involve virtual registers, and cause unexpected behavior, when
these registers are restored from buffer saved in setjmp.

To fix this, just disable dynamic alloca and UAR tricks whenever we see
a returns_twice call in the function.

Reviewers: rnk

Subscribers: llvm-commits, kcc

Differential Revision: http://reviews.llvm.org/D11495

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@243561 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Transforms/Instrumentation/AddressSanitizer.cpp
test/Instrumentation/AddressSanitizer/stack_dynamic_alloca.ll