diff options
| author | Peter Collingbourne <peter@pcc.me.uk> | 2013-10-20 21:29:19 +0000 |
|---|---|---|
| committer | Peter Collingbourne <peter@pcc.me.uk> | 2013-10-20 21:29:19 +0000 |
| commit | b914e87377fd4d7642f544000a79f8648c6f06c9 (patch) | |
| tree | d4f37f2920aee3b3c0a1accf1e1405121f0a7a81 /lib/CodeGen/CodeGenFunction.cpp | |
| parent | bf54855ac4476a54d9bafc5f67e433d3ac0fe512 (diff) | |
| download | clang-b914e87377fd4d7642f544000a79f8648c6f06c9.tar.gz clang-b914e87377fd4d7642f544000a79f8648c6f06c9.tar.bz2 clang-b914e87377fd4d7642f544000a79f8648c6f06c9.tar.xz | |
Implement function type checker for the undefined behavior sanitizer.
This uses function prefix data to store function type information at the
function pointer.
Differential Revision: http://llvm-reviews.chandlerc.com/D1338
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@193058 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CodeGenFunction.cpp')
| -rw-r--r-- | lib/CodeGen/CodeGenFunction.cpp | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/lib/CodeGen/CodeGenFunction.cpp b/lib/CodeGen/CodeGenFunction.cpp index 4ae0bdd97c..03a24eb5f7 100644 --- a/lib/CodeGen/CodeGenFunction.cpp +++ b/lib/CodeGen/CodeGenFunction.cpp @@ -16,6 +16,7 @@ #include "CGCXXABI.h" #include "CGDebugInfo.h" #include "CodeGenModule.h" +#include "TargetInfo.h" #include "clang/AST/ASTContext.h" #include "clang/AST/Decl.h" #include "clang/AST/DeclCXX.h" @@ -519,6 +520,22 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, EmitOpenCLKernelMetadata(FD, Fn); } + // If we are checking function types, emit a function type signature as + // prefix data. + if (getLangOpts().CPlusPlus && SanOpts->Function) { + if (const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(D)) { + if (llvm::Constant *PrefixSig = + CGM.getTargetCodeGenInfo().getUBSanFunctionSignature(CGM)) { + llvm::Constant *FTRTTIConst = + CGM.GetAddrOfRTTIDescriptor(FD->getType(), /*ForEH=*/true); + llvm::Constant *PrefixStructElems[] = { PrefixSig, FTRTTIConst }; + llvm::Constant *PrefixStructConst = + llvm::ConstantStruct::getAnon(PrefixStructElems, /*Packed=*/true); + Fn->setPrefixData(PrefixStructConst); + } + } + } + llvm::BasicBlock *EntryBB = createBasicBlock("entry", CurFn); // Create a marker to make it easy to insert allocas into the entryblock |
