[PATCH] D11109: basic code generation for use-after-dtor

Naomi Musgrave nmusgrave at google.com
Fri Jul 10 14:19:22 PDT 2015


nmusgrave created this revision.
nmusgrave added reviewers: eugenis, kcc.
nmusgrave added a subscriber: cfe-commits.

http://reviews.llvm.org/D11109

Files:
  lib/CodeGen/CGClass.cpp

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<CXXTryStmt>(Body), true);
+
+  // Insert memory-posioning instrumentation.
+  if (CGM.getCodeGenOpts().SanitizeMemoryUseAfterDtor) {
+    SmallVector<llvm::Value *, 4> Args;
+    SmallVector<llvm::Type *, 4> 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) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D11109.29496.patch
Type: text/x-patch
Size: 1145 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150710/89a17207/attachment.bin>


More information about the cfe-commits mailing list