[cfi] Fix weak functions handling.
authorEvgeniy Stepanov <eugeni.stepanov@gmail.com>
Fri, 11 Nov 2016 21:39:26 +0000 (21:39 +0000)
committerEvgeniy Stepanov <eugeni.stepanov@gmail.com>
Fri, 11 Nov 2016 21:39:26 +0000 (21:39 +0000)
commit1fe189d79585b5d1aea84e6c2f3eca781e21f32f
treed801eb0cc1d5e5e479e622b0115f29d2bc1131e3
parentd4372f783b52919c569f3e2007e3ba9edb45c7fb
[cfi] Fix weak functions handling.

When a function pointer is replaced with a jumptable pointer, special
case is needed to preserve the semantics of extern_weak functions.
Since a jumptable entry can not be extern_weak, we emulate that
behaviour by replacing all references to F (the extern_weak function)
with the following expression: F != nullptr ? JumpTablePtr : nullptr.

Extra special care is needed for global initializers, since most (or
probably all) backends can not lower an initializer that includes
this kind of constant expression. Initializers like that are replaced
with a global constructor (i.e. a runtime initializer).

llvm-svn: 286636
llvm/lib/Transforms/IPO/LowerTypeTests.cpp
llvm/test/Transforms/LowerTypeTests/function-weak.ll [new file with mode: 0644]