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

Naomi Musgrave nmusgrave at google.com
Mon Jul 13 10:51:20 PDT 2015


nmusgrave updated this revision to Diff 29587.
nmusgrave added a comment.

- changed arg types for generated dtor handler


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,29 @@
   // Exit the try if applicable.
   if (isTryBody)
     ExitCXXTryStmt(*cast<CXXTryStmt>(Body), true);
+
+  // Insert memory-posioning instrumentation.
+  // Invokes __sanitizer_dtor_exit_callback(void *, size_t), passing in
+  // references to 'this' and its size as arguments.
+  if (CGM.getCodeGenOpts().SanitizeMemoryUseAfterDtor) {
+    SmallVector<llvm::Value *, 4> Args;
+    SmallVector<llvm::Type *, 4> ArgTypes;
+
+    ArgTypes.push_back(VoidPtrTy);
+    Args.push_back(Builder.CreateBitCast(LoadCXXThis(), VoidPtrTy));
+
+    ArgTypes.push_back(SizeTy);
+    const ASTRecordLayout &Layout =
+        getContext().getASTRecordLayout(Dtor->getParent());
+    Args.push_back(
+        llvm::ConstantInt::get(CGM.SizeTy, 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.29587.patch
Type: text/x-patch
Size: 1274 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150713/0a5fdd99/attachment.bin>


More information about the cfe-commits mailing list