Coverage Report

Created: 2019-07-24 05:18

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