Coverage Report

Created: 2019-03-22 08:08

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