Coverage Report

Created: 2018-09-25 23:22

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/clang/include/clang/Sema/Initialization.h
Line
Count
Source (jump to first uncovered line)
1
//===- Initialization.h - Semantic Analysis for Initializers ----*- C++ -*-===//
2
//
3
//                     The LLVM Compiler Infrastructure
4
//
5
// This file is distributed under the University of Illinois Open Source
6
// License. See LICENSE.TXT for details.
7
//
8
//===----------------------------------------------------------------------===//
9
//
10
// This file provides supporting data types for initialization of objects.
11
//
12
//===----------------------------------------------------------------------===//
13
14
#ifndef LLVM_CLANG_SEMA_INITIALIZATION_H
15
#define LLVM_CLANG_SEMA_INITIALIZATION_H
16
17
#include "clang/AST/ASTContext.h"
18
#include "clang/AST/Attr.h"
19
#include "clang/AST/Decl.h"
20
#include "clang/AST/DeclAccessPair.h"
21
#include "clang/AST/DeclarationName.h"
22
#include "clang/AST/Expr.h"
23
#include "clang/AST/Type.h"
24
#include "clang/Basic/IdentifierTable.h"
25
#include "clang/Basic/LLVM.h"
26
#include "clang/Basic/LangOptions.h"
27
#include "clang/Basic/SourceLocation.h"
28
#include "clang/Basic/Specifiers.h"
29
#include "clang/Sema/Overload.h"
30
#include "clang/Sema/Ownership.h"
31
#include "llvm/ADT/ArrayRef.h"
32
#include "llvm/ADT/SmallVector.h"
33
#include "llvm/ADT/StringRef.h"
34
#include "llvm/ADT/iterator_range.h"
35
#include "llvm/Support/Casting.h"
36
#include <cassert>
37
#include <cstdint>
38
#include <string>
39
40
namespace clang {
41
42
class APValue;
43
class CXXBaseSpecifier;
44
class CXXConstructorDecl;
45
class ObjCMethodDecl;
46
class Sema;
47
48
/// Describes an entity that is being initialized.
49
class alignas(8) InitializedEntity {
50
public:
51
  /// Specifies the kind of entity being initialized.
52
  enum EntityKind {
53
    /// The entity being initialized is a variable.
54
    EK_Variable,
55
56
    /// The entity being initialized is a function parameter.
57
    EK_Parameter,
58
59
    /// The entity being initialized is the result of a function call.
60
    EK_Result,
61
62
    /// The entity being initialized is the result of a statement expression.
63
    EK_StmtExprResult,
64
65
    /// The entity being initialized is an exception object that
66
    /// is being thrown.
67
    EK_Exception,
68
69
    /// The entity being initialized is a non-static data member
70
    /// subobject.
71
    EK_Member,
72
73
    /// The entity being initialized is an element of an array.
74
    EK_ArrayElement,
75
76
    /// The entity being initialized is an object (or array of
77
    /// objects) allocated via new.
78
    EK_New,
79
80
    /// The entity being initialized is a temporary object.
81
    EK_Temporary,
82
83
    /// The entity being initialized is a base member subobject.
84
    EK_Base,
85
86
    /// The initialization is being done by a delegating constructor.
87
    EK_Delegating,
88
89
    /// The entity being initialized is an element of a vector.
90
    /// or vector.
91
    EK_VectorElement,
92
93
    /// The entity being initialized is a field of block descriptor for
94
    /// the copied-in c++ object.
95
    EK_BlockElement,
96
97
    /// The entity being initialized is a field of block descriptor for the
98
    /// copied-in lambda object that's used in the lambda to block conversion.
99
    EK_LambdaToBlockConversionBlockElement,
100
101
    /// The entity being initialized is the real or imaginary part of a
102
    /// complex number.
103
    EK_ComplexElement,
104
105
    /// The entity being initialized is the field that captures a
106
    /// variable in a lambda.
107
    EK_LambdaCapture,
108
109
    /// The entity being initialized is the initializer for a compound
110
    /// literal.
111
    EK_CompoundLiteralInit,
112
113
    /// The entity being implicitly initialized back to the formal
114
    /// result type.
115
    EK_RelatedResult,
116
117
    /// The entity being initialized is a function parameter; function
118
    /// is member of group of audited CF APIs.
119
    EK_Parameter_CF_Audited,
120
121
    /// The entity being initialized is a structured binding of a
122
    /// decomposition declaration.
123
    EK_Binding,
124
125
    // Note: err_init_conversion_failed in DiagnosticSemaKinds.td uses this
126
    // enum as an index for its first %select.  When modifying this list,
127
    // that diagnostic text needs to be updated as well.
128
  };
129
130
private:
131
  /// The kind of entity being initialized.
132
  EntityKind Kind;
133
134
  /// If non-NULL, the parent entity in which this
135
  /// initialization occurs.
136
  const InitializedEntity *Parent = nullptr;
137
138
  /// The type of the object or reference being initialized.
139
  QualType Type;
140
141
  /// The mangling number for the next reference temporary to be created.
142
  mutable unsigned ManglingNumber = 0;
143
144
  struct LN {
145
    /// When Kind == EK_Result, EK_Exception, EK_New, the
146
    /// location of the 'return', 'throw', or 'new' keyword,
147
    /// respectively. When Kind == EK_Temporary, the location where
148
    /// the temporary is being created.
149
    unsigned Location;
150
151
    /// Whether the entity being initialized may end up using the
152
    /// named return value optimization (NRVO).
153
    bool NRVO;
154
  };
155
156
  struct VD {
157
    /// The VarDecl, FieldDecl, or BindingDecl being initialized.
158
    ValueDecl *VariableOrMember;
159
160
    /// When Kind == EK_Member, whether this is an implicit member
161
    /// initialization in a copy or move constructor. These can perform array
162
    /// copies.
163
    bool IsImplicitFieldInit;
164
165
    /// When Kind == EK_Member, whether this is the initial initialization
166
    /// check for a default member initializer.
167
    bool IsDefaultMemberInit;
168
  };
169
170
  struct C {
171
    /// The name of the variable being captured by an EK_LambdaCapture.
172
    IdentifierInfo *VarID;
173
174
    /// The source location at which the capture occurs.
175
    unsigned Location;
176
  };
177
178
  union {
179
    /// When Kind == EK_Variable, EK_Member or EK_Binding, the variable.
180
    VD Variable;
181
182
    /// When Kind == EK_RelatedResult, the ObjectiveC method where
183
    /// result type was implicitly changed to accommodate ARC semantics.
184
    ObjCMethodDecl *MethodDecl;
185
186
    /// When Kind == EK_Parameter, the ParmVarDecl, with the
187
    /// low bit indicating whether the parameter is "consumed".
188
    uintptr_t Parameter;
189
190
    /// When Kind == EK_Temporary or EK_CompoundLiteralInit, the type
191
    /// source information for the temporary.
192
    TypeSourceInfo *TypeInfo;
193
194
    struct LN LocAndNRVO;
195
196
    /// When Kind == EK_Base, the base specifier that provides the
197
    /// base class. The lower bit specifies whether the base is an inherited
198
    /// virtual base.
199
    uintptr_t Base;
200
201
    /// When Kind == EK_ArrayElement, EK_VectorElement, or
202
    /// EK_ComplexElement, the index of the array or vector element being
203
    /// initialized.
204
    unsigned Index;
205
206
    struct C Capture;
207
  };
208
209
5.98M
  InitializedEntity() = default;
210
211
  /// Create the initialization entity for a variable.
212
  InitializedEntity(VarDecl *Var, EntityKind EK = EK_Variable)
213
2.67M
      : Kind(EK), Type(Var->getType()), Variable{Var, false, false} {}
214
215
  /// Create the initialization entity for the result of a
216
  /// function, throwing an object, performing an explicit cast, or
217
  /// initializing a parameter for which there is no declaration.
218
  InitializedEntity(EntityKind Kind, SourceLocation Loc, QualType Type,
219
                    bool NRVO = false)
220
3.28M
      : Kind(Kind), Type(Type) {
221
3.28M
    LocAndNRVO.Location = Loc.getRawEncoding();
222
3.28M
    LocAndNRVO.NRVO = NRVO;
223
3.28M
  }
224
225
  /// Create the initialization entity for a member subobject.
226
  InitializedEntity(FieldDecl *Member, const InitializedEntity *Parent,
227
                    bool Implicit, bool DefaultMemberInit)
228
      : Kind(EK_Member), Parent(Parent), Type(Member->getType()),
229
525k
        Variable{Member, Implicit, DefaultMemberInit} {}
230
231
  /// Create the initialization entity for an array element.
232
  InitializedEntity(ASTContext &Context, unsigned Index,
233
                    const InitializedEntity &Parent);
234
235
  /// Create the initialization entity for a lambda capture.
236
  InitializedEntity(IdentifierInfo *VarID, QualType FieldType, SourceLocation Loc)
237
4.26k
      : Kind(EK_LambdaCapture), Type(FieldType) {
238
4.26k
    Capture.VarID = VarID;
239
4.26k
    Capture.Location = Loc.getRawEncoding();
240
4.26k
  }
241
242
public:
243
  /// Create the initialization entity for a variable.
244
2.67M
  static InitializedEntity InitializeVariable(VarDecl *Var) {
245
2.67M
    return InitializedEntity(Var);
246
2.67M
  }
247
248
  /// Create the initialization entity for a parameter.
249
  static InitializedEntity InitializeParameter(ASTContext &Context,
250
296k
                                               const ParmVarDecl *Parm) {
251
296k
    return InitializeParameter(Context, Parm, Parm->getType());
252
296k
  }
253
254
  /// Create the initialization entity for a parameter, but use
255
  /// another type.
256
  static InitializedEntity InitializeParameter(ASTContext &Context,
257
                                               const ParmVarDecl *Parm,
258
5.87M
                                               QualType Type) {
259
5.87M
    bool Consumed = (Context.getLangOpts().ObjCAutoRefCount &&
260
5.87M
                     
Parm->hasAttr<NSConsumedAttr>()3.02k
);
261
5.87M
262
5.87M
    InitializedEntity Entity;
263
5.87M
    Entity.Kind = EK_Parameter;
264
5.87M
    Entity.Type =
265
5.87M
      Context.getVariableArrayDecayedType(Type.getUnqualifiedType());
266
5.87M
    Entity.Parent = nullptr;
267
5.87M
    Entity.Parameter
268
5.87M
      = (static_cast<uintptr_t>(Consumed) | reinterpret_cast<uintptr_t>(Parm));
269
5.87M
    return Entity;
270
5.87M
  }
271
272
  /// Create the initialization entity for a parameter that is
273
  /// only known by its type.
274
  static InitializedEntity InitializeParameter(ASTContext &Context,
275
                                               QualType Type,
276
43.7k
                                               bool Consumed) {
277
43.7k
    InitializedEntity Entity;
278
43.7k
    Entity.Kind = EK_Parameter;
279
43.7k
    Entity.Type = Context.getVariableArrayDecayedType(Type);
280
43.7k
    Entity.Parent = nullptr;
281
43.7k
    Entity.Parameter = (Consumed);
282
43.7k
    return Entity;
283
43.7k
  }
284
285
  /// Create the initialization entity for the result of a function.
286
  static InitializedEntity InitializeResult(SourceLocation ReturnLoc,
287
1.77M
                                            QualType Type, bool NRVO) {
288
1.77M
    return InitializedEntity(EK_Result, ReturnLoc, Type, NRVO);
289
1.77M
  }
290
291
  static InitializedEntity InitializeStmtExprResult(SourceLocation ReturnLoc,
292
10.6k
                                            QualType Type) {
293
10.6k
    return InitializedEntity(EK_StmtExprResult, ReturnLoc, Type);
294
10.6k
  }
295
296
  static InitializedEntity InitializeBlock(SourceLocation BlockVarLoc,
297
174
                                           QualType Type, bool NRVO) {
298
174
    return InitializedEntity(EK_BlockElement, BlockVarLoc, Type, NRVO);
299
174
  }
300
301
  static InitializedEntity InitializeLambdaToBlock(SourceLocation BlockVarLoc,
302
27
                                                   QualType Type, bool NRVO) {
303
27
    return InitializedEntity(EK_LambdaToBlockConversionBlockElement,
304
27
                             BlockVarLoc, Type, NRVO);
305
27
  }
306
307
  /// Create the initialization entity for an exception object.
308
  static InitializedEntity InitializeException(SourceLocation ThrowLoc,
309
3.56k
                                               QualType Type, bool NRVO) {
310
3.56k
    return InitializedEntity(EK_Exception, ThrowLoc, Type, NRVO);
311
3.56k
  }
312
313
  /// Create the initialization entity for an object allocated via new.
314
8.46k
  static InitializedEntity InitializeNew(SourceLocation NewLoc, QualType Type) {
315
8.46k
    return InitializedEntity(EK_New, NewLoc, Type);
316
8.46k
  }
317
318
  /// Create the initialization entity for a temporary.
319
1.29M
  static InitializedEntity InitializeTemporary(QualType Type) {
320
1.29M
    return InitializeTemporary(nullptr, Type);
321
1.29M
  }
322
323
  /// Create the initialization entity for a temporary.
324
156k
  static InitializedEntity InitializeTemporary(TypeSourceInfo *TypeInfo) {
325
156k
    return InitializeTemporary(TypeInfo, TypeInfo->getType());
326
156k
  }
327
328
  /// Create the initialization entity for a temporary.
329
  static InitializedEntity InitializeTemporary(TypeSourceInfo *TypeInfo,
330
1.45M
                                               QualType Type) {
331
1.45M
    InitializedEntity Result(EK_Temporary, SourceLocation(), Type);
332
1.45M
    Result.TypeInfo = TypeInfo;
333
1.45M
    return Result;
334
1.45M
  }
335
336
  /// Create the initialization entity for a related result.
337
  static InitializedEntity InitializeRelatedResult(ObjCMethodDecl *MD,
338
608
                                                   QualType Type) {
339
608
    InitializedEntity Result(EK_RelatedResult, SourceLocation(), Type);
340
608
    Result.MethodDecl = MD;
341
608
    return Result;
342
608
  }
343
344
  /// Create the initialization entity for a base class subobject.
345
  static InitializedEntity
346
  InitializeBase(ASTContext &Context, const CXXBaseSpecifier *Base,
347
                 bool IsInheritedVirtualBase,
348
                 const InitializedEntity *Parent = nullptr);
349
350
  /// Create the initialization entity for a delegated constructor.
351
572
  static InitializedEntity InitializeDelegation(QualType Type) {
352
572
    return InitializedEntity(EK_Delegating, SourceLocation(), Type);
353
572
  }
354
355
  /// Create the initialization entity for a member subobject.
356
  static InitializedEntity
357
  InitializeMember(FieldDecl *Member,
358
                   const InitializedEntity *Parent = nullptr,
359
519k
                   bool Implicit = false) {
360
519k
    return InitializedEntity(Member, Parent, Implicit, false);
361
519k
  }
362
363
  /// Create the initialization entity for a member subobject.
364
  static InitializedEntity
365
  InitializeMember(IndirectFieldDecl *Member,
366
                   const InitializedEntity *Parent = nullptr,
367
1.13k
                   bool Implicit = false) {
368
1.13k
    return InitializedEntity(Member->getAnonField(), Parent, Implicit, false);
369
1.13k
  }
370
371
  /// Create the initialization entity for a default member initializer.
372
  static InitializedEntity
373
5.23k
  InitializeMemberFromDefaultMemberInitializer(FieldDecl *Member) {
374
5.23k
    return InitializedEntity(Member, nullptr, false, true);
375
5.23k
  }
376
377
  /// Create the initialization entity for an array element.
378
  static InitializedEntity InitializeElement(ASTContext &Context,
379
                                             unsigned Index,
380
1.60M
                                             const InitializedEntity &Parent) {
381
1.60M
    return InitializedEntity(Context, Index, Parent);
382
1.60M
  }
383
384
  /// Create the initialization entity for a structured binding.
385
67
  static InitializedEntity InitializeBinding(VarDecl *Binding) {
386
67
    return InitializedEntity(Binding, EK_Binding);
387
67
  }
388
389
  /// Create the initialization entity for a lambda capture.
390
  static InitializedEntity InitializeLambdaCapture(IdentifierInfo *VarID,
391
                                                   QualType FieldType,
392
4.26k
                                                   SourceLocation Loc) {
393
4.26k
    return InitializedEntity(VarID, FieldType, Loc);
394
4.26k
  }
395
396
  /// Create the entity for a compound literal initializer.
397
29.1k
  static InitializedEntity InitializeCompoundLiteralInit(TypeSourceInfo *TSI) {
398
29.1k
    InitializedEntity Result(EK_CompoundLiteralInit, SourceLocation(),
399
29.1k
                             TSI->getType());
400
29.1k
    Result.TypeInfo = TSI;
401
29.1k
    return Result;
402
29.1k
  }
403
404
  /// Determine the kind of initialization.
405
79.4M
  EntityKind getKind() const { return Kind; }
406
407
  /// Retrieve the parent of the entity being initialized, when
408
  /// the initialization itself is occurring within the context of a
409
  /// larger initialization.
410
1.35M
  const InitializedEntity *getParent() const { return Parent; }
411
412
  /// Retrieve type being initialized.
413
49.5M
  QualType getType() const { return Type; }
414
415
  /// Retrieve complete type-source information for the object being
416
  /// constructed, if known.
417
65.6k
  TypeSourceInfo *getTypeSourceInfo() const {
418
65.6k
    if (Kind == EK_Temporary || 
Kind == EK_CompoundLiteralInit8
)
419
65.6k
      return TypeInfo;
420
0
421
0
    return nullptr;
422
0
  }
423
424
  /// Retrieve the name of the entity being initialized.
425
  DeclarationName getName() const;
426
427
  /// Retrieve the variable, parameter, or field being
428
  /// initialized.
429
  ValueDecl *getDecl() const;
430
431
  /// Retrieve the ObjectiveC method being initialized.
432
6
  ObjCMethodDecl *getMethodDecl() const { return MethodDecl; }
433
434
  /// Determine whether this initialization allows the named return
435
  /// value optimization, which also applies to thrown objects.
436
  bool allowsNRVO() const;
437
438
8.26M
  bool isParameterKind() const {
439
8.26M
    return (getKind() == EK_Parameter  ||
440
8.26M
            
getKind() == EK_Parameter_CF_Audited2.45M
);
441
8.26M
  }
442
443
  /// Determine whether this initialization consumes the
444
  /// parameter.
445
2.56k
  bool isParameterConsumed() const {
446
2.56k
    assert(isParameterKind() && "Not a parameter");
447
2.56k
    return (Parameter & 1);
448
2.56k
  }
449
450
  /// Retrieve the base specifier.
451
68.2k
  const CXXBaseSpecifier *getBaseSpecifier() const {
452
68.2k
    assert(getKind() == EK_Base && "Not a base specifier");
453
68.2k
    return reinterpret_cast<const CXXBaseSpecifier *>(Base & ~0x1);
454
68.2k
  }
455
456
  /// Return whether the base is an inherited virtual base.
457
9.45k
  bool isInheritedVirtualBase() const {
458
9.45k
    assert(getKind() == EK_Base && "Not a base specifier");
459
9.45k
    return Base & 0x1;
460
9.45k
  }
461
462
  /// Determine whether this is an array new with an unknown bound.
463
98.6k
  bool isVariableLengthArrayNew() const {
464
98.6k
    return getKind() == EK_New && dyn_cast_or_null<IncompleteArrayType>(
465
66
                                      getType()->getAsArrayTypeUnsafe());
466
98.6k
  }
467
468
  /// Is this the implicit initialization of a member of a class from
469
  /// a defaulted constructor?
470
1.02k
  bool isImplicitMemberInitializer() const {
471
1.02k
    return getKind() == EK_Member && Variable.IsImplicitFieldInit;
472
1.02k
  }
473
474
  /// Is this the default member initializer of a member (specified inside
475
  /// the class definition)?
476
203k
  bool isDefaultMemberInitializer() const {
477
203k
    return getKind() == EK_Member && Variable.IsDefaultMemberInit;
478
203k
  }
479
480
  /// Determine the location of the 'return' keyword when initializing
481
  /// the result of a function call.
482
1.59k
  SourceLocation getReturnLoc() const {
483
1.59k
    assert(getKind() == EK_Result && "No 'return' location!");
484
1.59k
    return SourceLocation::getFromRawEncoding(LocAndNRVO.Location);
485
1.59k
  }
486
487
  /// Determine the location of the 'throw' keyword when initializing
488
  /// an exception object.
489
0
  SourceLocation getThrowLoc() const {
490
0
    assert(getKind() == EK_Exception && "No 'throw' location!");
491
0
    return SourceLocation::getFromRawEncoding(LocAndNRVO.Location);
492
0
  }
493
494
  /// If this is an array, vector, or complex number element, get the
495
  /// element's index.
496
17
  unsigned getElementIndex() const {
497
17
    assert(getKind() == EK_ArrayElement || getKind() == EK_VectorElement ||
498
17
           getKind() == EK_ComplexElement);
499
17
    return Index;
500
17
  }
501
502
  /// If this is already the initializer for an array or vector
503
  /// element, sets the element index.
504
1.54M
  void setElementIndex(unsigned Index) {
505
1.54M
    assert(getKind() == EK_ArrayElement || getKind() == EK_VectorElement ||
506
1.54M
           getKind() == EK_ComplexElement);
507
1.54M
    this->Index = Index;
508
1.54M
  }
509
510
  /// For a lambda capture, return the capture's name.
511
2
  StringRef getCapturedVarName() const {
512
2
    assert(getKind() == EK_LambdaCapture && "Not a lambda capture!");
513
2
    return Capture.VarID->getName();
514
2
  }
515
516
  /// Determine the location of the capture when initializing
517
  /// field from a captured variable in a lambda.
518
0
  SourceLocation getCaptureLoc() const {
519
0
    assert(getKind() == EK_LambdaCapture && "Not a lambda capture!");
520
0
    return SourceLocation::getFromRawEncoding(Capture.Location);
521
0
  }
522
523
12
  void setParameterCFAudited() {
524
12
    Kind = EK_Parameter_CF_Audited;
525
12
  }
526
527
1.45k
  unsigned allocateManglingNumber() const { return ++ManglingNumber; }
528
529
  /// Dump a representation of the initialized entity to standard error,
530
  /// for debugging purposes.
531
  void dump() const;
532
533
private:
534
  unsigned dumpImpl(raw_ostream &OS) const;
535
};
536
537
/// Describes the kind of initialization being performed, along with
538
/// location information for tokens related to the initialization (equal sign,
539
/// parentheses).
540
class InitializationKind {
541
public:
542
  /// The kind of initialization being performed.
543
  enum InitKind {
544
    /// Direct initialization
545
    IK_Direct,
546
547
    /// Direct list-initialization
548
    IK_DirectList,
549
550
    /// Copy initialization
551
    IK_Copy,
552
553
    /// Default initialization
554
    IK_Default,
555
556
    /// Value initialization
557
    IK_Value
558
  };
559
560
private:
561
  /// The context of the initialization.
562
  enum InitContext {
563
    /// Normal context
564
    IC_Normal,
565
566
    /// Normal context, but allows explicit conversion functionss
567
    IC_ExplicitConvs,
568
569
    /// Implicit context (value initialization)
570
    IC_Implicit,
571
572
    /// Static cast context
573
    IC_StaticCast,
574
575
    /// C-style cast context
576
    IC_CStyleCast,
577
578
    /// Functional cast context
579
    IC_FunctionalCast
580
  };
581
582
  /// The kind of initialization being performed.
583
  InitKind Kind : 8;
584
585
  /// The context of the initialization.
586
  InitContext Context : 8;
587
588
  /// The source locations involved in the initialization.
589
  SourceLocation Locations[3];
590
591
  InitializationKind(InitKind Kind, InitContext Context, SourceLocation Loc1,
592
                     SourceLocation Loc2, SourceLocation Loc3)
593
13.6M
      : Kind(Kind), Context(Context) {
594
13.6M
    Locations[0] = Loc1;
595
13.6M
    Locations[1] = Loc2;
596
13.6M
    Locations[2] = Loc3;
597
13.6M
  }
598
599
public:
600
  /// Create a direct initialization.
601
  static InitializationKind CreateDirect(SourceLocation InitLoc,
602
                                         SourceLocation LParenLoc,
603
423k
                                         SourceLocation RParenLoc) {
604
423k
    return InitializationKind(IK_Direct, IC_Normal,
605
423k
                              InitLoc, LParenLoc, RParenLoc);
606
423k
  }
607
608
18
  static InitializationKind CreateDirectList(SourceLocation InitLoc) {
609
18
    return InitializationKind(IK_DirectList, IC_Normal, InitLoc, InitLoc,
610
18
                              InitLoc);
611
18
  }
612
613
  static InitializationKind CreateDirectList(SourceLocation InitLoc,
614
                                             SourceLocation LBraceLoc,
615
13.4k
                                             SourceLocation RBraceLoc) {
616
13.4k
    return InitializationKind(IK_DirectList, IC_Normal, InitLoc, LBraceLoc,
617
13.4k
                              RBraceLoc);
618
13.4k
  }
619
620
  /// Create a direct initialization due to a cast that isn't a C-style
621
  /// or functional cast.
622
56.3k
  static InitializationKind CreateCast(SourceRange TypeRange) {
623
56.3k
    return InitializationKind(IK_Direct, IC_StaticCast, TypeRange.getBegin(),
624
56.3k
                              TypeRange.getBegin(), TypeRange.getEnd());
625
56.3k
  }
626
627
  /// Create a direct initialization for a C-style cast.
628
  static InitializationKind CreateCStyleCast(SourceLocation StartLoc,
629
                                             SourceRange TypeRange,
630
630k
                                             bool InitList) {
631
630k
    // C++ cast syntax doesn't permit init lists, but C compound literals are
632
630k
    // exactly that.
633
630k
    return InitializationKind(InitList ? 
IK_DirectList29.1k
:
IK_Direct601k
,
634
630k
                              IC_CStyleCast, StartLoc, TypeRange.getBegin(),
635
630k
                              TypeRange.getEnd());
636
630k
  }
637
638
  /// Create a direct initialization for a functional cast.
639
  static InitializationKind CreateFunctionalCast(SourceRange TypeRange,
640
76.5k
                                                 bool InitList) {
641
76.5k
    return InitializationKind(InitList ? 
IK_DirectList0
: IK_Direct,
642
76.5k
                              IC_FunctionalCast, TypeRange.getBegin(),
643
76.5k
                              TypeRange.getBegin(), TypeRange.getEnd());
644
76.5k
  }
645
646
  /// Create a copy initialization.
647
  static InitializationKind CreateCopy(SourceLocation InitLoc,
648
                                       SourceLocation EqualLoc,
649
11.8M
                                       bool AllowExplicitConvs = false) {
650
11.8M
    return InitializationKind(IK_Copy,
651
11.8M
                              AllowExplicitConvs? 
IC_ExplicitConvs32.5k
:
IC_Normal11.8M
,
652
11.8M
                              InitLoc, EqualLoc, EqualLoc);
653
11.8M
  }
654
655
  /// Create a default initialization.
656
542k
  static InitializationKind CreateDefault(SourceLocation InitLoc) {
657
542k
    return InitializationKind(IK_Default, IC_Normal, InitLoc, InitLoc, InitLoc);
658
542k
  }
659
660
  /// Create a value initialization.
661
  static InitializationKind CreateValue(SourceLocation InitLoc,
662
                                        SourceLocation LParenLoc,
663
                                        SourceLocation RParenLoc,
664
72.5k
                                        bool isImplicit = false) {
665
72.5k
    return InitializationKind(IK_Value, isImplicit ? 
IC_Implicit26.3k
:
IC_Normal46.1k
,
666
72.5k
                              InitLoc, LParenLoc, RParenLoc);
667
72.5k
  }
668
669
  /// Create an initialization from an initializer (which, for direct
670
  /// initialization from a parenthesized list, will be a ParenListExpr).
671
  static InitializationKind CreateForInit(SourceLocation Loc, bool DirectInit,
672
2.18M
                                          Expr *Init) {
673
2.18M
    if (!Init) 
return CreateDefault(Loc)4
;
674
2.18M
    if (!DirectInit)
675
2.08M
      return CreateCopy(Loc, Init->getBeginLoc());
676
97.7k
    if (isa<InitListExpr>(Init))
677
3.92k
      return CreateDirectList(Loc, Init->getBeginLoc(), Init->getEndLoc());
678
93.8k
    return CreateDirect(Loc, Init->getBeginLoc(), Init->getEndLoc());
679
93.8k
  }
680
681
  /// Determine the initialization kind.
682
52.3M
  InitKind getKind() const {
683
52.3M
    return Kind;
684
52.3M
  }
685
686
  /// Determine whether this initialization is an explicit cast.
687
5.73M
  bool isExplicitCast() const {
688
5.73M
    return Context >= IC_StaticCast;
689
5.73M
  }
690
691
  /// Determine whether this initialization is a C-style cast.
692
6.75M
  bool isCStyleOrFunctionalCast() const {
693
6.75M
    return Context >= IC_CStyleCast;
694
6.75M
  }
695
696
  /// Determine whether this is a C-style cast.
697
6.23M
  bool isCStyleCast() const {
698
6.23M
    return Context == IC_CStyleCast;
699
6.23M
  }
700
701
  /// Determine whether this is a functional-style cast.
702
5.73M
  bool isFunctionalCast() const {
703
5.73M
    return Context == IC_FunctionalCast;
704
5.73M
  }
705
706
  /// Determine whether this initialization is an implicit
707
  /// value-initialization, e.g., as occurs during aggregate
708
  /// initialization.
709
14.6k
  bool isImplicitValueInit() const { return Context == IC_Implicit; }
710
711
  /// Retrieve the location at which initialization is occurring.
712
19.2M
  SourceLocation getLocation() const { return Locations[0]; }
713
714
  /// Retrieve the source range that covers the initialization.
715
6.89k
  SourceRange getRange() const {
716
6.89k
    return SourceRange(Locations[0], Locations[2]);
717
6.89k
  }
718
719
  /// Retrieve the location of the equal sign for copy initialization
720
  /// (if present).
721
211k
  SourceLocation getEqualLoc() const {
722
211k
    assert(Kind == IK_Copy && "Only copy initialization has an '='");
723
211k
    return Locations[1];
724
211k
  }
725
726
1.43M
  bool isCopyInit() const { return Kind == IK_Copy; }
727
728
  /// Retrieve whether this initialization allows the use of explicit
729
  ///        constructors.
730
780k
  bool AllowExplicit() const { return !isCopyInit(); }
731
732
  /// Retrieve whether this initialization allows the use of explicit
733
  /// conversion functions when binding a reference. If the reference is the
734
  /// first parameter in a copy or move constructor, such conversions are
735
  /// permitted even though we are performing copy-initialization.
736
1.71k
  bool allowExplicitConversionFunctionsInRefBinding() const {
737
1.71k
    return !isCopyInit() || 
Context == IC_ExplicitConvs1.62k
;
738
1.71k
  }
739
740
  /// Determine whether this initialization has a source range containing the
741
  /// locations of open and closing parentheses or braces.
742
375k
  bool hasParenOrBraceRange() const {
743
375k
    return Kind == IK_Direct || 
Kind == IK_Value247k
||
Kind == IK_DirectList208k
;
744
375k
  }
745
746
  /// Retrieve the source range containing the locations of the open
747
  /// and closing parentheses or braces for value, direct, and direct list
748
  /// initializations.
749
398k
  SourceRange getParenOrBraceRange() const {
750
398k
    assert(hasParenOrBraceRange() && "Only direct, value, and direct-list "
751
398k
                                     "initialization have parentheses or "
752
398k
                                     "braces");
753
398k
    return SourceRange(Locations[1], Locations[2]);
754
398k
  }
755
};
756
757
/// Describes the sequence of initializations required to initialize
758
/// a given object or reference with a set of arguments.
759
class InitializationSequence {
760
public:
761
  /// Describes the kind of initialization sequence computed.
762
  enum SequenceKind {
763
    /// A failed initialization sequence. The failure kind tells what
764
    /// happened.
765
    FailedSequence = 0,
766
767
    /// A dependent initialization, which could not be
768
    /// type-checked due to the presence of dependent types or
769
    /// dependently-typed expressions.
770
    DependentSequence,
771
772
    /// A normal sequence.
773
    NormalSequence
774
  };
775
776
  /// Describes the kind of a particular step in an initialization
777
  /// sequence.
778
  enum StepKind {
779
    /// Resolve the address of an overloaded function to a specific
780
    /// function declaration.
781
    SK_ResolveAddressOfOverloadedFunction,
782
783
    /// Perform a derived-to-base cast, producing an rvalue.
784
    SK_CastDerivedToBaseRValue,
785
786
    /// Perform a derived-to-base cast, producing an xvalue.
787
    SK_CastDerivedToBaseXValue,
788
789
    /// Perform a derived-to-base cast, producing an lvalue.
790
    SK_CastDerivedToBaseLValue,
791
792
    /// Reference binding to an lvalue.
793
    SK_BindReference,
794
795
    /// Reference binding to a temporary.
796
    SK_BindReferenceToTemporary,
797
798
    /// An optional copy of a temporary object to another
799
    /// temporary object, which is permitted (but not required) by
800
    /// C++98/03 but not C++0x.
801
    SK_ExtraneousCopyToTemporary,
802
803
    /// Direct-initialization from a reference-related object in the
804
    /// final stage of class copy-initialization.
805
    SK_FinalCopy,
806
807
    /// Perform a user-defined conversion, either via a conversion
808
    /// function or via a constructor.
809
    SK_UserConversion,
810
811
    /// Perform a qualification conversion, producing an rvalue.
812
    SK_QualificationConversionRValue,
813
814
    /// Perform a qualification conversion, producing an xvalue.
815
    SK_QualificationConversionXValue,
816
817
    /// Perform a qualification conversion, producing an lvalue.
818
    SK_QualificationConversionLValue,
819
820
    /// Perform a conversion adding _Atomic to a type.
821
    SK_AtomicConversion,
822
823
    /// Perform a load from a glvalue, producing an rvalue.
824
    SK_LValueToRValue,
825
826
    /// Perform an implicit conversion sequence.
827
    SK_ConversionSequence,
828
829
    /// Perform an implicit conversion sequence without narrowing.
830
    SK_ConversionSequenceNoNarrowing,
831
832
    /// Perform list-initialization without a constructor.
833
    SK_ListInitialization,
834
835
    /// Unwrap the single-element initializer list for a reference.
836
    SK_UnwrapInitList,
837
838
    /// Rewrap the single-element initializer list for a reference.
839
    SK_RewrapInitList,
840
841
    /// Perform initialization via a constructor.
842
    SK_ConstructorInitialization,
843
844
    /// Perform initialization via a constructor, taking arguments from
845
    /// a single InitListExpr.
846
    SK_ConstructorInitializationFromList,
847
848
    /// Zero-initialize the object
849
    SK_ZeroInitialization,
850
851
    /// C assignment
852
    SK_CAssignment,
853
854
    /// Initialization by string
855
    SK_StringInit,
856
857
    /// An initialization that "converts" an Objective-C object
858
    /// (not a point to an object) to another Objective-C object type.
859
    SK_ObjCObjectConversion,
860
861
    /// Array indexing for initialization by elementwise copy.
862
    SK_ArrayLoopIndex,
863
864
    /// Array initialization by elementwise copy.
865
    SK_ArrayLoopInit,
866
867
    /// Array initialization (from an array rvalue).
868
    SK_ArrayInit,
869
870
    /// Array initialization (from an array rvalue) as a GNU extension.
871
    SK_GNUArrayInit,
872
873
    /// Array initialization from a parenthesized initializer list.
874
    /// This is a GNU C++ extension.
875
    SK_ParenthesizedArrayInit,
876
877
    /// Pass an object by indirect copy-and-restore.
878
    SK_PassByIndirectCopyRestore,
879
880
    /// Pass an object by indirect restore.
881
    SK_PassByIndirectRestore,
882
883
    /// Produce an Objective-C object pointer.
884
    SK_ProduceObjCObject,
885
886
    /// Construct a std::initializer_list from an initializer list.
887
    SK_StdInitializerList,
888
889
    /// Perform initialization via a constructor taking a single
890
    /// std::initializer_list argument.
891
    SK_StdInitializerListConstructorCall,
892
893
    /// Initialize an OpenCL sampler from an integer.
894
    SK_OCLSamplerInit,
895
896
    /// Initialize queue_t from 0.
897
    SK_OCLZeroQueue,
898
899
    /// Passing zero to a function where OpenCL event_t is expected.
900
    SK_OCLZeroEvent
901
  };
902
903
  /// A single step in the initialization sequence.
904
  class Step {
905
  public:
906
    /// The kind of conversion or initialization step we are taking.
907
    StepKind Kind;
908
909
    // The type that results from this initialization.
910
    QualType Type;
911
912
    struct F {
913
      bool HadMultipleCandidates;
914
      FunctionDecl *Function;
915
      DeclAccessPair FoundDecl;
916
    };
917
918
    union {
919
      /// When Kind == SK_ResolvedOverloadedFunction or Kind ==
920
      /// SK_UserConversion, the function that the expression should be
921
      /// resolved to or the conversion function to call, respectively.
922
      /// When Kind == SK_ConstructorInitialization or SK_ListConstruction,
923
      /// the constructor to be called.
924
      ///
925
      /// Always a FunctionDecl, plus a Boolean flag telling if it was
926
      /// selected from an overloaded set having size greater than 1.
927
      /// For conversion decls, the naming class is the source type.
928
      /// For construct decls, the naming class is the target type.
929
      struct F Function;
930
931
      /// When Kind = SK_ConversionSequence, the implicit conversion
932
      /// sequence.
933
      ImplicitConversionSequence *ICS;
934
935
      /// When Kind = SK_RewrapInitList, the syntactic form of the
936
      /// wrapping list.
937
      InitListExpr *WrappingSyntacticList;
938
    };
939
940
    void Destroy();
941
  };
942
943
private:
944
  /// The kind of initialization sequence computed.
945
  enum SequenceKind SequenceKind;
946
947
  /// Steps taken by this initialization.
948
  SmallVector<Step, 4> Steps;
949
950
public:
951
  /// Describes why initialization failed.
952
  enum FailureKind {
953
    /// Too many initializers provided for a reference.
954
    FK_TooManyInitsForReference,
955
956
    /// Reference initialized from a parenthesized initializer list.
957
    FK_ParenthesizedListInitForReference,
958
959
    /// Array must be initialized with an initializer list.
960
    FK_ArrayNeedsInitList,
961
962
    /// Array must be initialized with an initializer list or a
963
    /// string literal.
964
    FK_ArrayNeedsInitListOrStringLiteral,
965
966
    /// Array must be initialized with an initializer list or a
967
    /// wide string literal.
968
    FK_ArrayNeedsInitListOrWideStringLiteral,
969
970
    /// Initializing a wide char array with narrow string literal.
971
    FK_NarrowStringIntoWideCharArray,
972
973
    /// Initializing char array with wide string literal.
974
    FK_WideStringIntoCharArray,
975
976
    /// Initializing wide char array with incompatible wide string
977
    /// literal.
978
    FK_IncompatWideStringIntoWideChar,
979
980
    /// Initializing char8_t array with plain string literal.
981
    FK_PlainStringIntoUTF8Char,
982
983
    /// Initializing char array with UTF-8 string literal.
984
    FK_UTF8StringIntoPlainChar,
985
986
    /// Array type mismatch.
987
    FK_ArrayTypeMismatch,
988
989
    /// Non-constant array initializer
990
    FK_NonConstantArrayInit,
991
992
    /// Cannot resolve the address of an overloaded function.
993
    FK_AddressOfOverloadFailed,
994
995
    /// Overloading due to reference initialization failed.
996
    FK_ReferenceInitOverloadFailed,
997
998
    /// Non-const lvalue reference binding to a temporary.
999
    FK_NonConstLValueReferenceBindingToTemporary,
1000
1001
    /// Non-const lvalue reference binding to a bit-field.
1002
    FK_NonConstLValueReferenceBindingToBitfield,
1003
1004
    /// Non-const lvalue reference binding to a vector element.
1005
    FK_NonConstLValueReferenceBindingToVectorElement,
1006
1007
    /// Non-const lvalue reference binding to an lvalue of unrelated
1008
    /// type.
1009
    FK_NonConstLValueReferenceBindingToUnrelated,
1010
1011
    /// Rvalue reference binding to an lvalue.
1012
    FK_RValueReferenceBindingToLValue,
1013
1014
    /// Reference binding drops qualifiers.
1015
    FK_ReferenceInitDropsQualifiers,
1016
1017
    /// Reference binding failed.
1018
    FK_ReferenceInitFailed,
1019
1020
    /// Implicit conversion failed.
1021
    FK_ConversionFailed,
1022
1023
    /// Implicit conversion failed.
1024
    FK_ConversionFromPropertyFailed,
1025
1026
    /// Too many initializers for scalar
1027
    FK_TooManyInitsForScalar,
1028
1029
    /// Scalar initialized from a parenthesized initializer list.
1030
    FK_ParenthesizedListInitForScalar,
1031
1032
    /// Reference initialization from an initializer list
1033
    FK_ReferenceBindingToInitList,
1034
1035
    /// Initialization of some unused destination type with an
1036
    /// initializer list.
1037
    FK_InitListBadDestinationType,
1038
1039
    /// Overloading for a user-defined conversion failed.
1040
    FK_UserConversionOverloadFailed,
1041
1042
    /// Overloading for initialization by constructor failed.
1043
    FK_ConstructorOverloadFailed,
1044
1045
    /// Overloading for list-initialization by constructor failed.
1046
    FK_ListConstructorOverloadFailed,
1047
1048
    /// Default-initialization of a 'const' object.
1049
    FK_DefaultInitOfConst,
1050
1051
    /// Initialization of an incomplete type.
1052
    FK_Incomplete,
1053
1054
    /// Variable-length array must not have an initializer.
1055
    FK_VariableLengthArrayHasInitializer,
1056
1057
    /// List initialization failed at some point.
1058
    FK_ListInitializationFailed,
1059
1060
    /// Initializer has a placeholder type which cannot be
1061
    /// resolved by initialization.
1062
    FK_PlaceholderType,
1063
1064
    /// Trying to take the address of a function that doesn't support
1065
    /// having its address taken.
1066
    FK_AddressOfUnaddressableFunction,
1067
1068
    /// List-copy-initialization chose an explicit constructor.
1069
    FK_ExplicitConstructor,
1070
  };
1071
1072
private:
1073
  /// The reason why initialization failed.
1074
  FailureKind Failure;
1075
1076
  /// The failed result of overload resolution.
1077
  OverloadingResult FailedOverloadResult;
1078
1079
  /// The candidate set created when initialization failed.
1080
  OverloadCandidateSet FailedCandidateSet;
1081
1082
  /// The incomplete type that caused a failure.
1083
  QualType FailedIncompleteType;
1084
1085
  /// The fixit that needs to be applied to make this initialization
1086
  /// succeed.
1087
  std::string ZeroInitializationFixit;
1088
  SourceLocation ZeroInitializationFixitLoc;
1089
1090
public:
1091
  /// Call for initializations are invalid but that would be valid
1092
  /// zero initialzations if Fixit was applied.
1093
40
  void SetZeroInitializationFixit(const std::string& Fixit, SourceLocation L) {
1094
40
    ZeroInitializationFixit = Fixit;
1095
40
    ZeroInitializationFixitLoc = L;
1096
40
  }
1097
1098
private:
1099
  /// Prints a follow-up note that highlights the location of
1100
  /// the initialized entity, if it's remote.
1101
  void PrintInitLocationNote(Sema &S, const InitializedEntity &Entity);
1102
1103
public:
1104
  /// Try to perform initialization of the given entity, creating a
1105
  /// record of the steps required to perform the initialization.
1106
  ///
1107
  /// The generated initialization sequence will either contain enough
1108
  /// information to diagnose
1109
  ///
1110
  /// \param S the semantic analysis object.
1111
  ///
1112
  /// \param Entity the entity being initialized.
1113
  ///
1114
  /// \param Kind the kind of initialization being performed.
1115
  ///
1116
  /// \param Args the argument(s) provided for initialization.
1117
  ///
1118
  /// \param TopLevelOfInitList true if we are initializing from an expression
1119
  ///        at the top level inside an initializer list. This disallows
1120
  ///        narrowing conversions in C++11 onwards.
1121
  /// \param TreatUnavailableAsInvalid true if we want to treat unavailable
1122
  ///        as invalid.
1123
  InitializationSequence(Sema &S,
1124
                         const InitializedEntity &Entity,
1125
                         const InitializationKind &Kind,
1126
                         MultiExprArg Args,
1127
                         bool TopLevelOfInitList = false,
1128
                         bool TreatUnavailableAsInvalid = true);
1129
  void InitializeFrom(Sema &S, const InitializedEntity &Entity,
1130
                      const InitializationKind &Kind, MultiExprArg Args,
1131
                      bool TopLevelOfInitList, bool TreatUnavailableAsInvalid);
1132
1133
  ~InitializationSequence();
1134
1135
  /// Perform the actual initialization of the given entity based on
1136
  /// the computed initialization sequence.
1137
  ///
1138
  /// \param S the semantic analysis object.
1139
  ///
1140
  /// \param Entity the entity being initialized.
1141
  ///
1142
  /// \param Kind the kind of initialization being performed.
1143
  ///
1144
  /// \param Args the argument(s) provided for initialization, ownership of
1145
  /// which is transferred into the routine.
1146
  ///
1147
  /// \param ResultType if non-NULL, will be set to the type of the
1148
  /// initialized object, which is the type of the declaration in most
1149
  /// cases. However, when the initialized object is a variable of
1150
  /// incomplete array type and the initializer is an initializer
1151
  /// list, this type will be set to the completed array type.
1152
  ///
1153
  /// \returns an expression that performs the actual object initialization, if
1154
  /// the initialization is well-formed. Otherwise, emits diagnostics
1155
  /// and returns an invalid expression.
1156
  ExprResult Perform(Sema &S,
1157
                     const InitializedEntity &Entity,
1158
                     const InitializationKind &Kind,
1159
                     MultiExprArg Args,
1160
                     QualType *ResultType = nullptr);
1161
1162
  /// Diagnose an potentially-invalid initialization sequence.
1163
  ///
1164
  /// \returns true if the initialization sequence was ill-formed,
1165
  /// false otherwise.
1166
  bool Diagnose(Sema &S,
1167
                const InitializedEntity &Entity,
1168
                const InitializationKind &Kind,
1169
                ArrayRef<Expr *> Args);
1170
1171
  /// Determine the kind of initialization sequence computed.
1172
12.4M
  enum SequenceKind getKind() const { return SequenceKind; }
1173
1174
  /// Set the kind of sequence computed.
1175
13.0M
  void setSequenceKind(enum SequenceKind SK) { SequenceKind = SK; }
1176
1177
  /// Determine whether the initialization sequence is valid.
1178
1.22M
  explicit operator bool() const { return !Failed(); }
1179
1180
  /// Determine whether the initialization sequence is invalid.
1181
15.1M
  bool Failed() const { return SequenceKind == FailedSequence; }
1182
1183
  using step_iterator = SmallVectorImpl<Step>::const_iterator;
1184
1185
11.4M
  step_iterator step_begin() const { return Steps.begin(); }
1186
11.4M
  step_iterator step_end()   const { return Steps.end(); }
1187
1188
  using step_range = llvm::iterator_range<step_iterator>;
1189
1190
13.6k
  step_range steps() const { return {step_begin(), step_end()}; }
1191
1192
  /// Determine whether this initialization is a direct reference
1193
  /// binding (C++ [dcl.init.ref]).
1194
  bool isDirectReferenceBinding() const;
1195
1196
  /// Determine whether this initialization failed due to an ambiguity.
1197
  bool isAmbiguous() const;
1198
1199
  /// Determine whether this initialization is direct call to a
1200
  /// constructor.
1201
  bool isConstructorInitialization() const;
1202
1203
  /// Returns whether the last step in this initialization sequence is a
1204
  /// narrowing conversion, defined by C++0x [dcl.init.list]p7.
1205
  ///
1206
  /// If this function returns true, *isInitializerConstant will be set to
1207
  /// describe whether *Initializer was a constant expression.  If
1208
  /// *isInitializerConstant is set to true, *ConstantValue will be set to the
1209
  /// evaluated value of *Initializer.
1210
  bool endsWithNarrowing(ASTContext &Ctx, const Expr *Initializer,
1211
                         bool *isInitializerConstant,
1212
                         APValue *ConstantValue) const;
1213
1214
  /// Add a new step in the initialization that resolves the address
1215
  /// of an overloaded function to a specific function declaration.
1216
  ///
1217
  /// \param Function the function to which the overloaded function reference
1218
  /// resolves.
1219
  void AddAddressOverloadResolutionStep(FunctionDecl *Function,
1220
                                        DeclAccessPair Found,
1221
                                        bool HadMultipleCandidates);
1222
1223
  /// Add a new step in the initialization that performs a derived-to-
1224
  /// base cast.
1225
  ///
1226
  /// \param BaseType the base type to which we will be casting.
1227
  ///
1228
  /// \param Category Indicates whether the result will be treated as an
1229
  /// rvalue, an xvalue, or an lvalue.
1230
  void AddDerivedToBaseCastStep(QualType BaseType,
1231
                                ExprValueKind Category);
1232
1233
  /// Add a new step binding a reference to an object.
1234
  ///
1235
  /// \param BindingTemporary True if we are binding a reference to a temporary
1236
  /// object (thereby extending its lifetime); false if we are binding to an
1237
  /// lvalue or an lvalue treated as an rvalue.
1238
  void AddReferenceBindingStep(QualType T, bool BindingTemporary);
1239
1240
  /// Add a new step that makes an extraneous copy of the input
1241
  /// to a temporary of the same class type.
1242
  ///
1243
  /// This extraneous copy only occurs during reference binding in
1244
  /// C++98/03, where we are permitted (but not required) to introduce
1245
  /// an extra copy. At a bare minimum, we must check that we could
1246
  /// call the copy constructor, and produce a diagnostic if the copy
1247
  /// constructor is inaccessible or no copy constructor matches.
1248
  //
1249
  /// \param T The type of the temporary being created.
1250
  void AddExtraneousCopyToTemporary(QualType T);
1251
1252
  /// Add a new step that makes a copy of the input to an object of
1253
  /// the given type, as the final step in class copy-initialization.
1254
  void AddFinalCopy(QualType T);
1255
1256
  /// Add a new step invoking a conversion function, which is either
1257
  /// a constructor or a conversion function.
1258
  void AddUserConversionStep(FunctionDecl *Function,
1259
                             DeclAccessPair FoundDecl,
1260
                             QualType T,
1261
                             bool HadMultipleCandidates);
1262
1263
  /// Add a new step that performs a qualification conversion to the
1264
  /// given type.
1265
  void AddQualificationConversionStep(QualType Ty,
1266
                                     ExprValueKind Category);
1267
1268
  /// Add a new step that performs conversion from non-atomic to atomic
1269
  /// type.
1270
  void AddAtomicConversionStep(QualType Ty);
1271
1272
  /// Add a new step that performs a load of the given type.
1273
  ///
1274
  /// Although the term "LValueToRValue" is conventional, this applies to both
1275
  /// lvalues and xvalues.
1276
  void AddLValueToRValueStep(QualType Ty);
1277
1278
  /// Add a new step that applies an implicit conversion sequence.
1279
  void AddConversionSequenceStep(const ImplicitConversionSequence &ICS,
1280
                                 QualType T, bool TopLevelOfInitList = false);
1281
1282
  /// Add a list-initialization step.
1283
  void AddListInitializationStep(QualType T);
1284
1285
  /// Add a constructor-initialization step.
1286
  ///
1287
  /// \param FromInitList The constructor call is syntactically an initializer
1288
  /// list.
1289
  /// \param AsInitList The constructor is called as an init list constructor.
1290
  void AddConstructorInitializationStep(DeclAccessPair FoundDecl,
1291
                                        CXXConstructorDecl *Constructor,
1292
                                        QualType T,
1293
                                        bool HadMultipleCandidates,
1294
                                        bool FromInitList, bool AsInitList);
1295
1296
  /// Add a zero-initialization step.
1297
  void AddZeroInitializationStep(QualType T);
1298
1299
  /// Add a C assignment step.
1300
  //
1301
  // FIXME: It isn't clear whether this should ever be needed;
1302
  // ideally, we would handle everything needed in C in the common
1303
  // path. However, that isn't the case yet.
1304
  void AddCAssignmentStep(QualType T);
1305
1306
  /// Add a string init step.
1307
  void AddStringInitStep(QualType T);
1308
1309
  /// Add an Objective-C object conversion step, which is
1310
  /// always a no-op.
1311
  void AddObjCObjectConversionStep(QualType T);
1312
1313
  /// Add an array initialization loop step.
1314
  void AddArrayInitLoopStep(QualType T, QualType EltTy);
1315
1316
  /// Add an array initialization step.
1317
  void AddArrayInitStep(QualType T, bool IsGNUExtension);
1318
1319
  /// Add a parenthesized array initialization step.
1320
  void AddParenthesizedArrayInitStep(QualType T);
1321
1322
  /// Add a step to pass an object by indirect copy-restore.
1323
  void AddPassByIndirectCopyRestoreStep(QualType T, bool shouldCopy);
1324
1325
  /// Add a step to "produce" an Objective-C object (by
1326
  /// retaining it).
1327
  void AddProduceObjCObjectStep(QualType T);
1328
1329
  /// Add a step to construct a std::initializer_list object from an
1330
  /// initializer list.
1331
  void AddStdInitializerListConstructionStep(QualType T);
1332
1333
  /// Add a step to initialize an OpenCL sampler from an integer
1334
  /// constant.
1335
  void AddOCLSamplerInitStep(QualType T);
1336
1337
  /// Add a step to initialize an OpenCL event_t from a NULL
1338
  /// constant.
1339
  void AddOCLZeroEventStep(QualType T);
1340
1341
  /// Add a step to initialize an OpenCL queue_t from 0.
1342
  void AddOCLZeroQueueStep(QualType T);
1343
1344
  /// Add steps to unwrap a initializer list for a reference around a
1345
  /// single element and rewrap it at the end.
1346
  void RewrapReferenceInitList(QualType T, InitListExpr *Syntactic);
1347
1348
  /// Note that this initialization sequence failed.
1349
112k
  void SetFailed(FailureKind Failure) {
1350
112k
    SequenceKind = FailedSequence;
1351
112k
    this->Failure = Failure;
1352
112k
    assert((Failure != FK_Incomplete || !FailedIncompleteType.isNull()) &&
1353
112k
           "Incomplete type failure requires a type!");
1354
112k
  }
1355
1356
  /// Note that this initialization sequence failed due to failed
1357
  /// overload resolution.
1358
  void SetOverloadFailure(FailureKind Failure, OverloadingResult Result);
1359
1360
  /// Retrieve a reference to the candidate set when overload
1361
  /// resolution fails.
1362
401k
  OverloadCandidateSet &getFailedCandidateSet() {
1363
401k
    return FailedCandidateSet;
1364
401k
  }
1365
1366
  /// Get the overloading result, for when the initialization
1367
  /// sequence failed due to a bad overload.
1368
38
  OverloadingResult getFailedOverloadResult() const {
1369
38
    return FailedOverloadResult;
1370
38
  }
1371
1372
  /// Note that this initialization sequence failed due to an
1373
  /// incomplete type.
1374
50
  void setIncompleteTypeFailure(QualType IncompleteType) {
1375
50
    FailedIncompleteType = IncompleteType;
1376
50
    SetFailed(FK_Incomplete);
1377
50
  }
1378
1379
  /// Determine why initialization failed.
1380
415
  FailureKind getFailureKind() const {
1381
415
    assert(Failed() && "Not an initialization failure!");
1382
415
    return Failure;
1383
415
  }
1384
1385
  /// Dump a representation of this initialization sequence to
1386
  /// the given stream, for debugging purposes.
1387
  void dump(raw_ostream &OS) const;
1388
1389
  /// Dump a representation of this initialization sequence to
1390
  /// standard error, for debugging purposes.
1391
  void dump() const;
1392
};
1393
1394
} // namespace clang
1395
1396
#endif // LLVM_CLANG_SEMA_INITIALIZATION_H