Index: lib/CodeGen/CGClass.cpp =================================================================== --- lib/CodeGen/CGClass.cpp +++ lib/CodeGen/CGClass.cpp @@ -1448,6 +1448,27 @@ // Exit the try if applicable. if (isTryBody) ExitCXXTryStmt(*cast(Body), true); + + // Insert memory-posioning instrumentation. + if (CGM.getCodeGenOpts().SanitizeMemoryUseAfterDtor) { + SmallVector Args; + SmallVector ArgTypes; + + ArgTypes.push_back(Int8PtrTy); + Args.push_back(Builder.CreateBitCast(LoadCXXThis(), Int8PtrTy)); + + ArgTypes.push_back(IntTy); + const ASTRecordLayout &Layout = + getContext().getASTRecordLayout(Dtor->getParent()); + Args.push_back( + llvm::ConstantInt::get(CGM.IntTy, Layout.getSize().getQuantity())); + + llvm::FunctionType *FnType = + llvm::FunctionType::get(CGM.VoidTy, ArgTypes, false); + llvm::Value *Fn = + CGM.CreateRuntimeFunction(FnType, "__sanitizer_dtor_exit_callback"); + EmitNounwindRuntimeCall(Fn, Args); + } } void CodeGenFunction::emitImplicitAssignmentOperatorBody(FunctionArgList &Args) {