Coverage Report

Created: 2020-09-15 12:33

/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
3.03M
  bool isScalar() const { return V1.getInt() == Scalar; }
53
470
  bool isComplex() const { return V1.getInt() == Complex; }
54
534k
  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
2.18M
  llvm::Value *getScalarVal() const {
60
2.18M
    assert(isScalar() && "Not a scalar!");
61
2.18M
    return V1.getPointer();
62
2.18M
  }
63
64
  /// getComplexVal - Return the real/imag components of this complex value.
65
  ///
66
1.05k
  std::pair<llvm::Value *, llvm::Value *> getComplexVal() const {
67
1.05k
    return std::make_pair(V1.getPointer(), V2.getPointer());
68
1.05k
  }
69
70
  /// getAggregateAddr() - Return the Value* of the address of the aggregate.
71
5.29k
  Address getAggregateAddress() const {
72
5.29k
    assert(isAggregate() && "Not an aggregate!");
73
5.29k
    auto align = reinterpret_cast<uintptr_t>(V2.getPointer()) >> AggAlignShift;
74
5.29k
    return Address(V1.getPointer(), CharUnits::fromQuantity(align));
75
5.29k
  }
76
194
  llvm::Value *getAggregatePointer() const {
77
194
    assert(isAggregate() && "Not an aggregate!");
78
194
    return V1.getPointer();
79
194
  }
80
81
1.50k
  static RValue getIgnored() {
82
    // FIXME: should we make this a more explicit state?
83
1.50k
    return get(nullptr);
84
1.50k
  }
85
86
2.30M
  static RValue get(llvm::Value *V) {
87
2.30M
    RValue ER;
88
2.30M
    ER.V1.setPointer(V);
89
2.30M
    ER.V1.setInt(Scalar);
90
2.30M
    ER.V2.setInt(false);
91
2.30M
    return ER;
92
2.30M
  }
93
1.49k
  static RValue getComplex(llvm::Value *V1, llvm::Value *V2) {
94
1.49k
    RValue ER;
95
1.49k
    ER.V1.setPointer(V1);
96
1.49k
    ER.V2.setPointer(V2);
97
1.49k
    ER.V1.setInt(Complex);
98
1.49k
    ER.V2.setInt(false);
99
1.49k
    return ER;
100
1.49k
  }
101
1.49k
  static RValue getComplex(const std::pair<llvm::Value *, llvm::Value *> &C) {
102
1.49k
    return getComplex(C.first, C.second);
103
1.49k
  }
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.5k
  static RValue getAggregate(Address addr, bool isVolatile = false) {
108
19.5k
    RValue ER;
109
19.5k
    ER.V1.setPointer(addr.getPointer());
110
19.5k
    ER.V1.setInt(Aggregate);
111
19.5k
112
19.5k
    auto align = static_cast<uintptr_t>(addr.getAlignment().getQuantity());
113
19.5k
    ER.V2.setPointer(reinterpret_cast<llvm::Value*>(align << AggAlignShift));
114
19.5k
    ER.V2.setInt(isVolatile);
115
19.5k
    return ER;
116
19.5k
  }
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
165k
static inline AlignmentSource getFieldAlignmentSource(AlignmentSource Source) {
145
  // For now, we don't distinguish fields of opaque pointers from
146
  // top-level declarations, but maybe we should.
147
165k
  return AlignmentSource::Decl;
148
165k
}
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
165k
static inline AlignmentSource getFieldAlignmentSource(AlignmentSource Source) {
145
  // For now, we don't distinguish fields of opaque pointers from
146
  // top-level declarations, but maybe we should.
147
165k
  return AlignmentSource::Decl;
148
165k
}
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: CGOpenMPRuntimeAMDGCN.cpp:clang::CodeGen::getFieldAlignmentSource(clang::CodeGen::AlignmentSource)
Unexecuted instantiation: CGOpenMPRuntimeGPU.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)
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
8.54M
    : AlignSource(Source) {}
156
172k
  AlignmentSource getAlignmentSource() const { return AlignSource; }
157
1.89k
  void setAlignmentSource(AlignmentSource Source) { AlignSource = Source; }
158
159
1.89k
  void mergeForCast(const LValueBaseInfo &Info) {
160
1.89k
    setAlignmentSource(Info.getAlignmentSource());
161
1.89k
  }
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
    MatrixElt     // This is a matrix element, use getVector*
175
  } LVType;
176
177
  llvm::Value *V;
178
179
  union {
180
    // Index into a vector subscript: V[i]
181
    llvm::Value *VectorIdx;
182
183
    // ExtVector element subset: V.xyx
184
    llvm::Constant *VectorElts;
185
186
    // BitField start bit and size
187
    const CGBitFieldInfo *BitFieldInfo;
188
  };
189
190
  QualType Type;
191
192
  // 'const' is unused here
193
  Qualifiers Quals;
194
195
  // The alignment to use when accessing this lvalue.  (For vector elements,
196
  // this is the alignment of the whole vector.)
197
  unsigned Alignment;
198
199
  // objective-c's ivar
200
  bool Ivar:1;
201
202
  // objective-c's ivar is an array
203
  bool ObjIsArray:1;
204
205
  // LValue is non-gc'able for any reason, including being a parameter or local
206
  // variable.
207
  bool NonGC: 1;
208
209
  // Lvalue is a global reference of an objective-c object
210
  bool GlobalObjCRef : 1;
211
212
  // Lvalue is a thread local reference
213
  bool ThreadLocalRef : 1;
214
215
  // Lvalue has ARC imprecise lifetime.  We store this inverted to try
216
  // to make the default bitfield pattern all-zeroes.
217
  bool ImpreciseLifetime : 1;
218
219
  // This flag shows if a nontemporal load/stores should be used when accessing
220
  // this lvalue.
221
  bool Nontemporal : 1;
222
223
  LValueBaseInfo BaseInfo;
224
  TBAAAccessInfo TBAAInfo;
225
226
  Expr *BaseIvarExp;
227
228
private:
229
  void Initialize(QualType Type, Qualifiers Quals, CharUnits Alignment,
230
4.25M
                  LValueBaseInfo BaseInfo, TBAAAccessInfo TBAAInfo) {
231
4.25M
    assert((!Alignment.isZero() || Type->isIncompleteType()) &&
232
4.25M
           "initializing l-value with zero alignment!");
233
4.25M
    this->Type = Type;
234
4.25M
    this->Quals = Quals;
235
4.25M
    const unsigned MaxAlign = 1U << 31;
236
4.25M
    this->Alignment = Alignment.getQuantity() <= MaxAlign
237
4.25M
                          ? Alignment.getQuantity()
238
0
                          : MaxAlign;
239
4.25M
    assert(this->Alignment == Alignment.getQuantity() &&
240
4.25M
           "Alignment exceeds allowed max!");
241
4.25M
    this->BaseInfo = BaseInfo;
242
4.25M
    this->TBAAInfo = TBAAInfo;
243
4.25M
244
    // Initialize Objective-C flags.
245
4.25M
    this->Ivar = this->ObjIsArray = this->NonGC = this->GlobalObjCRef = false;
246
4.25M
    this->ImpreciseLifetime = false;
247
4.25M
    this->Nontemporal = false;
248
4.25M
    this->ThreadLocalRef = false;
249
4.25M
    this->BaseIvarExp = nullptr;
250
4.25M
  }
251
252
public:
253
4.28M
  bool isSimple() const { return LVType == Simple; }
254
3.31k
  bool isVectorElt() const { return LVType == VectorElt; }
255
253k
  bool isBitField() const { return LVType == BitField; }
256
2.09k
  bool isExtVectorElt() const { return LVType == ExtVectorElt; }
257
3.44k
  bool isGlobalReg() const { return LVType == GlobalReg; }
258
1.14k
  bool isMatrixElt() const { return LVType == MatrixElt; }
259
260
18.1k
  bool isVolatileQualified() const { return Quals.hasVolatile(); }
261
0
  bool isRestrictQualified() const { return Quals.hasRestrict(); }
262
162k
  unsigned getVRQualifiers() const {
263
162k
    return Quals.getCVRQualifiers() & ~Qualifiers::Const;
264
162k
  }
265
266
4.61M
  QualType getType() const { return Type; }
267
268
153k
  Qualifiers::ObjCLifetime getObjCLifetime() const {
269
153k
    return Quals.getObjCLifetime();
270
153k
  }
271
272
381
  bool isObjCIvar() const { return Ivar; }
273
298
  void setObjCIvar(bool Value) { Ivar = Value; }
274
275
122
  bool isObjCArray() const { return ObjIsArray; }
276
1.32k
  void setObjCArray(bool Value) { ObjIsArray = Value; }
277
278
280
  bool isNonGC () const { return NonGC; }
279
1.02M
  void setNonGC(bool Value) { NonGC = Value; }
280
281
263
  bool isGlobalObjCRef() const { return GlobalObjCRef; }
282
288
  void setGlobalObjCRef(bool Value) { GlobalObjCRef = Value; }
283
284
81
  bool isThreadLocalRef() const { return ThreadLocalRef; }
285
284
  void setThreadLocalRef(bool Value) { ThreadLocalRef = Value;}
286
287
82
  ARCPreciseLifetime_t isARCPreciseLifetime() const {
288
82
    return ARCPreciseLifetime_t(!ImpreciseLifetime);
289
82
  }
290
925k
  void setARCPreciseLifetime(ARCPreciseLifetime_t value) {
291
925k
    ImpreciseLifetime = (value == ARCImpreciseLifetime);
292
925k
  }
293
1.75M
  bool isNontemporal() const { return Nontemporal; }
294
344
  void setNontemporal(bool Value) { Nontemporal = Value; }
295
296
1.21M
  bool isObjCWeak() const {
297
1.21M
    return Quals.getObjCGCAttr() == Qualifiers::Weak;
298
1.21M
  }
299
379k
  bool isObjCStrong() const {
300
379k
    return Quals.getObjCGCAttr() == Qualifiers::Strong;
301
379k
  }
302
303
1.83M
  bool isVolatile() const {
304
1.83M
    return Quals.hasVolatile();
305
1.83M
  }
306
307
108
  Expr *getBaseIvarExp() const { return BaseIvarExp; }
308
246
  void setBaseIvarExp(Expr *V) { BaseIvarExp = V; }
309
310
2.18M
  TBAAAccessInfo getTBAAInfo() const { return TBAAInfo; }
311
92
  void setTBAAInfo(TBAAAccessInfo Info) { TBAAInfo = Info; }
312
313
28.5k
  const Qualifiers &getQuals() const { return Quals; }
314
2.44M
  Qualifiers &getQuals() { return Quals; }
315
316
281
  LangAS getAddressSpace() const { return Quals.getAddressSpace(); }
317
318
2.54M
  CharUnits getAlignment() const { return CharUnits::fromQuantity(Alignment); }
319
0
  void setAlignment(CharUnits A) { Alignment = A.getQuantity(); }
320
321
1.95M
  LValueBaseInfo getBaseInfo() const { return BaseInfo; }
322
0
  void setBaseInfo(LValueBaseInfo Info) { BaseInfo = Info; }
323
324
  // simple lvalue
325
2.78M
  llvm::Value *getPointer(CodeGenFunction &CGF) const {
326
2.78M
    assert(isSimple());
327
2.78M
    return V;
328
2.78M
  }
329
2.36M
  Address getAddress(CodeGenFunction &CGF) const {
330
2.36M
    return Address(getPointer(CGF), getAlignment());
331
2.36M
  }
332
1.57k
  void setAddress(Address address) {
333
1.57k
    assert(isSimple());
334
1.57k
    V = address.getPointer();
335
1.57k
    Alignment = address.getAlignment().getQuantity();
336
1.57k
  }
337
338
  // vector elt lvalue
339
877
  Address getVectorAddress() const {
340
877
    return Address(getVectorPointer(), getAlignment());
341
877
  }
342
901
  llvm::Value *getVectorPointer() const {
343
901
    assert(isVectorElt());
344
901
    return V;
345
901
  }
346
475
  llvm::Value *getVectorIdx() const {
347
475
    assert(isVectorElt());
348
475
    return VectorIdx;
349
475
  }
350
351
36
  Address getMatrixAddress() const {
352
36
    return Address(getMatrixPointer(), getAlignment());
353
36
  }
354
36
  llvm::Value *getMatrixPointer() const {
355
36
    assert(isMatrixElt());
356
36
    return V;
357
36
  }
358
19
  llvm::Value *getMatrixIdx() const {
359
19
    assert(isMatrixElt());
360
19
    return VectorIdx;
361
19
  }
362
363
  // extended vector elements.
364
323
  Address getExtVectorAddress() const {
365
323
    return Address(getExtVectorPointer(), getAlignment());
366
323
  }
367
347
  llvm::Value *getExtVectorPointer() const {
368
347
    assert(isExtVectorElt());
369
347
    return V;
370
347
  }
371
298
  llvm::Constant *getExtVectorElts() const {
372
298
    assert(isExtVectorElt());
373
298
    return VectorElts;
374
298
  }
375
376
  // bitfield lvalue
377
1.58k
  Address getBitFieldAddress() const {
378
1.58k
    return Address(getBitFieldPointer(), getAlignment());
379
1.58k
  }
380
1.97k
  llvm::Value *getBitFieldPointer() const { assert(isBitField()); return V; }
381
1.80k
  const CGBitFieldInfo &getBitFieldInfo() const {
382
1.80k
    assert(isBitField());
383
1.80k
    return *BitFieldInfo;
384
1.80k
  }
385
386
  // global register lvalue
387
42
  llvm::Value *getGlobalReg() const { assert(isGlobalReg()); return V; }
388
389
  static LValue MakeAddr(Address address, QualType type, ASTContext &Context,
390
4.25M
                         LValueBaseInfo BaseInfo, TBAAAccessInfo TBAAInfo) {
391
4.25M
    Qualifiers qs = type.getQualifiers();
392
4.25M
    qs.setObjCGCAttr(Context.getObjCGCAttrKind(type));
393
4.25M
394
4.25M
    LValue R;
395
4.25M
    R.LVType = Simple;
396
4.25M
    assert(address.getPointer()->getType()->isPointerTy());
397
4.25M
    R.V = address.getPointer();
398
4.25M
    R.Initialize(type, qs, address.getAlignment(), BaseInfo, TBAAInfo);
399
4.25M
    return R;
400
4.25M
  }
401
402
  static LValue MakeVectorElt(Address vecAddress, llvm::Value *Idx,
403
                              QualType type, LValueBaseInfo BaseInfo,
404
429
                              TBAAAccessInfo TBAAInfo) {
405
429
    LValue R;
406
429
    R.LVType = VectorElt;
407
429
    R.V = vecAddress.getPointer();
408
429
    R.VectorIdx = Idx;
409
429
    R.Initialize(type, type.getQualifiers(), vecAddress.getAlignment(),
410
429
                 BaseInfo, TBAAInfo);
411
429
    return R;
412
429
  }
413
414
  static LValue MakeExtVectorElt(Address vecAddress, llvm::Constant *Elts,
415
                                 QualType type, LValueBaseInfo BaseInfo,
416
294
                                 TBAAAccessInfo TBAAInfo) {
417
294
    LValue R;
418
294
    R.LVType = ExtVectorElt;
419
294
    R.V = vecAddress.getPointer();
420
294
    R.VectorElts = Elts;
421
294
    R.Initialize(type, type.getQualifiers(), vecAddress.getAlignment(),
422
294
                 BaseInfo, TBAAInfo);
423
294
    return R;
424
294
  }
425
426
  /// Create a new object to represent a bit-field access.
427
  ///
428
  /// \param Addr - The base address of the bit-field sequence this
429
  /// bit-field refers to.
430
  /// \param Info - The information describing how to perform the bit-field
431
  /// access.
432
  static LValue MakeBitfield(Address Addr, const CGBitFieldInfo &Info,
433
                             QualType type, LValueBaseInfo BaseInfo,
434
1.59k
                             TBAAAccessInfo TBAAInfo) {
435
1.59k
    LValue R;
436
1.59k
    R.LVType = BitField;
437
1.59k
    R.V = Addr.getPointer();
438
1.59k
    R.BitFieldInfo = &Info;
439
1.59k
    R.Initialize(type, type.getQualifiers(), Addr.getAlignment(), BaseInfo,
440
1.59k
                 TBAAInfo);
441
1.59k
    return R;
442
1.59k
  }
443
444
38
  static LValue MakeGlobalReg(Address Reg, QualType type) {
445
38
    LValue R;
446
38
    R.LVType = GlobalReg;
447
38
    R.V = Reg.getPointer();
448
38
    R.Initialize(type, type.getQualifiers(), Reg.getAlignment(),
449
38
                 LValueBaseInfo(AlignmentSource::Decl), TBAAAccessInfo());
450
38
    return R;
451
38
  }
452
453
  static LValue MakeMatrixElt(Address matAddress, llvm::Value *Idx,
454
                              QualType type, LValueBaseInfo BaseInfo,
455
17
                              TBAAAccessInfo TBAAInfo) {
456
17
    LValue R;
457
17
    R.LVType = MatrixElt;
458
17
    R.V = matAddress.getPointer();
459
17
    R.VectorIdx = Idx;
460
17
    R.Initialize(type, type.getQualifiers(), matAddress.getAlignment(),
461
17
                 BaseInfo, TBAAInfo);
462
17
    return R;
463
17
  }
464
465
8.65k
  RValue asAggregateRValue(CodeGenFunction &CGF) const {
466
8.65k
    return RValue::getAggregate(getAddress(CGF), isVolatileQualified());
467
8.65k
  }
468
};
469
470
/// An aggregate value slot.
471
class AggValueSlot {
472
  /// The address.
473
  llvm::Value *Addr;
474
475
  // Qualifiers
476
  Qualifiers Quals;
477
478
  unsigned Alignment;
479
480
  /// DestructedFlag - This is set to true if some external code is
481
  /// responsible for setting up a destructor for the slot.  Otherwise
482
  /// the code which constructs it should push the appropriate cleanup.
483
  bool DestructedFlag : 1;
484
485
  /// ObjCGCFlag - This is set to true if writing to the memory in the
486
  /// slot might require calling an appropriate Objective-C GC
487
  /// barrier.  The exact interaction here is unnecessarily mysterious.
488
  bool ObjCGCFlag : 1;
489
490
  /// ZeroedFlag - This is set to true if the memory in the slot is
491
  /// known to be zero before the assignment into it.  This means that
492
  /// zero fields don't need to be set.
493
  bool ZeroedFlag : 1;
494
495
  /// AliasedFlag - This is set to true if the slot might be aliased
496
  /// and it's not undefined behavior to access it through such an
497
  /// alias.  Note that it's always undefined behavior to access a C++
498
  /// object that's under construction through an alias derived from
499
  /// outside the construction process.
500
  ///
501
  /// This flag controls whether calls that produce the aggregate
502
  /// value may be evaluated directly into the slot, or whether they
503
  /// must be evaluated into an unaliased temporary and then memcpy'ed
504
  /// over.  Since it's invalid in general to memcpy a non-POD C++
505
  /// object, it's important that this flag never be set when
506
  /// evaluating an expression which constructs such an object.
507
  bool AliasedFlag : 1;
508
509
  /// This is set to true if the tail padding of this slot might overlap
510
  /// another object that may have already been initialized (and whose
511
  /// value must be preserved by this initialization). If so, we may only
512
  /// store up to the dsize of the type. Otherwise we can widen stores to
513
  /// the size of the type.
514
  bool OverlapFlag : 1;
515
516
  /// If is set to true, sanitizer checks are already generated for this address
517
  /// or not required. For instance, if this address represents an object
518
  /// created in 'new' expression, sanitizer checks for memory is made as a part
519
  /// of 'operator new' emission and object constructor should not generate
520
  /// them.
521
  bool SanitizerCheckedFlag : 1;
522
523
public:
524
  enum IsAliased_t { IsNotAliased, IsAliased };
525
  enum IsDestructed_t { IsNotDestructed, IsDestructed };
526
  enum IsZeroed_t { IsNotZeroed, IsZeroed };
527
  enum Overlap_t { DoesNotOverlap, MayOverlap };
528
  enum NeedsGCBarriers_t { DoesNotNeedGCBarriers, NeedsGCBarriers };
529
  enum IsSanitizerChecked_t { IsNotSanitizerChecked, IsSanitizerChecked };
530
531
  /// ignored - Returns an aggregate value slot indicating that the
532
  /// aggregate value is being ignored.
533
827k
  static AggValueSlot ignored() {
534
827k
    return forAddr(Address::invalid(), Qualifiers(), IsNotDestructed,
535
827k
                   DoesNotNeedGCBarriers, IsNotAliased, DoesNotOverlap);
536
827k
  }
537
538
  /// forAddr - Make a slot for an aggregate value.
539
  ///
540
  /// \param quals - The qualifiers that dictate how the slot should
541
  /// be initialied. Only 'volatile' and the Objective-C lifetime
542
  /// qualifiers matter.
543
  ///
544
  /// \param isDestructed - true if something else is responsible
545
  ///   for calling destructors on this object
546
  /// \param needsGC - true if the slot is potentially located
547
  ///   somewhere that ObjC GC calls should be emitted for
548
  static AggValueSlot forAddr(Address addr,
549
                              Qualifiers quals,
550
                              IsDestructed_t isDestructed,
551
                              NeedsGCBarriers_t needsGC,
552
                              IsAliased_t isAliased,
553
                              Overlap_t mayOverlap,
554
                              IsZeroed_t isZeroed = IsNotZeroed,
555
895k
                       IsSanitizerChecked_t isChecked = IsNotSanitizerChecked) {
556
895k
    AggValueSlot AV;
557
895k
    if (addr.isValid()) {
558
67.0k
      AV.Addr = addr.getPointer();
559
67.0k
      AV.Alignment = addr.getAlignment().getQuantity();
560
827k
    } else {
561
827k
      AV.Addr = nullptr;
562
827k
      AV.Alignment = 0;
563
827k
    }
564
895k
    AV.Quals = quals;
565
895k
    AV.DestructedFlag = isDestructed;
566
895k
    AV.ObjCGCFlag = needsGC;
567
895k
    AV.ZeroedFlag = isZeroed;
568
895k
    AV.AliasedFlag = isAliased;
569
895k
    AV.OverlapFlag = mayOverlap;
570
895k
    AV.SanitizerCheckedFlag = isChecked;
571
895k
    return AV;
572
895k
  }
573
574
  static AggValueSlot
575
  forLValue(const LValue &LV, CodeGenFunction &CGF, IsDestructed_t isDestructed,
576
            NeedsGCBarriers_t needsGC, IsAliased_t isAliased,
577
            Overlap_t mayOverlap, IsZeroed_t isZeroed = IsNotZeroed,
578
28.5k
            IsSanitizerChecked_t isChecked = IsNotSanitizerChecked) {
579
28.5k
    return forAddr(LV.getAddress(CGF), LV.getQuals(), isDestructed, needsGC,
580
28.5k
                   isAliased, mayOverlap, isZeroed, isChecked);
581
28.5k
  }
582
583
19.6k
  IsDestructed_t isExternallyDestructed() const {
584
19.6k
    return IsDestructed_t(DestructedFlag);
585
19.6k
  }
586
6.26k
  void setExternallyDestructed(bool destructed = true) {
587
6.26k
    DestructedFlag = destructed;
588
6.26k
  }
589
590
41.1k
  Qualifiers getQualifiers() const { return Quals; }
591
592
104k
  bool isVolatile() const {
593
104k
    return Quals.hasVolatile();
594
104k
  }
595
596
5
  void setVolatile(bool flag) {
597
5
    if (flag)
598
5
      Quals.addVolatile();
599
0
    else
600
0
      Quals.removeVolatile();
601
5
  }
602
603
0
  Qualifiers::ObjCLifetime getObjCLifetime() const {
604
0
    return Quals.getObjCLifetime();
605
0
  }
606
607
9.47k
  NeedsGCBarriers_t requiresGCollection() const {
608
9.47k
    return NeedsGCBarriers_t(ObjCGCFlag);
609
9.47k
  }
610
611
194
  llvm::Value *getPointer() const {
612
194
    return Addr;
613
194
  }
614
615
241k
  Address getAddress() const {
616
241k
    return Address(Addr, getAlignment());
617
241k
  }
618
619
239k
  bool isIgnored() const {
620
239k
    return Addr == nullptr;
621
239k
  }
622
623
241k
  CharUnits getAlignment() const {
624
241k
    return CharUnits::fromQuantity(Alignment);
625
241k
  }
626
627
7.33k
  IsAliased_t isPotentiallyAliased() const {
628
7.33k
    return IsAliased_t(AliasedFlag);
629
7.33k
  }
630
631
71.2k
  Overlap_t mayOverlap() const {
632
71.2k
    return Overlap_t(OverlapFlag);
633
71.2k
  }
634
635
35.6k
  bool isSanitizerChecked() const {
636
35.6k
    return SanitizerCheckedFlag;
637
35.6k
  }
638
639
11.8k
  RValue asRValue() const {
640
11.8k
    if (isIgnored()) {
641
1.47k
      return RValue::getIgnored();
642
10.3k
    } else {
643
10.3k
      return RValue::getAggregate(getAddress(), isVolatile());
644
10.3k
    }
645
11.8k
  }
646
647
46
  void setZeroed(bool V = true) { ZeroedFlag = V; }
648
96.2k
  IsZeroed_t isZeroed() const {
649
96.2k
    return IsZeroed_t(ZeroedFlag);
650
96.2k
  }
651
652
  /// Get the preferred size to use when storing a value to this slot. This
653
  /// is the type size unless that might overlap another object, in which
654
  /// case it's the dsize.
655
27.1k
  CharUnits getPreferredSize(ASTContext &Ctx, QualType Type) const {
656
7.68k
    return mayOverlap() ? Ctx.getTypeInfoDataSizeInChars(Type).first
657
19.4k
                        : Ctx.getTypeSizeInChars(Type);
658
27.1k
  }
659
};
660
661
}  // end namespace CodeGen
662
}  // end namespace clang
663
664
#endif