Coverage Report

Created: 2018-07-21 08:31

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