diff options
| author | Kuba Brecka <kuba.brecka@gmail.com> | 2016-11-14 21:41:13 +0000 |
|---|---|---|
| committer | Kuba Brecka <kuba.brecka@gmail.com> | 2016-11-14 21:41:13 +0000 |
| commit | ddfdba3b01fa2ca9066feaf472feb78da1ca2cfc (patch) | |
| tree | f7bd88d769015d7c3bc086588aae672210cb6e3c /llvm/include | |
| parent | 5375fe820cff7ae7f3c5c771f28c6f5518f2ee60 (diff) | |
| download | bcm5719-llvm-ddfdba3b01fa2ca9066feaf472feb78da1ca2cfc.tar.gz bcm5719-llvm-ddfdba3b01fa2ca9066feaf472feb78da1ca2cfc.zip | |
[tsan] Add support for C++ exceptions into TSan (call __tsan_func_exit during unwinding), LLVM part
This adds support for TSan C++ exception handling, where we need to add extra calls to __tsan_func_exit when a function is exitted via exception mechanisms. Otherwise the shadow stack gets corrupted (leaked). This patch moves and enhances the existing implementation of EscapeEnumerator that finds all possible function exit points, and adds extra EH cleanup blocks where needed.
Differential Revision: https://reviews.llvm.org/D26177
llvm-svn: 286893
Diffstat (limited to 'llvm/include')
| -rw-r--r-- | llvm/include/llvm/Analysis/EHPersonalities.h | 5 | ||||
| -rw-r--r-- | llvm/include/llvm/Transforms/Utils/EscapeEnumerator.h | 49 | ||||
| -rw-r--r-- | llvm/include/llvm/Transforms/Utils/Local.h | 7 |
3 files changed, 61 insertions, 0 deletions
diff --git a/llvm/include/llvm/Analysis/EHPersonalities.h b/llvm/include/llvm/Analysis/EHPersonalities.h index a26c575cfe1..2c45ab4693e 100644 --- a/llvm/include/llvm/Analysis/EHPersonalities.h +++ b/llvm/include/llvm/Analysis/EHPersonalities.h @@ -12,6 +12,7 @@ #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/TinyPtrVector.h" +#include "llvm/ADT/Triple.h" #include "llvm/Support/ErrorHandling.h" namespace llvm { @@ -39,6 +40,10 @@ enum class EHPersonality { /// Unknown. EHPersonality classifyEHPersonality(const Value *Pers); +StringRef getEHPersonalityName(EHPersonality Pers); + +EHPersonality getDefaultEHPersonality(const Triple &T); + /// \brief Returns true if this personality function catches asynchronous /// exceptions. inline bool isAsynchronousEHPersonality(EHPersonality Pers) { diff --git a/llvm/include/llvm/Transforms/Utils/EscapeEnumerator.h b/llvm/include/llvm/Transforms/Utils/EscapeEnumerator.h new file mode 100644 index 00000000000..80d16ed4cf5 --- /dev/null +++ b/llvm/include/llvm/Transforms/Utils/EscapeEnumerator.h @@ -0,0 +1,49 @@ +//===-- EscapeEnumerator.h --------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// Defines a helper class that enumerates all possible exits from a function, +// including exception handling. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_TRANSFORMS_UTILS_ESCAPEENUMERATOR_H +#define LLVM_TRANSFORMS_UTILS_ESCAPEENUMERATOR_H + +#include "llvm/IR/IRBuilder.h" +#include "llvm/IR/Function.h" + +namespace llvm { + +/// EscapeEnumerator - This is a little algorithm to find all escape points +/// from a function so that "finally"-style code can be inserted. In addition +/// to finding the existing return and unwind instructions, it also (if +/// necessary) transforms any call instructions into invokes and sends them to +/// a landing pad. +class EscapeEnumerator { + Function &F; + const char *CleanupBBName; + + Function::iterator StateBB, StateE; + IRBuilder<> Builder; + bool Done; + bool HandleExceptions; + +public: + EscapeEnumerator(Function &F, const char *N = "cleanup", + bool HandleExceptions = true) + : F(F), CleanupBBName(N), StateBB(F.begin()), StateE(F.end()), + Builder(F.getContext()), Done(false), + HandleExceptions(HandleExceptions) {} + + IRBuilder<> *Next(); +}; + +} + +#endif // LLVM_TRANSFORMS_UTILS_ESCAPEENUMERATOR_H diff --git a/llvm/include/llvm/Transforms/Utils/Local.h b/llvm/include/llvm/Transforms/Utils/Local.h index e4185448f01..d967bd5840a 100644 --- a/llvm/include/llvm/Transforms/Utils/Local.h +++ b/llvm/include/llvm/Transforms/Utils/Local.h @@ -314,6 +314,13 @@ unsigned removeAllNonTerminatorAndEHPadInstructions(BasicBlock *BB); /// instruction, making it and the rest of the code in the block dead. unsigned changeToUnreachable(Instruction *I, bool UseLLVMTrap); +/// Convert the CallInst to InvokeInst with the specified unwind edge basic +/// block. This also splits the basic block where CI is located, because +/// InvokeInst is a terminator instruction. Returns the newly split basic +/// block. +BasicBlock *changeToInvokeAndSplitBasicBlock(CallInst *CI, + BasicBlock *UnwindEdge); + /// Replace 'BB's terminator with one that does not have an unwind successor /// block. Rewrites `invoke` to `call`, etc. Updates any PHIs in unwind /// successor. |

