Coverage Report

Created: 2020-03-31 06:27

/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/lib/CodeGen/CGValue.h
Line
Count
Source (jump to first uncovered line)
1
//===-- CGValue.h - LLVM CodeGen wrappers for llvm::Value* ------*- 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
// These classes implement wrappers around llvm::Value in order to
10
// fully represent the range of values for C L- and R- values.
11
//
12
//===----------------------------------------------------------------------===//
13
14
#ifndef LLVM_CLANG_LIB_CODEGEN_CGVALUE_H
15
#define LLVM_CLANG_LIB_CODEGEN_CGVALUE_H
16
17
#include "clang/AST/ASTContext.h"
18
#include "clang/AST/Type.h"
19
#include "llvm/IR/Value.h"
20
#include "llvm/IR/Type.h"
21
#include "Address.h"
22
#include "CodeGenTBAA.h"
23
24
namespace llvm {
25
  class Constant;
26
  class MDNode;
27
}
28
29
namespace clang {
30
namespace CodeGen {
31
  class AggValueSlot;
32
  class CodeGenFunction;
33
  struct CGBitFieldInfo;
34
35
/// RValue - This trivial value class is used to represent the result of an
36
/// expression that is evaluated.  It can be one of three things: either a
37
/// simple LLVM SSA value, a pair of SSA values for complex numbers, or the
38
/// address of an aggregate value in memory.
39
class RValue {
40
  enum Flavor { Scalar, Complex, Aggregate };
41
42
  // The shift to make to an aggregate's alignment to make it look
43
  // like a pointer.
44
  enum { AggAlignShift = 4 };
45
46
  // Stores first value and flavor.
47
  llvm::PointerIntPair<llvm::Value *, 2, Flavor> V1;
48
  // Stores second value and volatility.
49
  llvm::PointerIntPair<llvm::Value *, 1, bool> V2;
50
51
public:
52
2.70M
  bool isScalar() const { return V1.getInt() == Scalar; }
53
446
  bool isComplex() const { return V1.getInt() == Complex; }
54
518k
  bool isAggregate() const { return V1.getInt() == Aggregate; }
55
56
0
  bool isVolatileQualified() const { return V2.getInt(); }
57
58
  /// getScalarVal() - Return the Value* of this scalar value.
59
1.94M
  llvm::Value *getScalarVal() const {
60
1.94M
    assert(isScalar() && "Not a scalar!");
61
1.94M
    return V1.getPointer();
62
1.94M
  }
63
64
  /// getComplexVal - Return the real/imag components of this complex value.
65
  ///
66
971
  std::pair<llvm::Value *, llvm::Value *> getComplexVal() const {
67
971
    return std::make_pair(V1.getPointer(), V2.getPointer());
68
971
  }
69
70
  /// getAggregateAddr() - Return the Value* of the address of the aggregate.
71
5.23k
  Address getAggregateAddress() const {
72
5.23k
    assert(isAggregate() && "Not an aggregate!");
73
5.23k
    auto align = reinterpret_cast<uintptr_t>(V2.getPointer()) >> AggAlignShift;
74
5.23k
    return Address(V1.getPointer(), CharUnits::fromQuantity(align));
75
5.23k
  }
76
189
  llvm::Value *getAggregatePointer() const {
77
189
    assert(isAggregate() && "Not an aggregate!");
78
189
    return V1.getPointer();
79
189
  }
80
81
1.47k
  static RValue getIgnored() {
82
1.47k
    // FIXME: should we make this a more explicit state?
83
1.47k
    return get(nullptr);
84
1.47k
  }
85
86
2.06M
  static RValue get(llvm::Value *V) {
87
2.06M
    RValue ER;
88
2.06M
    ER.V1.setPointer(V);
89
2.06M
    ER.V1.setInt(Scalar);
90
2.06M
    ER.V2.setInt(false);
91
2.06M
    return ER;
92
2.06M
  }
93
1.38k
  static RValue getComplex(llvm::Value *V1, llvm::Value *V2) {
94
1.38k
    RValue ER;
95
1.38k
    ER.V1.setPointer(V1);
96
1.38k
    ER.V2.setPointer(V2);
97
1.38k
    ER.V1.setInt(Complex);
98
1.38k
    ER.V2.setInt(false);
99
1.38k
    return ER;
100
1.38k
  }
101
1.38k
  static RValue getComplex(const std::pair<llvm::Value *, llvm::Value *> &C) {
102
1.38k
    return getComplex(C.first, C.second);
103
1.38k
  }
104
  // FIXME: Aggregate rvalues need to retain information about whether they are
105
  // volatile or not.  Remove default to find all places that probably get this
106
  // wrong.
107
19.3k
  static RValue getAggregate(Address addr, bool isVolatile = false) {
108
19.3k
    RValue ER;
109
19.3k
    ER.V1.setPointer(addr.getPointer());
110
19.3k
    ER.V1.setInt(Aggregate);
111
19.3k
112
19.3k
    auto align = static_cast<uintptr_t>(addr.getAlignment().getQuantity());
113
19.3k
    ER.V2.setPointer(reinterpret_cast<llvm::Value*>(align << AggAlignShift));
114
19.3k
    ER.V2.setInt(isVolatile);
115
19.3k
    return ER;
116
19.3k
  }
117
};
118
119
/// Does an ARC strong l-value have precise lifetime?
120
enum ARCPreciseLifetime_t {
121
  ARCImpreciseLifetime, ARCPreciseLifetime
122
};
123
124
/// The source of the alignment of an l-value; an expression of
125
/// confidence in the alignment actually matching the estimate.
126
enum class AlignmentSource {
127
  /// The l-value was an access to a declared entity or something
128
  /// equivalently strong, like the address of an array allocated by a
129
  /// language runtime.
130
  Decl,
131
132
  /// The l-value was considered opaque, so the alignment was
133
  /// determined from a type, but that type was an explicitly-aligned
134
  /// typedef.
135
  AttributedType,
136
137
  /// The l-value was considered opaque, so the alignment was
138
  /// determined from a type.
139
  Type
140
};
141
142
/// Given that the base address has the given alignment source, what's
143
/// our confidence in the alignment of the field?
144
158k
static inline AlignmentSource getFieldAlignmentSource(AlignmentSource Source) {
145
158k
  // For now, we don't distinguish fields of opaque pointers from
146
158k
  // top-level declarations, but maybe we should.
147
158k
  return AlignmentSource::Decl;
148
158k
}
Unexecuted instantiation: CGAtomic.cpp:clang::CodeGen::getFieldAlignmentSource(clang::CodeGen::AlignmentSource)
Unexecuted instantiation: CGBlocks.cpp:clang::CodeGen::getFieldAlignmentSource(clang::CodeGen::AlignmentSource)
Unexecuted instantiation: CGBuiltin.cpp:clang::CodeGen::getFieldAlignmentSource(clang::CodeGen::AlignmentSource)
Unexecuted instantiation: CGCUDANV.cpp:clang::CodeGen::getFieldAlignmentSource(clang::CodeGen::AlignmentSource)
Unexecuted instantiation: CGCUDARuntime.cpp:clang::CodeGen::getFieldAlignmentSource(clang::CodeGen::AlignmentSource)
Unexecuted instantiation: CGCXX.cpp:clang::CodeGen::getFieldAlignmentSource(clang::CodeGen::AlignmentSource)
Unexecuted instantiation: CGCXXABI.cpp:clang::CodeGen::getFieldAlignmentSource(clang::CodeGen::AlignmentSource)
Unexecuted instantiation: CGCall.cpp:clang::CodeGen::getFieldAlignmentSource(clang::CodeGen::AlignmentSource)
Unexecuted instantiation: CGClass.cpp:clang::CodeGen::getFieldAlignmentSource(clang::CodeGen::AlignmentSource)
Unexecuted instantiation: CGCleanup.cpp:clang::CodeGen::getFieldAlignmentSource(clang::CodeGen::AlignmentSource)
Unexecuted instantiation: CGCoroutine.cpp:clang::CodeGen::getFieldAlignmentSource(clang::CodeGen::AlignmentSource)
Unexecuted instantiation: CGDebugInfo.cpp:clang::CodeGen::getFieldAlignmentSource(clang::CodeGen::AlignmentSource)
Unexecuted instantiation: CGDecl.cpp:clang::CodeGen::getFieldAlignmentSource(clang::CodeGen::AlignmentSource)
Unexecuted instantiation: CGDeclCXX.cpp:clang::CodeGen::getFieldAlignmentSource(clang::CodeGen::AlignmentSource)
Unexecuted instantiation: CGException.cpp:clang::CodeGen::getFieldAlignmentSource(clang::CodeGen::AlignmentSource)
CGExpr.cpp:clang::CodeGen::getFieldAlignmentSource(clang::CodeGen::AlignmentSource)
Line
Count
Source
144
158k
static inline AlignmentSource getFieldAlignmentSource(AlignmentSource Source) {
145
158k
  // For now, we don't distinguish fields of opaque pointers from
146
158k
  // top-level declarations, but maybe we should.
147
158k
  return AlignmentSource::Decl;
148
158k
}
Unexecuted instantiation: CGExprAgg.cpp:clang::CodeGen::getFieldAlignmentSource(clang::CodeGen::AlignmentSource)
Unexecuted instantiation: CGExprCXX.cpp:clang::CodeGen::getFieldAlignmentSource(clang::CodeGen::AlignmentSource)
Unexecuted instantiation: CGExprComplex.cpp:clang::CodeGen::getFieldAlignmentSource(clang::CodeGen::AlignmentSource)
Unexecuted instantiation: CGExprConstant.cpp:clang::CodeGen::getFieldAlignmentSource(clang::CodeGen::AlignmentSource)
Unexecuted instantiation: CGExprScalar.cpp:clang::CodeGen::getFieldAlignmentSource(clang::CodeGen::AlignmentSource)
Unexecuted instantiation: CGGPUBuiltin.cpp:clang::CodeGen::getFieldAlignmentSource(clang::CodeGen::AlignmentSource)
Unexecuted instantiation: CGNonTrivialStruct.cpp:clang::CodeGen::getFieldAlignmentSource(clang::CodeGen::AlignmentSource)
Unexecuted instantiation: CGObjC.cpp:clang::CodeGen::getFieldAlignmentSource(clang::CodeGen::AlignmentSource)
Unexecuted instantiation: CGObjCGNU.cpp:clang::CodeGen::getFieldAlignmentSource(clang::CodeGen::AlignmentSource)
Unexecuted instantiation: CGObjCMac.cpp:clang::CodeGen::getFieldAlignmentSource(clang::CodeGen::AlignmentSource)
Unexecuted instantiation: CGObjCRuntime.cpp:clang::CodeGen::getFieldAlignmentSource(clang::CodeGen::AlignmentSource)
Unexecuted instantiation: CGOpenCLRuntime.cpp:clang::CodeGen::getFieldAlignmentSource(clang::CodeGen::AlignmentSource)
Unexecuted instantiation: CGOpenMPRuntime.cpp:clang::CodeGen::getFieldAlignmentSource(clang::CodeGen::AlignmentSource)
Unexecuted instantiation: CGOpenMPRuntimeNVPTX.cpp:clang::CodeGen::getFieldAlignmentSource(clang::CodeGen::AlignmentSource)
Unexecuted instantiation: CGRecordLayoutBuilder.cpp:clang::CodeGen::getFieldAlignmentSource(clang::CodeGen::AlignmentSource)
Unexecuted instantiation: CGStmt.cpp:clang::CodeGen::getFieldAlignmentSource(clang::CodeGen::AlignmentSource)
Unexecuted instantiation: CGStmtOpenMP.cpp:clang::CodeGen::getFieldAlignmentSource(clang::CodeGen::AlignmentSource)
Unexecuted instantiation: CGVTT.cpp:clang::CodeGen::getFieldAlignmentSource(clang::CodeGen::AlignmentSource)
Unexecuted instantiation: CGVTables.cpp:clang::CodeGen::getFieldAlignmentSource(clang::CodeGen::AlignmentSource)
Unexecuted instantiation: CodeGenFunction.cpp:clang::CodeGen::getFieldAlignmentSource(clang::CodeGen::AlignmentSource)
Unexecuted instantiation: CodeGenModule.cpp:clang::CodeGen::getFieldAlignmentSource(clang::CodeGen::AlignmentSource)
Unexecuted instantiation: CodeGenPGO.cpp:clang::CodeGen::getFieldAlignmentSource(clang::CodeGen::AlignmentSource)
Unexecuted instantiation: CodeGenTypes.cpp:clang::CodeGen::getFieldAlignmentSource(clang::CodeGen::AlignmentSource)
Unexecuted instantiation: ConstantInitBuilder.cpp:clang::CodeGen::getFieldAlignmentSource(clang::CodeGen::AlignmentSource)
Unexecuted instantiation: CoverageMappingGen.cpp:clang::CodeGen::getFieldAlignmentSource(clang::CodeGen::AlignmentSource)
Unexecuted instantiation: ItaniumCXXABI.cpp:clang::CodeGen::getFieldAlignmentSource(clang::CodeGen::AlignmentSource)
Unexecuted instantiation: MicrosoftCXXABI.cpp:clang::CodeGen::getFieldAlignmentSource(clang::CodeGen::AlignmentSource)
Unexecuted instantiation: ObjectFilePCHContainerOperations.cpp:clang::CodeGen::getFieldAlignmentSource(clang::CodeGen::AlignmentSource)
Unexecuted instantiation: PatternInit.cpp:clang::CodeGen::getFieldAlignmentSource(clang::CodeGen::AlignmentSource)
Unexecuted instantiation: SanitizerMetadata.cpp:clang::CodeGen::getFieldAlignmentSource(clang::CodeGen::AlignmentSource)
Unexecuted instantiation: SwiftCallingConv.cpp:clang::CodeGen::getFieldAlignmentSource(clang::CodeGen::AlignmentSource)
Unexecuted instantiation: TargetInfo.cpp:clang::CodeGen::getFieldAlignmentSource(clang::CodeGen::AlignmentSource)
Unexecuted instantiation: ModuleBuilder.cpp:clang::CodeGen::getFieldAlignmentSource(clang::CodeGen::AlignmentSource)
Unexecuted instantiation: CodeGenAction.cpp:clang::CodeGen::getFieldAlignmentSource(clang::CodeGen::AlignmentSource)
Unexecuted instantiation: CodeGenABITypes.cpp:clang::CodeGen::getFieldAlignmentSource(clang::CodeGen::AlignmentSource)
149
150
class LValueBaseInfo {
151
  AlignmentSource AlignSource;
152
153
public:
154
  explicit LValueBaseInfo(AlignmentSource Source = AlignmentSource::Type)
155
7.38M
    : AlignSource(Source) {}
156
163k
  AlignmentSource getAlignmentSource() const { return AlignSource; }
157
1.37k
  void setAlignmentSource(AlignmentSource Source) { AlignSource = Source; }
158
159
1.37k
  void mergeForCast(const LValueBaseInfo &Info) {
160
1.37k
    setAlignmentSource(Info.getAlignmentSource());
161
1.37k
  }
162
};
163
164
/// LValue - This represents an lvalue references.  Because C/C++ allow
165
/// bitfields, this is not a simple LLVM pointer, it may be a pointer plus a
166
/// bitrange.
167
class LValue {
168
  enum {
169
    Simple,       // This is a normal l-value, use getAddress().
170
    VectorElt,    // This is a vector element l-value (V[i]), use getVector*
171
    BitField,     // This is a bitfield l-value, use getBitfield*.
172
    ExtVectorElt, // This is an extended vector subset, use getExtVectorComp
173
    GlobalReg     // This is a register l-value, use getGlobalReg()
174
  } LVType;
175
176
  llvm::Value *V;
177
178
  union {
179
    // Index into a vector subscript: V[i]
180
    llvm::Value *VectorIdx;
181
182
    // ExtVector element subset: V.xyx
183
    llvm::Constant *VectorElts;
184
185
    // BitField start bit and size
186
    const CGBitFieldInfo *BitFieldInfo;
187
  };
188
189
  QualType Type;
190
191
  // 'const' is unused here
192
  Qualifiers Quals;
193
194
  // The alignment to use when accessing this lvalue.  (For vector elements,
195
  // this is the alignment of the whole vector.)
196
  unsigned Alignment;
197
198
  // objective-c's ivar
199
  bool Ivar:1;
200
201
  // objective-c's ivar is an array
202
  bool ObjIsArray:1;
203
204
  // LValue is non-gc'able for any reason, including being a parameter or local
205
  // variable.
206
  bool NonGC: 1;
207
208
  // Lvalue is a global reference of an objective-c object
209
  bool GlobalObjCRef : 1;
210
211
  // Lvalue is a thread local reference
212
  bool ThreadLocalRef : 1;
213
214
  // Lvalue has ARC imprecise lifetime.  We store this inverted to try
215
  // to make the default bitfield pattern all-zeroes.
216
  bool ImpreciseLifetime : 1;
217
218
  // This flag shows if a nontemporal load/stores should be used when accessing
219
  // this lvalue.
220
  bool Nontemporal : 1;
221
222
  LValueBaseInfo BaseInfo;
223
  TBAAAccessInfo TBAAInfo;
224
225
  Expr *BaseIvarExp;
226
227
private:
228
  void Initialize(QualType Type, Qualifiers Quals, CharUnits Alignment,
229
3.64M
                  LValueBaseInfo BaseInfo, TBAAAccessInfo TBAAInfo) {
230
3.64M
    assert((!Alignment.isZero() || Type->isIncompleteType()) &&
231
3.64M
           "initializing l-value with zero alignment!");
232
3.64M
    this->Type = Type;
233
3.64M
    this->Quals = Quals;
234
3.64M
    const unsigned MaxAlign = 1U << 31;
235
3.64M
    this->Alignment = Alignment.getQuantity() <= MaxAlign
236
3.64M
                          ? Alignment.getQuantity()
237
3.64M
                          : 
MaxAlign0
;
238
3.64M
    assert(this->Alignment == Alignment.getQuantity() &&
239
3.64M
           "Alignment exceeds allowed max!");
240
3.64M
    this->BaseInfo = BaseInfo;
241
3.64M
    this->TBAAInfo = TBAAInfo;
242
3.64M
243
3.64M
    // Initialize Objective-C flags.
244
3.64M
    this->Ivar = this->ObjIsArray = this->NonGC = this->GlobalObjCRef = false;
245
3.64M
    this->ImpreciseLifetime = false;
246
3.64M
    this->Nontemporal = false;
247
3.64M
    this->ThreadLocalRef = false;
248
3.64M
    this->BaseIvarExp = nullptr;
249
3.64M
  }
250
251
public:
252
3.72M
  bool isSimple() const { return LVType == Simple; }
253
3.19k
  bool isVectorElt() const { return LVType == VectorElt; }
254
228k
  bool isBitField() const { return LVType == BitField; }
255
2.02k
  bool isExtVectorElt() const { return LVType == ExtVectorElt; }
256
3.32k
  bool isGlobalReg() const { return LVType == GlobalReg; }
257
258
17.6k
  bool isVolatileQualified() const { return Quals.hasVolatile(); }
259
0
  bool isRestrictQualified() const { return Quals.hasRestrict(); }
260
155k
  unsigned getVRQualifiers() const {
261
155k
    return Quals.getCVRQualifiers() & ~Qualifiers::Const;
262
155k
  }
263
264
2.52M
  QualType getType() const { return Type; }
265
266
132k
  Qualifiers::ObjCLifetime getObjCLifetime() const {
267
132k
    return Quals.getObjCLifetime();
268
132k
  }
269
270
381
  bool isObjCIvar() const { return Ivar; }
271
298
  void setObjCIvar(bool Value) { Ivar = Value; }
272
273
122
  bool isObjCArray() const { return ObjIsArray; }
274
1.32k
  void setObjCArray(bool Value) { ObjIsArray = Value; }
275
276
280
  bool isNonGC () const { return NonGC; }
277
863k
  void setNonGC(bool Value) { NonGC = Value; }
278
279
263
  bool isGlobalObjCRef() const { return GlobalObjCRef; }
280
288
  void setGlobalObjCRef(bool Value) { GlobalObjCRef = Value; }
281
282
81
  bool isThreadLocalRef() const { return ThreadLocalRef; }
283
284
  void setThreadLocalRef(bool Value) { ThreadLocalRef = Value;}
284
285
82
  ARCPreciseLifetime_t isARCPreciseLifetime() const {
286
82
    return ARCPreciseLifetime_t(!ImpreciseLifetime);
287
82
  }
288
783k
  void setARCPreciseLifetime(ARCPreciseLifetime_t value) {
289
783k
    ImpreciseLifetime = (value == ARCImpreciseLifetime);
290
783k
  }
291
1.48M
  bool isNontemporal() const { return Nontemporal; }
292
344
  void setNontemporal(bool Value) { Nontemporal = Value; }
293
294
1.03M
  bool isObjCWeak() const {
295
1.03M
    return Quals.getObjCGCAttr() == Qualifiers::Weak;
296
1.03M
  }
297
322k
  bool isObjCStrong() const {
298
322k
    return Quals.getObjCGCAttr() == Qualifiers::Strong;
299
322k
  }
300
301
1.55M
  bool isVolatile() const {
302
1.55M
    return Quals.hasVolatile();
303
1.55M
  }
304
305
108
  Expr *getBaseIvarExp() const { return BaseIvarExp; }
306
246
  void setBaseIvarExp(Expr *V) { BaseIvarExp = V; }
307
308
1.88M
  TBAAAccessInfo getTBAAInfo() const { return TBAAInfo; }
309
8
  void setTBAAInfo(TBAAAccessInfo Info) { TBAAInfo = Info; }
310
311
26.3k
  const Qualifiers &getQuals() const { return Quals; }
312
2.10M
  Qualifiers &getQuals() { return Quals; }
313
314
281
  LangAS getAddressSpace() const { return Quals.getAddressSpace(); }
315
316
2.18M
  CharUnits getAlignment() const { return CharUnits::fromQuantity(Alignment); }
317
0
  void setAlignment(CharUnits A) { Alignment = A.getQuantity(); }
318
319
1.66M
  LValueBaseInfo getBaseInfo() const { return BaseInfo; }
320
0
  void setBaseInfo(LValueBaseInfo Info) { BaseInfo = Info; }
321
322
  // simple lvalue
323
2.42M
  llvm::Value *getPointer(CodeGenFunction &CGF) const {
324
2.42M
    assert(isSimple());
325
2.42M
    return V;
326
2.42M
  }
327
2.01M
  Address getAddress(CodeGenFunction &CGF) const {
328
2.01M
    return Address(getPointer(CGF), getAlignment());
329
2.01M
  }
330
1.38k
  void setAddress(Address address) {
331
1.38k
    assert(isSimple());
332
1.38k
    V = address.getPointer();
333
1.38k
    Alignment = address.getAlignment().getQuantity();
334
1.38k
  }
335
336
  // vector elt lvalue
337
853
  Address getVectorAddress() const {
338
853
    return Address(getVectorPointer(), getAlignment());
339
853
  }
340
877
  llvm::Value *getVectorPointer() const { assert(isVectorElt()); return V; }
341
463
  llvm::Value *getVectorIdx() const { assert(isVectorElt()); return VectorIdx; }
342
343
  // extended vector elements.
344
323
  Address getExtVectorAddress() const {
345
323
    return Address(getExtVectorPointer(), getAlignment());
346
323
  }
347
347
  llvm::Value *getExtVectorPointer() const {
348
347
    assert(isExtVectorElt());
349
347
    return V;
350
347
  }
351
298
  llvm::Constant *getExtVectorElts() const {
352
298
    assert(isExtVectorElt());
353
298
    return VectorElts;
354
298
  }
355
356
  // bitfield lvalue
357
1.52k
  Address getBitFieldAddress() const {
358
1.52k
    return Address(getBitFieldPointer(), getAlignment());
359
1.52k
  }
360
1.90k
  llvm::Value *getBitFieldPointer() const { assert(isBitField()); return V; }
361
1.74k
  const CGBitFieldInfo &getBitFieldInfo() const {
362
1.74k
    assert(isBitField());
363
1.74k
    return *BitFieldInfo;
364
1.74k
  }
365
366
  // global register lvalue
367
42
  llvm::Value *getGlobalReg() const { assert(isGlobalReg()); return V; }
368
369
  static LValue MakeAddr(Address address, QualType type, ASTContext &Context,
370
3.64M
                         LValueBaseInfo BaseInfo, TBAAAccessInfo TBAAInfo) {
371
3.64M
    Qualifiers qs = type.getQualifiers();
372
3.64M
    qs.setObjCGCAttr(Context.getObjCGCAttrKind(type));
373
3.64M
374
3.64M
    LValue R;
375
3.64M
    R.LVType = Simple;
376
3.64M
    assert(address.getPointer()->getType()->isPointerTy());
377
3.64M
    R.V = address.getPointer();
378
3.64M
    R.Initialize(type, qs, address.getAlignment(), BaseInfo, TBAAInfo);
379
3.64M
    return R;
380
3.64M
  }
381
382
  static LValue MakeVectorElt(Address vecAddress, llvm::Value *Idx,
383
                              QualType type, LValueBaseInfo BaseInfo,
384
417
                              TBAAAccessInfo TBAAInfo) {
385
417
    LValue R;
386
417
    R.LVType = VectorElt;
387
417
    R.V = vecAddress.getPointer();
388
417
    R.VectorIdx = Idx;
389
417
    R.Initialize(type, type.getQualifiers(), vecAddress.getAlignment(),
390
417
                 BaseInfo, TBAAInfo);
391
417
    return R;
392
417
  }
393
394
  static LValue MakeExtVectorElt(Address vecAddress, llvm::Constant *Elts,
395
                                 QualType type, LValueBaseInfo BaseInfo,
396
294
                                 TBAAAccessInfo TBAAInfo) {
397
294
    LValue R;
398
294
    R.LVType = ExtVectorElt;
399
294
    R.V = vecAddress.getPointer();
400
294
    R.VectorElts = Elts;
401
294
    R.Initialize(type, type.getQualifiers(), vecAddress.getAlignment(),
402
294
                 BaseInfo, TBAAInfo);
403
294
    return R;
404
294
  }
405
406
  /// Create a new object to represent a bit-field access.
407
  ///
408
  /// \param Addr - The base address of the bit-field sequence this
409
  /// bit-field refers to.
410
  /// \param Info - The information describing how to perform the bit-field
411
  /// access.
412
  static LValue MakeBitfield(Address Addr, const CGBitFieldInfo &Info,
413
                             QualType type, LValueBaseInfo BaseInfo,
414
1.53k
                             TBAAAccessInfo TBAAInfo) {
415
1.53k
    LValue R;
416
1.53k
    R.LVType = BitField;
417
1.53k
    R.V = Addr.getPointer();
418
1.53k
    R.BitFieldInfo = &Info;
419
1.53k
    R.Initialize(type, type.getQualifiers(), Addr.getAlignment(), BaseInfo,
420
1.53k
                 TBAAInfo);
421
1.53k
    return R;
422
1.53k
  }
423
424
38
  static LValue MakeGlobalReg(Address Reg, QualType type) {
425
38
    LValue R;
426
38
    R.LVType = GlobalReg;
427
38
    R.V = Reg.getPointer();
428
38
    R.Initialize(type, type.getQualifiers(), Reg.getAlignment(),
429
38
                 LValueBaseInfo(AlignmentSource::Decl), TBAAAccessInfo());
430
38
    return R;
431
38
  }
432
433
8.58k
  RValue asAggregateRValue(CodeGenFunction &CGF) const {
434
8.58k
    return RValue::getAggregate(getAddress(CGF), isVolatileQualified());
435
8.58k
  }
436
};
437
438
/// An aggregate value slot.
439
class AggValueSlot {
440
  /// The address.
441
  llvm::Value *Addr;
442
443
  // Qualifiers
444
  Qualifiers Quals;
445
446
  unsigned Alignment;
447
448
  /// DestructedFlag - This is set to true if some external code is
449
  /// responsible for setting up a destructor for the slot.  Otherwise
450
  /// the code which constructs it should push the appropriate cleanup.
451
  bool DestructedFlag : 1;
452
453
  /// ObjCGCFlag - This is set to true if writing to the memory in the
454
  /// slot might require calling an appropriate Objective-C GC
455
  /// barrier.  The exact interaction here is unnecessarily mysterious.
456
  bool ObjCGCFlag : 1;
457
458
  /// ZeroedFlag - This is set to true if the memory in the slot is
459
  /// known to be zero before the assignment into it.  This means that
460
  /// zero fields don't need to be set.
461
  bool ZeroedFlag : 1;
462
463
  /// AliasedFlag - This is set to true if the slot might be aliased
464
  /// and it's not undefined behavior to access it through such an
465
  /// alias.  Note that it's always undefined behavior to access a C++
466
  /// object that's under construction through an alias derived from
467
  /// outside the construction process.
468
  ///
469
  /// This flag controls whether calls that produce the aggregate
470
  /// value may be evaluated directly into the slot, or whether they
471
  /// must be evaluated into an unaliased temporary and then memcpy'ed
472
  /// over.  Since it's invalid in general to memcpy a non-POD C++
473
  /// object, it's important that this flag never be set when
474
  /// evaluating an expression which constructs such an object.
475
  bool AliasedFlag : 1;
476
477
  /// This is set to true if the tail padding of this slot might overlap
478
  /// another object that may have already been initialized (and whose
479
  /// value must be preserved by this initialization). If so, we may only
480
  /// store up to the dsize of the type. Otherwise we can widen stores to
481
  /// the size of the type.
482
  bool OverlapFlag : 1;
483
484
  /// If is set to true, sanitizer checks are already generated for this address
485
  /// or not required. For instance, if this address represents an object
486
  /// created in 'new' expression, sanitizer checks for memory is made as a part
487
  /// of 'operator new' emission and object constructor should not generate
488
  /// them.
489
  bool SanitizerCheckedFlag : 1;
490
491
public:
492
  enum IsAliased_t { IsNotAliased, IsAliased };
493
  enum IsDestructed_t { IsNotDestructed, IsDestructed };
494
  enum IsZeroed_t { IsNotZeroed, IsZeroed };
495
  enum Overlap_t { DoesNotOverlap, MayOverlap };
496
  enum NeedsGCBarriers_t { DoesNotNeedGCBarriers, NeedsGCBarriers };
497
  enum IsSanitizerChecked_t { IsNotSanitizerChecked, IsSanitizerChecked };
498
499
  /// ignored - Returns an aggregate value slot indicating that the
500
  /// aggregate value is being ignored.
501
755k
  static AggValueSlot ignored() {
502
755k
    return forAddr(Address::invalid(), Qualifiers(), IsNotDestructed,
503
755k
                   DoesNotNeedGCBarriers, IsNotAliased, DoesNotOverlap);
504
755k
  }
505
506
  /// forAddr - Make a slot for an aggregate value.
507
  ///
508
  /// \param quals - The qualifiers that dictate how the slot should
509
  /// be initialied. Only 'volatile' and the Objective-C lifetime
510
  /// qualifiers matter.
511
  ///
512
  /// \param isDestructed - true if something else is responsible
513
  ///   for calling destructors on this object
514
  /// \param needsGC - true if the slot is potentially located
515
  ///   somewhere that ObjC GC calls should be emitted for
516
  static AggValueSlot forAddr(Address addr,
517
                              Qualifiers quals,
518
                              IsDestructed_t isDestructed,
519
                              NeedsGCBarriers_t needsGC,
520
                              IsAliased_t isAliased,
521
                              Overlap_t mayOverlap,
522
                              IsZeroed_t isZeroed = IsNotZeroed,
523
820k
                       IsSanitizerChecked_t isChecked = IsNotSanitizerChecked) {
524
820k
    AggValueSlot AV;
525
820k
    if (addr.isValid()) {
526
64.1k
      AV.Addr = addr.getPointer();
527
64.1k
      AV.Alignment = addr.getAlignment().getQuantity();
528
755k
    } else {
529
755k
      AV.Addr = nullptr;
530
755k
      AV.Alignment = 0;
531
755k
    }
532
820k
    AV.Quals = quals;
533
820k
    AV.DestructedFlag = isDestructed;
534
820k
    AV.ObjCGCFlag = needsGC;
535
820k
    AV.ZeroedFlag = isZeroed;
536
820k
    AV.AliasedFlag = isAliased;
537
820k
    AV.OverlapFlag = mayOverlap;
538
820k
    AV.SanitizerCheckedFlag = isChecked;
539
820k
    return AV;
540
820k
  }
541
542
  static AggValueSlot
543
  forLValue(const LValue &LV, CodeGenFunction &CGF, IsDestructed_t isDestructed,
544
            NeedsGCBarriers_t needsGC, IsAliased_t isAliased,
545
            Overlap_t mayOverlap, IsZeroed_t isZeroed = IsNotZeroed,
546
26.3k
            IsSanitizerChecked_t isChecked = IsNotSanitizerChecked) {
547
26.3k
    return forAddr(LV.getAddress(CGF), LV.getQuals(), isDestructed, needsGC,
548
26.3k
                   isAliased, mayOverlap, isZeroed, isChecked);
549
26.3k
  }
550
551
19.2k
  IsDestructed_t isExternallyDestructed() const {
552
19.2k
    return IsDestructed_t(DestructedFlag);
553
19.2k
  }
554
6.12k
  void setExternallyDestructed(bool destructed = true) {
555
6.12k
    DestructedFlag = destructed;
556
6.12k
  }
557
558
39.1k
  Qualifiers getQualifiers() const { return Quals; }
559
560
100k
  bool isVolatile() const {
561
100k
    return Quals.hasVolatile();
562
100k
  }
563
564
5
  void setVolatile(bool flag) {
565
5
    if (flag)
566
5
      Quals.addVolatile();
567
0
    else
568
0
      Quals.removeVolatile();
569
5
  }
570
571
0
  Qualifiers::ObjCLifetime getObjCLifetime() const {
572
0
    return Quals.getObjCLifetime();
573
0
  }
574
575
9.13k
  NeedsGCBarriers_t requiresGCollection() const {
576
9.13k
    return NeedsGCBarriers_t(ObjCGCFlag);
577
9.13k
  }
578
579
189
  llvm::Value *getPointer() const {
580
189
    return Addr;
581
189
  }
582
583
231k
  Address getAddress() const {
584
231k
    return Address(Addr, getAlignment());
585
231k
  }
586
587
230k
  bool isIgnored() const {
588
230k
    return Addr == nullptr;
589
230k
  }
590
591
231k
  CharUnits getAlignment() const {
592
231k
    return CharUnits::fromQuantity(Alignment);
593
231k
  }
594
595
7.14k
  IsAliased_t isPotentiallyAliased() const {
596
7.14k
    return IsAliased_t(AliasedFlag);
597
7.14k
  }
598
599
67.9k
  Overlap_t mayOverlap() const {
600
67.9k
    return Overlap_t(OverlapFlag);
601
67.9k
  }
602
603
33.7k
  bool isSanitizerChecked() const {
604
33.7k
    return SanitizerCheckedFlag;
605
33.7k
  }
606
607
11.6k
  RValue asRValue() const {
608
11.6k
    if (isIgnored()) {
609
1.45k
      return RValue::getIgnored();
610
10.2k
    } else {
611
10.2k
      return RValue::getAggregate(getAddress(), isVolatile());
612
10.2k
    }
613
11.6k
  }
614
615
42
  void setZeroed(bool V = true) { ZeroedFlag = V; }
616
92.8k
  IsZeroed_t isZeroed() const {
617
92.8k
    return IsZeroed_t(ZeroedFlag);
618
92.8k
  }
619
620
  /// Get the preferred size to use when storing a value to this slot. This
621
  /// is the type size unless that might overlap another object, in which
622
  /// case it's the dsize.
623
26.1k
  CharUnits getPreferredSize(ASTContext &Ctx, QualType Type) const {
624
26.1k
    return mayOverlap() ? 
Ctx.getTypeInfoDataSizeInChars(Type).first7.52k
625
26.1k
                        : 
Ctx.getTypeSizeInChars(Type)18.5k
;
626
26.1k
  }
627
};
628
629
}  // end namespace CodeGen
630
}  // end namespace clang
631
632
#endif