From 29477dc82e9f6e35a91210daa834c59d8216d308 Mon Sep 17 00:00:00 2001 From: Vedant Kumar Date: Fri, 8 Dec 2017 02:47:58 +0000 Subject: [PATCH] [Blocks] Inherit sanitizer options from parent decl There is no way to apply sanitizer suppressions to ObjC blocks. A reasonable default is to have blocks inherit their parent's sanitizer options. rdar://32769634 Differential Revision: https://reviews.llvm.org/D40668 llvm-svn: 320132 --- clang/lib/CodeGen/CGBlocks.cpp | 4 +++- clang/test/CodeGenObjC/no-sanitize.m | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/clang/lib/CodeGen/CGBlocks.cpp b/clang/lib/CodeGen/CGBlocks.cpp index 850681471df2..5f73d4cf7913 100644 --- a/clang/lib/CodeGen/CGBlocks.cpp +++ b/clang/lib/CodeGen/CGBlocks.cpp @@ -784,7 +784,9 @@ llvm::Value *CodeGenFunction::EmitBlockLiteral(const CGBlockInfo &blockInfo, 8); // Using the computed layout, generate the actual block function. bool isLambdaConv = blockInfo.getBlockDecl()->isConversionFromLambda(); - auto *InvokeFn = CodeGenFunction(CGM, true).GenerateBlockFunction( + CodeGenFunction BlockCGF{CGM, true}; + BlockCGF.SanOpts = SanOpts; + auto *InvokeFn = BlockCGF.GenerateBlockFunction( CurGD, blockInfo, LocalDeclMap, isLambdaConv, blockInfo.CanBeGlobal); if (InvokeF) *InvokeF = InvokeFn; diff --git a/clang/test/CodeGenObjC/no-sanitize.m b/clang/test/CodeGenObjC/no-sanitize.m index 39f8575670d5..07a196b6419d 100644 --- a/clang/test/CodeGenObjC/no-sanitize.m +++ b/clang/test/CodeGenObjC/no-sanitize.m @@ -1,8 +1,9 @@ -// RUN: %clang_cc1 %s -emit-llvm -fsanitize=address -o - | FileCheck %s +// RUN: %clang_cc1 %s -emit-llvm -fsanitize=address -fblocks -o - | FileCheck %s @interface I0 @end @implementation I0 // CHECK-NOT: sanitize_address - (void) im0: (int) a0 __attribute__((no_sanitize("address"))) { + int (^blockName)() = ^int() { return 0; }; } @end