clang  14.0.0git
CGBlocks.cpp
Go to the documentation of this file.
1 //===--- CGBlocks.cpp - Emit LLVM Code for declarations ---------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This contains code to emit blocks.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #include "CGBlocks.h"
14 #include "CGCXXABI.h"
15 #include "CGDebugInfo.h"
16 #include "CGObjCRuntime.h"
17 #include "CGOpenCLRuntime.h"
18 #include "CodeGenFunction.h"
19 #include "CodeGenModule.h"
20 #include "ConstantEmitter.h"
21 #include "TargetInfo.h"
22 #include "clang/AST/Attr.h"
23 #include "clang/AST/DeclObjC.h"
25 #include "llvm/ADT/SmallSet.h"
26 #include "llvm/IR/DataLayout.h"
27 #include "llvm/IR/Module.h"
28 #include "llvm/Support/ScopedPrinter.h"
29 #include <algorithm>
30 #include <cstdio>
31 
32 using namespace clang;
33 using namespace CodeGen;
34 
35 CGBlockInfo::CGBlockInfo(const BlockDecl *block, StringRef name)
36  : Name(name), CXXThisIndex(0), CanBeGlobal(false), NeedsCopyDispose(false),
37  HasCXXObject(false), UsesStret(false), HasCapturedVariableLayout(false),
38  CapturesNonExternalType(false), LocalAddress(Address::invalid()),
39  StructureType(nullptr), Block(block) {
40 
41  // Skip asm prefix, if any. 'name' is usually taken directly from
42  // the mangled name of the enclosing function.
43  if (!name.empty() && name[0] == '\01')
44  name = name.substr(1);
45 }
46 
47 // Anchor the vtable to this translation unit.
49 
50 /// Build the given block as a global block.
51 static llvm::Constant *buildGlobalBlock(CodeGenModule &CGM,
52  const CGBlockInfo &blockInfo,
53  llvm::Constant *blockFn);
54 
55 /// Build the helper function to copy a block.
56 static llvm::Constant *buildCopyHelper(CodeGenModule &CGM,
57  const CGBlockInfo &blockInfo) {
58  return CodeGenFunction(CGM).GenerateCopyHelperFunction(blockInfo);
59 }
60 
61 /// Build the helper function to dispose of a block.
62 static llvm::Constant *buildDisposeHelper(CodeGenModule &CGM,
63  const CGBlockInfo &blockInfo) {
64  return CodeGenFunction(CGM).GenerateDestroyHelperFunction(blockInfo);
65 }
66 
67 namespace {
68 
69 /// Represents a type of copy/destroy operation that should be performed for an
70 /// entity that's captured by a block.
71 enum class BlockCaptureEntityKind {
72  CXXRecord, // Copy or destroy
73  ARCWeak,
74  ARCStrong,
75  NonTrivialCStruct,
76  BlockObject, // Assign or release
77  None
78 };
79 
80 /// Represents a captured entity that requires extra operations in order for
81 /// this entity to be copied or destroyed correctly.
82 struct BlockCaptureManagedEntity {
83  BlockCaptureEntityKind CopyKind, DisposeKind;
84  BlockFieldFlags CopyFlags, DisposeFlags;
85  const BlockDecl::Capture *CI;
87 
88  BlockCaptureManagedEntity(BlockCaptureEntityKind CopyType,
89  BlockCaptureEntityKind DisposeType,
90  BlockFieldFlags CopyFlags,
91  BlockFieldFlags DisposeFlags,
92  const BlockDecl::Capture &CI,
94  : CopyKind(CopyType), DisposeKind(DisposeType), CopyFlags(CopyFlags),
95  DisposeFlags(DisposeFlags), CI(&CI), Capture(&Capture) {}
96 
97  bool operator<(const BlockCaptureManagedEntity &Other) const {
98  return Capture->getOffset() < Other.Capture->getOffset();
99  }
100 };
101 
102 enum class CaptureStrKind {
103  // String for the copy helper.
104  CopyHelper,
105  // String for the dispose helper.
106  DisposeHelper,
107  // Merge the strings for the copy helper and dispose helper.
108  Merged
109 };
110 
111 } // end anonymous namespace
112 
114  const CGBlockInfo &BlockInfo, const LangOptions &LangOpts,
115  SmallVectorImpl<BlockCaptureManagedEntity> &ManagedCaptures);
116 
117 static std::string getBlockCaptureStr(const BlockCaptureManagedEntity &E,
118  CaptureStrKind StrKind,
119  CharUnits BlockAlignment,
120  CodeGenModule &CGM);
121 
123  CodeGenModule &CGM) {
124  std::string Name = "__block_descriptor_";
125  Name += llvm::to_string(BlockInfo.BlockSize.getQuantity()) + "_";
126 
127  if (BlockInfo.needsCopyDisposeHelpers()) {
128  if (CGM.getLangOpts().Exceptions)
129  Name += "e";
130  if (CGM.getCodeGenOpts().ObjCAutoRefCountExceptions)
131  Name += "a";
132  Name += llvm::to_string(BlockInfo.BlockAlign.getQuantity()) + "_";
133 
136  ManagedCaptures);
137 
138  for (const BlockCaptureManagedEntity &E : ManagedCaptures) {
139  Name += llvm::to_string(E.Capture->getOffset().getQuantity());
140 
141  if (E.CopyKind == E.DisposeKind) {
142  // If CopyKind and DisposeKind are the same, merge the capture
143  // information.
144  assert(E.CopyKind != BlockCaptureEntityKind::None &&
145  "shouldn't see BlockCaptureManagedEntity that is None");
146  Name += getBlockCaptureStr(E, CaptureStrKind::Merged,
147  BlockInfo.BlockAlign, CGM);
148  } else {
149  // If CopyKind and DisposeKind are not the same, which can happen when
150  // either Kind is None or the captured object is a __strong block,
151  // concatenate the copy and dispose strings.
152  Name += getBlockCaptureStr(E, CaptureStrKind::CopyHelper,
153  BlockInfo.BlockAlign, CGM);
154  Name += getBlockCaptureStr(E, CaptureStrKind::DisposeHelper,
155  BlockInfo.BlockAlign, CGM);
156  }
157  }
158  Name += "_";
159  }
160 
161  std::string TypeAtEncoding =
163  /// Replace occurrences of '@' with '\1'. '@' is reserved on ELF platforms as
164  /// a separator between symbol name and symbol version.
165  std::replace(TypeAtEncoding.begin(), TypeAtEncoding.end(), '@', '\1');
166  Name += "e" + llvm::to_string(TypeAtEncoding.size()) + "_" + TypeAtEncoding;
167  Name += "l" + CGM.getObjCRuntime().getRCBlockLayoutStr(CGM, BlockInfo);
168  return Name;
169 }
170 
171 /// buildBlockDescriptor - Build the block descriptor meta-data for a block.
172 /// buildBlockDescriptor is accessed from 5th field of the Block_literal
173 /// meta-data and contains stationary information about the block literal.
174 /// Its definition will have 4 (or optionally 6) words.
175 /// \code
176 /// struct Block_descriptor {
177 /// unsigned long reserved;
178 /// unsigned long size; // size of Block_literal metadata in bytes.
179 /// void *copy_func_helper_decl; // optional copy helper.
180 /// void *destroy_func_decl; // optional destructor helper.
181 /// void *block_method_encoding_address; // @encode for block literal signature.
182 /// void *block_layout_info; // encoding of captured block variables.
183 /// };
184 /// \endcode
185 static llvm::Constant *buildBlockDescriptor(CodeGenModule &CGM,
186  const CGBlockInfo &blockInfo) {
187  ASTContext &C = CGM.getContext();
188 
189  llvm::IntegerType *ulong =
190  cast<llvm::IntegerType>(CGM.getTypes().ConvertType(C.UnsignedLongTy));
191  llvm::PointerType *i8p = nullptr;
192  if (CGM.getLangOpts().OpenCL)
193  i8p =
194  llvm::Type::getInt8PtrTy(
195  CGM.getLLVMContext(), C.getTargetAddressSpace(LangAS::opencl_constant));
196  else
197  i8p = CGM.VoidPtrTy;
198 
199  std::string descName;
200 
201  // If an equivalent block descriptor global variable exists, return it.
202  if (C.getLangOpts().ObjC &&
203  CGM.getLangOpts().getGC() == LangOptions::NonGC) {
204  descName = getBlockDescriptorName(blockInfo, CGM);
205  if (llvm::GlobalValue *desc = CGM.getModule().getNamedValue(descName))
206  return llvm::ConstantExpr::getBitCast(desc,
207  CGM.getBlockDescriptorType());
208  }
209 
210  // If there isn't an equivalent block descriptor global variable, create a new
211  // one.
212  ConstantInitBuilder builder(CGM);
213  auto elements = builder.beginStruct();
214 
215  // reserved
216  elements.addInt(ulong, 0);
217 
218  // Size
219  // FIXME: What is the right way to say this doesn't fit? We should give
220  // a user diagnostic in that case. Better fix would be to change the
221  // API to size_t.
222  elements.addInt(ulong, blockInfo.BlockSize.getQuantity());
223 
224  // Optional copy/dispose helpers.
225  bool hasInternalHelper = false;
226  if (blockInfo.needsCopyDisposeHelpers()) {
227  // copy_func_helper_decl
228  llvm::Constant *copyHelper = buildCopyHelper(CGM, blockInfo);
229  elements.add(copyHelper);
230 
231  // destroy_func_decl
232  llvm::Constant *disposeHelper = buildDisposeHelper(CGM, blockInfo);
233  elements.add(disposeHelper);
234 
235  if (cast<llvm::Function>(copyHelper->getOperand(0))->hasInternalLinkage() ||
236  cast<llvm::Function>(disposeHelper->getOperand(0))
237  ->hasInternalLinkage())
238  hasInternalHelper = true;
239  }
240 
241  // Signature. Mandatory ObjC-style method descriptor @encode sequence.
242  std::string typeAtEncoding =
244  elements.add(llvm::ConstantExpr::getBitCast(
245  CGM.GetAddrOfConstantCString(typeAtEncoding).getPointer(), i8p));
246 
247  // GC layout.
248  if (C.getLangOpts().ObjC) {
249  if (CGM.getLangOpts().getGC() != LangOptions::NonGC)
250  elements.add(CGM.getObjCRuntime().BuildGCBlockLayout(CGM, blockInfo));
251  else
252  elements.add(CGM.getObjCRuntime().BuildRCBlockLayout(CGM, blockInfo));
253  }
254  else
255  elements.addNullPointer(i8p);
256 
257  unsigned AddrSpace = 0;
258  if (C.getLangOpts().OpenCL)
259  AddrSpace = C.getTargetAddressSpace(LangAS::opencl_constant);
260 
261  llvm::GlobalValue::LinkageTypes linkage;
262  if (descName.empty()) {
264  descName = "__block_descriptor_tmp";
265  } else if (hasInternalHelper) {
266  // If either the copy helper or the dispose helper has internal linkage,
267  // the block descriptor must have internal linkage too.
269  } else {
270  linkage = llvm::GlobalValue::LinkOnceODRLinkage;
271  }
272 
273  llvm::GlobalVariable *global =
274  elements.finishAndCreateGlobal(descName, CGM.getPointerAlign(),
275  /*constant*/ true, linkage, AddrSpace);
276 
277  if (linkage == llvm::GlobalValue::LinkOnceODRLinkage) {
278  if (CGM.supportsCOMDAT())
279  global->setComdat(CGM.getModule().getOrInsertComdat(descName));
280  global->setVisibility(llvm::GlobalValue::HiddenVisibility);
281  global->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
282  }
283 
284  return llvm::ConstantExpr::getBitCast(global, CGM.getBlockDescriptorType());
285 }
286 
287 /*
288  Purely notional variadic template describing the layout of a block.
289 
290  template <class _ResultType, class... _ParamTypes, class... _CaptureTypes>
291  struct Block_literal {
292  /// Initialized to one of:
293  /// extern void *_NSConcreteStackBlock[];
294  /// extern void *_NSConcreteGlobalBlock[];
295  ///
296  /// In theory, we could start one off malloc'ed by setting
297  /// BLOCK_NEEDS_FREE, giving it a refcount of 1, and using
298  /// this isa:
299  /// extern void *_NSConcreteMallocBlock[];
300  struct objc_class *isa;
301 
302  /// These are the flags (with corresponding bit number) that the
303  /// compiler is actually supposed to know about.
304  /// 23. BLOCK_IS_NOESCAPE - indicates that the block is non-escaping
305  /// 25. BLOCK_HAS_COPY_DISPOSE - indicates that the block
306  /// descriptor provides copy and dispose helper functions
307  /// 26. BLOCK_HAS_CXX_OBJ - indicates that there's a captured
308  /// object with a nontrivial destructor or copy constructor
309  /// 28. BLOCK_IS_GLOBAL - indicates that the block is allocated
310  /// as global memory
311  /// 29. BLOCK_USE_STRET - indicates that the block function
312  /// uses stret, which objc_msgSend needs to know about
313  /// 30. BLOCK_HAS_SIGNATURE - indicates that the block has an
314  /// @encoded signature string
315  /// And we're not supposed to manipulate these:
316  /// 24. BLOCK_NEEDS_FREE - indicates that the block has been moved
317  /// to malloc'ed memory
318  /// 27. BLOCK_IS_GC - indicates that the block has been moved to
319  /// to GC-allocated memory
320  /// Additionally, the bottom 16 bits are a reference count which
321  /// should be zero on the stack.
322  int flags;
323 
324  /// Reserved; should be zero-initialized.
325  int reserved;
326 
327  /// Function pointer generated from block literal.
328  _ResultType (*invoke)(Block_literal *, _ParamTypes...);
329 
330  /// Block description metadata generated from block literal.
331  struct Block_descriptor *block_descriptor;
332 
333  /// Captured values follow.
334  _CapturesTypes captures...;
335  };
336  */
337 
338 namespace {
339  /// A chunk of data that we actually have to capture in the block.
340  struct BlockLayoutChunk {
341  CharUnits Alignment;
342  CharUnits Size;
343  Qualifiers::ObjCLifetime Lifetime;
344  const BlockDecl::Capture *Capture; // null for 'this'
345  llvm::Type *Type;
346  QualType FieldType;
347 
348  BlockLayoutChunk(CharUnits align, CharUnits size,
349  Qualifiers::ObjCLifetime lifetime,
350  const BlockDecl::Capture *capture,
351  llvm::Type *type, QualType fieldType)
352  : Alignment(align), Size(size), Lifetime(lifetime),
353  Capture(capture), Type(type), FieldType(fieldType) {}
354 
355  /// Tell the block info that this chunk has the given field index.
356  void setIndex(CGBlockInfo &info, unsigned index, CharUnits offset) {
357  if (!Capture) {
358  info.CXXThisIndex = index;
359  info.CXXThisOffset = offset;
360  } else {
361  auto C = CGBlockInfo::Capture::makeIndex(index, offset, FieldType);
362  info.Captures.insert({Capture->getVariable(), C});
363  }
364  }
365  };
366 
367  /// Order by 1) all __strong together 2) next, all byfref together 3) next,
368  /// all __weak together. Preserve descending alignment in all situations.
369  bool operator<(const BlockLayoutChunk &left, const BlockLayoutChunk &right) {
370  if (left.Alignment != right.Alignment)
371  return left.Alignment > right.Alignment;
372 
373  auto getPrefOrder = [](const BlockLayoutChunk &chunk) {
374  if (chunk.Capture && chunk.Capture->isByRef())
375  return 1;
376  if (chunk.Lifetime == Qualifiers::OCL_Strong)
377  return 0;
378  if (chunk.Lifetime == Qualifiers::OCL_Weak)
379  return 2;
380  return 3;
381  };
382 
383  return getPrefOrder(left) < getPrefOrder(right);
384  }
385 } // end anonymous namespace
386 
387 /// Determines if the given type is safe for constant capture in C++.
389  const RecordType *recordType =
390  type->getBaseElementTypeUnsafe()->getAs<RecordType>();
391 
392  // Only records can be unsafe.
393  if (!recordType) return true;
394 
395  const auto *record = cast<CXXRecordDecl>(recordType->getDecl());
396 
397  // Maintain semantics for classes with non-trivial dtors or copy ctors.
398  if (!record->hasTrivialDestructor()) return false;
399  if (record->hasNonTrivialCopyConstructor()) return false;
400 
401  // Otherwise, we just have to make sure there aren't any mutable
402  // fields that might have changed since initialization.
403  return !record->hasMutableFields();
404 }
405 
406 /// It is illegal to modify a const object after initialization.
407 /// Therefore, if a const object has a constant initializer, we don't
408 /// actually need to keep storage for it in the block; we'll just
409 /// rematerialize it at the start of the block function. This is
410 /// acceptable because we make no promises about address stability of
411 /// captured variables.
412 static llvm::Constant *tryCaptureAsConstant(CodeGenModule &CGM,
413  CodeGenFunction *CGF,
414  const VarDecl *var) {
415  // Return if this is a function parameter. We shouldn't try to
416  // rematerialize default arguments of function parameters.
417  if (isa<ParmVarDecl>(var))
418  return nullptr;
419 
420  QualType type = var->getType();
421 
422  // We can only do this if the variable is const.
423  if (!type.isConstQualified()) return nullptr;
424 
425  // Furthermore, in C++ we have to worry about mutable fields:
426  // C++ [dcl.type.cv]p4:
427  // Except that any class member declared mutable can be
428  // modified, any attempt to modify a const object during its
429  // lifetime results in undefined behavior.
430  if (CGM.getLangOpts().CPlusPlus && !isSafeForCXXConstantCapture(type))
431  return nullptr;
432 
433  // If the variable doesn't have any initializer (shouldn't this be
434  // invalid?), it's not clear what we should do. Maybe capture as
435  // zero?
436  const Expr *init = var->getInit();
437  if (!init) return nullptr;
438 
439  return ConstantEmitter(CGM, CGF).tryEmitAbstractForInitializer(*var);
440 }
441 
442 /// Get the low bit of a nonzero character count. This is the
443 /// alignment of the nth byte if the 0th byte is universally aligned.
445  return CharUnits::fromQuantity(v.getQuantity() & (~v.getQuantity() + 1));
446 }
447 
449  SmallVectorImpl<llvm::Type*> &elementTypes) {
450 
451  assert(elementTypes.empty());
452  if (CGM.getLangOpts().OpenCL) {
453  // The header is basically 'struct { int; int; generic void *;
454  // custom_fields; }'. Assert that struct is packed.
455  auto GenericAS =
457  auto GenPtrAlign =
458  CharUnits::fromQuantity(CGM.getTarget().getPointerAlign(GenericAS) / 8);
459  auto GenPtrSize =
460  CharUnits::fromQuantity(CGM.getTarget().getPointerWidth(GenericAS) / 8);
461  assert(CGM.getIntSize() <= GenPtrSize);
462  assert(CGM.getIntAlign() <= GenPtrAlign);
463  assert((2 * CGM.getIntSize()).isMultipleOf(GenPtrAlign));
464  elementTypes.push_back(CGM.IntTy); /* total size */
465  elementTypes.push_back(CGM.IntTy); /* align */
466  elementTypes.push_back(
467  CGM.getOpenCLRuntime()
468  .getGenericVoidPointerType()); /* invoke function */
469  unsigned Offset =
470  2 * CGM.getIntSize().getQuantity() + GenPtrSize.getQuantity();
471  unsigned BlockAlign = GenPtrAlign.getQuantity();
472  if (auto *Helper =
474  for (auto I : Helper->getCustomFieldTypes()) /* custom fields */ {
475  // TargetOpenCLBlockHelp needs to make sure the struct is packed.
476  // If necessary, add padding fields to the custom fields.
477  unsigned Align = CGM.getDataLayout().getABITypeAlignment(I);
478  if (BlockAlign < Align)
479  BlockAlign = Align;
480  assert(Offset % Align == 0);
481  Offset += CGM.getDataLayout().getTypeAllocSize(I);
482  elementTypes.push_back(I);
483  }
484  }
485  info.BlockAlign = CharUnits::fromQuantity(BlockAlign);
487  } else {
488  // The header is basically 'struct { void *; int; int; void *; void *; }'.
489  // Assert that the struct is packed.
490  assert(CGM.getIntSize() <= CGM.getPointerSize());
491  assert(CGM.getIntAlign() <= CGM.getPointerAlign());
492  assert((2 * CGM.getIntSize()).isMultipleOf(CGM.getPointerAlign()));
493  info.BlockAlign = CGM.getPointerAlign();
494  info.BlockSize = 3 * CGM.getPointerSize() + 2 * CGM.getIntSize();
495  elementTypes.push_back(CGM.VoidPtrTy);
496  elementTypes.push_back(CGM.IntTy);
497  elementTypes.push_back(CGM.IntTy);
498  elementTypes.push_back(CGM.VoidPtrTy);
499  elementTypes.push_back(CGM.getBlockDescriptorType());
500  }
501 }
502 
504  const BlockDecl::Capture &CI) {
505  const VarDecl *VD = CI.getVariable();
506 
507  // If the variable is captured by an enclosing block or lambda expression,
508  // use the type of the capture field.
509  if (CGF.BlockInfo && CI.isNested())
510  return CGF.BlockInfo->getCapture(VD).fieldType();
511  if (auto *FD = CGF.LambdaCaptureFields.lookup(VD))
512  return FD->getType();
513  // If the captured variable is a non-escaping __block variable, the field
514  // type is the reference type. If the variable is a __block variable that
515  // already has a reference type, the field type is the variable's type.
516  return VD->isNonEscapingByref() ?
517  CGF.getContext().getLValueReferenceType(VD->getType()) : VD->getType();
518 }
519 
520 /// Compute the layout of the given block. Attempts to lay the block
521 /// out with minimal space requirements.
523  CGBlockInfo &info) {
524  ASTContext &C = CGM.getContext();
525  const BlockDecl *block = info.getBlockDecl();
526 
527  SmallVector<llvm::Type*, 8> elementTypes;
528  initializeForBlockHeader(CGM, info, elementTypes);
529  bool hasNonConstantCustomFields = false;
530  if (auto *OpenCLHelper =
532  hasNonConstantCustomFields =
533  !OpenCLHelper->areAllCustomFieldValuesConstant(info);
534  if (!block->hasCaptures() && !hasNonConstantCustomFields) {
535  info.StructureType =
536  llvm::StructType::get(CGM.getLLVMContext(), elementTypes, true);
537  info.CanBeGlobal = true;
538  return;
539  }
540  else if (C.getLangOpts().ObjC &&
541  CGM.getLangOpts().getGC() == LangOptions::NonGC)
542  info.HasCapturedVariableLayout = true;
543 
544  // Collect the layout chunks.
546  layout.reserve(block->capturesCXXThis() +
547  (block->capture_end() - block->capture_begin()));
548 
549  CharUnits maxFieldAlign;
550 
551  // First, 'this'.
552  if (block->capturesCXXThis()) {
553  assert(CGF && CGF->CurFuncDecl && isa<CXXMethodDecl>(CGF->CurFuncDecl) &&
554  "Can't capture 'this' outside a method");
555  QualType thisType = cast<CXXMethodDecl>(CGF->CurFuncDecl)->getThisType();
556 
557  // Theoretically, this could be in a different address space, so
558  // don't assume standard pointer size/align.
559  llvm::Type *llvmType = CGM.getTypes().ConvertType(thisType);
560  auto TInfo = CGM.getContext().getTypeInfoInChars(thisType);
561  maxFieldAlign = std::max(maxFieldAlign, TInfo.Align);
562 
563  layout.push_back(BlockLayoutChunk(TInfo.Align, TInfo.Width,
565  nullptr, llvmType, thisType));
566  }
567 
568  // Next, all the block captures.
569  for (const auto &CI : block->captures()) {
570  const VarDecl *variable = CI.getVariable();
571 
572  if (CI.isEscapingByref()) {
573  // We have to copy/dispose of the __block reference.
574  info.NeedsCopyDispose = true;
575 
576  // Just use void* instead of a pointer to the byref type.
578  maxFieldAlign = std::max(maxFieldAlign, align);
579 
580  // Since a __block variable cannot be captured by lambdas, its type and
581  // the capture field type should always match.
582  assert(CGF && getCaptureFieldType(*CGF, CI) == variable->getType() &&
583  "capture type differs from the variable type");
584  layout.push_back(BlockLayoutChunk(align, CGM.getPointerSize(),
586  CGM.VoidPtrTy, variable->getType()));
587  continue;
588  }
589 
590  // Otherwise, build a layout chunk with the size and alignment of
591  // the declaration.
592  if (llvm::Constant *constant = tryCaptureAsConstant(CGM, CGF, variable)) {
593  info.Captures[variable] = CGBlockInfo::Capture::makeConstant(constant);
594  continue;
595  }
596 
597  QualType VT = getCaptureFieldType(*CGF, CI);
598 
599  // If we have a lifetime qualifier, honor it for capture purposes.
600  // That includes *not* copying it if it's __unsafe_unretained.
602  if (lifetime) {
603  switch (lifetime) {
604  case Qualifiers::OCL_None: llvm_unreachable("impossible");
607  break;
608 
611  info.NeedsCopyDispose = true;
612  }
613 
614  // Block pointers require copy/dispose. So do Objective-C pointers.
615  } else if (VT->isObjCRetainableType()) {
616  // But honor the inert __unsafe_unretained qualifier, which doesn't
617  // actually make it into the type system.
619  lifetime = Qualifiers::OCL_ExplicitNone;
620  } else {
621  info.NeedsCopyDispose = true;
622  // used for mrr below.
623  lifetime = Qualifiers::OCL_Strong;
624  }
625 
626  // So do types that require non-trivial copy construction.
627  } else if (CI.hasCopyExpr()) {
628  info.NeedsCopyDispose = true;
629  info.HasCXXObject = true;
631  info.CapturesNonExternalType = true;
632 
633  // So do C structs that require non-trivial copy construction or
634  // destruction.
637  info.NeedsCopyDispose = true;
638 
639  // And so do types with destructors.
640  } else if (CGM.getLangOpts().CPlusPlus) {
641  if (const CXXRecordDecl *record = VT->getAsCXXRecordDecl()) {
642  if (!record->hasTrivialDestructor()) {
643  info.HasCXXObject = true;
644  info.NeedsCopyDispose = true;
645  if (!record->isExternallyVisible())
646  info.CapturesNonExternalType = true;
647  }
648  }
649  }
650 
651  CharUnits size = C.getTypeSizeInChars(VT);
652  CharUnits align = C.getDeclAlign(variable);
653 
654  maxFieldAlign = std::max(maxFieldAlign, align);
655 
656  llvm::Type *llvmType =
657  CGM.getTypes().ConvertTypeForMem(VT);
658 
659  layout.push_back(
660  BlockLayoutChunk(align, size, lifetime, &CI, llvmType, VT));
661  }
662 
663  // If that was everything, we're done here.
664  if (layout.empty()) {
665  info.StructureType =
666  llvm::StructType::get(CGM.getLLVMContext(), elementTypes, true);
667  info.CanBeGlobal = true;
668  return;
669  }
670 
671  // Sort the layout by alignment. We have to use a stable sort here
672  // to get reproducible results. There should probably be an
673  // llvm::array_pod_stable_sort.
674  llvm::stable_sort(layout);
675 
676  // Needed for blocks layout info.
679 
680  CharUnits &blockSize = info.BlockSize;
681  info.BlockAlign = std::max(maxFieldAlign, info.BlockAlign);
682 
683  // Assuming that the first byte in the header is maximally aligned,
684  // get the alignment of the first byte following the header.
685  CharUnits endAlign = getLowBit(blockSize);
686 
687  // If the end of the header isn't satisfactorily aligned for the
688  // maximum thing, look for things that are okay with the header-end
689  // alignment, and keep appending them until we get something that's
690  // aligned right. This algorithm is only guaranteed optimal if
691  // that condition is satisfied at some point; otherwise we can get
692  // things like:
693  // header // next byte has alignment 4
694  // something_with_size_5; // next byte has alignment 1
695  // something_with_alignment_8;
696  // which has 7 bytes of padding, as opposed to the naive solution
697  // which might have less (?).
698  if (endAlign < maxFieldAlign) {
699  SmallVectorImpl<BlockLayoutChunk>::iterator
700  li = layout.begin() + 1, le = layout.end();
701 
702  // Look for something that the header end is already
703  // satisfactorily aligned for.
704  for (; li != le && endAlign < li->Alignment; ++li)
705  ;
706 
707  // If we found something that's naturally aligned for the end of
708  // the header, keep adding things...
709  if (li != le) {
710  SmallVectorImpl<BlockLayoutChunk>::iterator first = li;
711  for (; li != le; ++li) {
712  assert(endAlign >= li->Alignment);
713 
714  li->setIndex(info, elementTypes.size(), blockSize);
715  elementTypes.push_back(li->Type);
716  blockSize += li->Size;
717  endAlign = getLowBit(blockSize);
718 
719  // ...until we get to the alignment of the maximum field.
720  if (endAlign >= maxFieldAlign) {
721  break;
722  }
723  }
724  // Don't re-append everything we just appended.
725  layout.erase(first, li);
726  }
727  }
728 
729  assert(endAlign == getLowBit(blockSize));
730 
731  // At this point, we just have to add padding if the end align still
732  // isn't aligned right.
733  if (endAlign < maxFieldAlign) {
734  CharUnits newBlockSize = blockSize.alignTo(maxFieldAlign);
735  CharUnits padding = newBlockSize - blockSize;
736 
737  // If we haven't yet added any fields, remember that there was an
738  // initial gap; this need to go into the block layout bit map.
739  if (blockSize == info.BlockHeaderForcedGapOffset) {
740  info.BlockHeaderForcedGapSize = padding;
741  }
742 
743  elementTypes.push_back(llvm::ArrayType::get(CGM.Int8Ty,
744  padding.getQuantity()));
745  blockSize = newBlockSize;
746  endAlign = getLowBit(blockSize); // might be > maxFieldAlign
747  }
748 
749  assert(endAlign >= maxFieldAlign);
750  assert(endAlign == getLowBit(blockSize));
751  // Slam everything else on now. This works because they have
752  // strictly decreasing alignment and we expect that size is always a
753  // multiple of alignment.
754  for (SmallVectorImpl<BlockLayoutChunk>::iterator
755  li = layout.begin(), le = layout.end(); li != le; ++li) {
756  if (endAlign < li->Alignment) {
757  // size may not be multiple of alignment. This can only happen with
758  // an over-aligned variable. We will be adding a padding field to
759  // make the size be multiple of alignment.
760  CharUnits padding = li->Alignment - endAlign;
761  elementTypes.push_back(llvm::ArrayType::get(CGM.Int8Ty,
762  padding.getQuantity()));
763  blockSize += padding;
764  endAlign = getLowBit(blockSize);
765  }
766  assert(endAlign >= li->Alignment);
767  li->setIndex(info, elementTypes.size(), blockSize);
768  elementTypes.push_back(li->Type);
769  blockSize += li->Size;
770  endAlign = getLowBit(blockSize);
771  }
772 
773  info.StructureType =
774  llvm::StructType::get(CGM.getLLVMContext(), elementTypes, true);
775 }
776 
777 /// Emit a block literal expression in the current function.
779  // If the block has no captures, we won't have a pre-computed
780  // layout for it.
781  if (!blockExpr->getBlockDecl()->hasCaptures())
782  // The block literal is emitted as a global variable, and the block invoke
783  // function has to be extracted from its initializer.
784  if (llvm::Constant *Block = CGM.getAddrOfGlobalBlockIfEmitted(blockExpr))
785  return Block;
786 
787  CGBlockInfo blockInfo(blockExpr->getBlockDecl(), CurFn->getName());
788  computeBlockInfo(CGM, this, blockInfo);
789  blockInfo.BlockExpression = blockExpr;
790  if (!blockInfo.CanBeGlobal)
791  blockInfo.LocalAddress = CreateTempAlloca(blockInfo.StructureType,
792  blockInfo.BlockAlign, "block");
793  return EmitBlockLiteral(blockInfo);
794 }
795 
797  bool IsOpenCL = CGM.getContext().getLangOpts().OpenCL;
798  auto GenVoidPtrTy =
800  LangAS GenVoidPtrAddr = IsOpenCL ? LangAS::opencl_generic : LangAS::Default;
801  auto GenVoidPtrSize = CharUnits::fromQuantity(
803  CGM.getContext().getTargetAddressSpace(GenVoidPtrAddr)) /
804  8);
805  // Using the computed layout, generate the actual block function.
806  bool isLambdaConv = blockInfo.getBlockDecl()->isConversionFromLambda();
807  CodeGenFunction BlockCGF{CGM, true};
808  BlockCGF.SanOpts = SanOpts;
809  auto *InvokeFn = BlockCGF.GenerateBlockFunction(
810  CurGD, blockInfo, LocalDeclMap, isLambdaConv, blockInfo.CanBeGlobal);
811  auto *blockFn = llvm::ConstantExpr::getPointerCast(InvokeFn, GenVoidPtrTy);
812 
813  // If there is nothing to capture, we can emit this as a global block.
814  if (blockInfo.CanBeGlobal)
816 
817  // Otherwise, we have to emit this as a local block.
818 
819  Address blockAddr = blockInfo.LocalAddress;
820  assert(blockAddr.isValid() && "block has no address!");
821 
822  llvm::Constant *isa;
823  llvm::Constant *descriptor;
824  BlockFlags flags;
825  if (!IsOpenCL) {
826  // If the block is non-escaping, set field 'isa 'to NSConcreteGlobalBlock
827  // and set the BLOCK_IS_GLOBAL bit of field 'flags'. Copying a non-escaping
828  // block just returns the original block and releasing it is a no-op.
829  llvm::Constant *blockISA = blockInfo.getBlockDecl()->doesNotEscape()
832  isa = llvm::ConstantExpr::getBitCast(blockISA, VoidPtrTy);
833 
834  // Build the block descriptor.
835  descriptor = buildBlockDescriptor(CGM, blockInfo);
836 
837  // Compute the initial on-stack block flags.
838  flags = BLOCK_HAS_SIGNATURE;
839  if (blockInfo.HasCapturedVariableLayout)
840  flags |= BLOCK_HAS_EXTENDED_LAYOUT;
841  if (blockInfo.needsCopyDisposeHelpers())
842  flags |= BLOCK_HAS_COPY_DISPOSE;
843  if (blockInfo.HasCXXObject)
844  flags |= BLOCK_HAS_CXX_OBJ;
845  if (blockInfo.UsesStret)
846  flags |= BLOCK_USE_STRET;
847  if (blockInfo.getBlockDecl()->doesNotEscape())
849  }
850 
851  auto projectField = [&](unsigned index, const Twine &name) -> Address {
852  return Builder.CreateStructGEP(blockAddr, index, name);
853  };
854  auto storeField = [&](llvm::Value *value, unsigned index, const Twine &name) {
855  Builder.CreateStore(value, projectField(index, name));
856  };
857 
858  // Initialize the block header.
859  {
860  // We assume all the header fields are densely packed.
861  unsigned index = 0;
862  CharUnits offset;
863  auto addHeaderField = [&](llvm::Value *value, CharUnits size,
864  const Twine &name) {
865  storeField(value, index, name);
866  offset += size;
867  index++;
868  };
869 
870  if (!IsOpenCL) {
871  addHeaderField(isa, getPointerSize(), "block.isa");
872  addHeaderField(llvm::ConstantInt::get(IntTy, flags.getBitMask()),
873  getIntSize(), "block.flags");
874  addHeaderField(llvm::ConstantInt::get(IntTy, 0), getIntSize(),
875  "block.reserved");
876  } else {
877  addHeaderField(
878  llvm::ConstantInt::get(IntTy, blockInfo.BlockSize.getQuantity()),
879  getIntSize(), "block.size");
880  addHeaderField(
881  llvm::ConstantInt::get(IntTy, blockInfo.BlockAlign.getQuantity()),
882  getIntSize(), "block.align");
883  }
884  addHeaderField(blockFn, GenVoidPtrSize, "block.invoke");
885  if (!IsOpenCL)
886  addHeaderField(descriptor, getPointerSize(), "block.descriptor");
887  else if (auto *Helper =
889  for (auto I : Helper->getCustomFieldValues(*this, blockInfo)) {
890  addHeaderField(
891  I.first,
893  CGM.getDataLayout().getTypeAllocSize(I.first->getType())),
894  I.second);
895  }
896  }
897  }
898 
899  // Finally, capture all the values into the block.
900  const BlockDecl *blockDecl = blockInfo.getBlockDecl();
901 
902  // First, 'this'.
903  if (blockDecl->capturesCXXThis()) {
904  Address addr =
905  projectField(blockInfo.CXXThisIndex, "block.captured-this.addr");
907  }
908 
909  // Next, captured variables.
910  for (const auto &CI : blockDecl->captures()) {
911  const VarDecl *variable = CI.getVariable();
912  const CGBlockInfo::Capture &capture = blockInfo.getCapture(variable);
913 
914  // Ignore constant captures.
915  if (capture.isConstant()) continue;
916 
917  QualType type = capture.fieldType();
918 
919  // This will be a [[type]]*, except that a byref entry will just be
920  // an i8**.
921  Address blockField = projectField(capture.getIndex(), "block.captured");
922 
923  // Compute the address of the thing we're going to move into the
924  // block literal.
925  Address src = Address::invalid();
926 
927  if (blockDecl->isConversionFromLambda()) {
928  // The lambda capture in a lambda's conversion-to-block-pointer is
929  // special; we'll simply emit it directly.
930  src = Address::invalid();
931  } else if (CI.isEscapingByref()) {
932  if (BlockInfo && CI.isNested()) {
933  // We need to use the capture from the enclosing block.
934  const CGBlockInfo::Capture &enclosingCapture =
935  BlockInfo->getCapture(variable);
936 
937  // This is a [[type]]*, except that a byref entry will just be an i8**.
939  enclosingCapture.getIndex(),
940  "block.capture.addr");
941  } else {
942  auto I = LocalDeclMap.find(variable);
943  assert(I != LocalDeclMap.end());
944  src = I->second;
945  }
946  } else {
947  DeclRefExpr declRef(getContext(), const_cast<VarDecl *>(variable),
948  /*RefersToEnclosingVariableOrCapture*/ CI.isNested(),
949  type.getNonReferenceType(), VK_LValue,
950  SourceLocation());
951  src = EmitDeclRefLValue(&declRef).getAddress(*this);
952  };
953 
954  // For byrefs, we just write the pointer to the byref struct into
955  // the block field. There's no need to chase the forwarding
956  // pointer at this point, since we're building something that will
957  // live a shorter life than the stack byref anyway.
958  if (CI.isEscapingByref()) {
959  // Get a void* that points to the byref struct.
960  llvm::Value *byrefPointer;
961  if (CI.isNested())
962  byrefPointer = Builder.CreateLoad(src, "byref.capture");
963  else
964  byrefPointer = Builder.CreateBitCast(src.getPointer(), VoidPtrTy);
965 
966  // Write that void* into the capture field.
967  Builder.CreateStore(byrefPointer, blockField);
968 
969  // If we have a copy constructor, evaluate that into the block field.
970  } else if (const Expr *copyExpr = CI.getCopyExpr()) {
971  if (blockDecl->isConversionFromLambda()) {
972  // If we have a lambda conversion, emit the expression
973  // directly into the block instead.
974  AggValueSlot Slot =
975  AggValueSlot::forAddr(blockField, Qualifiers(),
980  EmitAggExpr(copyExpr, Slot);
981  } else {
982  EmitSynthesizedCXXCopyCtor(blockField, src, copyExpr);
983  }
984 
985  // If it's a reference variable, copy the reference into the block field.
986  } else if (type->isReferenceType()) {
987  Builder.CreateStore(src.getPointer(), blockField);
988 
989  // If type is const-qualified, copy the value into the block field.
990  } else if (type.isConstQualified() &&
991  type.getObjCLifetime() == Qualifiers::OCL_Strong &&
992  CGM.getCodeGenOpts().OptimizationLevel != 0) {
993  llvm::Value *value = Builder.CreateLoad(src, "captured");
994  Builder.CreateStore(value, blockField);
995 
996  // If this is an ARC __strong block-pointer variable, don't do a
997  // block copy.
998  //
999  // TODO: this can be generalized into the normal initialization logic:
1000  // we should never need to do a block-copy when initializing a local
1001  // variable, because the local variable's lifetime should be strictly
1002  // contained within the stack block's.
1003  } else if (type.getObjCLifetime() == Qualifiers::OCL_Strong &&
1004  type->isBlockPointerType()) {
1005  // Load the block and do a simple retain.
1006  llvm::Value *value = Builder.CreateLoad(src, "block.captured_block");
1007  value = EmitARCRetainNonBlock(value);
1008 
1009  // Do a primitive store to the block field.
1010  Builder.CreateStore(value, blockField);
1011 
1012  // Otherwise, fake up a POD copy into the block field.
1013  } else {
1014  // Fake up a new variable so that EmitScalarInit doesn't think
1015  // we're referring to the variable in its own initializer.
1016  ImplicitParamDecl BlockFieldPseudoVar(getContext(), type,
1018 
1019  // We use one of these or the other depending on whether the
1020  // reference is nested.
1021  DeclRefExpr declRef(getContext(), const_cast<VarDecl *>(variable),
1022  /*RefersToEnclosingVariableOrCapture*/ CI.isNested(),
1024 
1025  ImplicitCastExpr l2r(ImplicitCastExpr::OnStack, type, CK_LValueToRValue,
1026  &declRef, VK_PRValue, FPOptionsOverride());
1027  // FIXME: Pass a specific location for the expr init so that the store is
1028  // attributed to a reasonable location - otherwise it may be attributed to
1029  // locations of subexpressions in the initialization.
1030  EmitExprAsInit(&l2r, &BlockFieldPseudoVar,
1032  /*captured by init*/ false);
1033  }
1034 
1035  // Push a cleanup for the capture if necessary.
1036  if (!blockInfo.NeedsCopyDispose)
1037  continue;
1038 
1039  // Ignore __block captures; there's nothing special in the on-stack block
1040  // that we need to do for them.
1041  if (CI.isByRef())
1042  continue;
1043 
1044  // Ignore objects that aren't destructed.
1045  QualType::DestructionKind dtorKind = type.isDestructedType();
1046  if (dtorKind == QualType::DK_none)
1047  continue;
1048 
1049  CodeGenFunction::Destroyer *destroyer;
1050 
1051  // Block captures count as local values and have imprecise semantics.
1052  // They also can't be arrays, so need to worry about that.
1053  //
1054  // For const-qualified captures, emit clang.arc.use to ensure the captured
1055  // object doesn't get released while we are still depending on its validity
1056  // within the block.
1057  if (type.isConstQualified() &&
1058  type.getObjCLifetime() == Qualifiers::OCL_Strong &&
1059  CGM.getCodeGenOpts().OptimizationLevel != 0) {
1060  assert(CGM.getLangOpts().ObjCAutoRefCount &&
1061  "expected ObjC ARC to be enabled");
1062  destroyer = emitARCIntrinsicUse;
1063  } else if (dtorKind == QualType::DK_objc_strong_lifetime) {
1064  destroyer = destroyARCStrongImprecise;
1065  } else {
1066  destroyer = getDestroyer(dtorKind);
1067  }
1068 
1069  CleanupKind cleanupKind = NormalCleanup;
1070  bool useArrayEHCleanup = needsEHCleanup(dtorKind);
1071  if (useArrayEHCleanup)
1072  cleanupKind = NormalAndEHCleanup;
1073 
1074  // Extend the lifetime of the capture to the end of the scope enclosing the
1075  // block expression except when the block decl is in the list of RetExpr's
1076  // cleanup objects, in which case its lifetime ends after the full
1077  // expression.
1078  auto IsBlockDeclInRetExpr = [&]() {
1079  auto *EWC = llvm::dyn_cast_or_null<ExprWithCleanups>(RetExpr);
1080  if (EWC)
1081  for (auto &C : EWC->getObjects())
1082  if (auto *BD = C.dyn_cast<BlockDecl *>())
1083  if (BD == blockDecl)
1084  return true;
1085  return false;
1086  };
1087 
1088  if (IsBlockDeclInRetExpr())
1089  pushDestroy(cleanupKind, blockField, type, destroyer, useArrayEHCleanup);
1090  else
1091  pushLifetimeExtendedDestroy(cleanupKind, blockField, type, destroyer,
1092  useArrayEHCleanup);
1093  }
1094 
1095  // Cast to the converted block-pointer type, which happens (somewhat
1096  // unfortunately) to be a pointer to function type.
1097  llvm::Value *result = Builder.CreatePointerCast(
1098  blockAddr.getPointer(), ConvertType(blockInfo.getBlockExpr()->getType()));
1099 
1100  if (IsOpenCL) {
1101  CGM.getOpenCLRuntime().recordBlockInfo(blockInfo.BlockExpression, InvokeFn,
1102  result);
1103  }
1104 
1105  return result;
1106 }
1107 
1108 
1110  if (BlockDescriptorType)
1111  return BlockDescriptorType;
1112 
1113  llvm::Type *UnsignedLongTy =
1114  getTypes().ConvertType(getContext().UnsignedLongTy);
1115 
1116  // struct __block_descriptor {
1117  // unsigned long reserved;
1118  // unsigned long block_size;
1119  //
1120  // // later, the following will be added
1121  //
1122  // struct {
1123  // void (*copyHelper)();
1124  // void (*copyHelper)();
1125  // } helpers; // !!! optional
1126  //
1127  // const char *signature; // the block signature
1128  // const char *layout; // reserved
1129  // };
1130  BlockDescriptorType = llvm::StructType::create(
1131  "struct.__block_descriptor", UnsignedLongTy, UnsignedLongTy);
1132 
1133  // Now form a pointer to that.
1134  unsigned AddrSpace = 0;
1135  if (getLangOpts().OpenCL)
1137  BlockDescriptorType = llvm::PointerType::get(BlockDescriptorType, AddrSpace);
1138  return BlockDescriptorType;
1139 }
1140 
1142  if (GenericBlockLiteralType)
1143  return GenericBlockLiteralType;
1144 
1145  llvm::Type *BlockDescPtrTy = getBlockDescriptorType();
1146 
1147  if (getLangOpts().OpenCL) {
1148  // struct __opencl_block_literal_generic {
1149  // int __size;
1150  // int __align;
1151  // __generic void *__invoke;
1152  // /* custom fields */
1153  // };
1154  SmallVector<llvm::Type *, 8> StructFields(
1156  if (auto *Helper = getTargetCodeGenInfo().getTargetOpenCLBlockHelper()) {
1157  for (auto I : Helper->getCustomFieldTypes())
1158  StructFields.push_back(I);
1159  }
1160  GenericBlockLiteralType = llvm::StructType::create(
1161  StructFields, "struct.__opencl_block_literal_generic");
1162  } else {
1163  // struct __block_literal_generic {
1164  // void *__isa;
1165  // int __flags;
1166  // int __reserved;
1167  // void (*__invoke)(void *);
1168  // struct __block_descriptor *__descriptor;
1169  // };
1170  GenericBlockLiteralType =
1171  llvm::StructType::create("struct.__block_literal_generic", VoidPtrTy,
1172  IntTy, IntTy, VoidPtrTy, BlockDescPtrTy);
1173  }
1174 
1175  return GenericBlockLiteralType;
1176 }
1177 
1179  ReturnValueSlot ReturnValue) {
1180  const auto *BPT = E->getCallee()->getType()->castAs<BlockPointerType>();
1181  llvm::Value *BlockPtr = EmitScalarExpr(E->getCallee());
1182  llvm::Type *GenBlockTy = CGM.getGenericBlockLiteralType();
1183  llvm::Value *Func = nullptr;
1184  QualType FnType = BPT->getPointeeType();
1185  ASTContext &Ctx = getContext();
1186  CallArgList Args;
1187 
1188  if (getLangOpts().OpenCL) {
1189  // For OpenCL, BlockPtr is already casted to generic block literal.
1190 
1191  // First argument of a block call is a generic block literal casted to
1192  // generic void pointer, i.e. i8 addrspace(4)*
1193  llvm::Type *GenericVoidPtrTy =
1195  llvm::Value *BlockDescriptor = Builder.CreatePointerCast(
1196  BlockPtr, GenericVoidPtrTy);
1197  QualType VoidPtrQualTy = Ctx.getPointerType(
1199  Args.add(RValue::get(BlockDescriptor), VoidPtrQualTy);
1200  // And the rest of the arguments.
1201  EmitCallArgs(Args, FnType->getAs<FunctionProtoType>(), E->arguments());
1202 
1203  // We *can* call the block directly unless it is a function argument.
1204  if (!isa<ParmVarDecl>(E->getCalleeDecl()))
1206  else {
1207  llvm::Value *FuncPtr = Builder.CreateStructGEP(GenBlockTy, BlockPtr, 2);
1208  Func = Builder.CreateAlignedLoad(GenericVoidPtrTy, FuncPtr,
1209  getPointerAlign());
1210  }
1211  } else {
1212  // Bitcast the block literal to a generic block literal.
1213  BlockPtr = Builder.CreatePointerCast(
1214  BlockPtr, llvm::PointerType::get(GenBlockTy, 0), "block.literal");
1215  // Get pointer to the block invoke function
1216  llvm::Value *FuncPtr = Builder.CreateStructGEP(GenBlockTy, BlockPtr, 3);
1217 
1218  // First argument is a block literal casted to a void pointer
1219  BlockPtr = Builder.CreatePointerCast(BlockPtr, VoidPtrTy);
1220  Args.add(RValue::get(BlockPtr), Ctx.VoidPtrTy);
1221  // And the rest of the arguments.
1222  EmitCallArgs(Args, FnType->getAs<FunctionProtoType>(), E->arguments());
1223 
1224  // Load the function.
1225  Func = Builder.CreateAlignedLoad(VoidPtrTy, FuncPtr, getPointerAlign());
1226  }
1227 
1228  const FunctionType *FuncTy = FnType->castAs<FunctionType>();
1229  const CGFunctionInfo &FnInfo =
1230  CGM.getTypes().arrangeBlockFunctionCall(Args, FuncTy);
1231 
1232  // Cast the function pointer to the right type.
1233  llvm::Type *BlockFTy = CGM.getTypes().GetFunctionType(FnInfo);
1234 
1235  llvm::Type *BlockFTyPtr = llvm::PointerType::getUnqual(BlockFTy);
1236  Func = Builder.CreatePointerCast(Func, BlockFTyPtr);
1237 
1238  // Prepare the callee.
1239  CGCallee Callee(CGCalleeInfo(), Func);
1240 
1241  // And call the block.
1242  return EmitCall(FnInfo, Callee, ReturnValue, Args);
1243 }
1244 
1246  assert(BlockInfo && "evaluating block ref without block information?");
1247  const CGBlockInfo::Capture &capture = BlockInfo->getCapture(variable);
1248 
1249  // Handle constant captures.
1250  if (capture.isConstant()) return LocalDeclMap.find(variable)->second;
1251 
1253  "block.capture.addr");
1254 
1255  if (variable->isEscapingByref()) {
1256  // addr should be a void** right now. Load, then cast the result
1257  // to byref*.
1258 
1259  auto &byrefInfo = getBlockByrefInfo(variable);
1260  addr = Address(Builder.CreateLoad(addr), byrefInfo.ByrefAlignment);
1261 
1262  auto byrefPointerType = llvm::PointerType::get(byrefInfo.Type, 0);
1263  addr = Builder.CreateBitCast(addr, byrefPointerType, "byref.addr");
1264 
1265  addr = emitBlockByrefAddress(addr, byrefInfo, /*follow*/ true,
1266  variable->getName());
1267  }
1268 
1269  assert((!variable->isNonEscapingByref() ||
1270  capture.fieldType()->isReferenceType()) &&
1271  "the capture field of a non-escaping variable should have a "
1272  "reference type");
1273  if (capture.fieldType()->isReferenceType())
1274  addr = EmitLoadOfReference(MakeAddrLValue(addr, capture.fieldType()));
1275 
1276  return addr;
1277 }
1278 
1280  llvm::Constant *Addr) {
1281  bool Ok = EmittedGlobalBlocks.insert(std::make_pair(BE, Addr)).second;
1282  (void)Ok;
1283  assert(Ok && "Trying to replace an already-existing global block!");
1284 }
1285 
1286 llvm::Constant *
1288  StringRef Name) {
1289  if (llvm::Constant *Block = getAddrOfGlobalBlockIfEmitted(BE))
1290  return Block;
1291 
1292  CGBlockInfo blockInfo(BE->getBlockDecl(), Name);
1293  blockInfo.BlockExpression = BE;
1294 
1295  // Compute information about the layout, etc., of this block.
1296  computeBlockInfo(*this, nullptr, blockInfo);
1297 
1298  // Using that metadata, generate the actual block function.
1299  {
1300  CodeGenFunction::DeclMapTy LocalDeclMap;
1302  GlobalDecl(), blockInfo, LocalDeclMap,
1303  /*IsLambdaConversionToBlock*/ false, /*BuildGlobalBlock*/ true);
1304  }
1305 
1306  return getAddrOfGlobalBlockIfEmitted(BE);
1307 }
1308 
1309 static llvm::Constant *buildGlobalBlock(CodeGenModule &CGM,
1310  const CGBlockInfo &blockInfo,
1311  llvm::Constant *blockFn) {
1312  assert(blockInfo.CanBeGlobal);
1313  // Callers should detect this case on their own: calling this function
1314  // generally requires computing layout information, which is a waste of time
1315  // if we've already emitted this block.
1316  assert(!CGM.getAddrOfGlobalBlockIfEmitted(blockInfo.BlockExpression) &&
1317  "Refusing to re-emit a global block.");
1318 
1319  // Generate the constants for the block literal initializer.
1320  ConstantInitBuilder builder(CGM);
1321  auto fields = builder.beginStruct();
1322 
1323  bool IsOpenCL = CGM.getLangOpts().OpenCL;
1324  bool IsWindows = CGM.getTarget().getTriple().isOSWindows();
1325  if (!IsOpenCL) {
1326  // isa
1327  if (IsWindows)
1328  fields.addNullPointer(CGM.Int8PtrPtrTy);
1329  else
1330  fields.add(CGM.getNSConcreteGlobalBlock());
1331 
1332  // __flags
1334  if (blockInfo.UsesStret)
1335  flags |= BLOCK_USE_STRET;
1336 
1337  fields.addInt(CGM.IntTy, flags.getBitMask());
1338 
1339  // Reserved
1340  fields.addInt(CGM.IntTy, 0);
1341  } else {
1342  fields.addInt(CGM.IntTy, blockInfo.BlockSize.getQuantity());
1343  fields.addInt(CGM.IntTy, blockInfo.BlockAlign.getQuantity());
1344  }
1345 
1346  // Function
1347  fields.add(blockFn);
1348 
1349  if (!IsOpenCL) {
1350  // Descriptor
1351  fields.add(buildBlockDescriptor(CGM, blockInfo));
1352  } else if (auto *Helper =
1354  for (auto I : Helper->getCustomFieldValues(CGM, blockInfo)) {
1355  fields.add(I);
1356  }
1357  }
1358 
1359  unsigned AddrSpace = 0;
1360  if (CGM.getContext().getLangOpts().OpenCL)
1362 
1363  llvm::GlobalVariable *literal = fields.finishAndCreateGlobal(
1364  "__block_literal_global", blockInfo.BlockAlign,
1365  /*constant*/ !IsWindows, llvm::GlobalVariable::InternalLinkage, AddrSpace);
1366 
1367  literal->addAttribute("objc_arc_inert");
1368 
1369  // Windows does not allow globals to be initialised to point to globals in
1370  // different DLLs. Any such variables must run code to initialise them.
1371  if (IsWindows) {
1372  auto *Init = llvm::Function::Create(llvm::FunctionType::get(CGM.VoidTy,
1373  {}), llvm::GlobalValue::InternalLinkage, ".block_isa_init",
1374  &CGM.getModule());
1375  llvm::IRBuilder<> b(llvm::BasicBlock::Create(CGM.getLLVMContext(), "entry",
1376  Init));
1377  b.CreateAlignedStore(CGM.getNSConcreteGlobalBlock(),
1378  b.CreateStructGEP(literal->getValueType(), literal, 0),
1379  CGM.getPointerAlign().getAsAlign());
1380  b.CreateRetVoid();
1381  // We can't use the normal LLVM global initialisation array, because we
1382  // need to specify that this runs early in library initialisation.
1383  auto *InitVar = new llvm::GlobalVariable(CGM.getModule(), Init->getType(),
1384  /*isConstant*/true, llvm::GlobalValue::InternalLinkage,
1385  Init, ".block_isa_init_ptr");
1386  InitVar->setSection(".CRT$XCLa");
1387  CGM.addUsedGlobal(InitVar);
1388  }
1389 
1390  // Return a constant of the appropriately-casted type.
1391  llvm::Type *RequiredType =
1392  CGM.getTypes().ConvertType(blockInfo.getBlockExpr()->getType());
1393  llvm::Constant *Result =
1394  llvm::ConstantExpr::getPointerCast(literal, RequiredType);
1395  CGM.setAddrOfGlobalBlock(blockInfo.BlockExpression, Result);
1396  if (CGM.getContext().getLangOpts().OpenCL)
1398  blockInfo.BlockExpression,
1399  cast<llvm::Function>(blockFn->stripPointerCasts()), Result);
1400  return Result;
1401 }
1402 
1404  unsigned argNum,
1405  llvm::Value *arg) {
1406  assert(BlockInfo && "not emitting prologue of block invocation function?!");
1407 
1408  // Allocate a stack slot like for any local variable to guarantee optimal
1409  // debug info at -O0. The mem2reg pass will eliminate it when optimizing.
1410  Address alloc = CreateMemTemp(D->getType(), D->getName() + ".addr");
1411  Builder.CreateStore(arg, alloc);
1412  if (CGDebugInfo *DI = getDebugInfo()) {
1414  DI->setLocation(D->getLocation());
1415  DI->EmitDeclareOfBlockLiteralArgVariable(
1416  *BlockInfo, D->getName(), argNum,
1417  cast<llvm::AllocaInst>(alloc.getPointer()), Builder);
1418  }
1419  }
1420 
1422  ApplyDebugLocation Scope(*this, StartLoc);
1423 
1424  // Instead of messing around with LocalDeclMap, just set the value
1425  // directly as BlockPointer.
1426  BlockPointer = Builder.CreatePointerCast(
1427  arg,
1428  BlockInfo->StructureType->getPointerTo(
1430  ? getContext().getTargetAddressSpace(LangAS::opencl_generic)
1431  : 0),
1432  "block");
1433 }
1434 
1436  assert(BlockInfo && "not in a block invocation function!");
1437  assert(BlockPointer && "no block pointer set!");
1439 }
1440 
1441 llvm::Function *
1443  const CGBlockInfo &blockInfo,
1444  const DeclMapTy &ldm,
1445  bool IsLambdaConversionToBlock,
1446  bool BuildGlobalBlock) {
1447  const BlockDecl *blockDecl = blockInfo.getBlockDecl();
1448 
1449  CurGD = GD;
1450 
1451  CurEHLocation = blockInfo.getBlockExpr()->getEndLoc();
1452 
1453  BlockInfo = &blockInfo;
1454 
1455  // Arrange for local static and local extern declarations to appear
1456  // to be local to this function as well, in case they're directly
1457  // referenced in a block.
1458  for (DeclMapTy::const_iterator i = ldm.begin(), e = ldm.end(); i != e; ++i) {
1459  const auto *var = dyn_cast<VarDecl>(i->first);
1460  if (var && !var->hasLocalStorage())
1461  setAddrOfLocalVar(var, i->second);
1462  }
1463 
1464  // Begin building the function declaration.
1465 
1466  // Build the argument list.
1467  FunctionArgList args;
1468 
1469  // The first argument is the block pointer. Just take it as a void*
1470  // and cast it later.
1471  QualType selfTy = getContext().VoidPtrTy;
1472 
1473  // For OpenCL passed block pointer can be private AS local variable or
1474  // global AS program scope variable (for the case with and without captures).
1475  // Generic AS is used therefore to be able to accommodate both private and
1476  // generic AS in one implementation.
1477  if (getLangOpts().OpenCL)
1478  selfTy = getContext().getPointerType(getContext().getAddrSpaceQualType(
1480 
1481  IdentifierInfo *II = &CGM.getContext().Idents.get(".block_descriptor");
1482 
1483  ImplicitParamDecl SelfDecl(getContext(), const_cast<BlockDecl *>(blockDecl),
1484  SourceLocation(), II, selfTy,
1486  args.push_back(&SelfDecl);
1487 
1488  // Now add the rest of the parameters.
1489  args.append(blockDecl->param_begin(), blockDecl->param_end());
1490 
1491  // Create the function declaration.
1492  const FunctionProtoType *fnType = blockInfo.getBlockExpr()->getFunctionType();
1493  const CGFunctionInfo &fnInfo =
1495  if (CGM.ReturnSlotInterferesWithArgs(fnInfo))
1496  blockInfo.UsesStret = true;
1497 
1498  llvm::FunctionType *fnLLVMType = CGM.getTypes().GetFunctionType(fnInfo);
1499 
1500  StringRef name = CGM.getBlockMangledName(GD, blockDecl);
1501  llvm::Function *fn = llvm::Function::Create(
1504 
1505  if (BuildGlobalBlock) {
1506  auto GenVoidPtrTy = getContext().getLangOpts().OpenCL
1508  : VoidPtrTy;
1509  buildGlobalBlock(CGM, blockInfo,
1510  llvm::ConstantExpr::getPointerCast(fn, GenVoidPtrTy));
1511  }
1512 
1513  // Begin generating the function.
1514  StartFunction(blockDecl, fnType->getReturnType(), fn, fnInfo, args,
1515  blockDecl->getLocation(),
1516  blockInfo.getBlockExpr()->getBody()->getBeginLoc());
1517 
1518  // Okay. Undo some of what StartFunction did.
1519 
1520  // At -O0 we generate an explicit alloca for the BlockPointer, so the RA
1521  // won't delete the dbg.declare intrinsics for captured variables.
1522  llvm::Value *BlockPointerDbgLoc = BlockPointer;
1523  if (CGM.getCodeGenOpts().OptimizationLevel == 0) {
1524  // Allocate a stack slot for it, so we can point the debugger to it
1525  Address Alloca = CreateTempAlloca(BlockPointer->getType(),
1526  getPointerAlign(),
1527  "block.addr");
1528  // Set the DebugLocation to empty, so the store is recognized as a
1529  // frame setup instruction by llvm::DwarfDebug::beginFunction().
1530  auto NL = ApplyDebugLocation::CreateEmpty(*this);
1531  Builder.CreateStore(BlockPointer, Alloca);
1532  BlockPointerDbgLoc = Alloca.getPointer();
1533  }
1534 
1535  // If we have a C++ 'this' reference, go ahead and force it into
1536  // existence now.
1537  if (blockDecl->capturesCXXThis()) {
1539  LoadBlockStruct(), blockInfo.CXXThisIndex, "block.captured-this");
1540  CXXThisValue = Builder.CreateLoad(addr, "this");
1541  }
1542 
1543  // Also force all the constant captures.
1544  for (const auto &CI : blockDecl->captures()) {
1545  const VarDecl *variable = CI.getVariable();
1546  const CGBlockInfo::Capture &capture = blockInfo.getCapture(variable);
1547  if (!capture.isConstant()) continue;
1548 
1549  CharUnits align = getContext().getDeclAlign(variable);
1550  Address alloca =
1551  CreateMemTemp(variable->getType(), align, "block.captured-const");
1552 
1553  Builder.CreateStore(capture.getConstant(), alloca);
1554 
1555  setAddrOfLocalVar(variable, alloca);
1556  }
1557 
1558  // Save a spot to insert the debug information for all the DeclRefExprs.
1559  llvm::BasicBlock *entry = Builder.GetInsertBlock();
1560  llvm::BasicBlock::iterator entry_ptr = Builder.GetInsertPoint();
1561  --entry_ptr;
1562 
1563  if (IsLambdaConversionToBlock)
1565  else {
1567  incrementProfileCounter(blockDecl->getBody());
1568  EmitStmt(blockDecl->getBody());
1569  }
1570 
1571  // Remember where we were...
1572  llvm::BasicBlock *resume = Builder.GetInsertBlock();
1573 
1574  // Go back to the entry.
1575  ++entry_ptr;
1576  Builder.SetInsertPoint(entry, entry_ptr);
1577 
1578  // Emit debug information for all the DeclRefExprs.
1579  // FIXME: also for 'this'
1580  if (CGDebugInfo *DI = getDebugInfo()) {
1581  for (const auto &CI : blockDecl->captures()) {
1582  const VarDecl *variable = CI.getVariable();
1583  DI->EmitLocation(Builder, variable->getLocation());
1584 
1586  const CGBlockInfo::Capture &capture = blockInfo.getCapture(variable);
1587  if (capture.isConstant()) {
1588  auto addr = LocalDeclMap.find(variable)->second;
1589  (void)DI->EmitDeclareOfAutoVariable(variable, addr.getPointer(),
1590  Builder);
1591  continue;
1592  }
1593 
1594  DI->EmitDeclareOfBlockDeclRefVariable(
1595  variable, BlockPointerDbgLoc, Builder, blockInfo,
1596  entry_ptr == entry->end() ? nullptr : &*entry_ptr);
1597  }
1598  }
1599  // Recover location if it was changed in the above loop.
1600  DI->EmitLocation(Builder,
1601  cast<CompoundStmt>(blockDecl->getBody())->getRBracLoc());
1602  }
1603 
1604  // And resume where we left off.
1605  if (resume == nullptr)
1606  Builder.ClearInsertionPoint();
1607  else
1608  Builder.SetInsertPoint(resume);
1609 
1610  FinishFunction(cast<CompoundStmt>(blockDecl->getBody())->getRBracLoc());
1611 
1612  return fn;
1613 }
1614 
1615 static std::pair<BlockCaptureEntityKind, BlockFieldFlags>
1617  const LangOptions &LangOpts) {
1618  if (CI.getCopyExpr()) {
1619  assert(!CI.isByRef());
1620  // don't bother computing flags
1621  return std::make_pair(BlockCaptureEntityKind::CXXRecord, BlockFieldFlags());
1622  }
1623  BlockFieldFlags Flags;
1624  if (CI.isEscapingByref()) {
1625  Flags = BLOCK_FIELD_IS_BYREF;
1626  if (T.isObjCGCWeak())
1627  Flags |= BLOCK_FIELD_IS_WEAK;
1628  return std::make_pair(BlockCaptureEntityKind::BlockObject, Flags);
1629  }
1630 
1631  Flags = BLOCK_FIELD_IS_OBJECT;
1632  bool isBlockPointer = T->isBlockPointerType();
1633  if (isBlockPointer)
1634  Flags = BLOCK_FIELD_IS_BLOCK;
1635 
1636  switch (T.isNonTrivialToPrimitiveCopy()) {
1637  case QualType::PCK_Struct:
1638  return std::make_pair(BlockCaptureEntityKind::NonTrivialCStruct,
1639  BlockFieldFlags());
1640  case QualType::PCK_ARCWeak:
1641  // We need to register __weak direct captures with the runtime.
1642  return std::make_pair(BlockCaptureEntityKind::ARCWeak, Flags);
1644  // We need to retain the copied value for __strong direct captures.
1645  // If it's a block pointer, we have to copy the block and assign that to
1646  // the destination pointer, so we might as well use _Block_object_assign.
1647  // Otherwise we can avoid that.
1648  return std::make_pair(!isBlockPointer ? BlockCaptureEntityKind::ARCStrong
1649  : BlockCaptureEntityKind::BlockObject,
1650  Flags);
1651  case QualType::PCK_Trivial:
1653  if (!T->isObjCRetainableType())
1654  // For all other types, the memcpy is fine.
1655  return std::make_pair(BlockCaptureEntityKind::None, BlockFieldFlags());
1656 
1657  // Special rules for ARC captures:
1658  Qualifiers QS = T.getQualifiers();
1659 
1660  // Non-ARC captures of retainable pointers are strong and
1661  // therefore require a call to _Block_object_assign.
1662  if (!QS.getObjCLifetime() && !LangOpts.ObjCAutoRefCount)
1663  return std::make_pair(BlockCaptureEntityKind::BlockObject, Flags);
1664 
1665  // Otherwise the memcpy is fine.
1666  return std::make_pair(BlockCaptureEntityKind::None, BlockFieldFlags());
1667  }
1668  }
1669  llvm_unreachable("after exhaustive PrimitiveCopyKind switch");
1670 }
1671 
1672 static std::pair<BlockCaptureEntityKind, BlockFieldFlags>
1674  const LangOptions &LangOpts);
1675 
1676 /// Find the set of block captures that need to be explicitly copied or destroy.
1678  const CGBlockInfo &BlockInfo, const LangOptions &LangOpts,
1679  SmallVectorImpl<BlockCaptureManagedEntity> &ManagedCaptures) {
1680  for (const auto &CI : BlockInfo.getBlockDecl()->captures()) {
1681  const VarDecl *Variable = CI.getVariable();
1682  const CGBlockInfo::Capture &Capture = BlockInfo.getCapture(Variable);
1683  if (Capture.isConstant())
1684  continue;
1685 
1686  QualType VT = Capture.fieldType();
1687  auto CopyInfo = computeCopyInfoForBlockCapture(CI, VT, LangOpts);
1688  auto DisposeInfo = computeDestroyInfoForBlockCapture(CI, VT, LangOpts);
1689  if (CopyInfo.first != BlockCaptureEntityKind::None ||
1690  DisposeInfo.first != BlockCaptureEntityKind::None)
1691  ManagedCaptures.emplace_back(CopyInfo.first, DisposeInfo.first,
1692  CopyInfo.second, DisposeInfo.second, CI,
1693  Capture);
1694  }
1695 
1696  // Sort the captures by offset.
1697  llvm::sort(ManagedCaptures);
1698 }
1699 
1700 namespace {
1701 /// Release a __block variable.
1702 struct CallBlockRelease final : EHScopeStack::Cleanup {
1703  Address Addr;
1704  BlockFieldFlags FieldFlags;
1705  bool LoadBlockVarAddr, CanThrow;
1706 
1707  CallBlockRelease(Address Addr, BlockFieldFlags Flags, bool LoadValue,
1708  bool CT)
1709  : Addr(Addr), FieldFlags(Flags), LoadBlockVarAddr(LoadValue),
1710  CanThrow(CT) {}
1711 
1712  void Emit(CodeGenFunction &CGF, Flags flags) override {
1713  llvm::Value *BlockVarAddr;
1714  if (LoadBlockVarAddr) {
1715  BlockVarAddr = CGF.Builder.CreateLoad(Addr);
1716  BlockVarAddr = CGF.Builder.CreateBitCast(BlockVarAddr, CGF.VoidPtrTy);
1717  } else {
1718  BlockVarAddr = Addr.getPointer();
1719  }
1720 
1721  CGF.BuildBlockRelease(BlockVarAddr, FieldFlags, CanThrow);
1722  }
1723 };
1724 } // end anonymous namespace
1725 
1726 /// Check if \p T is a C++ class that has a destructor that can throw.
1728  if (const auto *RD = T->getAsCXXRecordDecl())
1729  if (const CXXDestructorDecl *DD = RD->getDestructor())
1730  return DD->getType()->castAs<FunctionProtoType>()->canThrow();
1731  return false;
1732 }
1733 
1734 // Return a string that has the information about a capture.
1735 static std::string getBlockCaptureStr(const BlockCaptureManagedEntity &E,
1736  CaptureStrKind StrKind,
1737  CharUnits BlockAlignment,
1738  CodeGenModule &CGM) {
1739  std::string Str;
1740  ASTContext &Ctx = CGM.getContext();
1741  const BlockDecl::Capture &CI = *E.CI;
1742  QualType CaptureTy = CI.getVariable()->getType();
1743 
1744  BlockCaptureEntityKind Kind;
1745  BlockFieldFlags Flags;
1746 
1747  // CaptureStrKind::Merged should be passed only when the operations and the
1748  // flags are the same for copy and dispose.
1749  assert((StrKind != CaptureStrKind::Merged ||
1750  (E.CopyKind == E.DisposeKind && E.CopyFlags == E.DisposeFlags)) &&
1751  "different operations and flags");
1752 
1753  if (StrKind == CaptureStrKind::DisposeHelper) {
1754  Kind = E.DisposeKind;
1755  Flags = E.DisposeFlags;
1756  } else {
1757  Kind = E.CopyKind;
1758  Flags = E.CopyFlags;
1759  }
1760 
1761  switch (Kind) {
1762  case BlockCaptureEntityKind::CXXRecord: {
1763  Str += "c";
1764  SmallString<256> TyStr;
1765  llvm::raw_svector_ostream Out(TyStr);
1766  CGM.getCXXABI().getMangleContext().mangleTypeName(CaptureTy, Out);
1767  Str += llvm::to_string(TyStr.size()) + TyStr.c_str();
1768  break;
1769  }
1770  case BlockCaptureEntityKind::ARCWeak:
1771  Str += "w";
1772  break;
1773  case BlockCaptureEntityKind::ARCStrong:
1774  Str += "s";
1775  break;
1776  case BlockCaptureEntityKind::BlockObject: {
1777  const VarDecl *Var = CI.getVariable();
1778  unsigned F = Flags.getBitMask();
1779  if (F & BLOCK_FIELD_IS_BYREF) {
1780  Str += "r";
1781  if (F & BLOCK_FIELD_IS_WEAK)
1782  Str += "w";
1783  else {
1784  // If CaptureStrKind::Merged is passed, check both the copy expression
1785  // and the destructor.
1786  if (StrKind != CaptureStrKind::DisposeHelper) {
1787  if (Ctx.getBlockVarCopyInit(Var).canThrow())
1788  Str += "c";
1789  }
1790  if (StrKind != CaptureStrKind::CopyHelper) {
1792  Str += "d";
1793  }
1794  }
1795  } else {
1796  assert((F & BLOCK_FIELD_IS_OBJECT) && "unexpected flag value");
1797  if (F == BLOCK_FIELD_IS_BLOCK)
1798  Str += "b";
1799  else
1800  Str += "o";
1801  }
1802  break;
1803  }
1804  case BlockCaptureEntityKind::NonTrivialCStruct: {
1805  bool IsVolatile = CaptureTy.isVolatileQualified();
1806  CharUnits Alignment =
1807  BlockAlignment.alignmentAtOffset(E.Capture->getOffset());
1808 
1809  Str += "n";
1810  std::string FuncStr;
1811  if (StrKind == CaptureStrKind::DisposeHelper)
1813  CaptureTy, Alignment, IsVolatile, Ctx);
1814  else
1815  // If CaptureStrKind::Merged is passed, use the copy constructor string.
1816  // It has all the information that the destructor string has.
1818  CaptureTy, Alignment, IsVolatile, Ctx);
1819  // The underscore is necessary here because non-trivial copy constructor
1820  // and destructor strings can start with a number.
1821  Str += llvm::to_string(FuncStr.size()) + "_" + FuncStr;
1822  break;
1823  }
1825  break;
1826  }
1827 
1828  return Str;
1829 }
1830 
1832  const SmallVectorImpl<BlockCaptureManagedEntity> &Captures,
1833  CharUnits BlockAlignment, CaptureStrKind StrKind, CodeGenModule &CGM) {
1834  assert((StrKind == CaptureStrKind::CopyHelper ||
1835  StrKind == CaptureStrKind::DisposeHelper) &&
1836  "unexpected CaptureStrKind");
1837  std::string Name = StrKind == CaptureStrKind::CopyHelper
1838  ? "__copy_helper_block_"
1839  : "__destroy_helper_block_";
1840  if (CGM.getLangOpts().Exceptions)
1841  Name += "e";
1842  if (CGM.getCodeGenOpts().ObjCAutoRefCountExceptions)
1843  Name += "a";
1844  Name += llvm::to_string(BlockAlignment.getQuantity()) + "_";
1845 
1846  for (const BlockCaptureManagedEntity &E : Captures) {
1847  Name += llvm::to_string(E.Capture->getOffset().getQuantity());
1848  Name += getBlockCaptureStr(E, StrKind, BlockAlignment, CGM);
1849  }
1850 
1851  return Name;
1852 }
1853 
1854 static void pushCaptureCleanup(BlockCaptureEntityKind CaptureKind,
1855  Address Field, QualType CaptureType,
1856  BlockFieldFlags Flags, bool ForCopyHelper,
1857  VarDecl *Var, CodeGenFunction &CGF) {
1858  bool EHOnly = ForCopyHelper;
1859 
1860  switch (CaptureKind) {
1861  case BlockCaptureEntityKind::CXXRecord:
1862  case BlockCaptureEntityKind::ARCWeak:
1863  case BlockCaptureEntityKind::NonTrivialCStruct:
1864  case BlockCaptureEntityKind::ARCStrong: {
1865  if (CaptureType.isDestructedType() &&
1866  (!EHOnly || CGF.needsEHCleanup(CaptureType.isDestructedType()))) {
1867  CodeGenFunction::Destroyer *Destroyer =
1868  CaptureKind == BlockCaptureEntityKind::ARCStrong
1870  : CGF.getDestroyer(CaptureType.isDestructedType());
1871  CleanupKind Kind =
1872  EHOnly ? EHCleanup
1873  : CGF.getCleanupKind(CaptureType.isDestructedType());
1874  CGF.pushDestroy(Kind, Field, CaptureType, Destroyer, Kind & EHCleanup);
1875  }
1876  break;
1877  }
1878  case BlockCaptureEntityKind::BlockObject: {
1879  if (!EHOnly || CGF.getLangOpts().Exceptions) {
1881  // Calls to _Block_object_dispose along the EH path in the copy helper
1882  // function don't throw as newly-copied __block variables always have a
1883  // reference count of 2.
1884  bool CanThrow =
1885  !ForCopyHelper && CGF.cxxDestructorCanThrow(CaptureType);
1886  CGF.enterByrefCleanup(Kind, Field, Flags, /*LoadBlockVarAddr*/ true,
1887  CanThrow);
1888  }
1889  break;
1890  }
1892  break;
1893  }
1894 }
1895 
1896 static void setBlockHelperAttributesVisibility(bool CapturesNonExternalType,
1897  llvm::Function *Fn,
1898  const CGFunctionInfo &FI,
1899  CodeGenModule &CGM) {
1900  if (CapturesNonExternalType) {
1902  } else {
1903  Fn->setVisibility(llvm::GlobalValue::HiddenVisibility);
1904  Fn->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
1905  CGM.SetLLVMFunctionAttributes(GlobalDecl(), FI, Fn, /*IsThunk=*/false);
1906  CGM.SetLLVMFunctionAttributesForDefinition(nullptr, Fn);
1907  }
1908 }
1909 /// Generate the copy-helper function for a block closure object:
1910 /// static void block_copy_helper(block_t *dst, block_t *src);
1911 /// The runtime will have previously initialized 'dst' by doing a
1912 /// bit-copy of 'src'.
1913 ///
1914 /// Note that this copies an entire block closure object to the heap;
1915 /// it should not be confused with a 'byref copy helper', which moves
1916 /// the contents of an individual __block variable to the heap.
1917 llvm::Constant *
1920  findBlockCapturedManagedEntities(blockInfo, getLangOpts(), CopiedCaptures);
1921  std::string FuncName =
1922  getCopyDestroyHelperFuncName(CopiedCaptures, blockInfo.BlockAlign,
1923  CaptureStrKind::CopyHelper, CGM);
1924 
1925  if (llvm::GlobalValue *Func = CGM.getModule().getNamedValue(FuncName))
1926  return llvm::ConstantExpr::getBitCast(Func, VoidPtrTy);
1927 
1928  ASTContext &C = getContext();
1929 
1930  QualType ReturnTy = C.VoidTy;
1931 
1932  FunctionArgList args;
1933  ImplicitParamDecl DstDecl(C, C.VoidPtrTy, ImplicitParamDecl::Other);
1934  args.push_back(&DstDecl);
1935  ImplicitParamDecl SrcDecl(C, C.VoidPtrTy, ImplicitParamDecl::Other);
1936  args.push_back(&SrcDecl);
1937 
1938  const CGFunctionInfo &FI =
1940 
1941  // FIXME: it would be nice if these were mergeable with things with
1942  // identical semantics.
1943  llvm::FunctionType *LTy = CGM.getTypes().GetFunctionType(FI);
1944 
1945  llvm::Function *Fn =
1946  llvm::Function::Create(LTy, llvm::GlobalValue::LinkOnceODRLinkage,
1947  FuncName, &CGM.getModule());
1948  if (CGM.supportsCOMDAT())
1949  Fn->setComdat(CGM.getModule().getOrInsertComdat(FuncName));
1950 
1951  SmallVector<QualType, 2> ArgTys;
1952  ArgTys.push_back(C.VoidPtrTy);
1953  ArgTys.push_back(C.VoidPtrTy);
1954 
1956  CGM);
1957  StartFunction(GlobalDecl(), ReturnTy, Fn, FI, args);
1958  auto AL = ApplyDebugLocation::CreateArtificial(*this);
1959 
1960  llvm::Type *structPtrTy = blockInfo.StructureType->getPointerTo();
1961 
1962  Address src = GetAddrOfLocalVar(&SrcDecl);
1963  src = Address(Builder.CreateLoad(src), blockInfo.BlockAlign);
1964  src = Builder.CreateBitCast(src, structPtrTy, "block.source");
1965 
1966  Address dst = GetAddrOfLocalVar(&DstDecl);
1967  dst = Address(Builder.CreateLoad(dst), blockInfo.BlockAlign);
1968  dst = Builder.CreateBitCast(dst, structPtrTy, "block.dest");
1969 
1970  for (const auto &CopiedCapture : CopiedCaptures) {
1971  const BlockDecl::Capture &CI = *CopiedCapture.CI;
1972  const CGBlockInfo::Capture &capture = *CopiedCapture.Capture;
1973  QualType captureType = CI.getVariable()->getType();
1974  BlockFieldFlags flags = CopiedCapture.CopyFlags;
1975 
1976  unsigned index = capture.getIndex();
1977  Address srcField = Builder.CreateStructGEP(src, index);
1978  Address dstField = Builder.CreateStructGEP(dst, index);
1979 
1980  switch (CopiedCapture.CopyKind) {
1981  case BlockCaptureEntityKind::CXXRecord:
1982  // If there's an explicit copy expression, we do that.
1983  assert(CI.getCopyExpr() && "copy expression for variable is missing");
1984  EmitSynthesizedCXXCopyCtor(dstField, srcField, CI.getCopyExpr());
1985  break;
1986  case BlockCaptureEntityKind::ARCWeak:
1987  EmitARCCopyWeak(dstField, srcField);
1988  break;
1989  case BlockCaptureEntityKind::NonTrivialCStruct: {
1990  // If this is a C struct that requires non-trivial copy construction,
1991  // emit a call to its copy constructor.
1992  QualType varType = CI.getVariable()->getType();
1993  callCStructCopyConstructor(MakeAddrLValue(dstField, varType),
1994  MakeAddrLValue(srcField, varType));
1995  break;
1996  }
1997  case BlockCaptureEntityKind::ARCStrong: {
1998  llvm::Value *srcValue = Builder.CreateLoad(srcField, "blockcopy.src");
1999  // At -O0, store null into the destination field (so that the
2000  // storeStrong doesn't over-release) and then call storeStrong.
2001  // This is a workaround to not having an initStrong call.
2002  if (CGM.getCodeGenOpts().OptimizationLevel == 0) {
2003  auto *ty = cast<llvm::PointerType>(srcValue->getType());
2004  llvm::Value *null = llvm::ConstantPointerNull::get(ty);
2005  Builder.CreateStore(null, dstField);
2006  EmitARCStoreStrongCall(dstField, srcValue, true);
2007 
2008  // With optimization enabled, take advantage of the fact that
2009  // the blocks runtime guarantees a memcpy of the block data, and
2010  // just emit a retain of the src field.
2011  } else {
2012  EmitARCRetainNonBlock(srcValue);
2013 
2014  // Unless EH cleanup is required, we don't need this anymore, so kill
2015  // it. It's not quite worth the annoyance to avoid creating it in the
2016  // first place.
2017  if (!needsEHCleanup(captureType.isDestructedType()))
2018  cast<llvm::Instruction>(dstField.getPointer())->eraseFromParent();
2019  }
2020  break;
2021  }
2022  case BlockCaptureEntityKind::BlockObject: {
2023  llvm::Value *srcValue = Builder.CreateLoad(srcField, "blockcopy.src");
2024  srcValue = Builder.CreateBitCast(srcValue, VoidPtrTy);
2025  llvm::Value *dstAddr =
2027  llvm::Value *args[] = {
2028  dstAddr, srcValue, llvm::ConstantInt::get(Int32Ty, flags.getBitMask())
2029  };
2030 
2031  if (CI.isByRef() && C.getBlockVarCopyInit(CI.getVariable()).canThrow())
2033  else
2035  break;
2036  }
2038  continue;
2039  }
2040 
2041  // Ensure that we destroy the copied object if an exception is thrown later
2042  // in the helper function.
2043  pushCaptureCleanup(CopiedCapture.CopyKind, dstField, captureType, flags,
2044  /*ForCopyHelper*/ true, CI.getVariable(), *this);
2045  }
2046 
2047  FinishFunction();
2048 
2049  return llvm::ConstantExpr::getBitCast(Fn, VoidPtrTy);
2050 }
2051 
2052 static BlockFieldFlags
2054  QualType T) {
2056  if (T->isBlockPointerType())
2057  Flags = BLOCK_FIELD_IS_BLOCK;
2058  return Flags;
2059 }
2060 
2061 static std::pair<BlockCaptureEntityKind, BlockFieldFlags>
2063  const LangOptions &LangOpts) {
2064  if (CI.isEscapingByref()) {
2066  if (T.isObjCGCWeak())
2067  Flags |= BLOCK_FIELD_IS_WEAK;
2068  return std::make_pair(BlockCaptureEntityKind::BlockObject, Flags);
2069  }
2070 
2071  switch (T.isDestructedType()) {
2073  return std::make_pair(BlockCaptureEntityKind::CXXRecord, BlockFieldFlags());
2075  // Use objc_storeStrong for __strong direct captures; the
2076  // dynamic tools really like it when we do this.
2077  return std::make_pair(BlockCaptureEntityKind::ARCStrong,
2080  // Support __weak direct captures.
2081  return std::make_pair(BlockCaptureEntityKind::ARCWeak,
2084  return std::make_pair(BlockCaptureEntityKind::NonTrivialCStruct,
2085  BlockFieldFlags());
2086  case QualType::DK_none: {
2087  // Non-ARC captures are strong, and we need to use _Block_object_dispose.
2088  if (T->isObjCRetainableType() && !T.getQualifiers().hasObjCLifetime() &&
2089  !LangOpts.ObjCAutoRefCount)
2090  return std::make_pair(BlockCaptureEntityKind::BlockObject,
2092  // Otherwise, we have nothing to do.
2093  return std::make_pair(BlockCaptureEntityKind::None, BlockFieldFlags());
2094  }
2095  }
2096  llvm_unreachable("after exhaustive DestructionKind switch");
2097 }
2098 
2099 /// Generate the destroy-helper function for a block closure object:
2100 /// static void block_destroy_helper(block_t *theBlock);
2101 ///
2102 /// Note that this destroys a heap-allocated block closure object;
2103 /// it should not be confused with a 'byref destroy helper', which
2104 /// destroys the heap-allocated contents of an individual __block
2105 /// variable.
2106 llvm::Constant *
2109  findBlockCapturedManagedEntities(blockInfo, getLangOpts(), DestroyedCaptures);
2110  std::string FuncName =
2111  getCopyDestroyHelperFuncName(DestroyedCaptures, blockInfo.BlockAlign,
2112  CaptureStrKind::DisposeHelper, CGM);
2113 
2114  if (llvm::GlobalValue *Func = CGM.getModule().getNamedValue(FuncName))
2115  return llvm::ConstantExpr::getBitCast(Func, VoidPtrTy);
2116 
2117  ASTContext &C = getContext();
2118 
2119  QualType ReturnTy = C.VoidTy;
2120 
2121  FunctionArgList args;
2122  ImplicitParamDecl SrcDecl(C, C.VoidPtrTy, ImplicitParamDecl::Other);
2123  args.push_back(&SrcDecl);
2124 
2125  const CGFunctionInfo &FI =
2127 
2128  // FIXME: We'd like to put these into a mergable by content, with
2129  // internal linkage.
2130  llvm::FunctionType *LTy = CGM.getTypes().GetFunctionType(FI);
2131 
2132  llvm::Function *Fn =
2133  llvm::Function::Create(LTy, llvm::GlobalValue::LinkOnceODRLinkage,
2134  FuncName, &CGM.getModule());
2135  if (CGM.supportsCOMDAT())
2136  Fn->setComdat(CGM.getModule().getOrInsertComdat(FuncName));
2137 
2138  SmallVector<QualType, 1> ArgTys;
2139  ArgTys.push_back(C.VoidPtrTy);
2140 
2142  CGM);
2143  StartFunction(GlobalDecl(), ReturnTy, Fn, FI, args);
2145 
2146  auto AL = ApplyDebugLocation::CreateArtificial(*this);
2147 
2148  llvm::Type *structPtrTy = blockInfo.StructureType->getPointerTo();
2149 
2150  Address src = GetAddrOfLocalVar(&SrcDecl);
2151  src = Address(Builder.CreateLoad(src), blockInfo.BlockAlign);
2152  src = Builder.CreateBitCast(src, structPtrTy, "block");
2153 
2154  CodeGenFunction::RunCleanupsScope cleanups(*this);
2155 
2156  for (const auto &DestroyedCapture : DestroyedCaptures) {
2157  const BlockDecl::Capture &CI = *DestroyedCapture.CI;
2158  const CGBlockInfo::Capture &capture = *DestroyedCapture.Capture;
2159  BlockFieldFlags flags = DestroyedCapture.DisposeFlags;
2160 
2161  Address srcField = Builder.CreateStructGEP(src, capture.getIndex());
2162 
2163  pushCaptureCleanup(DestroyedCapture.DisposeKind, srcField,
2164  CI.getVariable()->getType(), flags,
2165  /*ForCopyHelper*/ false, CI.getVariable(), *this);
2166  }
2167 
2168  cleanups.ForceCleanup();
2169 
2170  FinishFunction();
2171 
2172  return llvm::ConstantExpr::getBitCast(Fn, VoidPtrTy);
2173 }
2174 
2175 namespace {
2176 
2177 /// Emits the copy/dispose helper functions for a __block object of id type.
2178 class ObjectByrefHelpers final : public BlockByrefHelpers {
2179  BlockFieldFlags Flags;
2180 
2181 public:
2182  ObjectByrefHelpers(CharUnits alignment, BlockFieldFlags flags)
2183  : BlockByrefHelpers(alignment), Flags(flags) {}
2184 
2185  void emitCopy(CodeGenFunction &CGF, Address destField,
2186  Address srcField) override {
2187  destField = CGF.Builder.CreateBitCast(destField, CGF.VoidPtrTy);
2188 
2189  srcField = CGF.Builder.CreateBitCast(srcField, CGF.VoidPtrPtrTy);
2190  llvm::Value *srcValue = CGF.Builder.CreateLoad(srcField);
2191 
2192  unsigned flags = (Flags | BLOCK_BYREF_CALLER).getBitMask();
2193 
2194  llvm::Value *flagsVal = llvm::ConstantInt::get(CGF.Int32Ty, flags);
2195  llvm::FunctionCallee fn = CGF.CGM.getBlockObjectAssign();
2196 
2197  llvm::Value *args[] = { destField.getPointer(), srcValue, flagsVal };
2198  CGF.EmitNounwindRuntimeCall(fn, args);
2199  }
2200 
2201  void emitDispose(CodeGenFunction &CGF, Address field) override {
2202  field = CGF.Builder.CreateBitCast(field, CGF.Int8PtrTy->getPointerTo(0));
2203  llvm::Value *value = CGF.Builder.CreateLoad(field);
2204 
2205  CGF.BuildBlockRelease(value, Flags | BLOCK_BYREF_CALLER, false);
2206  }
2207 
2208  void profileImpl(llvm::FoldingSetNodeID &id) const override {
2209  id.AddInteger(Flags.getBitMask());
2210  }
2211 };
2212 
2213 /// Emits the copy/dispose helpers for an ARC __block __weak variable.
2214 class ARCWeakByrefHelpers final : public BlockByrefHelpers {
2215 public:
2216  ARCWeakByrefHelpers(CharUnits alignment) : BlockByrefHelpers(alignment) {}
2217 
2218  void emitCopy(CodeGenFunction &CGF, Address destField,
2219  Address srcField) override {
2220  CGF.EmitARCMoveWeak(destField, srcField);
2221  }
2222 
2223  void emitDispose(CodeGenFunction &CGF, Address field) override {
2224  CGF.EmitARCDestroyWeak(field);
2225  }
2226 
2227  void profileImpl(llvm::FoldingSetNodeID &id) const override {
2228  // 0 is distinguishable from all pointers and byref flags
2229  id.AddInteger(0);
2230  }
2231 };
2232 
2233 /// Emits the copy/dispose helpers for an ARC __block __strong variable
2234 /// that's not of block-pointer type.
2235 class ARCStrongByrefHelpers final : public BlockByrefHelpers {
2236 public:
2237  ARCStrongByrefHelpers(CharUnits alignment) : BlockByrefHelpers(alignment) {}
2238 
2239  void emitCopy(CodeGenFunction &CGF, Address destField,
2240  Address srcField) override {
2241  // Do a "move" by copying the value and then zeroing out the old
2242  // variable.
2243 
2244  llvm::Value *value = CGF.Builder.CreateLoad(srcField);
2245 
2246  llvm::Value *null =
2247  llvm::ConstantPointerNull::get(cast<llvm::PointerType>(value->getType()));
2248 
2249  if (CGF.CGM.getCodeGenOpts().OptimizationLevel == 0) {
2250  CGF.Builder.CreateStore(null, destField);
2251  CGF.EmitARCStoreStrongCall(destField, value, /*ignored*/ true);
2252  CGF.EmitARCStoreStrongCall(srcField, null, /*ignored*/ true);
2253  return;
2254  }
2255  CGF.Builder.CreateStore(value, destField);
2256  CGF.Builder.CreateStore(null, srcField);
2257  }
2258 
2259  void emitDispose(CodeGenFunction &CGF, Address field) override {
2261  }
2262 
2263  void profileImpl(llvm::FoldingSetNodeID &id) const override {
2264  // 1 is distinguishable from all pointers and byref flags
2265  id.AddInteger(1);
2266  }
2267 };
2268 
2269 /// Emits the copy/dispose helpers for an ARC __block __strong
2270 /// variable that's of block-pointer type.
2271 class ARCStrongBlockByrefHelpers final : public BlockByrefHelpers {
2272 public:
2273  ARCStrongBlockByrefHelpers(CharUnits alignment)
2274  : BlockByrefHelpers(alignment) {}
2275 
2276  void emitCopy(CodeGenFunction &CGF, Address destField,
2277  Address srcField) override {
2278  // Do the copy with objc_retainBlock; that's all that
2279  // _Block_object_assign would do anyway, and we'd have to pass the
2280  // right arguments to make sure it doesn't get no-op'ed.
2281  llvm::Value *oldValue = CGF.Builder.CreateLoad(srcField);
2282  llvm::Value *copy = CGF.EmitARCRetainBlock(oldValue, /*mandatory*/ true);
2283  CGF.Builder.CreateStore(copy, destField);
2284  }
2285 
2286  void emitDispose(CodeGenFunction &CGF, Address field) override {
2288  }
2289 
2290  void profileImpl(llvm::FoldingSetNodeID &id) const override {
2291  // 2 is distinguishable from all pointers and byref flags
2292  id.AddInteger(2);
2293  }
2294 };
2295 
2296 /// Emits the copy/dispose helpers for a __block variable with a
2297 /// nontrivial copy constructor or destructor.
2298 class CXXByrefHelpers final : public BlockByrefHelpers {
2299  QualType VarType;
2300  const Expr *CopyExpr;
2301 
2302 public:
2303  CXXByrefHelpers(CharUnits alignment, QualType type,
2304  const Expr *copyExpr)
2305  : BlockByrefHelpers(alignment), VarType(type), CopyExpr(copyExpr) {}
2306 
2307  bool needsCopy() const override { return CopyExpr != nullptr; }
2308  void emitCopy(CodeGenFunction &CGF, Address destField,
2309  Address srcField) override {
2310  if (!CopyExpr) return;
2311  CGF.EmitSynthesizedCXXCopyCtor(destField, srcField, CopyExpr);
2312  }
2313 
2314  void emitDispose(CodeGenFunction &CGF, Address field) override {
2315  EHScopeStack::stable_iterator cleanupDepth = CGF.EHStack.stable_begin();
2316  CGF.PushDestructorCleanup(VarType, field);
2317  CGF.PopCleanupBlocks(cleanupDepth);
2318  }
2319 
2320  void profileImpl(llvm::FoldingSetNodeID &id) const override {
2321  id.AddPointer(VarType.getCanonicalType().getAsOpaquePtr());
2322  }
2323 };
2324 
2325 /// Emits the copy/dispose helpers for a __block variable that is a non-trivial
2326 /// C struct.
2327 class NonTrivialCStructByrefHelpers final : public BlockByrefHelpers {
2328  QualType VarType;
2329 
2330 public:
2331  NonTrivialCStructByrefHelpers(CharUnits alignment, QualType type)
2332  : BlockByrefHelpers(alignment), VarType(type) {}
2333 
2334  void emitCopy(CodeGenFunction &CGF, Address destField,
2335  Address srcField) override {
2336  CGF.callCStructMoveConstructor(CGF.MakeAddrLValue(destField, VarType),
2337  CGF.MakeAddrLValue(srcField, VarType));
2338  }
2339 
2340  bool needsDispose() const override {
2341  return VarType.isDestructedType();
2342  }
2343 
2344  void emitDispose(CodeGenFunction &CGF, Address field) override {
2345  EHScopeStack::stable_iterator cleanupDepth = CGF.EHStack.stable_begin();
2346  CGF.pushDestroy(VarType.isDestructedType(), field, VarType);
2347  CGF.PopCleanupBlocks(cleanupDepth);
2348  }
2349 
2350  void profileImpl(llvm::FoldingSetNodeID &id) const override {
2351  id.AddPointer(VarType.getCanonicalType().getAsOpaquePtr());
2352  }
2353 };
2354 } // end anonymous namespace
2355 
2356 static llvm::Constant *
2358  BlockByrefHelpers &generator) {
2359  ASTContext &Context = CGF.getContext();
2360 
2361  QualType ReturnTy = Context.VoidTy;
2362 
2363  FunctionArgList args;
2364  ImplicitParamDecl Dst(Context, Context.VoidPtrTy, ImplicitParamDecl::Other);
2365  args.push_back(&Dst);
2366 
2367  ImplicitParamDecl Src(Context, Context.VoidPtrTy, ImplicitParamDecl::Other);
2368  args.push_back(&Src);
2369 
2370  const CGFunctionInfo &FI =
2371  CGF.CGM.getTypes().arrangeBuiltinFunctionDeclaration(ReturnTy, args);
2372 
2373  llvm::FunctionType *LTy = CGF.CGM.getTypes().GetFunctionType(FI);
2374 
2375  // FIXME: We'd like to put these into a mergable by content, with
2376  // internal linkage.
2377  llvm::Function *Fn =
2378  llvm::Function::Create(LTy, llvm::GlobalValue::InternalLinkage,
2379  "__Block_byref_object_copy_", &CGF.CGM.getModule());
2380 
2381  SmallVector<QualType, 2> ArgTys;
2382  ArgTys.push_back(Context.VoidPtrTy);
2383  ArgTys.push_back(Context.VoidPtrTy);
2384 
2386 
2387  CGF.StartFunction(GlobalDecl(), ReturnTy, Fn, FI, args);
2388  // Create a scope with an artificial location for the body of this function.
2389  auto AL = ApplyDebugLocation::CreateArtificial(CGF);
2390 
2391  if (generator.needsCopy()) {
2392  llvm::Type *byrefPtrType = byrefInfo.Type->getPointerTo(0);
2393 
2394  // dst->x
2395  Address destField = CGF.GetAddrOfLocalVar(&Dst);
2396  destField = Address(CGF.Builder.CreateLoad(destField),
2397  byrefInfo.ByrefAlignment);
2398  destField = CGF.Builder.CreateBitCast(destField, byrefPtrType);
2399  destField = CGF.emitBlockByrefAddress(destField, byrefInfo, false,
2400  "dest-object");
2401 
2402  // src->x
2403  Address srcField = CGF.GetAddrOfLocalVar(&Src);
2404  srcField = Address(CGF.Builder.CreateLoad(srcField),
2405  byrefInfo.ByrefAlignment);
2406  srcField = CGF.Builder.CreateBitCast(srcField, byrefPtrType);
2407  srcField = CGF.emitBlockByrefAddress(srcField, byrefInfo, false,
2408  "src-object");
2409 
2410  generator.emitCopy(CGF, destField, srcField);
2411  }
2412 
2413  CGF.FinishFunction();
2414 
2415  return llvm::ConstantExpr::getBitCast(Fn, CGF.Int8PtrTy);
2416 }
2417 
2418 /// Build the copy helper for a __block variable.
2419 static llvm::Constant *buildByrefCopyHelper(CodeGenModule &CGM,
2420  const BlockByrefInfo &byrefInfo,
2421  BlockByrefHelpers &generator) {
2422  CodeGenFunction CGF(CGM);
2423  return generateByrefCopyHelper(CGF, byrefInfo, generator);
2424 }
2425 
2426 /// Generate code for a __block variable's dispose helper.
2427 static llvm::Constant *
2429  const BlockByrefInfo &byrefInfo,
2430  BlockByrefHelpers &generator) {
2431  ASTContext &Context = CGF.getContext();
2432  QualType R = Context.VoidTy;
2433 
2434  FunctionArgList args;
2435  ImplicitParamDecl Src(CGF.getContext(), Context.VoidPtrTy,
2437  args.push_back(&Src);
2438 
2439  const CGFunctionInfo &FI =
2441 
2442  llvm::FunctionType *LTy = CGF.CGM.getTypes().GetFunctionType(FI);
2443 
2444  // FIXME: We'd like to put these into a mergable by content, with
2445  // internal linkage.
2446  llvm::Function *Fn =
2447  llvm::Function::Create(LTy, llvm::GlobalValue::InternalLinkage,
2448  "__Block_byref_object_dispose_",
2449  &CGF.CGM.getModule());
2450 
2451  SmallVector<QualType, 1> ArgTys;
2452  ArgTys.push_back(Context.VoidPtrTy);
2453 
2455 
2456  CGF.StartFunction(GlobalDecl(), R, Fn, FI, args);
2457  // Create a scope with an artificial location for the body of this function.
2458  auto AL = ApplyDebugLocation::CreateArtificial(CGF);
2459 
2460  if (generator.needsDispose()) {
2461  Address addr = CGF.GetAddrOfLocalVar(&Src);
2462  addr = Address(CGF.Builder.CreateLoad(addr), byrefInfo.ByrefAlignment);
2463  auto byrefPtrType = byrefInfo.Type->getPointerTo(0);
2464  addr = CGF.Builder.CreateBitCast(addr, byrefPtrType);
2465  addr = CGF.emitBlockByrefAddress(addr, byrefInfo, false, "object");
2466 
2467  generator.emitDispose(CGF, addr);
2468  }
2469 
2470  CGF.FinishFunction();
2471 
2472  return llvm::ConstantExpr::getBitCast(Fn, CGF.Int8PtrTy);
2473 }
2474 
2475 /// Build the dispose helper for a __block variable.
2476 static llvm::Constant *buildByrefDisposeHelper(CodeGenModule &CGM,
2477  const BlockByrefInfo &byrefInfo,
2478  BlockByrefHelpers &generator) {
2479  CodeGenFunction CGF(CGM);
2480  return generateByrefDisposeHelper(CGF, byrefInfo, generator);
2481 }
2482 
2483 /// Lazily build the copy and dispose helpers for a __block variable
2484 /// with the given information.
2485 template <class T>
2486 static T *buildByrefHelpers(CodeGenModule &CGM, const BlockByrefInfo &byrefInfo,
2487  T &&generator) {
2488  llvm::FoldingSetNodeID id;
2489  generator.Profile(id);
2490 
2491  void *insertPos;
2493  = CGM.ByrefHelpersCache.FindNodeOrInsertPos(id, insertPos);
2494  if (node) return static_cast<T*>(node);
2495 
2496  generator.CopyHelper = buildByrefCopyHelper(CGM, byrefInfo, generator);
2497  generator.DisposeHelper = buildByrefDisposeHelper(CGM, byrefInfo, generator);
2498 
2499  T *copy = new (CGM.getContext()) T(std::forward<T>(generator));
2500  CGM.ByrefHelpersCache.InsertNode(copy, insertPos);
2501  return copy;
2502 }
2503 
2504 /// Build the copy and dispose helpers for the given __block variable
2505 /// emission. Places the helpers in the global cache. Returns null
2506 /// if no helpers are required.
2508 CodeGenFunction::buildByrefHelpers(llvm::StructType &byrefType,
2509  const AutoVarEmission &emission) {
2510  const VarDecl &var = *emission.Variable;
2511  assert(var.isEscapingByref() &&
2512  "only escaping __block variables need byref helpers");
2513 
2514  QualType type = var.getType();
2515 
2516  auto &byrefInfo = getBlockByrefInfo(&var);
2517 
2518  // The alignment we care about for the purposes of uniquing byref
2519  // helpers is the alignment of the actual byref value field.
2520  CharUnits valueAlignment =
2521  byrefInfo.ByrefAlignment.alignmentAtOffset(byrefInfo.FieldOffset);
2522 
2523  if (const CXXRecordDecl *record = type->getAsCXXRecordDecl()) {
2524  const Expr *copyExpr =
2526  if (!copyExpr && record->hasTrivialDestructor()) return nullptr;
2527 
2529  CGM, byrefInfo, CXXByrefHelpers(valueAlignment, type, copyExpr));
2530  }
2531 
2532  // If type is a non-trivial C struct type that is non-trivial to
2533  // destructly move or destroy, build the copy and dispose helpers.
2534  if (type.isNonTrivialToPrimitiveDestructiveMove() == QualType::PCK_Struct ||
2535  type.isDestructedType() == QualType::DK_nontrivial_c_struct)
2537  CGM, byrefInfo, NonTrivialCStructByrefHelpers(valueAlignment, type));
2538 
2539  // Otherwise, if we don't have a retainable type, there's nothing to do.
2540  // that the runtime does extra copies.
2541  if (!type->isObjCRetainableType()) return nullptr;
2542 
2543  Qualifiers qs = type.getQualifiers();
2544 
2545  // If we have lifetime, that dominates.
2546  if (Qualifiers::ObjCLifetime lifetime = qs.getObjCLifetime()) {
2547  switch (lifetime) {
2548  case Qualifiers::OCL_None: llvm_unreachable("impossible");
2549 
2550  // These are just bits as far as the runtime is concerned.
2553  return nullptr;
2554 
2555  // Tell the runtime that this is ARC __weak, called by the
2556  // byref routines.
2557  case Qualifiers::OCL_Weak:
2558  return ::buildByrefHelpers(CGM, byrefInfo,
2559  ARCWeakByrefHelpers(valueAlignment));
2560 
2561  // ARC __strong __block variables need to be retained.
2563  // Block pointers need to be copied, and there's no direct
2564  // transfer possible.
2565  if (type->isBlockPointerType()) {
2566  return ::buildByrefHelpers(CGM, byrefInfo,
2567  ARCStrongBlockByrefHelpers(valueAlignment));
2568 
2569  // Otherwise, we transfer ownership of the retain from the stack
2570  // to the heap.
2571  } else {
2572  return ::buildByrefHelpers(CGM, byrefInfo,
2573  ARCStrongByrefHelpers(valueAlignment));
2574  }
2575  }
2576  llvm_unreachable("fell out of lifetime switch!");
2577  }
2578 
2579  BlockFieldFlags flags;
2580  if (type->isBlockPointerType()) {
2581  flags |= BLOCK_FIELD_IS_BLOCK;
2582  } else if (CGM.getContext().isObjCNSObjectType(type) ||
2583  type->isObjCObjectPointerType()) {
2584  flags |= BLOCK_FIELD_IS_OBJECT;
2585  } else {
2586  return nullptr;
2587  }
2588 
2589  if (type.isObjCGCWeak())
2590  flags |= BLOCK_FIELD_IS_WEAK;
2591 
2592  return ::buildByrefHelpers(CGM, byrefInfo,
2593  ObjectByrefHelpers(valueAlignment, flags));
2594 }
2595 
2597  const VarDecl *var,
2598  bool followForward) {
2599  auto &info = getBlockByrefInfo(var);
2600  return emitBlockByrefAddress(baseAddr, info, followForward, var->getName());
2601 }
2602 
2604  const BlockByrefInfo &info,
2605  bool followForward,
2606  const llvm::Twine &name) {
2607  // Chase the forwarding address if requested.
2608  if (followForward) {
2609  Address forwardingAddr = Builder.CreateStructGEP(baseAddr, 1, "forwarding");
2610  baseAddr = Address(Builder.CreateLoad(forwardingAddr), info.ByrefAlignment);
2611  }
2612 
2613  return Builder.CreateStructGEP(baseAddr, info.FieldIndex, name);
2614 }
2615 
2616 /// BuildByrefInfo - This routine changes a __block variable declared as T x
2617 /// into:
2618 ///
2619 /// struct {
2620 /// void *__isa;
2621 /// void *__forwarding;
2622 /// int32_t __flags;
2623 /// int32_t __size;
2624 /// void *__copy_helper; // only if needed
2625 /// void *__destroy_helper; // only if needed
2626 /// void *__byref_variable_layout;// only if needed
2627 /// char padding[X]; // only if needed
2628 /// T x;
2629 /// } x
2630 ///
2632  auto it = BlockByrefInfos.find(D);
2633  if (it != BlockByrefInfos.end())
2634  return it->second;
2635 
2636  llvm::StructType *byrefType =
2638  "struct.__block_byref_" + D->getNameAsString());
2639 
2640  QualType Ty = D->getType();
2641 
2642  CharUnits size;
2644 
2645  // void *__isa;
2646  types.push_back(Int8PtrTy);
2647  size += getPointerSize();
2648 
2649  // void *__forwarding;
2650  types.push_back(llvm::PointerType::getUnqual(byrefType));
2651  size += getPointerSize();
2652 
2653  // int32_t __flags;
2654  types.push_back(Int32Ty);
2655  size += CharUnits::fromQuantity(4);
2656 
2657  // int32_t __size;
2658  types.push_back(Int32Ty);
2659  size += CharUnits::fromQuantity(4);
2660 
2661  // Note that this must match *exactly* the logic in buildByrefHelpers.
2662  bool hasCopyAndDispose = getContext().BlockRequiresCopying(Ty, D);
2663  if (hasCopyAndDispose) {
2664  /// void *__copy_helper;
2665  types.push_back(Int8PtrTy);
2666  size += getPointerSize();
2667 
2668  /// void *__destroy_helper;
2669  types.push_back(Int8PtrTy);
2670  size += getPointerSize();
2671  }
2672 
2673  bool HasByrefExtendedLayout = false;
2675  if (getContext().getByrefLifetime(Ty, Lifetime, HasByrefExtendedLayout) &&
2676  HasByrefExtendedLayout) {
2677  /// void *__byref_variable_layout;
2678  types.push_back(Int8PtrTy);
2680  }
2681 
2682  // T x;
2683  llvm::Type *varTy = ConvertTypeForMem(Ty);
2684 
2685  bool packed = false;
2686  CharUnits varAlign = getContext().getDeclAlign(D);
2687  CharUnits varOffset = size.alignTo(varAlign);
2688 
2689  // We may have to insert padding.
2690  if (varOffset != size) {
2691  llvm::Type *paddingTy =
2692  llvm::ArrayType::get(Int8Ty, (varOffset - size).getQuantity());
2693 
2694  types.push_back(paddingTy);
2695  size = varOffset;
2696 
2697  // Conversely, we might have to prevent LLVM from inserting padding.
2698  } else if (CGM.getDataLayout().getABITypeAlignment(varTy) >
2699  uint64_t(varAlign.getQuantity())) {
2700  packed = true;
2701  }
2702  types.push_back(varTy);
2703 
2704  byrefType->setBody(types, packed);
2705 
2706  BlockByrefInfo info;
2707  info.Type = byrefType;
2708  info.FieldIndex = types.size() - 1;
2709  info.FieldOffset = varOffset;
2710  info.ByrefAlignment = std::max(varAlign, getPointerAlign());
2711 
2712  auto pair = BlockByrefInfos.insert({D, info});
2713  assert(pair.second && "info was inserted recursively?");
2714  return pair.first->second;
2715 }
2716 
2717 /// Initialize the structural components of a __block variable, i.e.
2718 /// everything but the actual object.
2720  // Find the address of the local.
2721  Address addr = emission.Addr;
2722 
2723  // That's an alloca of the byref structure type.
2724  llvm::StructType *byrefType = cast<llvm::StructType>(
2725  cast<llvm::PointerType>(addr.getPointer()->getType())->getElementType());
2726 
2727  unsigned nextHeaderIndex = 0;
2728  CharUnits nextHeaderOffset;
2729  auto storeHeaderField = [&](llvm::Value *value, CharUnits fieldSize,
2730  const Twine &name) {
2731  auto fieldAddr = Builder.CreateStructGEP(addr, nextHeaderIndex, name);
2732  Builder.CreateStore(value, fieldAddr);
2733 
2734  nextHeaderIndex++;
2735  nextHeaderOffset += fieldSize;
2736  };
2737 
2738  // Build the byref helpers if necessary. This is null if we don't need any.
2739  BlockByrefHelpers *helpers = buildByrefHelpers(*byrefType, emission);
2740 
2741  const VarDecl &D = *emission.Variable;
2742  QualType type = D.getType();
2743 
2744  bool HasByrefExtendedLayout = false;
2746  bool ByRefHasLifetime =
2747  getContext().getByrefLifetime(type, ByrefLifetime, HasByrefExtendedLayout);
2748 
2749  llvm::Value *V;
2750 
2751  // Initialize the 'isa', which is just 0 or 1.
2752  int isa = 0;
2753  if (type.isObjCGCWeak())
2754  isa = 1;
2755  V = Builder.CreateIntToPtr(Builder.getInt32(isa), Int8PtrTy, "isa");
2756  storeHeaderField(V, getPointerSize(), "byref.isa");
2757 
2758  // Store the address of the variable into its own forwarding pointer.
2759  storeHeaderField(addr.getPointer(), getPointerSize(), "byref.forwarding");
2760 
2761  // Blocks ABI:
2762  // c) the flags field is set to either 0 if no helper functions are
2763  // needed or BLOCK_BYREF_HAS_COPY_DISPOSE if they are,
2764  BlockFlags flags;
2765  if (helpers) flags |= BLOCK_BYREF_HAS_COPY_DISPOSE;
2766  if (ByRefHasLifetime) {
2767  if (HasByrefExtendedLayout) flags |= BLOCK_BYREF_LAYOUT_EXTENDED;
2768  else switch (ByrefLifetime) {
2770  flags |= BLOCK_BYREF_LAYOUT_STRONG;
2771  break;
2772  case Qualifiers::OCL_Weak:
2773  flags |= BLOCK_BYREF_LAYOUT_WEAK;
2774  break;
2777  break;
2778  case Qualifiers::OCL_None:
2779  if (!type->isObjCObjectPointerType() && !type->isBlockPointerType())
2781  break;
2782  default:
2783  break;
2784  }
2785  if (CGM.getLangOpts().ObjCGCBitmapPrint) {
2786  printf("\n Inline flag for BYREF variable layout (%d):", flags.getBitMask());
2787  if (flags & BLOCK_BYREF_HAS_COPY_DISPOSE)
2788  printf(" BLOCK_BYREF_HAS_COPY_DISPOSE");
2789  if (flags & BLOCK_BYREF_LAYOUT_MASK) {
2790  BlockFlags ThisFlag(flags.getBitMask() & BLOCK_BYREF_LAYOUT_MASK);
2791  if (ThisFlag == BLOCK_BYREF_LAYOUT_EXTENDED)
2792  printf(" BLOCK_BYREF_LAYOUT_EXTENDED");
2793  if (ThisFlag == BLOCK_BYREF_LAYOUT_STRONG)
2794  printf(" BLOCK_BYREF_LAYOUT_STRONG");
2795  if (ThisFlag == BLOCK_BYREF_LAYOUT_WEAK)
2796  printf(" BLOCK_BYREF_LAYOUT_WEAK");
2797  if (ThisFlag == BLOCK_BYREF_LAYOUT_UNRETAINED)
2798  printf(" BLOCK_BYREF_LAYOUT_UNRETAINED");
2799  if (ThisFlag == BLOCK_BYREF_LAYOUT_NON_OBJECT)
2800  printf(" BLOCK_BYREF_LAYOUT_NON_OBJECT");
2801  }
2802  printf("\n");
2803  }
2804  }
2805  storeHeaderField(llvm::ConstantInt::get(IntTy, flags.getBitMask()),
2806  getIntSize(), "byref.flags");
2807 
2808  CharUnits byrefSize = CGM.GetTargetTypeStoreSize(byrefType);
2809  V = llvm::ConstantInt::get(IntTy, byrefSize.getQuantity());
2810  storeHeaderField(V, getIntSize(), "byref.size");
2811 
2812  if (helpers) {
2813  storeHeaderField(helpers->CopyHelper, getPointerSize(),
2814  "byref.copyHelper");
2815  storeHeaderField(helpers->DisposeHelper, getPointerSize(),
2816  "byref.disposeHelper");
2817  }
2818 
2819  if (ByRefHasLifetime && HasByrefExtendedLayout) {
2820  auto layoutInfo = CGM.getObjCRuntime().BuildByrefLayout(CGM, type);
2821  storeHeaderField(layoutInfo, getPointerSize(), "byref.layout");
2822  }
2823 }
2824 
2826  bool CanThrow) {
2827  llvm::FunctionCallee F = CGM.getBlockObjectDispose();
2828  llvm::Value *args[] = {
2830  llvm::ConstantInt::get(Int32Ty, flags.getBitMask())
2831  };
2832 
2833  if (CanThrow)
2834  EmitRuntimeCallOrInvoke(F, args);
2835  else
2836  EmitNounwindRuntimeCall(F, args);
2837 }
2838 
2840  BlockFieldFlags Flags,
2841  bool LoadBlockVarAddr, bool CanThrow) {
2842  EHStack.pushCleanup<CallBlockRelease>(Kind, Addr, Flags, LoadBlockVarAddr,
2843  CanThrow);
2844 }
2845 
2846 /// Adjust the declaration of something from the blocks API.
2848  llvm::Constant *C) {
2849  auto *GV = cast<llvm::GlobalValue>(C->stripPointerCasts());
2850 
2851  if (CGM.getTarget().getTriple().isOSBinFormatCOFF()) {
2852  IdentifierInfo &II = CGM.getContext().Idents.get(C->getName());
2855 
2856  assert((isa<llvm::Function>(C->stripPointerCasts()) ||
2857  isa<llvm::GlobalVariable>(C->stripPointerCasts())) &&
2858  "expected Function or GlobalVariable");
2859 
2860  const NamedDecl *ND = nullptr;
2861  for (const auto *Result : DC->lookup(&II))
2862  if ((ND = dyn_cast<FunctionDecl>(Result)) ||
2863  (ND = dyn_cast<VarDecl>(Result)))
2864  break;
2865 
2866  // TODO: support static blocks runtime
2867  if (GV->isDeclaration() && (!ND || !ND->hasAttr<DLLExportAttr>())) {
2868  GV->setDLLStorageClass(llvm::GlobalValue::DLLImportStorageClass);
2869  GV->setLinkage(llvm::GlobalValue::ExternalLinkage);
2870  } else {
2871  GV->setDLLStorageClass(llvm::GlobalValue::DLLExportStorageClass);
2872  GV->setLinkage(llvm::GlobalValue::ExternalLinkage);
2873  }
2874  }
2875 
2876  if (CGM.getLangOpts().BlocksRuntimeOptional && GV->isDeclaration() &&
2877  GV->hasExternalLinkage())
2878  GV->setLinkage(llvm::GlobalValue::ExternalWeakLinkage);
2879 
2880  CGM.setDSOLocal(GV);
2881 }
2882 
2884  if (BlockObjectDispose)
2885  return BlockObjectDispose;
2886 
2887  llvm::Type *args[] = { Int8PtrTy, Int32Ty };
2888  llvm::FunctionType *fty
2889  = llvm::FunctionType::get(VoidTy, args, false);
2890  BlockObjectDispose = CreateRuntimeFunction(fty, "_Block_object_dispose");
2892  *this, cast<llvm::Constant>(BlockObjectDispose.getCallee()));
2893  return BlockObjectDispose;
2894 }
2895 
2896 llvm::FunctionCallee CodeGenModule::getBlockObjectAssign() {
2897  if (BlockObjectAssign)
2898  return BlockObjectAssign;
2899 
2900  llvm::Type *args[] = { Int8PtrTy, Int8PtrTy, Int32Ty };
2901  llvm::FunctionType *fty
2902  = llvm::FunctionType::get(VoidTy, args, false);
2903  BlockObjectAssign = CreateRuntimeFunction(fty, "_Block_object_assign");
2905  *this, cast<llvm::Constant>(BlockObjectAssign.getCallee()));
2906  return BlockObjectAssign;
2907 }
2908 
2910  if (NSConcreteGlobalBlock)
2911  return NSConcreteGlobalBlock;
2912 
2913  NSConcreteGlobalBlock = GetOrCreateLLVMGlobal(
2914  "_NSConcreteGlobalBlock", Int8PtrTy, LangAS::Default, nullptr);
2915  configureBlocksRuntimeObject(*this, NSConcreteGlobalBlock);
2916  return NSConcreteGlobalBlock;
2917 }
2918 
2920  if (NSConcreteStackBlock)
2921  return NSConcreteStackBlock;
2922 
2923  NSConcreteStackBlock = GetOrCreateLLVMGlobal(
2924  "_NSConcreteStackBlock", Int8PtrTy, LangAS::Default, nullptr);
2925  configureBlocksRuntimeObject(*this, NSConcreteStackBlock);
2926  return NSConcreteStackBlock;
2927 }
clang::OpenCL
@ OpenCL
Definition: LangStandard.h:58
clang::CodeGen::CGBlockInfo::BlockExpression
const BlockExpr * BlockExpression
Definition: CGBlocks.h:247
clang::QualType::PCK_Struct
@ PCK_Struct
The type is a struct containing a field whose type is neither PCK_Trivial nor PCK_VolatileTrivial.
Definition: Type.h:1186
clang::InternalLinkage
@ InternalLinkage
Internal linkage, which indicates that the entity can be referred to from within the translation unit...
Definition: Linkage.h:31
clang::CodeGen::CGObjCRuntime::BuildByrefLayout
virtual llvm::Constant * BuildByrefLayout(CodeGen::CodeGenModule &CGM, QualType T)=0
Returns an i8* which points to the byref layout information.
clang::CodeGen::CodeGenFunction::ConvertTypeForMem
llvm::Type * ConvertTypeForMem(QualType T)
Definition: CodeGenFunction.cpp:207
clang::CodeGen::BlockByrefHelpers::~BlockByrefHelpers
virtual ~BlockByrefHelpers()
Definition: CGBlocks.cpp:48
clang::CodeGen::CodeGenFunction::EmitARCRetainNonBlock
llvm::Value * EmitARCRetainNonBlock(llvm::Value *value)
Retain the given object, with normal retain semantics.
Definition: CGObjC.cpp:2264
clang::BlockExpr::getEndLoc
SourceLocation getEndLoc() const LLVM_READONLY
Definition: Expr.h:5989
clang::CodeGen::CodeGenFunction::callCStructCopyConstructor
void callCStructCopyConstructor(LValue Dst, LValue Src)
Definition: CGNonTrivialStruct.cpp:885
clang::CodeGen::CodeGenFunction::emitByrefStructureInit
void emitByrefStructureInit(const AutoVarEmission &emission)
Initialize the structural components of a __block variable, i.e.
Definition: CGBlocks.cpp:2719
clang::QualType::DK_nontrivial_c_struct
@ DK_nontrivial_c_struct
Definition: Type.h:1207
max
__DEVICE__ int max(int __a, int __b)
Definition: __clang_cuda_math.h:196
clang::QualType::getObjCLifetime
Qualifiers::ObjCLifetime getObjCLifetime() const
Returns lifetime attribute of this type.
Definition: Type.h:1120
clang::HiddenVisibility
@ HiddenVisibility
Objects with "hidden" visibility are not seen by the dynamic linker.
Definition: Visibility.h:36
clang::CodeGen::CodeGenTypeCache::Int8PtrTy
llvm::PointerType * Int8PtrTy
Definition: CodeGenTypeCache.h:57
buildBlockDescriptor
static llvm::Constant * buildBlockDescriptor(CodeGenModule &CGM, const CGBlockInfo &blockInfo)
buildBlockDescriptor - Build the block descriptor meta-data for a block.
Definition: CGBlocks.cpp:185
clang::CodeGen::CodeGenFunction::markAsIgnoreThreadCheckingAtRuntime
void markAsIgnoreThreadCheckingAtRuntime(llvm::Function *Fn)
Annotate the function with an attribute that disables TSan checking at runtime.
Definition: CodeGenFunction.cpp:657
buildCopyHelper
static llvm::Constant * buildCopyHelper(CodeGenModule &CGM, const CGBlockInfo &blockInfo)
Build the helper function to copy a block.
Definition: CGBlocks.cpp:56
clang::Type::isBlockPointerType
bool isBlockPointerType() const
Definition: Type.h:6680
clang::CodeGen::CodeGenFunction::LoadCXXThis
llvm::Value * LoadCXXThis()
LoadCXXThis - Load the value of 'this'.
Definition: CodeGenFunction.h:2763
clang::CharUnits::getAsAlign
llvm::Align getAsAlign() const
getAsAlign - Returns Quantity as a valid llvm::Align, Beware llvm::Align assumes power of two 8-bit b...
Definition: CharUnits.h:183
clang::CodeGen::CGBlockInfo::CGBlockInfo
CGBlockInfo(const BlockDecl *blockDecl, StringRef Name)
Definition: CGBlocks.cpp:35
clang::ast_matchers::blockExpr
const internal::VariadicDynCastAllOfMatcher< Stmt, BlockExpr > blockExpr
Matches a reference to a block.
Definition: ASTMatchersInternal.cpp:892
clang::CodeGen::CodeGenTypeCache::IntTy
llvm::IntegerType * IntTy
int
Definition: CodeGenTypeCache.h:42
clang::CodeGen::CGBlockInfo::CXXThisOffset
CharUnits CXXThisOffset
Definition: CGBlocks.h:250
clang::CodeGen::RValue
RValue - This trivial value class is used to represent the result of an expression that is evaluated.
Definition: CGValue.h:39
clang::CodeGen::CodeGenModule::CreateRuntimeFunction
llvm::FunctionCallee CreateRuntimeFunction(llvm::FunctionType *Ty, StringRef Name, llvm::AttributeList ExtraAttrs=llvm::AttributeList(), bool Local=false, bool AssumeConvergent=false)
Create or return a runtime function declaration with the specified type and name.
Definition: CodeGenModule.cpp:3792
clang::QualType::PCK_ARCWeak
@ PCK_ARCWeak
The type is an Objective-C retainable pointer type that is qualified with the ARC __weak qualifier.
Definition: Type.h:1178
clang::CodeGen::CodeGenModule::setAddrOfGlobalBlock
void setAddrOfGlobalBlock(const BlockExpr *BE, llvm::Constant *Addr)
Notes that BE's global block is available via Addr.
Definition: CGBlocks.cpp:1279
type
clang::CodeGen::CGBlockInfo::LocalAddress
Address LocalAddress
Definition: CGBlocks.h:244
clang::CodeGen::BlockByrefInfo::FieldIndex
unsigned FieldIndex
Definition: CGBlocks.h:146
computeDestroyInfoForBlockCapture
static std::pair< BlockCaptureEntityKind, BlockFieldFlags > computeDestroyInfoForBlockCapture(const BlockDecl::Capture &CI, QualType T, const LangOptions &LangOpts)
Definition: CGBlocks.cpp:2062
clang::CodeGen::CodeGenFunction::EmitARCDestroyWeak
void EmitARCDestroyWeak(Address addr)
void @objc_destroyWeak(i8** addr) Essentially objc_storeWeak(addr, nil).
Definition: CGObjC.cpp:2604
clang::interp::align
constexpr size_t align(size_t Size)
Aligns a size to the pointer alignment.
Definition: PrimType.h:57
initializeForBlockHeader
static void initializeForBlockHeader(CodeGenModule &CGM, CGBlockInfo &info, SmallVectorImpl< llvm::Type * > &elementTypes)
Definition: CGBlocks.cpp:448
clang::CodeGen::ConstantInitBuilder
The standard implementation of ConstantInitBuilder used in Clang.
Definition: ConstantInitBuilder.h:535
clang::Type::isObjCRetainableType
bool isObjCRetainableType() const
Definition: Type.cpp:4284
CodeGenFunction.h
string
string(SUBSTRING ${CMAKE_CURRENT_BINARY_DIR} 0 ${PATH_LIB_START} PATH_HEAD) string(SUBSTRING $
Definition: CMakeLists.txt:22
clang::DeclContext
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1347
clang::CodeGen::CodeGenFunction::EmitLoadOfReference
Address EmitLoadOfReference(LValue RefLVal, LValueBaseInfo *PointeeBaseInfo=nullptr, TBAAAccessInfo *PointeeTBAAInfo=nullptr)
Definition: CGExpr.cpp:2472
clang::CodeGen::CodeGenFunction::EmitCall
RValue EmitCall(const CGFunctionInfo &CallInfo, const CGCallee &Callee, ReturnValueSlot ReturnValue, const CallArgList &Args, llvm::CallBase **callOrInvoke, bool IsMustTail, SourceLocation Loc)
EmitCall - Generate a call of the given function, expecting the given result type,...
Definition: CGCall.cpp:4616
clang::CodeGen::BlockByrefInfo
Information about the layout of a __block variable.
Definition: CGBlocks.h:143
clang::CodeGen::BlockByrefInfo::ByrefAlignment
CharUnits ByrefAlignment
Definition: CGBlocks.h:147
clang::Decl::hasAttr
bool hasAttr() const
Definition: DeclBase.h:547
clang::CodeGen::CodeGenFunction::LambdaCaptureFields
llvm::DenseMap< const VarDecl *, FieldDecl * > LambdaCaptureFields
Definition: CodeGenFunction.h:578
clang::CodeGen::CodeGenModule::addUsedGlobal
void addUsedGlobal(llvm::GlobalValue *GV)
Add a global to a list to be added to the llvm.used metadata.
Definition: CodeGenModule.cpp:2205
clang::CodeGen::CodeGenModule::getOpenCLRuntime
CGOpenCLRuntime & getOpenCLRuntime()
Return a reference to the configured OpenCL runtime.
Definition: CodeGenModule.h:610
clang::CodeGen::AggValueSlot::DoesNotNeedGCBarriers
@ DoesNotNeedGCBarriers
Definition: CGValue.h:528
clang::CodeGen::CodeGenFunction::EmitNounwindRuntimeCall
llvm::CallInst * EmitNounwindRuntimeCall(llvm::FunctionCallee callee, const Twine &name="")
clang::VarDecl::isNonEscapingByref
bool isNonEscapingByref() const
Indicates the capture is a __block variable that is never captured by an escaping block.
Definition: Decl.cpp:2553
clang::ImplicitCastExpr::OnStack
@ OnStack
Definition: Expr.h:3642
clang::NamedDecl::isExternallyVisible
bool isExternallyVisible() const
Definition: Decl.h:407
clang::Qualifiers::OCL_Weak
@ OCL_Weak
Reading or writing from this object requires a barrier call.
Definition: Type.h:176
clang::ASTContext::VoidTy
CanQualType VoidTy
Definition: ASTContext.h:1075
clang::sema::Capture::getVariable
VarDecl * getVariable() const
Definition: ScopeInfo.h:638
llvm::SmallVector
Definition: LLVM.h:38
clang::IdentifierTable::get
IdentifierInfo & get(StringRef Name)
Return the identifier token info for the specified named identifier.
Definition: IdentifierTable.h:592
clang::SourceLocation
Encodes a location in the source.
Definition: SourceLocation.h:88
clang::CodeGen::CGBlockInfo::UsesStret
bool UsesStret
UsesStret : True if the block uses an stret return.
Definition: CGBlocks.h:230
clang::QualType::getQualifiers
Qualifiers getQualifiers() const
Retrieve the set of qualifiers applied to this type.
Definition: Type.h:6451
clang::CodeGen::CodeGenModule::SetInternalFunctionAttributes
void SetInternalFunctionAttributes(GlobalDecl GD, llvm::Function *F, const CGFunctionInfo &FI)
Set the attributes on the LLVM function for the given decl and function info.
Definition: CodeGenModule.cpp:2058
clang::CodeGen::CGCXXABI::getMangleContext
MangleContext & getMangleContext()
Gets the mangle context.
Definition: CGCXXABI.h:97
setBlockHelperAttributesVisibility
static void setBlockHelperAttributesVisibility(bool CapturesNonExternalType, llvm::Function *Fn, const CGFunctionInfo &FI, CodeGenModule &CGM)
Definition: CGBlocks.cpp:1896
clang::CodeGen::LValue::getAddress
Address getAddress(CodeGenFunction &CGF) const
Definition: CGValue.h:329
clang::NamedDecl
This represents a decl that may have a name.
Definition: Decl.h:249
clang::BlockDecl::Capture::getCopyExpr
Expr * getCopyExpr() const
Definition: Decl.h:4199
clang::CodeGen::CodeGenTypes::arrangeBlockFunctionCall
const CGFunctionInfo & arrangeBlockFunctionCall(const CallArgList &args, const FunctionType *type)
A block function is essentially a free function with an extra implicit argument.
Definition: CGCall.cpp:625
clang::CodeGen::CGBlockInfo::BlockAlign
CharUnits BlockAlign
Definition: CGBlocks.h:249
clang::CodeGen::CodeGenTypeCache::getPointerAlign
CharUnits getPointerAlign() const
Definition: CodeGenTypeCache.h:117
clang::QualType
A (possibly-)qualified type.
Definition: Type.h:673
Attr.h
AttributeLangSupport::C
@ C
Definition: SemaDeclAttr.cpp:54
clang::CodeGen::CGBlockInfo
CGBlockInfo - Information to generate a block literal.
Definition: CGBlocks.h:152
clang::CodeGen::CodeGenModule::getContext
ASTContext & getContext() const
Definition: CodeGenModule.h:702
clang::CodeGen::Address::isValid
bool isValid() const
Definition: Address.h:35
clang::CodeGen::CodeGenFunction::EmitARCDestroyStrong
void EmitARCDestroyStrong(Address addr, ARCPreciseLifetime_t precise)
Destroy a __strong variable.
Definition: CGObjC.cpp:2432
clang::CodeGen::BlockByrefHelpers::DisposeHelper
llvm::Constant * DisposeHelper
Definition: CodeGenModule.h:257
clang::Qualifiers
The collection of all-type qualifiers we support.
Definition: Type.h:145
clang::CodeGen::BLOCK_BYREF_HAS_COPY_DISPOSE
@ BLOCK_BYREF_HAS_COPY_DISPOSE
Definition: CGBlocks.h:46
clang::QualType::PCK_ARCStrong
@ PCK_ARCStrong
The type is an Objective-C retainable pointer type that is qualified with the ARC __strong qualifier.
Definition: Type.h:1174
clang::ASTContext::BlockRequiresCopying
bool BlockRequiresCopying(QualType Ty, const VarDecl *D)
Returns true iff we need copy/dispose helpers for the given type.
Definition: ASTContext.cpp:6849
clang::CodeGen::CodeGenFunction::GenerateCopyHelperFunction
llvm::Constant * GenerateCopyHelperFunction(const CGBlockInfo &blockInfo)
Generate the copy-helper function for a block closure object: static void block_copy_helper(block_t *...
Definition: CGBlocks.cpp:1918
clang::CodeGen::BLOCK_HAS_EXTENDED_LAYOUT
@ BLOCK_HAS_EXTENDED_LAYOUT
Definition: CGBlocks.h:62
clang::CodeGen::CodeGenFunction::EmitARCCopyWeak
void EmitARCCopyWeak(Address dst, Address src)
void @objc_copyWeak(i8** dest, i8** src) Disregards the current value in dest.
Definition: CGObjC.cpp:2627
clang::CodeGen::CGBuilderTy::CreateStore
llvm::StoreInst * CreateStore(llvm::Value *Val, Address Addr, bool IsVolatile=false)
Definition: CGBuilder.h:95
clang::CodeGen::CGBlockInfo::getCapture
const Capture & getCapture(const VarDecl *var) const
Definition: CGBlocks.h:266
CGObjCRuntime.h
TargetInfo.h
clang::Qualifiers::OCL_ExplicitNone
@ OCL_ExplicitNone
This object can be modified without requiring retains or releases.
Definition: Type.h:166
clang::CodeGen::CodeGenTypes::arrangeBuiltinFunctionDeclaration
const CGFunctionInfo & arrangeBuiltinFunctionDeclaration(QualType resultType, const FunctionArgList &args)
A builtin function is a freestanding function using the default C conventions.
Definition: CGCall.cpp:657
clang::CodeGen::CodeGenModule::getGenericBlockLiteralType
llvm::Type * getGenericBlockLiteralType()
The type of a generic block literal.
Definition: CGBlocks.cpp:1141
buildDisposeHelper
static llvm::Constant * buildDisposeHelper(CodeGenModule &CGM, const CGBlockInfo &blockInfo)
Build the helper function to dispose of a block.
Definition: CGBlocks.cpp:62
clang::CodeGen::BlockByrefHelpers::emitCopy
virtual void emitCopy(CodeGenFunction &CGF, Address dest, Address src)=0
getBlockDescriptorName
static std::string getBlockDescriptorName(const CGBlockInfo &BlockInfo, CodeGenModule &CGM)
Definition: CGBlocks.cpp:122
clang::CodeGen::CodeGenFunction::BlockPointer
llvm::Value * BlockPointer
Definition: CodeGenFunction.h:576
clang::CodeGen::CodeGenModule::SetLLVMFunctionAttributes
void SetLLVMFunctionAttributes(GlobalDecl GD, const CGFunctionInfo &Info, llvm::Function *F, bool IsThunk)
Set the LLVM function attributes (sext, zext, etc).
Definition: CodeGenModule.cpp:1517
clang::CodeGen::CodeGenModule::getLangOpts
const LangOptions & getLangOpts() const
Definition: CodeGenModule.h:703
clang::QualType::isVolatileQualified
bool isVolatileQualified() const
Determine whether this type is volatile-qualified.
Definition: Type.h:6494
clang::CodeGen::BLOCK_BYREF_LAYOUT_UNRETAINED
@ BLOCK_BYREF_LAYOUT_UNRETAINED
Definition: CGBlocks.h:52
clang::CodeGen::BLOCK_USE_STRET
@ BLOCK_USE_STRET
Definition: CGBlocks.h:60
clang::CodeGen::CodeGenFunction::getDestroyer
Destroyer * getDestroyer(QualType::DestructionKind destructionKind)
Definition: CGDecl.cpp:2079
clang::CodeGen::EHCleanup
@ EHCleanup
Denotes a cleanup that should run when a scope is exited using exceptional control flow (a throw stat...
Definition: EHScopeStack.h:80
clang::CallExpr::getCalleeDecl
Decl * getCalleeDecl()
Definition: Expr.h:2959
clang::CodeGen::CodeGenFunction::CreateTempAlloca
llvm::AllocaInst * CreateTempAlloca(llvm::Type *Ty, const Twine &Name="tmp", llvm::Value *ArraySize=nullptr)
CreateTempAlloca - This creates an alloca and inserts it into the entry block if ArraySize is nullptr...
Definition: CGExpr.cpp:110
clang::sema::Capture
Definition: ScopeInfo.h:529
clang::CharUnits::alignmentAtOffset
CharUnits alignmentAtOffset(CharUnits offset) const
Given that this is a non-zero alignment value, what is the alignment at the given offset?
Definition: CharUnits.h:194
clang::CodeGen::CGBlockInfo::needsCopyDisposeHelpers
bool needsCopyDisposeHelpers() const
Definition: CGBlocks.h:286
clang::CodeGen::CGBlockInfo::NeedsCopyDispose
bool NeedsCopyDispose
True if the block has captures that would necessitate custom copy or dispose helper functions if the ...
Definition: CGBlocks.h:222
clang::CodeGen::CodeGenModule::getTargetCodeGenInfo
const TargetCodeGenInfo & getTargetCodeGenInfo()
Definition: TargetInfo.cpp:11083
clang::CodeGen::CodeGenModule::ReturnSlotInterferesWithArgs
bool ReturnSlotInterferesWithArgs(const CGFunctionInfo &FI)
Return true iff the given type uses an argument slot when 'sret' is used as a return type.
Definition: CGCall.cpp:1556
clang::FunctionType
FunctionType - C99 6.7.5.3 - Function Declarators.
Definition: Type.h:3546
clang::ast_matchers::blockDecl
const internal::VariadicDynCastAllOfMatcher< Decl, BlockDecl > blockDecl
Matches block declarations.
Definition: ASTMatchersInternal.cpp:835
clang::CodeGen::CodeGenTypes::arrangeBlockFunctionDeclaration
const CGFunctionInfo & arrangeBlockFunctionDeclaration(const FunctionProtoType *type, const FunctionArgList &args)
Block invocation functions are C functions with an implicit parameter.
Definition: CGCall.cpp:632
getCaptureFieldType
static QualType getCaptureFieldType(const CodeGenFunction &CGF, const BlockDecl::Capture &CI)
Definition: CGBlocks.cpp:503
clang::CodeGen::CodeGenTypeCache::getIntAlign
CharUnits getIntAlign() const
Definition: CodeGenTypeCache.h:87
clang::CodeGen::CGBuilderTy::CreateStructGEP
Address CreateStructGEP(Address Addr, unsigned Index, const llvm::Twine &Name="")
Definition: CGBuilder.h:188
clang::CodeGen::CodeGenFunction::EmitStmt
void EmitStmt(const Stmt *S, ArrayRef< const Attr * > Attrs=None)
EmitStmt - Emit the code for the statement.
Definition: CGStmt.cpp:53
ConstantEmitter.h
clang::CodeGen::CodeGenFunction::pushLifetimeExtendedDestroy
void pushLifetimeExtendedDestroy(CleanupKind kind, Address addr, QualType type, Destroyer *destroyer, bool useEHCleanupForArray)
Definition: CGDecl.cpp:2126
b
__device__ __2f16 b
Definition: __clang_hip_libdevice_declares.h:314
clang::CodeGen::CodeGenFunction::EmitExprAsInit
void EmitExprAsInit(const Expr *init, const ValueDecl *D, LValue lvalue, bool capturedByInit)
EmitExprAsInit - Emits the code necessary to initialize a location in memory with the given initializ...
Definition: CGDecl.cpp:1921
clang::ASTContext::getTranslationUnitDecl
TranslationUnitDecl * getTranslationUnitDecl() const
Definition: ASTContext.h:1057
clang::QualType::PCK_VolatileTrivial
@ PCK_VolatileTrivial
The type would be trivial except that it is volatile-qualified.
Definition: Type.h:1170
clang::CodeGen::CodeGenFunction::EmitBlockLiteral
llvm::Value * EmitBlockLiteral(const BlockExpr *)
Emit block literal.
Definition: CGBlocks.cpp:778
clang::CodeGen::CGBlockInfo::Capture
Definition: CGBlocks.h:160
clang::CodeGen::CallArgList::add
void add(RValue rvalue, QualType type)
Definition: CGCall.h:288
clang::CodeGen::ConstantEmitter::tryEmitAbstractForInitializer
llvm::Constant * tryEmitAbstractForInitializer(const VarDecl &D)
Try to emit the initializer of the given declaration as an abstract constant.
Definition: CGExprConstant.cpp:1346
clang::CodeGen::CodeGenFunction::Builder
CGBuilderTy Builder
Definition: CodeGenFunction.h:274
tryCaptureAsConstant
static llvm::Constant * tryCaptureAsConstant(CodeGenModule &CGM, CodeGenFunction *CGF, const VarDecl *var)
It is illegal to modify a const object after initialization.
Definition: CGBlocks.cpp:412
CGDebugInfo.h
clang::CodeGen::CodeGenTypes::ConvertType
llvm::Type * ConvertType(QualType T)
ConvertType - Convert type T into a llvm::Type.
Definition: CodeGenTypes.cpp:395
clang::CodeGen::CGBuilderTy::CreateBitCast
Address CreateBitCast(Address Addr, llvm::Type *Ty, const llvm::Twine &Name="")
Definition: CGBuilder.h:151
pushCaptureCleanup
static void pushCaptureCleanup(BlockCaptureEntityKind CaptureKind, Address Field, QualType CaptureType, BlockFieldFlags Flags, bool ForCopyHelper, VarDecl *Var, CodeGenFunction &CGF)
Definition: CGBlocks.cpp:1854
clang::CodeGen::BLOCK_HAS_CXX_OBJ
@ BLOCK_HAS_CXX_OBJ
Definition: CGBlocks.h:58
clang::Type
The base class of the type hierarchy.
Definition: Type.h:1490
clang::CodeGen::CodeGenTypeCache::VoidPtrTy
llvm::PointerType * VoidPtrTy
Definition: CodeGenTypeCache.h:56
clang::CodeGen::BlockByrefHelpers::needsDispose
virtual bool needsDispose() const
Definition: CodeGenModule.h:278
clang::CodeGen::CodeGenFunction::GetAddrOfLocalVar
Address GetAddrOfLocalVar(const VarDecl *VD)
GetAddrOfLocalVar - Return the address of a local variable.
Definition: CodeGenFunction.h:2679
DeclObjC.h
Offset
unsigned Offset
Definition: Format.cpp:2335
clang::CodeGen::ARCImpreciseLifetime
@ ARCImpreciseLifetime
Definition: CGValue.h:121
clang::GlobalDecl
GlobalDecl - represents a global declaration.
Definition: GlobalDecl.h:55
clang::CodeGen::AlignmentSource::Decl
@ Decl
The l-value was an access to a declared entity or something equivalently strong, like the address of ...
clang::BlockDecl::captures
ArrayRef< Capture > captures() const
Definition: Decl.h:4280
clang::BlockDecl::doesNotEscape
bool doesNotEscape() const
Definition: Decl.h:4304
clang::BlockDecl::Capture::isByRef
bool isByRef() const
Whether this is a "by ref" capture, i.e.
Definition: Decl.h:4184
clang::CodeGen::CGBlockInfo::HasCapturedVariableLayout
bool HasCapturedVariableLayout
HasCapturedVariableLayout : True if block has captured variables and their layout meta-data has been ...
Definition: CGBlocks.h:234
clang::CodeGen::BLOCK_BYREF_LAYOUT_EXTENDED
@ BLOCK_BYREF_LAYOUT_EXTENDED
Definition: CGBlocks.h:48
clang::CodeGen::CodeGenTypes::ConvertTypeForMem
llvm::Type * ConvertTypeForMem(QualType T, bool ForBitField=false)
ConvertTypeForMem - Convert type T into a llvm::Type.
Definition: CodeGenTypes.cpp:90
clang::CodeGen::ReturnValueSlot
ReturnValueSlot - Contains the address where the return value of a function can be stored,...
Definition: CGCall.h:362
clang::CodeGen::CGOpenCLRuntime::recordBlockInfo
void recordBlockInfo(const BlockExpr *E, llvm::Function *InvokeF, llvm::Value *Block)
Record invoke function and block literal emitted during normal codegen for a block expression.
Definition: CGOpenCLRuntime.cpp:144
configureBlocksRuntimeObject
static void configureBlocksRuntimeObject(CodeGenModule &CGM, llvm::Constant *C)
Adjust the declaration of something from the blocks API.
Definition: CGBlocks.cpp:2847
clang::CodeGen::CGObjCRuntime::getRCBlockLayoutStr
virtual std::string getRCBlockLayoutStr(CodeGen::CodeGenModule &CGM, const CGBlockInfo &blockInfo)
Definition: CGObjCRuntime.h:319
clang::CodeGen::BLOCK_BYREF_LAYOUT_NON_OBJECT
@ BLOCK_BYREF_LAYOUT_NON_OBJECT
Definition: CGBlocks.h:49
clang::QualType::DK_cxx_destructor
@ DK_cxx_destructor
Definition: Type.h:1204
clang::CodeGen::CGBlockInfo::BlockHeaderForcedGapSize
CharUnits BlockHeaderForcedGapSize
Definition: CGBlocks.h:258
clang::Type::isReferenceType
bool isReferenceType() const
Definition: Type.h:6684
clang::CallExpr::getCallee
Expr * getCallee()
Definition: Expr.h:2945
V
#define V(N, I)
Definition: ASTContext.h:3121
clang::BlockDecl::capture_begin
capture_const_iterator capture_begin() const
Definition: Decl.h:4282
clang::TranslationUnitDecl
The top declaration context.
Definition: Decl.h:82
clang::CodeGen::CodeGenFunction::RunCleanupsScope
Enters a new scope for capturing cleanups, all of which will be executed once the scope is exited.
Definition: CodeGenFunction.h:838
clang::CodeGen::CodeGenModule::SetLLVMFunctionAttributesForDefinition
void SetLLVMFunctionAttributesForDefinition(const Decl *D, llvm::Function *F)
Set the LLVM function attributes which only apply to a function definition.
Definition: CodeGenModule.cpp:1761
clang::CodeGen::CodeGenFunction::BlockInfo
const CodeGen::CGBlockInfo * BlockInfo
Definition: CodeGenFunction.h:575
clang::RecordType
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
Definition: Type.h:4613
clang::CodeGen::CodeGenModule::getAddrOfGlobalBlockIfEmitted
llvm::Constant * getAddrOfGlobalBlockIfEmitted(const BlockExpr *BE)
Returns the address of a block which requires no caputres, or null if we've yet to emit the block for...
Definition: CodeGenModule.h:955
clang::CodeGen::CGObjCRuntime::BuildRCBlockLayout
virtual llvm::Constant * BuildRCBlockLayout(CodeGen::CodeGenModule &CGM, const CodeGen::CGBlockInfo &blockInfo)=0
clang::CodeGen::BlockByrefInfo::Type
llvm::StructType * Type
Definition: CGBlocks.h:145
clang::CodeGen::CGBlockInfo::CanBeGlobal
bool CanBeGlobal
CanBeGlobal - True if the block can be global, i.e.
Definition: CGBlocks.h:218
clang::CodeGen::EHScopeStack::Cleanup
Information for lazily generating a cleanup.
Definition: EHScopeStack.h:141
clang::CodeGen::CodeGenFunction::getNonTrivialCopyConstructorStr
static std::string getNonTrivialCopyConstructorStr(QualType QT, CharUnits Alignment, bool IsVolatile, ASTContext &Ctx)
Definition: CGNonTrivialStruct.cpp:860
clang::CodeGen::CodeGenModule::getObjCRuntime
CGObjCRuntime & getObjCRuntime()
Return a reference to the configured Objective-C runtime.
Definition: CodeGenModule.h:599
clang::BlockDecl
Represents a block literal declaration, which is like an unnamed FunctionDecl.
Definition: Decl.h:4153
clang::Qualifiers::OCL_Strong
@ OCL_Strong
Assigning into this object requires the old value to be released and the new value to be retained.
Definition: Type.h:173
clang::CodeGen::BlockByrefHelpers
A pair of helper functions for a __block variable.
Definition: CodeGenModule.h:252
clang::XRayInstrKind::None
constexpr XRayInstrMask None
Definition: XRayInstr.h:38
clang::Scope
Scope - A scope is a transient data structure that is used while parsing the program.
Definition: Scope.h:40
clang::CodeGen::CGBlockInfo::StructureType
llvm::StructType * StructureType
Definition: CGBlocks.h:245
clang::CodeGen::CodeGenFunction::AutoVarEmission
Definition: CodeGenFunction.h:3013
clang::CodeGen::BLOCK_IS_GLOBAL
@ BLOCK_IS_GLOBAL
Definition: CGBlocks.h:59
clang::CodeGen::CodeGenFunction::GenerateDestroyHelperFunction
llvm::Constant * GenerateDestroyHelperFunction(const CGBlockInfo &blockInfo)
Generate the destroy-helper function for a block closure object: static void block_destroy_helper(blo...
Definition: CGBlocks.cpp:2107
getBlockFieldFlagsForObjCObjectPointer
static BlockFieldFlags getBlockFieldFlagsForObjCObjectPointer(const BlockDecl::Capture &CI, QualType T)
Definition: CGBlocks.cpp:2053
clang::CharUnits::fromQuantity
static CharUnits fromQuantity(QuantityType Quantity)
fromQuantity - Construct a CharUnits quantity from a raw integer type.
Definition: CharUnits.h:63
clang::ASTContext::getBlockVarCopyInit
BlockVarCopyInit getBlockVarCopyInit(const VarDecl *VD) const
Get the copy initialization expression of the VarDecl VD, or nullptr if none exists.
Definition: ASTContext.cpp:2917
clang::BlockExpr::getBlockDecl
const BlockDecl * getBlockDecl() const
Definition: Expr.h:5977
clang::CodeGen::CodeGenModule::getCodeGenOpts
const CodeGenOptions & getCodeGenOpts() const
Definition: CodeGenModule.h:708
clang::FPOptionsOverride
Represents difference between two FPOptions values.
Definition: LangOptions.h:600
clang::ASTContext
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:212
buildGlobalBlock
static llvm::Constant * buildGlobalBlock(CodeGenModule &CGM, const CGBlockInfo &blockInfo, llvm::Constant *blockFn)
Build the given block as a global block.
Definition: CGBlocks.cpp:1309
clang::TargetInfo::getPointerAlign
uint64_t getPointerAlign(unsigned AddrSpace) const
Definition: TargetInfo.h:420
clang::CodeGen::BLOCK_BYREF_CALLER
@ BLOCK_BYREF_CALLER
Definition: CGBlocks.h:104
clang::Type::getAs
const T * getAs() const
Member-template getAs<specific type>'.
Definition: Type.h:7161
clang::CodeGen::BlockByrefHelpers::needsCopy
virtual bool needsCopy() const
Definition: CodeGenModule.h:275
clang::QualType::DK_none
@ DK_none
Definition: Type.h:1203
clang::CodeGen::CodeGenFunction::getDebugInfo
CGDebugInfo * getDebugInfo()
Definition: CodeGenFunction.h:1948
clang::BlockDecl::Capture::isEscapingByref
bool isEscapingByref() const
Definition: Decl.h:4186
clang::CodeGen::CodeGenTypeCache::VoidTy
llvm::Type * VoidTy
void
Definition: CodeGenTypeCache.h:34
clang::VarDecl::isEscapingByref
bool isEscapingByref() const
Indicates the capture is a __block variable that is captured by a block that can potentially escape (...
Definition: Decl.cpp:2549
clang::CodeGen::BLOCK_HAS_COPY_DISPOSE
@ BLOCK_HAS_COPY_DISPOSE
Definition: CGBlocks.h:57
clang::BlockVarCopyInit::getCopyExpr
Expr * getCopyExpr() const
Definition: Expr.h:6018
buildByrefHelpers
static T * buildByrefHelpers(CodeGenModule &CGM, const BlockByrefInfo &byrefInfo, T &&generator)
Lazily build the copy and dispose helpers for a __block variable with the given information.
Definition: CGBlocks.cpp:2486
clang::CodeGen::CodeGenModule::getModule
llvm::Module & getModule() const
Definition: CodeGenModule.h:709
clang::CodeGen::CodeGenFunction::EmitARCStoreStrongCall
llvm::Value * EmitARCStoreStrongCall(Address addr, llvm::Value *value, bool resultIgnored)
Store into a strong object.
Definition: CGObjC.cpp:2446
clang::isa
bool isa(CodeGen::Address addr)
Definition: Address.h:111
clang::CXXDestructorDecl
Represents a C++ destructor within a class.
Definition: DeclCXX.h:2668
clang::CodeGen::CGDebugInfo
This class gathers all debug information during compilation and is responsible for emitting to llvm g...
Definition: CGDebugInfo.h:56
clang::CodeGen::CodeGenTypeCache::getIntSize
CharUnits getIntSize() const
Definition: CodeGenTypeCache.h:84
clang::MangleContext::mangleTypeName
virtual void mangleTypeName(QualType T, raw_ostream &)=0
Generates a unique string for an externally visible type for use with TBAA or type uniquing.
clang::CodeGen::CodeGenFunction::getCleanupKind
CleanupKind getCleanupKind(QualType::DestructionKind kind)
Definition: CodeGenFunction.h:2055
clang::ImplicitParamDecl
Definition: Decl.h:1601
clang::Qualifiers::hasObjCLifetime
bool hasObjCLifetime() const
Definition: Type.h:334
clang::ASTContext::getObjCEncodingForBlock
std::string getObjCEncodingForBlock(const BlockExpr *blockExpr) const
Return the encoded type for this block declaration.
Definition: ASTContext.cpp:6997
llvm::SmallString
Definition: LLVM.h:37
clang::CodeGen::CodeGenFunction::needsEHCleanup
bool needsEHCleanup(QualType::DestructionKind kind)
Determines whether an EH cleanup is required to destroy a type with the given destruction kind.
Definition: CodeGenFunction.h:2040
clang::LangAS::opencl_constant
@ opencl_constant
clang::CodeGen::TargetCodeGenInfo::getTargetOpenCLBlockHelper
virtual TargetOpenCLBlockHelper * getTargetOpenCLBlockHelper() const
Definition: TargetInfo.h:321
clang::VarDecl
Represents a variable declaration or definition.
Definition: Decl.h:876
buildByrefCopyHelper
static llvm::Constant * buildByrefCopyHelper(CodeGenModule &CGM, const BlockByrefInfo &byrefInfo, BlockByrefHelpers &generator)
Build the copy helper for a __block variable.
Definition: CGBlocks.cpp:2419
clang::CodeGen::CodeGenFunction::PushDestructorCleanup
void PushDestructorCleanup(QualType T, Address Addr)
PushDestructorCleanup - Push a cleanup to call the complete-object destructor of an object of the giv...
Definition: CGClass.cpp:2473
findBlockCapturedManagedEntities
static void findBlockCapturedManagedEntities(const CGBlockInfo &BlockInfo, const LangOptions &LangOpts, SmallVectorImpl< BlockCaptureManagedEntity > &ManagedCaptures)
Find the set of block captures that need to be explicitly copied or destroy.
Definition: CGBlocks.cpp:1677
clang::Type::getPointeeType
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
Definition: Type.cpp:625
clang::CodeGen::CGBlockInfo::CXXThisIndex
unsigned CXXThisIndex
The field index of 'this' within the block, if there is one.
Definition: CGBlocks.h:158
clang::CodeGen::CodeGenModule::getTypes
CodeGenTypes & getTypes()
Definition: CodeGenModule.h:726
clang::BlockDecl::Capture::getVariable
VarDecl * getVariable() const
The variable being captured.
Definition: Decl.h:4180
clang::CodeGen::CodeGenFunction::getBlockByrefInfo
const BlockByrefInfo & getBlockByrefInfo(const VarDecl *var)
BuildByrefInfo - This routine changes a __block variable declared as T x into:
Definition: CGBlocks.cpp:2631
clang::Type::getAsCXXRecordDecl
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
Definition: Type.cpp:1760
generateByrefCopyHelper
static llvm::Constant * generateByrefCopyHelper(CodeGenFunction &CGF, const BlockByrefInfo &byrefInfo, BlockByrefHelpers &generator)
Definition: CGBlocks.cpp:2357
clang::CodeGen::AggValueSlot::IsDestructed
@ IsDestructed
Definition: CGValue.h:525
clang::CodeGen::BlockFieldFlags::getBitMask
uint32_t getBitMask() const
Definition: CGBlocks.h:117
isSafeForCXXConstantCapture
static bool isSafeForCXXConstantCapture(QualType type)
Determines if the given type is safe for constant capture in C++.
Definition: CGBlocks.cpp:388
clang::CodeGen::BlockFlags
Definition: CGBlocks.h:64
clang::CodeGen::CodeGenFunction::getLLVMContext
llvm::LLVMContext & getLLVMContext()
Definition: CodeGenFunction.h:1990
clang::CodeGen::CodeGenModule::getBlockObjectDispose
llvm::FunctionCallee getBlockObjectDispose()
Definition: CGBlocks.cpp:2883
clang::CodeGen::CodeGenFunction::getContext
ASTContext & getContext() const
Definition: CodeGenFunction.h:1947
clang::CodeGen::CodeGenTypeCache::getPointerSize
CharUnits getPointerSize() const
Definition: CodeGenTypeCache.h:114
clang::CodeGen::NormalCleanup
@ NormalCleanup
Denotes a cleanup that should run when a scope is exited using normal control flow (falling off the e...
Definition: EHScopeStack.h:84
clang::CodeGen::BlockFieldFlags
Definition: CGBlocks.h:109
getLowBit
static CharUnits getLowBit(CharUnits v)
Get the low bit of a nonzero character count.
Definition: CGBlocks.cpp:444
clang::CharUnits::Zero
static CharUnits Zero()
Zero - Construct a CharUnits quantity of zero.
Definition: CharUnits.h:53
clang::CodeGen::CodeGenFunction::incrementProfileCounter
void incrementProfileCounter(const Stmt *S, llvm::Value *StepV=nullptr)
Increment the profiler's counter for the given statement by StepV.
Definition: CodeGenFunction.h:1490
clang::CodeGen::CodeGenFunction::FinishFunction
void FinishFunction(SourceLocation EndLoc=SourceLocation())
FinishFunction - Complete IR generation of the current function.
Definition: CodeGenFunction.cpp:324
clang::CodeGen::Address
An aligned address.
Definition: Address.h:24
clang::CodeGen::CodeGenFunction::enterByrefCleanup
void enterByrefCleanup(CleanupKind Kind, Address Addr, BlockFieldFlags Flags, bool LoadBlockVarAddr, bool CanThrow)
Enter a cleanup to destroy a __block variable.
Definition: CGBlocks.cpp:2839
CodeGenModule.h
clang::CodeGen::CodeGenModule::GetAddrOfGlobalBlock
llvm::Constant * GetAddrOfGlobalBlock(const BlockExpr *BE, StringRef Name)
Gets the address of a block which requires no captures.
Definition: CGBlocks.cpp:1287
clang::CodeGen::CodeGenFunction::SanOpts
SanitizerSet SanOpts
Sanitizers enabled for this function.
Definition: CodeGenFunction.h:490
clang::CodeGen::CGBlockInfo::HasCXXObject
bool HasCXXObject
HasCXXObject - True if the block's custom copy/dispose functions need to be run even in GC mode.
Definition: CGBlocks.h:226
clang::BlockPointerType
Pointer to a block type.
Definition: Type.h:2720
clang::CodeGen::CodeGenFunction::EmitLambdaBlockInvokeBody
void EmitLambdaBlockInvokeBody()
Definition: CGClass.cpp:2912
clang::CodeGen::CodeGenFunction::emitARCIntrinsicUse
static Destroyer emitARCIntrinsicUse
Definition: CodeGenFunction.h:4298
clang::CodeGen::BLOCK_FIELD_IS_BLOCK
@ BLOCK_FIELD_IS_BLOCK
Definition: CGBlocks.h:97
clang::CodeGen::ConstantInitBuilderTemplateBase::beginStruct
StructBuilder beginStruct(llvm::StructType *structTy=nullptr)
Definition: ConstantInitBuilder.h:518
clang::CodeGen::CodeGenFunction::GetAddrOfBlockDecl
Address GetAddrOfBlockDecl(const VarDecl *var)
Definition: CGBlocks.cpp:1245
clang::Qualifiers::OCL_Autoreleasing
@ OCL_Autoreleasing
Assigning into this object requires a lifetime extension.
Definition: Type.h:179
clang::Qualifiers::ObjCLifetime
ObjCLifetime
Definition: Type.h:160
clang::CodeGen::CodeGenModule::getTarget
const TargetInfo & getTarget() const
Definition: CodeGenModule.h:714
clang::CodeGen::CodeGenFunction::callCStructMoveConstructor
void callCStructMoveConstructor(LValue Dst, LValue Src)
Definition: CGNonTrivialStruct.cpp:910
clang::CodeGen::CodeGenModule::ByrefHelpersCache
llvm::FoldingSet< BlockByrefHelpers > ByrefHelpersCache
Definition: CodeGenModule.h:939
clang::CodeGen::CodeGenFunction::CurGD
GlobalDecl CurGD
CurGD - The GlobalDecl for the current function being compiled.
Definition: CodeGenFunction.h:350
clang::CodeGen::CodeGenTypeCache::Int32Ty
llvm::IntegerType * Int32Ty
Definition: CodeGenTypeCache.h:37
clang::CodeGen::CodeGenFunction::destroyARCStrongImprecise
static Destroyer destroyARCStrongImprecise
Definition: CodeGenFunction.h:4295
clang::QualType::PCK_Trivial
@ PCK_Trivial
The type does not fall into any of the following categories.
Definition: Type.h:1165
clang::CodeGen::CodeGenModule::getBlockDescriptorType
llvm::Type * getBlockDescriptorType()
Fetches the type of a generic block descriptor.
Definition: CGBlocks.cpp:1109
clang::CodeGen::BLOCK_BYREF_LAYOUT_STRONG
@ BLOCK_BYREF_LAYOUT_STRONG
Definition: CGBlocks.h:50
clang::ASTContext::getTargetAddressSpace
unsigned getTargetAddressSpace(QualType T) const
Definition: ASTContext.h:2720
clang::BlockDecl::hasCaptures
bool hasCaptures() const
True if this block (or its nested blocks) captures anything of local storage from its enclosing scope...
Definition: Decl.h:4272
clang::CodeGen::CodeGenModule::GetTargetTypeStoreSize
CharUnits GetTargetTypeStoreSize(llvm::Type *Ty) const
Return the store size, in character units, of the given LLVM type.
Definition: CodeGenModule.cpp:4179
clang::LangAS
LangAS
Defines the address space values used by the address space qualifier of QualType.
Definition: AddressSpaces.h:25
clang::VK_LValue
@ VK_LValue
An l-value expression is a reference to an object with independent storage.
Definition: Specifiers.h:124
clang::CodeGen::CodeGenTypes::GetFunctionType
llvm::FunctionType * GetFunctionType(const CGFunctionInfo &Info)
GetFunctionType - Get the LLVM function type for.
Definition: CGCall.cpp:1595
clang::CodeGen::CodeGenModule::getDataLayout
const llvm::DataLayout & getDataLayout() const
Definition: CodeGenModule.h:711
clang::Type::castAs
const T * castAs() const
Member-template castAs<specific type>.
Definition: Type.h:7226
clang::CodeGen::ApplyDebugLocation
A scoped helper to set the current debug location to the specified location or preferred location of ...
Definition: CGDebugInfo.h:778
clang::TargetInfo::getTriple
const llvm::Triple & getTriple() const
Returns the target triple of the primary target.
Definition: TargetInfo.h:1130
clang::CodeGen::CodeGenFunction::StartFunction
void StartFunction(GlobalDecl GD, QualType RetTy, llvm::Function *Fn, const CGFunctionInfo &FnInfo, const FunctionArgList &Args, SourceLocation Loc=SourceLocation(), SourceLocation StartLoc=SourceLocation())
Emit code for the start of a function.
Definition: CodeGenFunction.cpp:700
clang::CXXRecordDecl
Represents a C++ struct/union/class.
Definition: DeclCXX.h:255
clang::BlockDecl::Capture::isNested
bool isNested() const
Whether this is a nested capture, i.e.
Definition: Decl.h:4196
clang::CodeGen::CodeGenFunction::EHStack
EHScopeStack EHStack
Definition: CodeGenFunction.h:585
clang::VK_PRValue
@ VK_PRValue
A pr-value expression (in the C++11 taxonomy) produces a temporary value.
Definition: Specifiers.h:120
clang::serialized_diags::create
std::unique_ptr< DiagnosticConsumer > create(StringRef OutputFile, DiagnosticOptions *Diags, bool MergeChildRecords=false)
Returns a DiagnosticConsumer that serializes diagnostics to a bitcode file.
Definition: SerializedDiagnosticPrinter.cpp:302
clang::CodeGen::CGBlockInfo::Capture::isConstant
bool isConstant() const
Definition: CGBlocks.h:172
clang::CodeGen::CodeGenModule::getNSConcreteGlobalBlock
llvm::Constant * getNSConcreteGlobalBlock()
Definition: CGBlocks.cpp:2909
clang::CodeGen::AggValueSlot::forAddr
static AggValueSlot forAddr(Address addr, Qualifiers quals, IsDestructed_t isDestructed, NeedsGCBarriers_t needsGC, IsAliased_t isAliased, Overlap_t mayOverlap, IsZeroed_t isZeroed=IsNotZeroed, IsSanitizerChecked_t isChecked=IsNotSanitizerChecked)
forAddr - Make a slot for an aggregate value.
Definition: CGValue.h:548
clang::CodeGen::CodeGenFunction::EmitDeclRefLValue
LValue EmitDeclRefLValue(const DeclRefExpr *E)
Definition: CGExpr.cpp:2668
clang::CodeGen::BLOCK_FIELD_IS_BYREF
@ BLOCK_FIELD_IS_BYREF
Definition: CGBlocks.h:99
clang::CodeGen::CodeGenFunction::DeclMapTy
llvm::DenseMap< const Decl *, Address > DeclMapTy
Definition: CodeGenFunction.h:950
clang::ASTContext::VoidPtrTy
CanQualType VoidPtrTy
Definition: ASTContext.h:1102
clang::CodeGen::CGOpenCLRuntime::getInvokeFunction
llvm::Function * getInvokeFunction(const Expr *E)
Definition: CGOpenCLRuntime.cpp:156
clang::syntax::NodeRole::Size
@ Size
false
#define false
Definition: stdbool.h:17
clang::CodeGen::Address::getPointer
llvm::Value * getPointer() const
Definition: Address.h:37
clang::CodeGen::CodeGenFunction
CodeGenFunction - This class organizes the per-function state that is used while generating LLVM code...
Definition: CodeGenFunction.h:235
clang::ASTContext::getDeclAlign
CharUnits getDeclAlign(const Decl *D, bool ForAlignof=false) const
Return a conservative estimate of the alignment of the specified decl D.
Definition: ASTContext.cpp:1727
ulong
unsigned long ulong
An unsigned 64-bit integer.
Definition: opencl-c-base.h:94
clang::CodeGen::CodeGenFunction::pushDestroy
void pushDestroy(QualType::DestructionKind dtorKind, Address addr, QualType type)
pushDestroy - Push the standard destructor for the given type as at least a normal cleanup.
Definition: CGDecl.cpp:2106
clang::LangOptions::NonGC
@ NonGC
Definition: LangOptions.h:63
clang::CodeGen::CodeGenModule::getCXXABI
CGCXXABI & getCXXABI() const
Definition: CodeGenModule.h:719
clang::FunctionProtoType
Represents a prototype with parameter type info, e.g.
Definition: Type.h:3885
clang::CodeGen::AggValueSlot::IsNotAliased
@ IsNotAliased
Definition: CGValue.h:524
clang::ASTContext::Idents
IdentifierTable & Idents
Definition: ASTContext.h:648
clang::CodeGen::CodeGenFunction::EmitARCMoveWeak
void EmitARCMoveWeak(Address dst, Address src)
void @objc_moveWeak(i8** dest, i8** src) Disregards the current value in dest.
Definition: CGObjC.cpp:2618
clang::CodeGen::CodeGenModule
This class organizes the cross-function state that is used while generating LLVM code.
Definition: CodeGenModule.h:284
clang::QualType::DK_objc_strong_lifetime
@ DK_objc_strong_lifetime
Definition: Type.h:1205
clang::CodeGen::CodeGenModule::setDSOLocal
void setDSOLocal(llvm::GlobalValue *GV) const
Definition: CodeGenModule.cpp:1105
clang::BlockExpr
BlockExpr - Adaptor class for mixing a BlockDecl with expressions.
Definition: Expr.h:5965
clang::CodeGen::CGBlockInfo::getBlockDecl
const BlockDecl * getBlockDecl() const
Definition: CGBlocks.h:276
clang::LangAS::opencl_global
@ opencl_global
Value
Value
Definition: UninitializedValues.cpp:102
clang::CodeGen::CodeGenFunction::EmitAggExpr
void EmitAggExpr(const Expr *E, AggValueSlot AS)
EmitAggExpr - Emit the computation of the specified expression of aggregate type.
Definition: CGExprAgg.cpp:1989
clang::CodeGen::Address::invalid
static Address invalid()
Definition: Address.h:34
clang::CodeGen::CGBuilderTy::CreateAlignedLoad
llvm::LoadInst * CreateAlignedLoad(llvm::Type *Ty, llvm::Value *Addr, CharUnits Align, const llvm::Twine &Name="")
Definition: CGBuilder.h:86
clang::QualType::isObjCGCWeak
bool isObjCGCWeak() const
true when Type is objc's weak.
Definition: Type.h:1110
clang::CodeGen::CGCallee
All available information about a concrete callee.
Definition: CGCall.h:67
clang::CodeGen::FunctionArgList
FunctionArgList - Type for representing both the decl and type of parameters to a function.
Definition: CGCall.h:358
clang::CharUnits::alignTo
CharUnits alignTo(const CharUnits &Align) const
alignTo - Returns the next integer (mod 2**64) that is greater than or equal to this quantity and is ...
Definition: CharUnits.h:188
clang::QualType::DestructionKind
DestructionKind
Definition: Type.h:1202
clang::CodeGen::BLOCK_IS_NOESCAPE
@ BLOCK_IS_NOESCAPE
Definition: CGBlocks.h:56
clang::CodeGen::AggValueSlot
An aggregate value slot.
Definition: CGValue.h:471
clang::CodeGen::CodeGenFunction::ConvertType
llvm::Type * ConvertType(QualType T)
Definition: CodeGenFunction.cpp:211
clang::CodeGen::CodeGenModule::getBlockObjectAssign
llvm::FunctionCallee getBlockObjectAssign()
Definition: CGBlocks.cpp:2896
clang::Type::isObjCInertUnsafeUnretainedType
bool isObjCInertUnsafeUnretainedType() const
Was this type written with the special inert-in-ARC __unsafe_unretained qualifier?
Definition: Type.h:2072
clang::CodeGen::NormalAndEHCleanup
@ NormalAndEHCleanup
Definition: EHScopeStack.h:86
clang::CodeGenOptions::hasReducedDebugInfo
bool hasReducedDebugInfo() const
Check if type and variable info should be emitted.
Definition: CodeGenOptions.h:454
clang::ImplicitParamDecl::ObjCSelf
@ ObjCSelf
Parameter for Objective-C 'self' argument.
Definition: Decl.h:1610
clang::CodeGen::CGBlockInfo::Capture::getIndex
unsigned getIndex() const
Definition: CGBlocks.h:174
clang::VarDecl::getInit
const Expr * getInit() const
Definition: Decl.h:1285
clang::QualType::DK_objc_weak_lifetime
@ DK_objc_weak_lifetime
Definition: Type.h:1206
clang::CodeGen::CodeGenFunction::MakeAddrLValue
LValue MakeAddrLValue(Address Addr, QualType T, AlignmentSource Source=AlignmentSource::Type)
Definition: CodeGenFunction.h:2456
clang::CodeGen::CGBlockInfo::Capture::fieldType
QualType fieldType() const
Definition: CGBlocks.h:196
clang::IdentifierInfo
One of these records is kept for each identifier that is lexed.
Definition: IdentifierTable.h:84
clang::CodeGen::CodeGenModule::getNSConcreteStackBlock
llvm::Constant * getNSConcreteStackBlock()
Definition: CGBlocks.cpp:2919
clang::CodeGen::CodeGenFunction::EmitSynthesizedCXXCopyCtor
void EmitSynthesizedCXXCopyCtor(Address Dest, Address Src, const Expr *Exp)
Definition: CGExprCXX.cpp:659
clang::CodeGen::CGCalleeInfo
Abstract information about a function or function prototype.
Definition: CGCall.h:45
clang::CodeGen::CodeGenFunction::EmitRuntimeCallOrInvoke
llvm::CallBase * EmitRuntimeCallOrInvoke(llvm::FunctionCallee callee, ArrayRef< llvm::Value * > args, const Twine &name="")
Emits a call or invoke instruction to the given runtime function.
Definition: CGCall.cpp:4473
clang::CodeGen::CodeGenFunction::EmitScalarExpr
llvm::Value * EmitScalarExpr(const Expr *E, bool IgnoreResultAssign=false)
EmitScalarExpr - Emit the computation of the specified expression of LLVM scalar type,...
Definition: CGExprScalar.cpp:4848
clang::CodeGen::CGBlockInfo::BlockHeaderForcedGapOffset
CharUnits BlockHeaderForcedGapOffset
Definition: CGBlocks.h:255
clang::NamedDecl::getNameAsString
std::string getNameAsString() const
Get a human-readable name for the declaration, even if it is one of the special kinds of names (C++ c...
Definition: Decl.h:292
clang::LangOptions
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:58
clang::CodeGen::CodeGenModule::supportsCOMDAT
bool supportsCOMDAT() const
Definition: TargetInfo.cpp:11079
clang::ASTContext::getLValueReferenceType
QualType getLValueReferenceType(QualType T, bool SpelledAsLValue=true) const
Return the uniqued reference to the type for an lvalue reference to the specified type.
Definition: ASTContext.cpp:3369
clang::ObjCPropertyAttribute::Kind
Kind
Definition: DeclObjCCommon.h:22
clang::CodeGen::ConstantAddress::getPointer
llvm::Constant * getPointer() const
Definition: Address.h:83
clang::CodeGen::CGFunctionInfo
CGFunctionInfo - Class to encapsulate the information about a function definition.
Definition: CGFunctionInfo.h:546
clang::CodeGen::CodeGenFunction::PopCleanupBlocks
void PopCleanupBlocks(EHScopeStack::stable_iterator OldCleanupStackSize, std::initializer_list< llvm::Value ** > ValuesToReload={})
Takes the old cleanup stack size and emits the cleanup blocks that have been added.
Definition: CGCleanup.cpp:420
clang::ASTContext::isObjCNSObjectType
static bool isObjCNSObjectType(QualType Ty)
Return true if this is an NSObject object with its NSObject attribute set.
Definition: ASTContext.h:2225
CGCXXABI.h
clang::CodeGen::BLOCK_FIELD_IS_WEAK
@ BLOCK_FIELD_IS_WEAK
Definition: CGBlocks.h:101
clang::CodeGen::CodeGenPGO::assignRegionCounters
void assignRegionCounters(GlobalDecl GD, llvm::Function *Fn)
Assign counters to regions and configure them for PGO of a given function.
Definition: CodeGenPGO.cpp:794
clang::CodeGen::CodeGenFunction::setBlockContextParameter
void setBlockContextParameter(const ImplicitParamDecl *D, unsigned argNum, llvm::Value *ptr)
Definition: CGBlocks.cpp:1403
clang::driver::types
Definition: Types.h:22
clang::ast_matchers::recordType
const AstTypeMatcher< RecordType > recordType
Matches record types (e.g.
Definition: ASTMatchersInternal.cpp:1058
clang::LangAS::Default
@ Default
clang::Qualifiers::OCL_None
@ OCL_None
There is no lifetime qualification on this type.
Definition: Type.h:162
clang::CodeGen::CodeGenFunction::CGM
CodeGenModule & CGM
Definition: CodeGenFunction.h:266
clang::CodeGen::CodeGenFunction::cxxDestructorCanThrow
static bool cxxDestructorCanThrow(QualType T)
Check if T is a C++ class that has a destructor that can throw.
Definition: CGBlocks.cpp:1727
clang::ASTContext::getAddrSpaceQualType
QualType getAddrSpaceQualType(QualType T, LangAS AddressSpace) const
Return the uniqued reference to the type for an address space qualified type with the specified type ...
Definition: ASTContext.cpp:3002
CGBlocks.h
clang::CodeGen::CodeGenFunction::CurFn
llvm::Function * CurFn
Definition: CodeGenFunction.h:330
clang::CodeGen::CleanupKind
CleanupKind
Definition: EHScopeStack.h:77
clang::TranslationUnitDecl::castToDeclContext
static DeclContext * castToDeclContext(const TranslationUnitDecl *D)
Definition: Decl.h:130
clang::CodeGen::CodeGenFunction::BuildBlockRelease
void BuildBlockRelease(llvm::Value *DeclPtr, BlockFieldFlags flags, bool CanThrow)
Definition: CGBlocks.cpp:2825
clang::CodeGen::BLOCK_BYREF_LAYOUT_WEAK
@ BLOCK_BYREF_LAYOUT_WEAK
Definition: CGBlocks.h:51
clang
Definition: CalledOnceCheck.h:17
CGOpenCLRuntime.h
clang::CodeGen::BLOCK_FIELD_IS_OBJECT
@ BLOCK_FIELD_IS_OBJECT
Definition: CGBlocks.h:95
clang::DeclContext::lookup
lookup_result lookup(DeclarationName Name) const
lookup - Find the declarations (if any) with the given Name in this context.
Definition: DeclBase.cpp:1645
clang::CodeGen::RValue::get
static RValue get(llvm::Value *V)
Definition: CGValue.h:86
clang::CodeGen::CodeGenFunction::EmitCallArgs
void EmitCallArgs(CallArgList &Args, PrototypeWrapper Prototype, llvm::iterator_range< CallExpr::const_arg_iterator > ArgRange, AbstractCallee AC=AbstractCallee(), unsigned ParamsToSkip=0, EvaluationOrder Order=EvaluationOrder::Default)
EmitCallArgs - Emit call arguments for a function.
Definition: CGCall.cpp:4084
clang::CodeGen::ApplyDebugLocation::CreateArtificial
static ApplyDebugLocation CreateArtificial(CodeGenFunction &CGF)
Apply TemporaryLocation if it is valid.
Definition: CGDebugInfo.h:810
clang::TargetInfo::getPointerWidth
uint64_t getPointerWidth(unsigned AddrSpace) const
Return the width of pointers on this target, for the specified address space.
Definition: TargetInfo.h:417
clang::CodeGen::CodeGenModule::GetAddrOfConstantCString
ConstantAddress GetAddrOfConstantCString(const std::string &Str, const char *GlobalName=nullptr)
Returns a pointer to a character array containing the literal and a terminating '\0' character.
Definition: CodeGenModule.cpp:5442
clang::CodeGen::BLOCK_BYREF_LAYOUT_MASK
@ BLOCK_BYREF_LAYOUT_MASK
Definition: CGBlocks.h:47
clang::Qualifiers::getObjCLifetime
ObjCLifetime getObjCLifetime() const
Definition: Type.h:335
clang::CodeGen::CodeGenFunction::getNonTrivialDestructorStr
static std::string getNonTrivialDestructorStr(QualType QT, CharUnits Alignment, bool IsVolatile, ASTContext &Ctx)
Definition: CGNonTrivialStruct.cpp:866
clang::DeclaratorContext::Block
@ Block
clang::ExternalLinkage
@ ExternalLinkage
External linkage, which indicates that the entity can be referred to from other translation units.
Definition: Linkage.h:59
clang::QualType::isNonTrivialToPrimitiveCopy
PrimitiveCopyKind isNonTrivialToPrimitiveCopy() const
Check if this is a non-trivial type that would cause a C struct transitively containing this type to ...
Definition: Type.cpp:2526
clang::ASTContext::getByrefLifetime
bool getByrefLifetime(QualType Ty, Qualifiers::ObjCLifetime &Lifetime, bool &HasByrefExtendedLayout) const
Returns true, if given type has a known lifetime.
Definition: ASTContext.cpp:6889
generateByrefDisposeHelper
static llvm::Constant * generateByrefDisposeHelper(CodeGenFunction &CGF, const BlockByrefInfo &byrefInfo, BlockByrefHelpers &generator)
Generate code for a __block variable's dispose helper.
Definition: CGBlocks.cpp:2428
clang::CodeGen::CodeGenFunction::RunCleanupsScope::ForceCleanup
void ForceCleanup(std::initializer_list< llvm::Value ** > ValuesToReload={})
Force the emission of cleanups now, instead of waiting until this object is destroyed.
Definition: CodeGenFunction.h:883
std::arg
__DEVICE__ _Tp arg(const std::complex< _Tp > &__c)
Definition: complex_cmath.h:40
clang::operator<
bool operator<(DeclarationName LHS, DeclarationName RHS)
Ordering on two declaration names.
Definition: DeclarationName.h:540
clang::Expr::getType
QualType getType() const
Definition: Expr.h:141
clang::FunctionType::getReturnType
QualType getReturnType() const
Definition: Type.h:3809
clang::CodeGen::BLOCK_HAS_SIGNATURE
@ BLOCK_HAS_SIGNATURE
Definition: CGBlocks.h:61
getCopyDestroyHelperFuncName
static std::string getCopyDestroyHelperFuncName(const SmallVectorImpl< BlockCaptureManagedEntity > &Captures, CharUnits BlockAlignment, CaptureStrKind StrKind, CodeGenModule &CGM)
Definition: CGBlocks.cpp:1831
clang::CodeGen::CGObjCRuntime::BuildGCBlockLayout
virtual llvm::Constant * BuildGCBlockLayout(CodeGen::CodeGenModule &CGM, const CodeGen::CGBlockInfo &blockInfo)=0
clang::BlockVarCopyInit::canThrow
bool canThrow() const
Definition: Expr.h:6019
clang::CodeGen::ApplyDebugLocation::CreateEmpty
static ApplyDebugLocation CreateEmpty(CodeGenFunction &CGF)
Set the IRBuilder to not attach debug locations.
Definition: CGDebugInfo.h:827
clang::Stmt::getBeginLoc
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Stmt.cpp:336
clang::BlockDecl::capture_end
capture_const_iterator capture_end() const
Definition: Decl.h:4283
CanThrow
static bool CanThrow(Expr *E, ASTContext &Ctx)
Definition: CFG.cpp:2613
clang::CodeGen::EHScopeStack::stable_begin
stable_iterator stable_begin() const
Create a stable reference to the top of the EH stack.
Definition: EHScopeStack.h:384
clang::CodeGen::CodeGenFunction::Destroyer
void Destroyer(CodeGenFunction &CGF, Address addr, QualType ty)
Definition: CodeGenFunction.h:1999
printf
int printf(__constant const char *st,...) __attribute__((format(printf
getBlockCaptureStr
static std::string getBlockCaptureStr(const BlockCaptureManagedEntity &E, CaptureStrKind StrKind, CharUnits BlockAlignment, CodeGenModule &CGM)
Definition: CGBlocks.cpp:1735
clang::CodeGen::CodeGenFunction::LoadBlockStruct
Address LoadBlockStruct()
Definition: CGBlocks.cpp:1435
clang::CodeGen::CodeGenModule::getBlockMangledName
StringRef getBlockMangledName(GlobalDecl GD, const BlockDecl *BD)
Definition: CodeGenModule.cpp:1404
clang::ImplicitCastExpr
ImplicitCastExpr - Allows us to explicitly represent implicit type conversions, which have no direct ...
Definition: Expr.h:3618
clang::CodeGen::ConstantEmitter
Definition: ConstantEmitter.h:23
clang::CodeGen::CodeGenFunction::EmitARCRetainBlock
llvm::Value * EmitARCRetainBlock(llvm::Value *value, bool mandatory)
Retain the given block, with _Block_copy semantics.
Definition: CGObjC.cpp:2276
clang::CodeGen::CGBlockInfo::getBlockExpr
const BlockExpr * getBlockExpr() const
Definition: CGBlocks.h:277
clang::ASTContext::getPointerType
QualType getPointerType(QualType T) const
Return the uniqued reference to the type for a pointer to the specified type.
Definition: ASTContext.cpp:3249
clang::CodeGen::BlockFlags::getBitMask
uint32_t getBitMask() const
Definition: CGBlocks.h:73
clang::CodeGen::CodeGenFunction::RetExpr
const Expr * RetExpr
If a return statement is being visited, this holds the return statment's result expression.
Definition: CodeGenFunction.h:369
v
do v
Definition: arm_acle.h:76
clang::CharUnits
CharUnits - This is an opaque type for sizes expressed in character units.
Definition: CharUnits.h:38
clang::ASTContext::getTypeInfoInChars
TypeInfoChars getTypeInfoInChars(const Type *T) const
Definition: ASTContext.cpp:1874
clang::CodeGen::CodeGenFunction::GenerateBlockFunction
llvm::Function * GenerateBlockFunction(GlobalDecl GD, const CGBlockInfo &Info, const DeclMapTy &ldm, bool IsLambdaConversionToBlock, bool BuildGlobalBlock)
Definition: CGBlocks.cpp:1442
clang::transformer::node
RangeSelector node(std::string ID)
Selects a node, including trailing semicolon, if any (for declarations and non-expression statements)...
Definition: RangeSelector.cpp:141
clang::CallExpr::arguments
arg_range arguments()
Definition: Expr.h:3034
clang::CodeGen::CGOpenCLRuntime::getGenericVoidPointerType
llvm::PointerType * getGenericVoidPointerType()
Definition: CGOpenCLRuntime.cpp:118
clang::ValueDecl::getType
QualType getType() const
Definition: Decl.h:687
computeBlockInfo
static void computeBlockInfo(CodeGenModule &CGM, CodeGenFunction *CGF, CGBlockInfo &info)
Compute the layout of the given block.
Definition: CGBlocks.cpp:522
clang::CodeGen::CodeGenFunction::CreateMemTemp
Address CreateMemTemp(QualType T, const Twine &Name="tmp", Address *Alloca=nullptr)
CreateMemTemp - Create a temporary memory object of the given type, with appropriate alignmen and cas...
Definition: CGExpr.cpp:135
clang::Expr
This represents one expression.
Definition: Expr.h:109
clang::CodeGen::CGBlockInfo::Capture::getConstant
llvm::Value * getConstant() const
Definition: CGBlocks.h:191
clang::CodeGen::CodeGenFunction::EmitBlockCallExpr
RValue EmitBlockCallExpr(const CallExpr *E, ReturnValueSlot ReturnValue)
Definition: CGBlocks.cpp:1178
clang::BlockExpr::getFunctionType
const FunctionProtoType * getFunctionType() const
getFunctionType - Return the underlying function type for this block.
Definition: Expr.cpp:2378
clang::QualType::isDestructedType
DestructionKind isDestructedType() const
Returns a nonzero value if objects of this type require non-trivial work to clean up after.
Definition: Type.h:1214
clang::CodeGen::CodeGenTypeCache::Int8Ty
llvm::IntegerType * Int8Ty
i8, i16, i32, and i64
Definition: CodeGenTypeCache.h:37
clang::BlockDecl::Capture
A class which contains all the information about a particular captured value.
Definition: Decl.h:4159
clang::transformer::name
RangeSelector name(std::string ID)
Given a node with a "name", (like NamedDecl, DeclRefExpr, CxxCtorInitializer, and TypeLoc) selects th...
Definition: RangeSelector.cpp:200
clang::CodeGen::BlockByrefInfo::FieldOffset
CharUnits FieldOffset
Definition: CGBlocks.h:148
clang::BlockDecl::Capture::hasCopyExpr
bool hasCopyExpr() const
Definition: Decl.h:4198
clang::CodeGen::CodeGenTypeCache::VoidPtrPtrTy
llvm::PointerType * VoidPtrPtrTy
Definition: CodeGenTypeCache.h:62
clang::BlockExpr::getBody
const Stmt * getBody() const
Definition: Expr.cpp:2387
clang::Decl::getLocation
SourceLocation getLocation() const
Definition: DeclBase.h:430
clang::CodeGen::CallArgList
CallArgList - Type for representing both the value and type of arguments in a call.
Definition: CGCall.h:264
clang::LangAS::opencl_generic
@ opencl_generic
clang::CodeGen::BlockByrefHelpers::CopyHelper
llvm::Constant * CopyHelper
Definition: CodeGenModule.h:256
clang::DeclRefExpr
A reference to a declared variable, function, enum, etc.
Definition: Expr.h:1217
clang::CodeGen::BlockByrefHelpers::emitDispose
virtual void emitDispose(CodeGenFunction &CGF, Address field)=0
clang::CodeGen::CGBlockInfo::Captures
llvm::DenseMap< const VarDecl *, Capture > Captures
The mapping of allocated indexes within the block.
Definition: CGBlocks.h:242
clang::CodeGen::CGBlockInfo::BlockSize
CharUnits BlockSize
Definition: CGBlocks.h:248
clang::BlockDecl::capturesCXXThis
bool capturesCXXThis() const
Definition: Decl.h:4285
clang::CodeGen::CodeGenTypeCache::Int8PtrPtrTy
llvm::PointerType * Int8PtrPtrTy
Definition: CodeGenTypeCache.h:63
clang::CallExpr
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
Definition: Expr.h:2795
clang::CodeGen::CGBlockInfo::Capture::makeIndex
static Capture makeIndex(unsigned index, CharUnits offset, QualType FieldType)
Definition: CGBlocks.h:200
clang::CodeGen::CodeGenTypeCache::PointerSizeInBytes
unsigned char PointerSizeInBytes
Definition: CodeGenTypeCache.h:97
clang::CodeGen::CodeGenModule::getLLVMContext
llvm::LLVMContext & getLLVMContext()
Definition: CodeGenModule.h:720
clang::ASTContext::getLangOpts
const LangOptions & getLangOpts() const
Definition: ASTContext.h:765
clang::CodeGen::CGBlockInfo::CapturesNonExternalType
bool CapturesNonExternalType
Indicates whether an object of a non-external C++ class is captured.
Definition: CGBlocks.h:239
clang::CharUnits::getQuantity
QuantityType getQuantity() const
getQuantity - Get the raw integer representation of this quantity.
Definition: CharUnits.h:179
clang::CodeGen::EHScopeStack::stable_iterator
A saved depth on the scope stack.
Definition: EHScopeStack.h:101
clang::CodeGen::CodeGenFunction::getLangOpts
const LangOptions & getLangOpts() const
Definition: CodeGenFunction.h:1960
buildByrefDisposeHelper
static llvm::Constant * buildByrefDisposeHelper(CodeGenModule &CGM, const BlockByrefInfo &byrefInfo, BlockByrefHelpers &generator)
Build the dispose helper for a __block variable.
Definition: CGBlocks.cpp:2476
ConstantInitBuilder.h
clang::CodeGen::CodeGenFunction::emitBlockByrefAddress
Address emitBlockByrefAddress(Address baseAddr, const VarDecl *V, bool followForward=true)
BuildBlockByrefAddress - Computes the location of the data in a variable which is declared as __block...
Definition: CGBlocks.cpp:2596
clang::BlockDecl::isConversionFromLambda
bool isConversionFromLambda() const
Definition: Decl.h:4296
clang::CodeGen::CodeGenFunction::CurFuncDecl
const Decl * CurFuncDecl
CurFuncDecl - Holds the Decl for the current outermost non-closure context.
Definition: CodeGenFunction.h:325
clang::ImplicitParamDecl::Other
@ Other
Other implicit parameter.
Definition: Decl.h:1625
clang::CodeGen::CGBuilderTy::CreateLoad
llvm::LoadInst * CreateLoad(Address Addr, const llvm::Twine &Name="")
Definition: CGBuilder.h:68
isBlockPointer
static bool isBlockPointer(Expr *Arg)
Definition: SemaChecking.cpp:815
clang::CodeGen::CodeGenFunction::ReturnValue
Address ReturnValue
ReturnValue - The temporary alloca to hold the return value.
Definition: CodeGenFunction.h:361
clang::CodeGen::AggValueSlot::DoesNotOverlap
@ DoesNotOverlap
Definition: CGValue.h:527
computeCopyInfoForBlockCapture
static std::pair< BlockCaptureEntityKind, BlockFieldFlags > computeCopyInfoForBlockCapture(const BlockDecl::Capture &CI, QualType T, const LangOptions &LangOpts)
Definition: CGBlocks.cpp:1616
clang::CodeGen::CGBlockInfo::Capture::makeConstant
static Capture makeConstant(llvm::Value *value)
Definition: CGBlocks.h:209
clang::NamedDecl::getName
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
Definition: Decl.h:276