clang  8.0.0svn
CGNonTrivialStruct.cpp
Go to the documentation of this file.
1 //===--- CGNonTrivialStruct.cpp - Emit Special Functions for C Structs ----===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines functions to generate various special functions for C
11 // structs.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #include "CodeGenFunction.h"
16 #include "CodeGenModule.h"
18 #include "llvm/Support/ScopedPrinter.h"
19 #include <array>
20 
21 using namespace clang;
22 using namespace CodeGen;
23 
24 // Return the size of a field in number of bits.
25 static uint64_t getFieldSize(const FieldDecl *FD, QualType FT,
26  ASTContext &Ctx) {
27  if (FD && FD->isBitField())
28  return FD->getBitWidthValue(Ctx);
29  return Ctx.getTypeSize(FT);
30 }
31 
32 namespace {
33 enum { DstIdx = 0, SrcIdx = 1 };
34 const char *ValNameStr[2] = {"dst", "src"};
35 
36 template <class Derived> struct StructVisitor {
37  StructVisitor(ASTContext &Ctx) : Ctx(Ctx) {}
38 
39  template <class... Ts>
40  void visitStructFields(QualType QT, CharUnits CurStructOffset, Ts... Args) {
41  const RecordDecl *RD = QT->castAs<RecordType>()->getDecl();
42 
43  // Iterate over the fields of the struct.
44  for (const FieldDecl *FD : RD->fields()) {
45  QualType FT = FD->getType();
46  FT = QT.isVolatileQualified() ? FT.withVolatile() : FT;
47  asDerived().visit(FT, FD, CurStructOffset, Args...);
48  }
49 
50  asDerived().flushTrivialFields(Args...);
51  }
52 
53  template <class... Ts> void visitTrivial(Ts... Args) {}
54 
55  template <class... Ts> void visitCXXDestructor(Ts... Args) {
56  llvm_unreachable("field of a C++ struct type is not expected");
57  }
58 
59  template <class... Ts> void flushTrivialFields(Ts... Args) {}
60 
61  uint64_t getFieldOffsetInBits(const FieldDecl *FD) {
62  return FD ? Ctx.getASTRecordLayout(FD->getParent())
64  : 0;
65  }
66 
68  return Ctx.toCharUnitsFromBits(getFieldOffsetInBits(FD));
69  }
70 
71  Derived &asDerived() { return static_cast<Derived &>(*this); }
72 
73  ASTContext &getContext() { return Ctx; }
74  ASTContext &Ctx;
75 };
76 
77 template <class Derived, bool IsMove>
78 struct CopyStructVisitor : StructVisitor<Derived>,
79  CopiedTypeVisitor<Derived, IsMove> {
80  using StructVisitor<Derived>::asDerived;
82 
83  CopyStructVisitor(ASTContext &Ctx) : StructVisitor<Derived>(Ctx) {}
84 
85  template <class... Ts>
86  void preVisit(QualType::PrimitiveCopyKind PCK, QualType FT,
87  const FieldDecl *FD, CharUnits CurStructOffsset,
88  Ts &&... Args) {
89  if (PCK)
90  asDerived().flushTrivialFields(std::forward<Ts>(Args)...);
91  }
92 
93  template <class... Ts>
94  void visitWithKind(QualType::PrimitiveCopyKind PCK, QualType FT,
95  const FieldDecl *FD, CharUnits CurStructOffsset,
96  Ts &&... Args) {
97  if (const auto *AT = asDerived().getContext().getAsArrayType(FT)) {
98  asDerived().visitArray(PCK, AT, FT.isVolatileQualified(), FD,
99  CurStructOffsset, std::forward<Ts>(Args)...);
100  return;
101  }
102 
103  Super::visitWithKind(PCK, FT, FD, CurStructOffsset,
104  std::forward<Ts>(Args)...);
105  }
106 
107  template <class... Ts>
108  void visitTrivial(QualType FT, const FieldDecl *FD, CharUnits CurStructOffset,
109  Ts... Args) {
110  assert(!FT.isVolatileQualified() && "volatile field not expected");
111  ASTContext &Ctx = asDerived().getContext();
112  uint64_t FieldSize = getFieldSize(FD, FT, Ctx);
113 
114  // Ignore zero-sized fields.
115  if (FieldSize == 0)
116  return;
117 
118  uint64_t FStartInBits = asDerived().getFieldOffsetInBits(FD);
119  uint64_t FEndInBits = FStartInBits + FieldSize;
120  uint64_t RoundedFEnd = llvm::alignTo(FEndInBits, Ctx.getCharWidth());
121 
122  // Set Start if this is the first field of a sequence of trivial fields.
123  if (Start == End)
124  Start = CurStructOffset + Ctx.toCharUnitsFromBits(FStartInBits);
125  End = CurStructOffset + Ctx.toCharUnitsFromBits(RoundedFEnd);
126  }
127 
129 };
130 
131 // This function creates the mangled name of a special function of a non-trivial
132 // C struct. Since there is no ODR in C, the function is mangled based on the
133 // struct contents and not the name. The mangled name has the following
134 // structure:
135 //
136 // <function-name> ::= <prefix> <alignment-info> "_" <struct-field-info>
137 // <prefix> ::= "__destructor_" | "__default_constructor_" |
138 // "__copy_constructor_" | "__move_constructor_" |
139 // "__copy_assignment_" | "__move_assignment_"
140 // <alignment-info> ::= <dst-alignment> ["_" <src-alignment>]
141 // <struct-field-info> ::= <field-info>+
142 // <field-info> ::= <struct-or-scalar-field-info> | <array-field-info>
143 // <struct-or-scalar-field-info> ::= <struct-field-info> | <strong-field-info> |
144 // <trivial-field-info>
145 // <array-field-info> ::= "_AB" <array-offset> "s" <element-size> "n"
146 // <num-elements> <innermost-element-info> "_AE"
147 // <innermost-element-info> ::= <struct-or-scalar-field-info>
148 // <strong-field-info> ::= "_s" ["b"] ["v"] <field-offset>
149 // <trivial-field-info> ::= "_t" ["v"] <field-offset> "_" <field-size>
150 
151 template <class Derived> struct GenFuncNameBase {
152  std::string getVolatileOffsetStr(bool IsVolatile, CharUnits Offset) {
153  std::string S;
154  if (IsVolatile)
155  S = "v";
156  S += llvm::to_string(Offset.getQuantity());
157  return S;
158  }
159 
160  void visitARCStrong(QualType FT, const FieldDecl *FD,
161  CharUnits CurStructOffset) {
162  appendStr("_s");
163  if (FT->isBlockPointerType())
164  appendStr("b");
165  CharUnits FieldOffset = CurStructOffset + asDerived().getFieldOffset(FD);
166  appendStr(getVolatileOffsetStr(FT.isVolatileQualified(), FieldOffset));
167  }
168 
169  void visitARCWeak(QualType FT, const FieldDecl *FD,
170  CharUnits CurStructOffset) {
171  appendStr("_w");
172  CharUnits FieldOffset = CurStructOffset + asDerived().getFieldOffset(FD);
173  appendStr(getVolatileOffsetStr(FT.isVolatileQualified(), FieldOffset));
174  }
175 
176  void visitStruct(QualType QT, const FieldDecl *FD,
177  CharUnits CurStructOffset) {
178  CharUnits FieldOffset = CurStructOffset + asDerived().getFieldOffset(FD);
179  asDerived().visitStructFields(QT, FieldOffset);
180  }
181 
182  template <class FieldKind>
183  void visitArray(FieldKind FK, const ArrayType *AT, bool IsVolatile,
184  const FieldDecl *FD, CharUnits CurStructOffset) {
185  // String for non-volatile trivial fields is emitted when
186  // flushTrivialFields is called.
187  if (!FK)
188  return asDerived().visitTrivial(QualType(AT, 0), FD, CurStructOffset);
189 
190  CharUnits FieldOffset = CurStructOffset + asDerived().getFieldOffset(FD);
191  ASTContext &Ctx = asDerived().getContext();
192  const ConstantArrayType *CAT = cast<ConstantArrayType>(AT);
193  unsigned NumElts = Ctx.getConstantArrayElementCount(CAT);
194  QualType EltTy = Ctx.getBaseElementType(CAT);
195  CharUnits EltSize = Ctx.getTypeSizeInChars(EltTy);
196  appendStr("_AB" + llvm::to_string(FieldOffset.getQuantity()) + "s" +
197  llvm::to_string(EltSize.getQuantity()) + "n" +
198  llvm::to_string(NumElts));
199  EltTy = IsVolatile ? EltTy.withVolatile() : EltTy;
200  asDerived().visitWithKind(FK, EltTy, nullptr, FieldOffset);
201  appendStr("_AE");
202  }
203 
204  void appendStr(StringRef Str) { Name += Str; }
205 
206  std::string getName(QualType QT, bool IsVolatile) {
207  QT = IsVolatile ? QT.withVolatile() : QT;
208  asDerived().visitStructFields(QT, CharUnits::Zero());
209  return Name;
210  }
211 
212  Derived &asDerived() { return static_cast<Derived &>(*this); }
213 
214  std::string Name;
215 };
216 
217 template <class Derived>
218 struct GenUnaryFuncName : StructVisitor<Derived>, GenFuncNameBase<Derived> {
219  GenUnaryFuncName(StringRef Prefix, CharUnits DstAlignment, ASTContext &Ctx)
220  : StructVisitor<Derived>(Ctx) {
221  this->appendStr(Prefix);
222  this->appendStr(llvm::to_string(DstAlignment.getQuantity()));
223  }
224 };
225 
226 // Helper function to create a null constant.
227 static llvm::Constant *getNullForVariable(Address Addr) {
228  llvm::Type *Ty = Addr.getElementType();
229  return llvm::ConstantPointerNull::get(cast<llvm::PointerType>(Ty));
230 }
231 
232 template <bool IsMove>
233 struct GenBinaryFuncName : CopyStructVisitor<GenBinaryFuncName<IsMove>, IsMove>,
234  GenFuncNameBase<GenBinaryFuncName<IsMove>> {
235 
236  GenBinaryFuncName(StringRef Prefix, CharUnits DstAlignment,
237  CharUnits SrcAlignment, ASTContext &Ctx)
238  : CopyStructVisitor<GenBinaryFuncName<IsMove>, IsMove>(Ctx) {
239  this->appendStr(Prefix);
240  this->appendStr(llvm::to_string(DstAlignment.getQuantity()));
241  this->appendStr("_" + llvm::to_string(SrcAlignment.getQuantity()));
242  }
243 
244  void flushTrivialFields() {
245  if (this->Start == this->End)
246  return;
247 
248  this->appendStr("_t" + llvm::to_string(this->Start.getQuantity()) + "w" +
249  llvm::to_string((this->End - this->Start).getQuantity()));
250 
251  this->Start = this->End = CharUnits::Zero();
252  }
253 
254  void visitVolatileTrivial(QualType FT, const FieldDecl *FD,
255  CharUnits CurStackOffset) {
256  // Because volatile fields can be bit-fields and are individually copied,
257  // their offset and width are in bits.
258  uint64_t OffsetInBits =
259  this->Ctx.toBits(CurStackOffset) + this->getFieldOffsetInBits(FD);
260  this->appendStr("_tv" + llvm::to_string(OffsetInBits) + "w" +
261  llvm::to_string(getFieldSize(FD, FT, this->Ctx)));
262  }
263 };
264 
265 struct GenDefaultInitializeFuncName
266  : GenUnaryFuncName<GenDefaultInitializeFuncName>,
267  DefaultInitializedTypeVisitor<GenDefaultInitializeFuncName> {
269  GenDefaultInitializeFuncName(CharUnits DstAlignment, ASTContext &Ctx)
270  : GenUnaryFuncName<GenDefaultInitializeFuncName>("__default_constructor_",
271  DstAlignment, Ctx) {}
272  void visitWithKind(QualType::PrimitiveDefaultInitializeKind PDIK, QualType FT,
273  const FieldDecl *FD, CharUnits CurStructOffset) {
274  if (const auto *AT = getContext().getAsArrayType(FT)) {
275  visitArray(PDIK, AT, FT.isVolatileQualified(), FD, CurStructOffset);
276  return;
277  }
278 
279  Super::visitWithKind(PDIK, FT, FD, CurStructOffset);
280  }
281 };
282 
283 struct GenDestructorFuncName : GenUnaryFuncName<GenDestructorFuncName>,
284  DestructedTypeVisitor<GenDestructorFuncName> {
286  GenDestructorFuncName(const char *Prefix, CharUnits DstAlignment,
287  ASTContext &Ctx)
288  : GenUnaryFuncName<GenDestructorFuncName>(Prefix, DstAlignment,
289  Ctx) {}
290  void visitWithKind(QualType::DestructionKind DK, QualType FT,
291  const FieldDecl *FD, CharUnits CurStructOffset) {
292  if (const auto *AT = getContext().getAsArrayType(FT)) {
293  visitArray(DK, AT, FT.isVolatileQualified(), FD, CurStructOffset);
294  return;
295  }
296 
297  Super::visitWithKind(DK, FT, FD, CurStructOffset);
298  }
299 };
300 
301 // Helper function that creates CGFunctionInfo for an N-ary special function.
302 template <size_t N>
303 static const CGFunctionInfo &getFunctionInfo(CodeGenModule &CGM,
304  FunctionArgList &Args) {
305  ASTContext &Ctx = CGM.getContext();
307  QualType ParamTy = Ctx.getPointerType(Ctx.VoidPtrTy);
308 
309  for (unsigned I = 0; I < N; ++I)
310  Params.push_back(ImplicitParamDecl::Create(
311  Ctx, nullptr, SourceLocation(), &Ctx.Idents.get(ValNameStr[I]), ParamTy,
313 
314  for (auto &P : Params)
315  Args.push_back(P);
316 
317  return CGM.getTypes().arrangeBuiltinFunctionDeclaration(Ctx.VoidTy, Args);
318 }
319 
320 // Template classes that are used as bases for classes that emit special
321 // functions.
322 template <class Derived> struct GenFuncBase {
323  template <size_t N>
324  void visitStruct(QualType FT, const FieldDecl *FD, CharUnits CurStackOffset,
325  std::array<Address, N> Addrs) {
326  this->asDerived().callSpecialFunction(
327  FT, CurStackOffset + asDerived().getFieldOffset(FD), Addrs);
328  }
329 
330  template <class FieldKind, size_t N>
331  void visitArray(FieldKind FK, const ArrayType *AT, bool IsVolatile,
332  const FieldDecl *FD, CharUnits CurStackOffset,
333  std::array<Address, N> Addrs) {
334  // Non-volatile trivial fields are copied when flushTrivialFields is called.
335  if (!FK)
336  return asDerived().visitTrivial(QualType(AT, 0), FD, CurStackOffset,
337  Addrs);
338 
339  CodeGenFunction &CGF = *this->CGF;
340  ASTContext &Ctx = CGF.getContext();
341 
342  // Compute the end address.
343  QualType BaseEltQT;
344  std::array<Address, N> StartAddrs = Addrs;
345  for (unsigned I = 0; I < N; ++I)
346  StartAddrs[I] = getAddrWithOffset(Addrs[I], CurStackOffset, FD);
347  Address DstAddr = StartAddrs[DstIdx];
348  llvm::Value *NumElts = CGF.emitArrayLength(AT, BaseEltQT, DstAddr);
349  unsigned BaseEltSize = Ctx.getTypeSizeInChars(BaseEltQT).getQuantity();
350  llvm::Value *BaseEltSizeVal =
351  llvm::ConstantInt::get(NumElts->getType(), BaseEltSize);
352  llvm::Value *SizeInBytes =
353  CGF.Builder.CreateNUWMul(BaseEltSizeVal, NumElts);
354  Address BC = CGF.Builder.CreateBitCast(DstAddr, CGF.CGM.Int8PtrTy);
355  llvm::Value *DstArrayEnd =
356  CGF.Builder.CreateInBoundsGEP(BC.getPointer(), SizeInBytes);
357  DstArrayEnd = CGF.Builder.CreateBitCast(DstArrayEnd, CGF.CGM.Int8PtrPtrTy,
358  "dstarray.end");
359  llvm::BasicBlock *PreheaderBB = CGF.Builder.GetInsertBlock();
360 
361  // Create the header block and insert the phi instructions.
362  llvm::BasicBlock *HeaderBB = CGF.createBasicBlock("loop.header");
363  CGF.EmitBlock(HeaderBB);
364  llvm::PHINode *PHIs[N];
365 
366  for (unsigned I = 0; I < N; ++I) {
367  PHIs[I] = CGF.Builder.CreatePHI(CGF.CGM.Int8PtrPtrTy, 2, "addr.cur");
368  PHIs[I]->addIncoming(StartAddrs[I].getPointer(), PreheaderBB);
369  }
370 
371  // Create the exit and loop body blocks.
372  llvm::BasicBlock *ExitBB = CGF.createBasicBlock("loop.exit");
373  llvm::BasicBlock *LoopBB = CGF.createBasicBlock("loop.body");
374 
375  // Emit the comparison and conditional branch instruction that jumps to
376  // either the exit or the loop body.
377  llvm::Value *Done =
378  CGF.Builder.CreateICmpEQ(PHIs[DstIdx], DstArrayEnd, "done");
379  CGF.Builder.CreateCondBr(Done, ExitBB, LoopBB);
380 
381  // Visit the element of the array in the loop body.
382  CGF.EmitBlock(LoopBB);
383  QualType EltQT = AT->getElementType();
384  CharUnits EltSize = Ctx.getTypeSizeInChars(EltQT);
385  std::array<Address, N> NewAddrs = Addrs;
386 
387  for (unsigned I = 0; I < N; ++I)
388  NewAddrs[I] = Address(
389  PHIs[I], StartAddrs[I].getAlignment().alignmentAtOffset(EltSize));
390 
391  EltQT = IsVolatile ? EltQT.withVolatile() : EltQT;
392  this->asDerived().visitWithKind(FK, EltQT, nullptr, CharUnits::Zero(),
393  NewAddrs);
394 
395  LoopBB = CGF.Builder.GetInsertBlock();
396 
397  for (unsigned I = 0; I < N; ++I) {
398  // Instrs to update the destination and source addresses.
399  // Update phi instructions.
400  NewAddrs[I] = getAddrWithOffset(NewAddrs[I], EltSize);
401  PHIs[I]->addIncoming(NewAddrs[I].getPointer(), LoopBB);
402  }
403 
404  // Insert an unconditional branch to the header block.
405  CGF.Builder.CreateBr(HeaderBB);
406  CGF.EmitBlock(ExitBB);
407  }
408 
409  /// Return an address with the specified offset from the passed address.
410  Address getAddrWithOffset(Address Addr, CharUnits Offset) {
411  assert(Addr.isValid() && "invalid address");
412  if (Offset.getQuantity() == 0)
413  return Addr;
414  Addr = CGF->Builder.CreateBitCast(Addr, CGF->CGM.Int8PtrTy);
415  Addr = CGF->Builder.CreateConstInBoundsGEP(Addr, Offset.getQuantity(),
416  CharUnits::One());
417  return CGF->Builder.CreateBitCast(Addr, CGF->CGM.Int8PtrPtrTy);
418  }
419 
420  Address getAddrWithOffset(Address Addr, CharUnits StructFieldOffset,
421  const FieldDecl *FD) {
422  return getAddrWithOffset(Addr, StructFieldOffset +
423  asDerived().getFieldOffset(FD));
424  }
425 
426  template <size_t N>
427  llvm::Function *
428  getFunction(StringRef FuncName, QualType QT, std::array<Address, N> Addrs,
429  std::array<CharUnits, N> Alignments, CodeGenModule &CGM) {
430  // If the special function already exists in the module, return it.
431  if (llvm::Function *F = CGM.getModule().getFunction(FuncName)) {
432  bool WrongType = false;
433  if (!F->getReturnType()->isVoidTy())
434  WrongType = true;
435  else {
436  for (const llvm::Argument &Arg : F->args())
437  if (Arg.getType() != CGM.Int8PtrPtrTy)
438  WrongType = true;
439  }
440 
441  if (WrongType) {
442  std::string FuncName = F->getName();
443  SourceLocation Loc = QT->castAs<RecordType>()->getDecl()->getLocation();
444  CGM.Error(Loc, "special function " + FuncName +
445  " for non-trivial C struct has incorrect type");
446  return nullptr;
447  }
448  return F;
449  }
450 
451  ASTContext &Ctx = CGM.getContext();
452  FunctionArgList Args;
453  const CGFunctionInfo &FI = getFunctionInfo<N>(CGM, Args);
454  llvm::FunctionType *FuncTy = CGM.getTypes().GetFunctionType(FI);
455  llvm::Function *F =
456  llvm::Function::Create(FuncTy, llvm::GlobalValue::LinkOnceODRLinkage,
457  FuncName, &CGM.getModule());
458  F->setVisibility(llvm::GlobalValue::HiddenVisibility);
459  CGM.SetLLVMFunctionAttributes(nullptr, FI, F);
460  CGM.SetLLVMFunctionAttributesForDefinition(nullptr, F);
461  IdentifierInfo *II = &Ctx.Idents.get(FuncName);
464  II, Ctx.VoidTy, nullptr, SC_PrivateExtern, false, false);
465  CodeGenFunction NewCGF(CGM);
466  setCGF(&NewCGF);
467  CGF->StartFunction(FD, Ctx.VoidTy, F, FI, Args);
468 
469  for (unsigned I = 0; I < N; ++I) {
470  llvm::Value *V = CGF->Builder.CreateLoad(CGF->GetAddrOfLocalVar(Args[I]));
471  Addrs[I] = Address(V, Alignments[I]);
472  }
473 
474  asDerived().visitStructFields(QT, CharUnits::Zero(), Addrs);
475  CGF->FinishFunction();
476  return F;
477  }
478 
479  template <size_t N>
480  void callFunc(StringRef FuncName, QualType QT, std::array<Address, N> Addrs,
481  CodeGenFunction &CallerCGF) {
482  std::array<CharUnits, N> Alignments;
483  llvm::Value *Ptrs[N];
484 
485  for (unsigned I = 0; I < N; ++I) {
486  Alignments[I] = Addrs[I].getAlignment();
487  Ptrs[I] =
488  CallerCGF.Builder.CreateBitCast(Addrs[I], CallerCGF.CGM.Int8PtrPtrTy)
489  .getPointer();
490  }
491 
492  if (llvm::Function *F =
493  getFunction(FuncName, QT, Addrs, Alignments, CallerCGF.CGM))
494  CallerCGF.EmitNounwindRuntimeCall(F, Ptrs);
495  }
496 
497  Derived &asDerived() { return static_cast<Derived &>(*this); }
498 
499  void setCGF(CodeGenFunction *F) { CGF = F; }
500 
501  CodeGenFunction *CGF = nullptr;
502 };
503 
504 template <class Derived, bool IsMove>
505 struct GenBinaryFunc : CopyStructVisitor<Derived, IsMove>,
506  GenFuncBase<Derived> {
507  GenBinaryFunc(ASTContext &Ctx) : CopyStructVisitor<Derived, IsMove>(Ctx) {}
508 
509  void flushTrivialFields(std::array<Address, 2> Addrs) {
510  CharUnits Size = this->End - this->Start;
511 
512  if (Size.getQuantity() == 0)
513  return;
514 
515  Address DstAddr = this->getAddrWithOffset(Addrs[DstIdx], this->Start);
516  Address SrcAddr = this->getAddrWithOffset(Addrs[SrcIdx], this->Start);
517 
518  // Emit memcpy.
519  if (Size.getQuantity() >= 16 || !llvm::isPowerOf2_32(Size.getQuantity())) {
520  llvm::Value *SizeVal =
521  llvm::ConstantInt::get(this->CGF->SizeTy, Size.getQuantity());
522  DstAddr =
523  this->CGF->Builder.CreateElementBitCast(DstAddr, this->CGF->Int8Ty);
524  SrcAddr =
525  this->CGF->Builder.CreateElementBitCast(SrcAddr, this->CGF->Int8Ty);
526  this->CGF->Builder.CreateMemCpy(DstAddr, SrcAddr, SizeVal, false);
527  } else {
528  llvm::Type *Ty = llvm::Type::getIntNTy(
529  this->CGF->getLLVMContext(),
530  Size.getQuantity() * this->CGF->getContext().getCharWidth());
531  DstAddr = this->CGF->Builder.CreateElementBitCast(DstAddr, Ty);
532  SrcAddr = this->CGF->Builder.CreateElementBitCast(SrcAddr, Ty);
533  llvm::Value *SrcVal = this->CGF->Builder.CreateLoad(SrcAddr, false);
534  this->CGF->Builder.CreateStore(SrcVal, DstAddr, false);
535  }
536 
537  this->Start = this->End = CharUnits::Zero();
538  }
539 
540  template <class... Ts>
541  void visitVolatileTrivial(QualType FT, const FieldDecl *FD, CharUnits Offset,
542  std::array<Address, 2> Addrs) {
543  LValue DstLV, SrcLV;
544  if (FD) {
545  QualType RT = QualType(FD->getParent()->getTypeForDecl(), 0);
546  llvm::PointerType *PtrTy = this->CGF->ConvertType(RT)->getPointerTo();
547  Address DstAddr = this->getAddrWithOffset(Addrs[DstIdx], Offset);
548  LValue DstBase = this->CGF->MakeAddrLValue(
549  this->CGF->Builder.CreateBitCast(DstAddr, PtrTy), FT);
550  DstLV = this->CGF->EmitLValueForField(DstBase, FD);
551  Address SrcAddr = this->getAddrWithOffset(Addrs[SrcIdx], Offset);
552  LValue SrcBase = this->CGF->MakeAddrLValue(
553  this->CGF->Builder.CreateBitCast(SrcAddr, PtrTy), FT);
554  SrcLV = this->CGF->EmitLValueForField(SrcBase, FD);
555  } else {
556  llvm::PointerType *Ty = this->CGF->ConvertType(FT)->getPointerTo();
557  Address DstAddr = this->CGF->Builder.CreateBitCast(Addrs[DstIdx], Ty);
558  Address SrcAddr = this->CGF->Builder.CreateBitCast(Addrs[SrcIdx], Ty);
559  DstLV = this->CGF->MakeAddrLValue(DstAddr, FT);
560  SrcLV = this->CGF->MakeAddrLValue(SrcAddr, FT);
561  }
562  RValue SrcVal = this->CGF->EmitLoadOfLValue(SrcLV, SourceLocation());
563  this->CGF->EmitStoreThroughLValue(SrcVal, DstLV);
564  }
565 };
566 
567 // These classes that emit the special functions for a non-trivial struct.
568 struct GenDestructor : StructVisitor<GenDestructor>,
569  GenFuncBase<GenDestructor>,
570  DestructedTypeVisitor<GenDestructor> {
572  GenDestructor(ASTContext &Ctx) : StructVisitor<GenDestructor>(Ctx) {}
573 
574  void visitWithKind(QualType::DestructionKind DK, QualType FT,
575  const FieldDecl *FD, CharUnits CurStructOffset,
576  std::array<Address, 1> Addrs) {
577  if (const auto *AT = getContext().getAsArrayType(FT)) {
578  visitArray(DK, AT, FT.isVolatileQualified(), FD, CurStructOffset, Addrs);
579  return;
580  }
581 
582  Super::visitWithKind(DK, FT, FD, CurStructOffset, Addrs);
583  }
584 
585  void visitARCStrong(QualType QT, const FieldDecl *FD,
586  CharUnits CurStackOffset, std::array<Address, 1> Addrs) {
587  CGF->destroyARCStrongImprecise(
588  *CGF, getAddrWithOffset(Addrs[DstIdx], CurStackOffset, FD), QT);
589  }
590 
591  void visitARCWeak(QualType QT, const FieldDecl *FD, CharUnits CurStackOffset,
592  std::array<Address, 1> Addrs) {
593  CGF->destroyARCWeak(
594  *CGF, getAddrWithOffset(Addrs[DstIdx], CurStackOffset, FD), QT);
595  }
596 
598  std::array<Address, 1> Addrs) {
599  CGF->callCStructDestructor(
600  CGF->MakeAddrLValue(getAddrWithOffset(Addrs[DstIdx], Offset), FT));
601  }
602 };
603 
604 struct GenDefaultInitialize
605  : StructVisitor<GenDefaultInitialize>,
606  GenFuncBase<GenDefaultInitialize>,
607  DefaultInitializedTypeVisitor<GenDefaultInitialize> {
609  typedef GenFuncBase<GenDefaultInitialize> GenFuncBaseTy;
610 
611  GenDefaultInitialize(ASTContext &Ctx)
612  : StructVisitor<GenDefaultInitialize>(Ctx) {}
613 
614  void visitWithKind(QualType::PrimitiveDefaultInitializeKind PDIK, QualType FT,
615  const FieldDecl *FD, CharUnits CurStructOffset,
616  std::array<Address, 1> Addrs) {
617  if (const auto *AT = getContext().getAsArrayType(FT)) {
618  visitArray(PDIK, AT, FT.isVolatileQualified(), FD, CurStructOffset,
619  Addrs);
620  return;
621  }
622 
623  Super::visitWithKind(PDIK, FT, FD, CurStructOffset, Addrs);
624  }
625 
626  void visitARCStrong(QualType QT, const FieldDecl *FD,
627  CharUnits CurStackOffset, std::array<Address, 1> Addrs) {
628  CGF->EmitNullInitialization(
629  getAddrWithOffset(Addrs[DstIdx], CurStackOffset, FD), QT);
630  }
631 
632  void visitARCWeak(QualType QT, const FieldDecl *FD, CharUnits CurStackOffset,
633  std::array<Address, 1> Addrs) {
634  CGF->EmitNullInitialization(
635  getAddrWithOffset(Addrs[DstIdx], CurStackOffset, FD), QT);
636  }
637 
638  template <class FieldKind, size_t... Is>
639  void visitArray(FieldKind FK, const ArrayType *AT, bool IsVolatile,
640  const FieldDecl *FD, CharUnits CurStackOffset,
641  std::array<Address, 1> Addrs) {
642  if (!FK)
643  return visitTrivial(QualType(AT, 0), FD, CurStackOffset, Addrs);
644 
645  ASTContext &Ctx = getContext();
646  CharUnits Size = Ctx.getTypeSizeInChars(QualType(AT, 0));
647  QualType EltTy = Ctx.getBaseElementType(QualType(AT, 0));
648 
649  if (Size < CharUnits::fromQuantity(16) || EltTy->getAs<RecordType>()) {
650  GenFuncBaseTy::visitArray(FK, AT, IsVolatile, FD, CurStackOffset, Addrs);
651  return;
652  }
653 
654  llvm::Constant *SizeVal = CGF->Builder.getInt64(Size.getQuantity());
655  Address DstAddr = getAddrWithOffset(Addrs[DstIdx], CurStackOffset, FD);
656  Address Loc = CGF->Builder.CreateElementBitCast(DstAddr, CGF->Int8Ty);
657  CGF->Builder.CreateMemSet(Loc, CGF->Builder.getInt8(0), SizeVal,
658  IsVolatile);
659  }
660 
662  std::array<Address, 1> Addrs) {
663  CGF->callCStructDefaultConstructor(
664  CGF->MakeAddrLValue(getAddrWithOffset(Addrs[DstIdx], Offset), FT));
665  }
666 };
667 
668 struct GenCopyConstructor : GenBinaryFunc<GenCopyConstructor, false> {
669  GenCopyConstructor(ASTContext &Ctx)
670  : GenBinaryFunc<GenCopyConstructor, false>(Ctx) {}
671 
672  void visitARCStrong(QualType QT, const FieldDecl *FD,
673  CharUnits CurStackOffset, std::array<Address, 2> Addrs) {
674  Addrs[DstIdx] = getAddrWithOffset(Addrs[DstIdx], CurStackOffset, FD);
675  Addrs[SrcIdx] = getAddrWithOffset(Addrs[SrcIdx], CurStackOffset, FD);
676  llvm::Value *SrcVal = CGF->EmitLoadOfScalar(
677  Addrs[SrcIdx], QT.isVolatileQualified(), QT, SourceLocation());
678  llvm::Value *Val = CGF->EmitARCRetain(QT, SrcVal);
679  CGF->EmitStoreOfScalar(Val, CGF->MakeAddrLValue(Addrs[DstIdx], QT), true);
680  }
681 
682  void visitARCWeak(QualType QT, const FieldDecl *FD, CharUnits CurStackOffset,
683  std::array<Address, 2> Addrs) {
684  Addrs[DstIdx] = getAddrWithOffset(Addrs[DstIdx], CurStackOffset, FD);
685  Addrs[SrcIdx] = getAddrWithOffset(Addrs[SrcIdx], CurStackOffset, FD);
686  CGF->EmitARCCopyWeak(Addrs[DstIdx], Addrs[SrcIdx]);
687  }
688 
690  std::array<Address, 2> Addrs) {
691  CGF->callCStructCopyConstructor(CGF->MakeAddrLValue(Addrs[DstIdx], FT),
692  CGF->MakeAddrLValue(Addrs[SrcIdx], FT));
693  }
694 };
695 
696 struct GenMoveConstructor : GenBinaryFunc<GenMoveConstructor, true> {
697  GenMoveConstructor(ASTContext &Ctx)
698  : GenBinaryFunc<GenMoveConstructor, true>(Ctx) {}
699 
700  void visitARCStrong(QualType QT, const FieldDecl *FD,
701  CharUnits CurStackOffset, std::array<Address, 2> Addrs) {
702  Addrs[DstIdx] = getAddrWithOffset(Addrs[DstIdx], CurStackOffset, FD);
703  Addrs[SrcIdx] = getAddrWithOffset(Addrs[SrcIdx], CurStackOffset, FD);
704  LValue SrcLV = CGF->MakeAddrLValue(Addrs[SrcIdx], QT);
705  llvm::Value *SrcVal =
706  CGF->EmitLoadOfLValue(SrcLV, SourceLocation()).getScalarVal();
707  CGF->EmitStoreOfScalar(getNullForVariable(SrcLV.getAddress()), SrcLV);
708  CGF->EmitStoreOfScalar(SrcVal, CGF->MakeAddrLValue(Addrs[DstIdx], QT),
709  /* isInitialization */ true);
710  }
711 
712  void visitARCWeak(QualType QT, const FieldDecl *FD, CharUnits CurStackOffset,
713  std::array<Address, 2> Addrs) {
714  Addrs[DstIdx] = getAddrWithOffset(Addrs[DstIdx], CurStackOffset, FD);
715  Addrs[SrcIdx] = getAddrWithOffset(Addrs[SrcIdx], CurStackOffset, FD);
716  CGF->EmitARCMoveWeak(Addrs[DstIdx], Addrs[SrcIdx]);
717  }
718 
720  std::array<Address, 2> Addrs) {
721  CGF->callCStructMoveConstructor(CGF->MakeAddrLValue(Addrs[DstIdx], FT),
722  CGF->MakeAddrLValue(Addrs[SrcIdx], FT));
723  }
724 };
725 
726 struct GenCopyAssignment : GenBinaryFunc<GenCopyAssignment, false> {
727  GenCopyAssignment(ASTContext &Ctx)
728  : GenBinaryFunc<GenCopyAssignment, false>(Ctx) {}
729 
730  void visitARCStrong(QualType QT, const FieldDecl *FD,
731  CharUnits CurStackOffset, std::array<Address, 2> Addrs) {
732  Addrs[DstIdx] = getAddrWithOffset(Addrs[DstIdx], CurStackOffset, FD);
733  Addrs[SrcIdx] = getAddrWithOffset(Addrs[SrcIdx], CurStackOffset, FD);
734  llvm::Value *SrcVal = CGF->EmitLoadOfScalar(
735  Addrs[SrcIdx], QT.isVolatileQualified(), QT, SourceLocation());
736  CGF->EmitARCStoreStrong(CGF->MakeAddrLValue(Addrs[DstIdx], QT), SrcVal,
737  false);
738  }
739 
740  void visitARCWeak(QualType QT, const FieldDecl *FD, CharUnits CurStackOffset,
741  std::array<Address, 2> Addrs) {
742  Addrs[DstIdx] = getAddrWithOffset(Addrs[DstIdx], CurStackOffset, FD);
743  Addrs[SrcIdx] = getAddrWithOffset(Addrs[SrcIdx], CurStackOffset, FD);
744  CGF->emitARCCopyAssignWeak(QT, Addrs[DstIdx], Addrs[SrcIdx]);
745  }
746 
748  std::array<Address, 2> Addrs) {
749  CGF->callCStructCopyAssignmentOperator(
750  CGF->MakeAddrLValue(Addrs[DstIdx], FT),
751  CGF->MakeAddrLValue(Addrs[SrcIdx], FT));
752  }
753 };
754 
755 struct GenMoveAssignment : GenBinaryFunc<GenMoveAssignment, true> {
756  GenMoveAssignment(ASTContext &Ctx)
757  : GenBinaryFunc<GenMoveAssignment, true>(Ctx) {}
758 
759  void visitARCStrong(QualType QT, const FieldDecl *FD,
760  CharUnits CurStackOffset, std::array<Address, 2> Addrs) {
761  Addrs[DstIdx] = getAddrWithOffset(Addrs[DstIdx], CurStackOffset, FD);
762  Addrs[SrcIdx] = getAddrWithOffset(Addrs[SrcIdx], CurStackOffset, FD);
763  LValue SrcLV = CGF->MakeAddrLValue(Addrs[SrcIdx], QT);
764  llvm::Value *SrcVal =
765  CGF->EmitLoadOfLValue(SrcLV, SourceLocation()).getScalarVal();
766  CGF->EmitStoreOfScalar(getNullForVariable(SrcLV.getAddress()), SrcLV);
767  LValue DstLV = CGF->MakeAddrLValue(Addrs[DstIdx], QT);
768  llvm::Value *DstVal =
769  CGF->EmitLoadOfLValue(DstLV, SourceLocation()).getScalarVal();
770  CGF->EmitStoreOfScalar(SrcVal, DstLV);
771  CGF->EmitARCRelease(DstVal, ARCImpreciseLifetime);
772  }
773 
774  void visitARCWeak(QualType QT, const FieldDecl *FD, CharUnits CurStackOffset,
775  std::array<Address, 2> Addrs) {
776  Addrs[DstIdx] = getAddrWithOffset(Addrs[DstIdx], CurStackOffset, FD);
777  Addrs[SrcIdx] = getAddrWithOffset(Addrs[SrcIdx], CurStackOffset, FD);
778  CGF->emitARCMoveAssignWeak(QT, Addrs[DstIdx], Addrs[SrcIdx]);
779  }
780 
782  std::array<Address, 2> Addrs) {
783  CGF->callCStructMoveAssignmentOperator(
784  CGF->MakeAddrLValue(Addrs[DstIdx], FT),
785  CGF->MakeAddrLValue(Addrs[SrcIdx], FT));
786  }
787 };
788 
789 } // namespace
790 
792  Address Addr, QualType Type) {
793  CGF.callCStructDestructor(CGF.MakeAddrLValue(Addr, Type));
794 }
795 
796 // Default-initialize a variable that is a non-trivial struct or an array of
797 // such structure.
799  GenDefaultInitialize Gen(getContext());
800  Address DstPtr = Builder.CreateBitCast(Dst.getAddress(), CGM.Int8PtrPtrTy);
801  Gen.setCGF(this);
802  QualType QT = Dst.getType();
803  QT = Dst.isVolatile() ? QT.withVolatile() : QT;
804  Gen.visit(QT, nullptr, CharUnits::Zero(), std::array<Address, 1>({{DstPtr}}));
805 }
806 
807 template <class G, size_t N>
808 static void callSpecialFunction(G &&Gen, StringRef FuncName, QualType QT,
809  bool IsVolatile, CodeGenFunction &CGF,
810  std::array<Address, N> Addrs) {
811  for (unsigned I = 0; I < N; ++I)
812  Addrs[I] = CGF.Builder.CreateBitCast(Addrs[I], CGF.CGM.Int8PtrPtrTy);
813  QT = IsVolatile ? QT.withVolatile() : QT;
814  Gen.callFunc(FuncName, QT, Addrs, CGF);
815 }
816 
817 // Functions to emit calls to the special functions of a non-trivial C struct.
819  bool IsVolatile = Dst.isVolatile();
820  Address DstPtr = Dst.getAddress();
821  QualType QT = Dst.getType();
822  GenDefaultInitializeFuncName GenName(DstPtr.getAlignment(), getContext());
823  std::string FuncName = GenName.getName(QT, IsVolatile);
824  callSpecialFunction(GenDefaultInitialize(getContext()), FuncName, QT,
825  IsVolatile, *this, std::array<Address, 1>({{DstPtr}}));
826 }
827 
828 std::string
830  CharUnits Alignment,
831  bool IsVolatile,
832  ASTContext &Ctx) {
833  GenBinaryFuncName<false> GenName("", Alignment, Alignment, Ctx);
834  return GenName.getName(QT, IsVolatile);
835 }
836 
837 std::string
839  bool IsVolatile, ASTContext &Ctx) {
840  GenDestructorFuncName GenName("", Alignment, Ctx);
841  return GenName.getName(QT, IsVolatile);
842 }
843 
845  bool IsVolatile = Dst.isVolatile();
846  Address DstPtr = Dst.getAddress();
847  QualType QT = Dst.getType();
848  GenDestructorFuncName GenName("__destructor_", DstPtr.getAlignment(),
849  getContext());
850  std::string FuncName = GenName.getName(QT, IsVolatile);
851  callSpecialFunction(GenDestructor(getContext()), FuncName, QT, IsVolatile,
852  *this, std::array<Address, 1>({{DstPtr}}));
853 }
854 
856  bool IsVolatile = Dst.isVolatile() || Src.isVolatile();
857  Address DstPtr = Dst.getAddress(), SrcPtr = Src.getAddress();
858  QualType QT = Dst.getType();
859  GenBinaryFuncName<false> GenName("__copy_constructor_", DstPtr.getAlignment(),
860  SrcPtr.getAlignment(), getContext());
861  std::string FuncName = GenName.getName(QT, IsVolatile);
862  callSpecialFunction(GenCopyConstructor(getContext()), FuncName, QT,
863  IsVolatile, *this,
864  std::array<Address, 2>({{DstPtr, SrcPtr}}));
865 }
866 
868 
869 ) {
870  bool IsVolatile = Dst.isVolatile() || Src.isVolatile();
871  Address DstPtr = Dst.getAddress(), SrcPtr = Src.getAddress();
872  QualType QT = Dst.getType();
873  GenBinaryFuncName<false> GenName("__copy_assignment_", DstPtr.getAlignment(),
874  SrcPtr.getAlignment(), getContext());
875  std::string FuncName = GenName.getName(QT, IsVolatile);
876  callSpecialFunction(GenCopyAssignment(getContext()), FuncName, QT, IsVolatile,
877  *this, std::array<Address, 2>({{DstPtr, SrcPtr}}));
878 }
879 
881  bool IsVolatile = Dst.isVolatile() || Src.isVolatile();
882  Address DstPtr = Dst.getAddress(), SrcPtr = Src.getAddress();
883  QualType QT = Dst.getType();
884  GenBinaryFuncName<true> GenName("__move_constructor_", DstPtr.getAlignment(),
885  SrcPtr.getAlignment(), getContext());
886  std::string FuncName = GenName.getName(QT, IsVolatile);
887  callSpecialFunction(GenMoveConstructor(getContext()), FuncName, QT,
888  IsVolatile, *this,
889  std::array<Address, 2>({{DstPtr, SrcPtr}}));
890 }
891 
893 
894 ) {
895  bool IsVolatile = Dst.isVolatile() || Src.isVolatile();
896  Address DstPtr = Dst.getAddress(), SrcPtr = Src.getAddress();
897  QualType QT = Dst.getType();
898  GenBinaryFuncName<true> GenName("__move_assignment_", DstPtr.getAlignment(),
899  SrcPtr.getAlignment(), getContext());
900  std::string FuncName = GenName.getName(QT, IsVolatile);
901  callSpecialFunction(GenMoveAssignment(getContext()), FuncName, QT, IsVolatile,
902  *this, std::array<Address, 2>({{DstPtr, SrcPtr}}));
903 }
const CGFunctionInfo & arrangeBuiltinFunctionDeclaration(QualType resultType, const FunctionArgList &args)
A builtin function is a freestanding function using the default C conventions.
Definition: CGCall.cpp:653
static uint64_t getFieldOffset(const ASTContext &C, const FieldDecl *FD)
Represents a function declaration or definition.
Definition: Decl.h:1717
Other implicit parameter.
Definition: Decl.h:1496
CanQualType VoidPtrTy
Definition: ASTContext.h:1053
A (possibly-)qualified type.
Definition: Type.h:642
bool isBlockPointerType() const
Definition: Type.h:6185
const ASTRecordLayout & getASTRecordLayout(const RecordDecl *D) const
Get or compute information about the layout of the specified record (struct/union/class) D...
const Type * getTypeForDecl() const
Definition: Decl.h:2875
StringRef P
unsigned getFieldIndex() const
Returns the index of this field within its record, as appropriate for passing to ASTRecordLayout::get...
Definition: Decl.cpp:3775
bool isVolatile() const
Definition: CGValue.h:301
const RecordDecl * getParent() const
Returns the parent of this field declaration, which is the struct in which this field is defined...
Definition: Decl.h:2740
The base class of the type hierarchy.
Definition: Type.h:1415
Represents an array type, per C99 6.7.5.2 - Array Declarators.
Definition: Type.h:2786
QualType getElementType() const
Definition: Type.h:2821
Objects with "hidden" visibility are not seen by the dynamic linker.
Definition: Visibility.h:37
const T * getAs() const
Member-template getAs<specific type>&#39;.
Definition: Type.h:6590
llvm::Value * getPointer() const
Definition: Address.h:38
std::string getName(ArrayRef< StringRef > Parts) const
Get the platform-specific name separator.
Represents a struct/union/class.
Definition: Decl.h:3570
One of these records is kept for each identifier that is lexed.
Address getAddress() const
Definition: CGValue.h:327
CodeGenFunction - This class organizes the per-function state that is used while generating LLVM code...
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:154
field_range fields() const
Definition: Decl.h:3761
Represents a member of a struct/union/class.
Definition: Decl.h:2556
static uint64_t getFieldSize(const FieldDecl *FD, QualType FT, ASTContext &Ctx)
static CharUnits Zero()
Zero - Construct a CharUnits quantity of zero.
Definition: CharUnits.h:53
IdentifierTable & Idents
Definition: ASTContext.h:565
uint64_t getConstantArrayElementCount(const ConstantArrayType *CA) const
Return number of constant array elements.
bool isBitField() const
Determines whether this field is a bitfield.
Definition: Decl.h:2634
void defaultInitNonTrivialCStructVar(LValue Dst)
CharUnits - This is an opaque type for sizes expressed in character units.
Definition: CharUnits.h:38
uint32_t Offset
Definition: CacheTokens.cpp:43
CharUnits getAlignment() const
Return the alignment of this pointer.
Definition: Address.h:67
bool isVolatileQualified() const
Determine whether this type is volatile-qualified.
Definition: Type.h:6023
unsigned getBitWidthValue(const ASTContext &Ctx) const
Definition: Decl.cpp:3765
llvm::BasicBlock * createBasicBlock(const Twine &name="", llvm::Function *parent=nullptr, llvm::BasicBlock *before=nullptr)
createBasicBlock - Create an LLVM basic block.
void callCStructMoveConstructor(LValue Dst, LValue Src)
PrimitiveDefaultInitializeKind
Definition: Type.h:1081
static std::string getNonTrivialCopyConstructorStr(QualType QT, CharUnits Alignment, bool IsVolatile, ASTContext &Ctx)
static FunctionDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation NLoc, DeclarationName N, QualType T, TypeSourceInfo *TInfo, StorageClass SC, bool isInlineSpecified=false, bool hasWrittenPrototype=true, bool isConstexprSpecified=false)
Definition: Decl.h:1854
static ImplicitParamDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation IdLoc, IdentifierInfo *Id, QualType T, ImplicitParamKind ParamKind)
Create implicit parameter.
Definition: Decl.cpp:4382
bool isValid() const
Definition: Address.h:36
static CharUnits One()
One - Construct a CharUnits quantity of one.
Definition: CharUnits.h:58
llvm::CallInst * EmitNounwindRuntimeCall(llvm::Value *callee, const Twine &name="")
RValue - This trivial value class is used to represent the result of an expression that is evaluated...
Definition: CGValue.h:39
QuantityType getQuantity() const
getQuantity - Get the raw integer representation of this quantity.
Definition: CharUnits.h:179
void callCStructMoveAssignmentOperator(LValue Dst, LValue Src)
SourceLocation End
const T * castAs() const
Member-template castAs<specific type>.
Definition: Type.h:6653
static CharUnits fromQuantity(QuantityType Quantity)
fromQuantity - Construct a CharUnits quantity from a raw integer type.
Definition: CharUnits.h:63
ASTContext & getContext() const
void callCStructCopyAssignmentOperator(LValue Dst, LValue Src)
The l-value was considered opaque, so the alignment was determined from a type.
Address CreateBitCast(Address Addr, llvm::Type *Ty, const llvm::Twine &Name="")
Definition: CGBuilder.h:142
Encodes a location in the source.
IdentifierInfo & get(StringRef Name)
Return the identifier token info for the specified named identifier.
QualType getBaseElementType(const ArrayType *VAT) const
Return the innermost element type of an array type.
CanQualType VoidTy
Definition: ASTContext.h:1025
An aligned address.
Definition: Address.h:25
QualType getType() const
Definition: CGValue.h:264
void Error(SourceLocation loc, StringRef error)
Emit a general error that something can&#39;t be done.
static void callSpecialFunction(G &&Gen, StringRef FuncName, QualType QT, bool IsVolatile, CodeGenFunction &CGF, std::array< Address, N > Addrs)
FunctionArgList - Type for representing both the decl and type of parameters to a function...
Definition: CGCall.h:356
QualType withVolatile() const
Definition: Type.h:822
CGFunctionInfo - Class to encapsulate the information about a function definition.
This class organizes the cross-function state that is used while generating LLVM code.
Dataflow Directional Tag Classes.
llvm::Module & getModule() const
LValue MakeAddrLValue(Address Addr, QualType T, AlignmentSource Source=AlignmentSource::Type)
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
Definition: Type.h:4253
llvm::Type * getElementType() const
Return the type of the values stored in this address.
Definition: Address.h:52
void EmitBlock(llvm::BasicBlock *BB, bool IsFinished=false)
EmitBlock - Emit the given block.
Definition: CGStmt.cpp:445
static Destroyer destroyNonTrivialCStruct
uint64_t getTypeSize(QualType T) const
Return the size of the specified (complete) type T, in bits.
Definition: ASTContext.h:2076
CharUnits toCharUnitsFromBits(int64_t BitSize) const
Convert a size in bits to a size in characters.
void callCStructCopyConstructor(LValue Dst, LValue Src)
int64_t toBits(CharUnits CharSize) const
Convert a size in characters to a size in bits.
TranslationUnitDecl * getTranslationUnitDecl() const
Definition: ASTContext.h:1018
static std::string getNonTrivialDestructorStr(QualType QT, CharUnits Alignment, bool IsVolatile, ASTContext &Ctx)
static llvm::Constant * getNullForVariable(Address addr)
Given the address of a variable of pointer type, find the correct null to store into it...
Definition: CGObjC.cpp:40
QualType getPointerType(QualType T) const
Return the uniqued reference to the type for a pointer to the specified type.
CharUnits getTypeSizeInChars(QualType T) const
Return the size of the specified (complete) type T, in characters.
LValue - This represents an lvalue references.
Definition: CGValue.h:167
llvm::Value * emitArrayLength(const ArrayType *arrayType, QualType &baseType, Address &addr)
emitArrayLength - Compute the length of an array, even if it&#39;s a VLA, and drill down to the base elem...
Represents the canonical version of C arrays with a specified constant size.
Definition: Type.h:2846
static OMPLinearClause * Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc, SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef< Expr *> VL, ArrayRef< Expr *> PL, ArrayRef< Expr *> IL, Expr *Step, Expr *CalcStep, Stmt *PreInit, Expr *PostUpdate)
Creates clause with a list of variables VL and a linear step Step.