/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/include/clang/Sema/Overload.h
Line | Count | Source (jump to first uncovered line) |
1 | | //===- Overload.h - C++ Overloading -----------------------------*- 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 defines the data structures and types used in C++ |
10 | | // overload resolution. |
11 | | // |
12 | | //===----------------------------------------------------------------------===// |
13 | | |
14 | | #ifndef LLVM_CLANG_SEMA_OVERLOAD_H |
15 | | #define LLVM_CLANG_SEMA_OVERLOAD_H |
16 | | |
17 | | #include "clang/AST/Decl.h" |
18 | | #include "clang/AST/DeclAccessPair.h" |
19 | | #include "clang/AST/DeclBase.h" |
20 | | #include "clang/AST/DeclCXX.h" |
21 | | #include "clang/AST/DeclTemplate.h" |
22 | | #include "clang/AST/Expr.h" |
23 | | #include "clang/AST/Type.h" |
24 | | #include "clang/Basic/LLVM.h" |
25 | | #include "clang/Basic/SourceLocation.h" |
26 | | #include "clang/Sema/SemaFixItUtils.h" |
27 | | #include "clang/Sema/TemplateDeduction.h" |
28 | | #include "llvm/ADT/ArrayRef.h" |
29 | | #include "llvm/ADT/None.h" |
30 | | #include "llvm/ADT/STLExtras.h" |
31 | | #include "llvm/ADT/SmallPtrSet.h" |
32 | | #include "llvm/ADT/SmallVector.h" |
33 | | #include "llvm/ADT/StringRef.h" |
34 | | #include "llvm/Support/AlignOf.h" |
35 | | #include "llvm/Support/Allocator.h" |
36 | | #include "llvm/Support/Casting.h" |
37 | | #include "llvm/Support/ErrorHandling.h" |
38 | | #include <cassert> |
39 | | #include <cstddef> |
40 | | #include <cstdint> |
41 | | #include <utility> |
42 | | |
43 | | namespace clang { |
44 | | |
45 | | class APValue; |
46 | | class ASTContext; |
47 | | class Sema; |
48 | | |
49 | | /// OverloadingResult - Capture the result of performing overload |
50 | | /// resolution. |
51 | | enum OverloadingResult { |
52 | | /// Overload resolution succeeded. |
53 | | OR_Success, |
54 | | |
55 | | /// No viable function found. |
56 | | OR_No_Viable_Function, |
57 | | |
58 | | /// Ambiguous candidates found. |
59 | | OR_Ambiguous, |
60 | | |
61 | | /// Succeeded, but refers to a deleted function. |
62 | | OR_Deleted |
63 | | }; |
64 | | |
65 | | enum OverloadCandidateDisplayKind { |
66 | | /// Requests that all candidates be shown. Viable candidates will |
67 | | /// be printed first. |
68 | | OCD_AllCandidates, |
69 | | |
70 | | /// Requests that only viable candidates be shown. |
71 | | OCD_ViableCandidates, |
72 | | |
73 | | /// Requests that only tied-for-best candidates be shown. |
74 | | OCD_AmbiguousCandidates |
75 | | }; |
76 | | |
77 | | /// The parameter ordering that will be used for the candidate. This is |
78 | | /// used to represent C++20 binary operator rewrites that reverse the order |
79 | | /// of the arguments. If the parameter ordering is Reversed, the Args list is |
80 | | /// reversed (but obviously the ParamDecls for the function are not). |
81 | | /// |
82 | | /// After forming an OverloadCandidate with reversed parameters, the list |
83 | | /// of conversions will (as always) be indexed by argument, so will be |
84 | | /// in reverse parameter order. |
85 | | enum class OverloadCandidateParamOrder : char { Normal, Reversed }; |
86 | | |
87 | | /// The kinds of rewrite we perform on overload candidates. Note that the |
88 | | /// values here are chosen to serve as both bitflags and as a rank (lower |
89 | | /// values are preferred by overload resolution). |
90 | | enum OverloadCandidateRewriteKind : unsigned { |
91 | | /// Candidate is not a rewritten candidate. |
92 | | CRK_None = 0x0, |
93 | | |
94 | | /// Candidate is a rewritten candidate with a different operator name. |
95 | | CRK_DifferentOperator = 0x1, |
96 | | |
97 | | /// Candidate is a rewritten candidate with a reversed order of parameters. |
98 | | CRK_Reversed = 0x2, |
99 | | }; |
100 | | |
101 | | /// ImplicitConversionKind - The kind of implicit conversion used to |
102 | | /// convert an argument to a parameter's type. The enumerator values |
103 | | /// match with the table titled 'Conversions' in [over.ics.scs] and are listed |
104 | | /// such that better conversion kinds have smaller values. |
105 | | enum ImplicitConversionKind { |
106 | | /// Identity conversion (no conversion) |
107 | | ICK_Identity = 0, |
108 | | |
109 | | /// Lvalue-to-rvalue conversion (C++ [conv.lval]) |
110 | | ICK_Lvalue_To_Rvalue, |
111 | | |
112 | | /// Array-to-pointer conversion (C++ [conv.array]) |
113 | | ICK_Array_To_Pointer, |
114 | | |
115 | | /// Function-to-pointer (C++ [conv.array]) |
116 | | ICK_Function_To_Pointer, |
117 | | |
118 | | /// Function pointer conversion (C++17 [conv.fctptr]) |
119 | | ICK_Function_Conversion, |
120 | | |
121 | | /// Qualification conversions (C++ [conv.qual]) |
122 | | ICK_Qualification, |
123 | | |
124 | | /// Integral promotions (C++ [conv.prom]) |
125 | | ICK_Integral_Promotion, |
126 | | |
127 | | /// Floating point promotions (C++ [conv.fpprom]) |
128 | | ICK_Floating_Promotion, |
129 | | |
130 | | /// Complex promotions (Clang extension) |
131 | | ICK_Complex_Promotion, |
132 | | |
133 | | /// Integral conversions (C++ [conv.integral]) |
134 | | ICK_Integral_Conversion, |
135 | | |
136 | | /// Floating point conversions (C++ [conv.double] |
137 | | ICK_Floating_Conversion, |
138 | | |
139 | | /// Complex conversions (C99 6.3.1.6) |
140 | | ICK_Complex_Conversion, |
141 | | |
142 | | /// Floating-integral conversions (C++ [conv.fpint]) |
143 | | ICK_Floating_Integral, |
144 | | |
145 | | /// Pointer conversions (C++ [conv.ptr]) |
146 | | ICK_Pointer_Conversion, |
147 | | |
148 | | /// Pointer-to-member conversions (C++ [conv.mem]) |
149 | | ICK_Pointer_Member, |
150 | | |
151 | | /// Boolean conversions (C++ [conv.bool]) |
152 | | ICK_Boolean_Conversion, |
153 | | |
154 | | /// Conversions between compatible types in C99 |
155 | | ICK_Compatible_Conversion, |
156 | | |
157 | | /// Derived-to-base (C++ [over.best.ics]) |
158 | | ICK_Derived_To_Base, |
159 | | |
160 | | /// Vector conversions |
161 | | ICK_Vector_Conversion, |
162 | | |
163 | | /// Arm SVE Vector conversions |
164 | | ICK_SVE_Vector_Conversion, |
165 | | |
166 | | /// A vector splat from an arithmetic type |
167 | | ICK_Vector_Splat, |
168 | | |
169 | | /// Complex-real conversions (C99 6.3.1.7) |
170 | | ICK_Complex_Real, |
171 | | |
172 | | /// Block Pointer conversions |
173 | | ICK_Block_Pointer_Conversion, |
174 | | |
175 | | /// Transparent Union Conversions |
176 | | ICK_TransparentUnionConversion, |
177 | | |
178 | | /// Objective-C ARC writeback conversion |
179 | | ICK_Writeback_Conversion, |
180 | | |
181 | | /// Zero constant to event (OpenCL1.2 6.12.10) |
182 | | ICK_Zero_Event_Conversion, |
183 | | |
184 | | /// Zero constant to queue |
185 | | ICK_Zero_Queue_Conversion, |
186 | | |
187 | | /// Conversions allowed in C, but not C++ |
188 | | ICK_C_Only_Conversion, |
189 | | |
190 | | /// C-only conversion between pointers with incompatible types |
191 | | ICK_Incompatible_Pointer_Conversion, |
192 | | |
193 | | /// The number of conversion kinds |
194 | | ICK_Num_Conversion_Kinds, |
195 | | }; |
196 | | |
197 | | /// ImplicitConversionRank - The rank of an implicit conversion |
198 | | /// kind. The enumerator values match with Table 9 of (C++ |
199 | | /// 13.3.3.1.1) and are listed such that better conversion ranks |
200 | | /// have smaller values. |
201 | | enum ImplicitConversionRank { |
202 | | /// Exact Match |
203 | | ICR_Exact_Match = 0, |
204 | | |
205 | | /// Promotion |
206 | | ICR_Promotion, |
207 | | |
208 | | /// Conversion |
209 | | ICR_Conversion, |
210 | | |
211 | | /// OpenCL Scalar Widening |
212 | | ICR_OCL_Scalar_Widening, |
213 | | |
214 | | /// Complex <-> Real conversion |
215 | | ICR_Complex_Real_Conversion, |
216 | | |
217 | | /// ObjC ARC writeback conversion |
218 | | ICR_Writeback_Conversion, |
219 | | |
220 | | /// Conversion only allowed in the C standard (e.g. void* to char*). |
221 | | ICR_C_Conversion, |
222 | | |
223 | | /// Conversion not allowed by the C standard, but that we accept as an |
224 | | /// extension anyway. |
225 | | ICR_C_Conversion_Extension |
226 | | }; |
227 | | |
228 | | ImplicitConversionRank GetConversionRank(ImplicitConversionKind Kind); |
229 | | |
230 | | /// NarrowingKind - The kind of narrowing conversion being performed by a |
231 | | /// standard conversion sequence according to C++11 [dcl.init.list]p7. |
232 | | enum NarrowingKind { |
233 | | /// Not a narrowing conversion. |
234 | | NK_Not_Narrowing, |
235 | | |
236 | | /// A narrowing conversion by virtue of the source and destination types. |
237 | | NK_Type_Narrowing, |
238 | | |
239 | | /// A narrowing conversion, because a constant expression got narrowed. |
240 | | NK_Constant_Narrowing, |
241 | | |
242 | | /// A narrowing conversion, because a non-constant-expression variable might |
243 | | /// have got narrowed. |
244 | | NK_Variable_Narrowing, |
245 | | |
246 | | /// Cannot tell whether this is a narrowing conversion because the |
247 | | /// expression is value-dependent. |
248 | | NK_Dependent_Narrowing, |
249 | | }; |
250 | | |
251 | | /// StandardConversionSequence - represents a standard conversion |
252 | | /// sequence (C++ 13.3.3.1.1). A standard conversion sequence |
253 | | /// contains between zero and three conversions. If a particular |
254 | | /// conversion is not needed, it will be set to the identity conversion |
255 | | /// (ICK_Identity). Note that the three conversions are |
256 | | /// specified as separate members (rather than in an array) so that |
257 | | /// we can keep the size of a standard conversion sequence to a |
258 | | /// single word. |
259 | | class StandardConversionSequence { |
260 | | public: |
261 | | /// First -- The first conversion can be an lvalue-to-rvalue |
262 | | /// conversion, array-to-pointer conversion, or |
263 | | /// function-to-pointer conversion. |
264 | | ImplicitConversionKind First : 8; |
265 | | |
266 | | /// Second - The second conversion can be an integral promotion, |
267 | | /// floating point promotion, integral conversion, floating point |
268 | | /// conversion, floating-integral conversion, pointer conversion, |
269 | | /// pointer-to-member conversion, or boolean conversion. |
270 | | ImplicitConversionKind Second : 8; |
271 | | |
272 | | /// Third - The third conversion can be a qualification conversion |
273 | | /// or a function conversion. |
274 | | ImplicitConversionKind Third : 8; |
275 | | |
276 | | /// Whether this is the deprecated conversion of a |
277 | | /// string literal to a pointer to non-const character data |
278 | | /// (C++ 4.2p2). |
279 | | unsigned DeprecatedStringLiteralToCharPtr : 1; |
280 | | |
281 | | /// Whether the qualification conversion involves a change in the |
282 | | /// Objective-C lifetime (for automatic reference counting). |
283 | | unsigned QualificationIncludesObjCLifetime : 1; |
284 | | |
285 | | /// IncompatibleObjC - Whether this is an Objective-C conversion |
286 | | /// that we should warn about (if we actually use it). |
287 | | unsigned IncompatibleObjC : 1; |
288 | | |
289 | | /// ReferenceBinding - True when this is a reference binding |
290 | | /// (C++ [over.ics.ref]). |
291 | | unsigned ReferenceBinding : 1; |
292 | | |
293 | | /// DirectBinding - True when this is a reference binding that is a |
294 | | /// direct binding (C++ [dcl.init.ref]). |
295 | | unsigned DirectBinding : 1; |
296 | | |
297 | | /// Whether this is an lvalue reference binding (otherwise, it's |
298 | | /// an rvalue reference binding). |
299 | | unsigned IsLvalueReference : 1; |
300 | | |
301 | | /// Whether we're binding to a function lvalue. |
302 | | unsigned BindsToFunctionLvalue : 1; |
303 | | |
304 | | /// Whether we're binding to an rvalue. |
305 | | unsigned BindsToRvalue : 1; |
306 | | |
307 | | /// Whether this binds an implicit object argument to a |
308 | | /// non-static member function without a ref-qualifier. |
309 | | unsigned BindsImplicitObjectArgumentWithoutRefQualifier : 1; |
310 | | |
311 | | /// Whether this binds a reference to an object with a different |
312 | | /// Objective-C lifetime qualifier. |
313 | | unsigned ObjCLifetimeConversionBinding : 1; |
314 | | |
315 | | /// FromType - The type that this conversion is converting |
316 | | /// from. This is an opaque pointer that can be translated into a |
317 | | /// QualType. |
318 | | void *FromTypePtr; |
319 | | |
320 | | /// ToType - The types that this conversion is converting to in |
321 | | /// each step. This is an opaque pointer that can be translated |
322 | | /// into a QualType. |
323 | | void *ToTypePtrs[3]; |
324 | | |
325 | | /// CopyConstructor - The copy constructor that is used to perform |
326 | | /// this conversion, when the conversion is actually just the |
327 | | /// initialization of an object via copy constructor. Such |
328 | | /// conversions are either identity conversions or derived-to-base |
329 | | /// conversions. |
330 | | CXXConstructorDecl *CopyConstructor; |
331 | | DeclAccessPair FoundCopyConstructor; |
332 | | |
333 | 25.4M | void setFromType(QualType T) { FromTypePtr = T.getAsOpaquePtr(); } |
334 | | |
335 | 68.9M | void setToType(unsigned Idx, QualType T) { |
336 | 68.9M | assert(Idx < 3 && "To type index is out of range"); |
337 | 68.9M | ToTypePtrs[Idx] = T.getAsOpaquePtr(); |
338 | 68.9M | } |
339 | | |
340 | 1.64M | void setAllToTypes(QualType T) { |
341 | 1.64M | ToTypePtrs[0] = T.getAsOpaquePtr(); |
342 | 1.64M | ToTypePtrs[1] = ToTypePtrs[0]; |
343 | 1.64M | ToTypePtrs[2] = ToTypePtrs[0]; |
344 | 1.64M | } |
345 | | |
346 | 12.3M | QualType getFromType() const { |
347 | 12.3M | return QualType::getFromOpaquePtr(FromTypePtr); |
348 | 12.3M | } |
349 | | |
350 | 31.1M | QualType getToType(unsigned Idx) const { |
351 | 31.1M | assert(Idx < 3 && "To type index is out of range"); |
352 | 31.1M | return QualType::getFromOpaquePtr(ToTypePtrs[Idx]); |
353 | 31.1M | } |
354 | | |
355 | | void setAsIdentityConversion(); |
356 | | |
357 | 41.8M | bool isIdentityConversion() const { |
358 | 41.8M | return Second == ICK_Identity && Third == ICK_Identity15.2M ; |
359 | 41.8M | } |
360 | | |
361 | | ImplicitConversionRank getRank() const; |
362 | | NarrowingKind |
363 | | getNarrowingKind(ASTContext &Context, const Expr *Converted, |
364 | | APValue &ConstantValue, QualType &ConstantType, |
365 | | bool IgnoreFloatToIntegralConversion = false) const; |
366 | | bool isPointerConversionToBool() const; |
367 | | bool isPointerConversionToVoidPointer(ASTContext& Context) const; |
368 | | void dump() const; |
369 | | }; |
370 | | |
371 | | /// UserDefinedConversionSequence - Represents a user-defined |
372 | | /// conversion sequence (C++ 13.3.3.1.2). |
373 | | struct UserDefinedConversionSequence { |
374 | | /// Represents the standard conversion that occurs before |
375 | | /// the actual user-defined conversion. |
376 | | /// |
377 | | /// C++11 13.3.3.1.2p1: |
378 | | /// If the user-defined conversion is specified by a constructor |
379 | | /// (12.3.1), the initial standard conversion sequence converts |
380 | | /// the source type to the type required by the argument of the |
381 | | /// constructor. If the user-defined conversion is specified by |
382 | | /// a conversion function (12.3.2), the initial standard |
383 | | /// conversion sequence converts the source type to the implicit |
384 | | /// object parameter of the conversion function. |
385 | | StandardConversionSequence Before; |
386 | | |
387 | | /// EllipsisConversion - When this is true, it means user-defined |
388 | | /// conversion sequence starts with a ... (ellipsis) conversion, instead of |
389 | | /// a standard conversion. In this case, 'Before' field must be ignored. |
390 | | // FIXME. I much rather put this as the first field. But there seems to be |
391 | | // a gcc code gen. bug which causes a crash in a test. Putting it here seems |
392 | | // to work around the crash. |
393 | | bool EllipsisConversion : 1; |
394 | | |
395 | | /// HadMultipleCandidates - When this is true, it means that the |
396 | | /// conversion function was resolved from an overloaded set having |
397 | | /// size greater than 1. |
398 | | bool HadMultipleCandidates : 1; |
399 | | |
400 | | /// After - Represents the standard conversion that occurs after |
401 | | /// the actual user-defined conversion. |
402 | | StandardConversionSequence After; |
403 | | |
404 | | /// ConversionFunction - The function that will perform the |
405 | | /// user-defined conversion. Null if the conversion is an |
406 | | /// aggregate initialization from an initializer list. |
407 | | FunctionDecl* ConversionFunction; |
408 | | |
409 | | /// The declaration that we found via name lookup, which might be |
410 | | /// the same as \c ConversionFunction or it might be a using declaration |
411 | | /// that refers to \c ConversionFunction. |
412 | | DeclAccessPair FoundConversionFunction; |
413 | | |
414 | | void dump() const; |
415 | | }; |
416 | | |
417 | | /// Represents an ambiguous user-defined conversion sequence. |
418 | | struct AmbiguousConversionSequence { |
419 | | using ConversionSet = |
420 | | SmallVector<std::pair<NamedDecl *, FunctionDecl *>, 4>; |
421 | | |
422 | | void *FromTypePtr; |
423 | | void *ToTypePtr; |
424 | | char Buffer[sizeof(ConversionSet)]; |
425 | | |
426 | 11 | QualType getFromType() const { |
427 | 11 | return QualType::getFromOpaquePtr(FromTypePtr); |
428 | 11 | } |
429 | | |
430 | 11 | QualType getToType() const { |
431 | 11 | return QualType::getFromOpaquePtr(ToTypePtr); |
432 | 11 | } |
433 | | |
434 | 7.98k | void setFromType(QualType T) { FromTypePtr = T.getAsOpaquePtr(); } |
435 | 7.98k | void setToType(QualType T) { ToTypePtr = T.getAsOpaquePtr(); } |
436 | | |
437 | 47.9k | ConversionSet &conversions() { |
438 | 47.9k | return *reinterpret_cast<ConversionSet*>(Buffer); |
439 | 47.9k | } |
440 | | |
441 | 8.03k | const ConversionSet &conversions() const { |
442 | 8.03k | return *reinterpret_cast<const ConversionSet*>(Buffer); |
443 | 8.03k | } |
444 | | |
445 | 15.9k | void addConversion(NamedDecl *Found, FunctionDecl *D) { |
446 | 15.9k | conversions().push_back(std::make_pair(Found, D)); |
447 | 15.9k | } |
448 | | |
449 | | using iterator = ConversionSet::iterator; |
450 | | |
451 | 0 | iterator begin() { return conversions().begin(); } |
452 | 0 | iterator end() { return conversions().end(); } |
453 | | |
454 | | using const_iterator = ConversionSet::const_iterator; |
455 | | |
456 | 11 | const_iterator begin() const { return conversions().begin(); } |
457 | 11 | const_iterator end() const { return conversions().end(); } |
458 | | |
459 | | void construct(); |
460 | | void destruct(); |
461 | | void copyFrom(const AmbiguousConversionSequence &); |
462 | | }; |
463 | | |
464 | | /// BadConversionSequence - Records information about an invalid |
465 | | /// conversion sequence. |
466 | | struct BadConversionSequence { |
467 | | enum FailureKind { |
468 | | no_conversion, |
469 | | unrelated_class, |
470 | | bad_qualifiers, |
471 | | lvalue_ref_to_rvalue, |
472 | | rvalue_ref_to_lvalue |
473 | | }; |
474 | | |
475 | | // This can be null, e.g. for implicit object arguments. |
476 | | Expr *FromExpr; |
477 | | |
478 | | FailureKind Kind; |
479 | | |
480 | | private: |
481 | | // The type we're converting from (an opaque QualType). |
482 | | void *FromTy; |
483 | | |
484 | | // The type we're converting to (an opaque QualType). |
485 | | void *ToTy; |
486 | | |
487 | | public: |
488 | 6.13M | void init(FailureKind K, Expr *From, QualType To) { |
489 | 6.13M | init(K, From->getType(), To); |
490 | 6.13M | FromExpr = From; |
491 | 6.13M | } |
492 | | |
493 | 6.14M | void init(FailureKind K, QualType From, QualType To) { |
494 | 6.14M | Kind = K; |
495 | 6.14M | FromExpr = nullptr; |
496 | 6.14M | setFromType(From); |
497 | 6.14M | setToType(To); |
498 | 6.14M | } |
499 | | |
500 | 21.5k | QualType getFromType() const { return QualType::getFromOpaquePtr(FromTy); } |
501 | 21.5k | QualType getToType() const { return QualType::getFromOpaquePtr(ToTy); } |
502 | | |
503 | 0 | void setFromExpr(Expr *E) { |
504 | 0 | FromExpr = E; |
505 | 0 | setFromType(E->getType()); |
506 | 0 | } |
507 | | |
508 | 6.14M | void setFromType(QualType T) { FromTy = T.getAsOpaquePtr(); } |
509 | 6.14M | void setToType(QualType T) { ToTy = T.getAsOpaquePtr(); } |
510 | | }; |
511 | | |
512 | | /// ImplicitConversionSequence - Represents an implicit conversion |
513 | | /// sequence, which may be a standard conversion sequence |
514 | | /// (C++ 13.3.3.1.1), user-defined conversion sequence (C++ 13.3.3.1.2), |
515 | | /// or an ellipsis conversion sequence (C++ 13.3.3.1.3). |
516 | | class ImplicitConversionSequence { |
517 | | public: |
518 | | /// Kind - The kind of implicit conversion sequence. BadConversion |
519 | | /// specifies that there is no conversion from the source type to |
520 | | /// the target type. AmbiguousConversion represents the unique |
521 | | /// ambiguous conversion (C++0x [over.best.ics]p10). |
522 | | enum Kind { |
523 | | StandardConversion = 0, |
524 | | UserDefinedConversion, |
525 | | AmbiguousConversion, |
526 | | EllipsisConversion, |
527 | | BadConversion |
528 | | }; |
529 | | |
530 | | private: |
531 | | enum { |
532 | | Uninitialized = BadConversion + 1 |
533 | | }; |
534 | | |
535 | | /// ConversionKind - The kind of implicit conversion sequence. |
536 | | unsigned ConversionKind : 30; |
537 | | |
538 | | /// Whether the target is really a std::initializer_list, and the |
539 | | /// sequence only represents the worst element conversion. |
540 | | unsigned StdInitializerListElement : 1; |
541 | | |
542 | 29.9M | void setKind(Kind K) { |
543 | 29.9M | destruct(); |
544 | 29.9M | ConversionKind = K; |
545 | 29.9M | } |
546 | | |
547 | 127M | void destruct() { |
548 | 127M | if (ConversionKind == AmbiguousConversion) Ambiguous.destruct()16.0k ; |
549 | 127M | } |
550 | | |
551 | | public: |
552 | | union { |
553 | | /// When ConversionKind == StandardConversion, provides the |
554 | | /// details of the standard conversion sequence. |
555 | | StandardConversionSequence Standard; |
556 | | |
557 | | /// When ConversionKind == UserDefinedConversion, provides the |
558 | | /// details of the user-defined conversion sequence. |
559 | | UserDefinedConversionSequence UserDefined; |
560 | | |
561 | | /// When ConversionKind == AmbiguousConversion, provides the |
562 | | /// details of the ambiguous conversion. |
563 | | AmbiguousConversionSequence Ambiguous; |
564 | | |
565 | | /// When ConversionKind == BadConversion, provides the details |
566 | | /// of the bad conversion. |
567 | | BadConversionSequence Bad; |
568 | | }; |
569 | | |
570 | | ImplicitConversionSequence() |
571 | 53.9M | : ConversionKind(Uninitialized), StdInitializerListElement(false) { |
572 | 53.9M | Standard.setAsIdentityConversion(); |
573 | 53.9M | } |
574 | | |
575 | | ImplicitConversionSequence(const ImplicitConversionSequence &Other) |
576 | | : ConversionKind(Other.ConversionKind), |
577 | 44.0M | StdInitializerListElement(Other.StdInitializerListElement) { |
578 | 44.0M | switch (ConversionKind) { |
579 | 0 | case Uninitialized: break; |
580 | 37.9M | case StandardConversion: Standard = Other.Standard; break; |
581 | 432k | case UserDefinedConversion: UserDefined = Other.UserDefined; break; |
582 | 8.01k | case AmbiguousConversion: Ambiguous.copyFrom(Other.Ambiguous); break; |
583 | 0 | case EllipsisConversion: break; |
584 | 5.60M | case BadConversion: Bad = Other.Bad; break; |
585 | 44.0M | } |
586 | 44.0M | } |
587 | | |
588 | | ImplicitConversionSequence & |
589 | 18.3M | operator=(const ImplicitConversionSequence &Other) { |
590 | 18.3M | destruct(); |
591 | 18.3M | new (this) ImplicitConversionSequence(Other); |
592 | 18.3M | return *this; |
593 | 18.3M | } |
594 | | |
595 | 79.6M | ~ImplicitConversionSequence() { |
596 | 79.6M | destruct(); |
597 | 79.6M | } |
598 | | |
599 | 311M | Kind getKind() const { |
600 | 311M | assert(isInitialized() && "querying uninitialized conversion"); |
601 | 311M | return Kind(ConversionKind); |
602 | 311M | } |
603 | | |
604 | | /// Return a ranking of the implicit conversion sequence |
605 | | /// kind, where smaller ranks represent better conversion |
606 | | /// sequences. |
607 | | /// |
608 | | /// In particular, this routine gives user-defined conversion |
609 | | /// sequences and ambiguous conversion sequences the same rank, |
610 | | /// per C++ [over.best.ics]p10. |
611 | 66.7M | unsigned getKindRank() const { |
612 | 66.7M | switch (getKind()) { |
613 | 63.9M | case StandardConversion: |
614 | 63.9M | return 0; |
615 | | |
616 | 2.59M | case UserDefinedConversion: |
617 | 2.61M | case AmbiguousConversion: |
618 | 2.61M | return 1; |
619 | | |
620 | 81.5k | case EllipsisConversion: |
621 | 81.5k | return 2; |
622 | | |
623 | 55.2k | case BadConversion: |
624 | 55.2k | return 3; |
625 | 0 | } |
626 | | |
627 | 0 | llvm_unreachable("Invalid ImplicitConversionSequence::Kind!"); |
628 | 0 | } |
629 | | |
630 | 39.8M | bool isBad() const { return getKind() == BadConversion; } |
631 | 92.3M | bool isStandard() const { return getKind() == StandardConversion; } |
632 | 25.9k | bool isEllipsis() const { return getKind() == EllipsisConversion; } |
633 | 1.04k | bool isAmbiguous() const { return getKind() == AmbiguousConversion; } |
634 | 66.2M | bool isUserDefined() const { return getKind() == UserDefinedConversion; } |
635 | 1.30k | bool isFailure() const { return isBad() || isAmbiguous()937 ; } |
636 | | |
637 | | /// Determines whether this conversion sequence has been |
638 | | /// initialized. Most operations should never need to query |
639 | | /// uninitialized conversions and should assert as above. |
640 | 315M | bool isInitialized() const { return ConversionKind != Uninitialized; } |
641 | | |
642 | | /// Sets this sequence as a bad conversion for an explicit argument. |
643 | | void setBad(BadConversionSequence::FailureKind Failure, |
644 | 6.13M | Expr *FromExpr, QualType ToType) { |
645 | 6.13M | setKind(BadConversion); |
646 | 6.13M | Bad.init(Failure, FromExpr, ToType); |
647 | 6.13M | } |
648 | | |
649 | | /// Sets this sequence as a bad conversion for an implicit argument. |
650 | | void setBad(BadConversionSequence::FailureKind Failure, |
651 | 19.1k | QualType FromType, QualType ToType) { |
652 | 19.1k | setKind(BadConversion); |
653 | 19.1k | Bad.init(Failure, FromType, ToType); |
654 | 19.1k | } |
655 | | |
656 | 23.3M | void setStandard() { setKind(StandardConversion); } |
657 | 84.9k | void setEllipsis() { setKind(EllipsisConversion); } |
658 | 410k | void setUserDefined() { setKind(UserDefinedConversion); } |
659 | | |
660 | 7.98k | void setAmbiguous() { |
661 | 7.98k | if (ConversionKind == AmbiguousConversion) return0 ; |
662 | 7.98k | ConversionKind = AmbiguousConversion; |
663 | 7.98k | Ambiguous.construct(); |
664 | 7.98k | } |
665 | | |
666 | 25 | void setAsIdentityConversion(QualType T) { |
667 | 25 | setStandard(); |
668 | 25 | Standard.setAsIdentityConversion(); |
669 | 25 | Standard.setFromType(T); |
670 | 25 | Standard.setAllToTypes(T); |
671 | 25 | } |
672 | | |
673 | | /// Whether the target is really a std::initializer_list, and the |
674 | | /// sequence only represents the worst element conversion. |
675 | 49.6M | bool isStdInitializerListElement() const { |
676 | 49.6M | return StdInitializerListElement; |
677 | 49.6M | } |
678 | | |
679 | 1.02k | void setStdInitializerListElement(bool V = true) { |
680 | 1.02k | StdInitializerListElement = V; |
681 | 1.02k | } |
682 | | |
683 | | /// Form an "implicit" conversion sequence from nullptr_t to bool, for a |
684 | | /// direct-initialization of a bool object from nullptr_t. |
685 | | static ImplicitConversionSequence getNullptrToBool(QualType SourceType, |
686 | | QualType DestType, |
687 | 26 | bool NeedLValToRVal) { |
688 | 26 | ImplicitConversionSequence ICS; |
689 | 26 | ICS.setStandard(); |
690 | 26 | ICS.Standard.setAsIdentityConversion(); |
691 | 26 | ICS.Standard.setFromType(SourceType); |
692 | 26 | if (NeedLValToRVal) |
693 | 1 | ICS.Standard.First = ICK_Lvalue_To_Rvalue; |
694 | 26 | ICS.Standard.setToType(0, SourceType); |
695 | 26 | ICS.Standard.Second = ICK_Boolean_Conversion; |
696 | 26 | ICS.Standard.setToType(1, DestType); |
697 | 26 | ICS.Standard.setToType(2, DestType); |
698 | 26 | return ICS; |
699 | 26 | } |
700 | | |
701 | | // The result of a comparison between implicit conversion |
702 | | // sequences. Use Sema::CompareImplicitConversionSequences to |
703 | | // actually perform the comparison. |
704 | | enum CompareKind { |
705 | | Better = -1, |
706 | | Indistinguishable = 0, |
707 | | Worse = 1 |
708 | | }; |
709 | | |
710 | | void DiagnoseAmbiguousConversion(Sema &S, |
711 | | SourceLocation CaretLoc, |
712 | | const PartialDiagnostic &PDiag) const; |
713 | | |
714 | | void dump() const; |
715 | | }; |
716 | | |
717 | | enum OverloadFailureKind { |
718 | | ovl_fail_too_many_arguments, |
719 | | ovl_fail_too_few_arguments, |
720 | | ovl_fail_bad_conversion, |
721 | | ovl_fail_bad_deduction, |
722 | | |
723 | | /// This conversion candidate was not considered because it |
724 | | /// duplicates the work of a trivial or derived-to-base |
725 | | /// conversion. |
726 | | ovl_fail_trivial_conversion, |
727 | | |
728 | | /// This conversion candidate was not considered because it is |
729 | | /// an illegal instantiation of a constructor temploid: it is |
730 | | /// callable with one argument, we only have one argument, and |
731 | | /// its first parameter type is exactly the type of the class. |
732 | | /// |
733 | | /// Defining such a constructor directly is illegal, and |
734 | | /// template-argument deduction is supposed to ignore such |
735 | | /// instantiations, but we can still get one with the right |
736 | | /// kind of implicit instantiation. |
737 | | ovl_fail_illegal_constructor, |
738 | | |
739 | | /// This conversion candidate is not viable because its result |
740 | | /// type is not implicitly convertible to the desired type. |
741 | | ovl_fail_bad_final_conversion, |
742 | | |
743 | | /// This conversion function template specialization candidate is not |
744 | | /// viable because the final conversion was not an exact match. |
745 | | ovl_fail_final_conversion_not_exact, |
746 | | |
747 | | /// (CUDA) This candidate was not viable because the callee |
748 | | /// was not accessible from the caller's target (i.e. host->device, |
749 | | /// global->host, device->host). |
750 | | ovl_fail_bad_target, |
751 | | |
752 | | /// This candidate function was not viable because an enable_if |
753 | | /// attribute disabled it. |
754 | | ovl_fail_enable_if, |
755 | | |
756 | | /// This candidate constructor or conversion function is explicit but |
757 | | /// the context doesn't permit explicit functions. |
758 | | ovl_fail_explicit, |
759 | | |
760 | | /// This candidate was not viable because its address could not be taken. |
761 | | ovl_fail_addr_not_available, |
762 | | |
763 | | /// This candidate was not viable because its OpenCL extension is disabled. |
764 | | ovl_fail_ext_disabled, |
765 | | |
766 | | /// This inherited constructor is not viable because it would slice the |
767 | | /// argument. |
768 | | ovl_fail_inhctor_slice, |
769 | | |
770 | | /// This candidate was not viable because it is a non-default multiversioned |
771 | | /// function. |
772 | | ovl_non_default_multiversion_function, |
773 | | |
774 | | /// This constructor/conversion candidate fail due to an address space |
775 | | /// mismatch between the object being constructed and the overload |
776 | | /// candidate. |
777 | | ovl_fail_object_addrspace_mismatch, |
778 | | |
779 | | /// This candidate was not viable because its associated constraints were |
780 | | /// not satisfied. |
781 | | ovl_fail_constraints_not_satisfied, |
782 | | }; |
783 | | |
784 | | /// A list of implicit conversion sequences for the arguments of an |
785 | | /// OverloadCandidate. |
786 | | using ConversionSequenceList = |
787 | | llvm::MutableArrayRef<ImplicitConversionSequence>; |
788 | | |
789 | | /// OverloadCandidate - A single candidate in an overload set (C++ 13.3). |
790 | | struct OverloadCandidate { |
791 | | /// Function - The actual function that this candidate |
792 | | /// represents. When NULL, this is a built-in candidate |
793 | | /// (C++ [over.oper]) or a surrogate for a conversion to a |
794 | | /// function pointer or reference (C++ [over.call.object]). |
795 | | FunctionDecl *Function; |
796 | | |
797 | | /// FoundDecl - The original declaration that was looked up / |
798 | | /// invented / otherwise found, together with its access. |
799 | | /// Might be a UsingShadowDecl or a FunctionTemplateDecl. |
800 | | DeclAccessPair FoundDecl; |
801 | | |
802 | | /// BuiltinParamTypes - Provides the parameter types of a built-in overload |
803 | | /// candidate. Only valid when Function is NULL. |
804 | | QualType BuiltinParamTypes[3]; |
805 | | |
806 | | /// Surrogate - The conversion function for which this candidate |
807 | | /// is a surrogate, but only if IsSurrogate is true. |
808 | | CXXConversionDecl *Surrogate; |
809 | | |
810 | | /// The conversion sequences used to convert the function arguments |
811 | | /// to the function parameters. Note that these are indexed by argument, |
812 | | /// so may not match the parameter order of Function. |
813 | | ConversionSequenceList Conversions; |
814 | | |
815 | | /// The FixIt hints which can be used to fix the Bad candidate. |
816 | | ConversionFixItGenerator Fix; |
817 | | |
818 | | /// Viable - True to indicate that this overload candidate is viable. |
819 | | bool Viable : 1; |
820 | | |
821 | | /// Whether this candidate is the best viable function, or tied for being |
822 | | /// the best viable function. |
823 | | /// |
824 | | /// For an ambiguous overload resolution, indicates whether this candidate |
825 | | /// was part of the ambiguity kernel: the minimal non-empty set of viable |
826 | | /// candidates such that all elements of the ambiguity kernel are better |
827 | | /// than all viable candidates not in the ambiguity kernel. |
828 | | bool Best : 1; |
829 | | |
830 | | /// IsSurrogate - True to indicate that this candidate is a |
831 | | /// surrogate for a conversion to a function pointer or reference |
832 | | /// (C++ [over.call.object]). |
833 | | bool IsSurrogate : 1; |
834 | | |
835 | | /// IgnoreObjectArgument - True to indicate that the first |
836 | | /// argument's conversion, which for this function represents the |
837 | | /// implicit object argument, should be ignored. This will be true |
838 | | /// when the candidate is a static member function (where the |
839 | | /// implicit object argument is just a placeholder) or a |
840 | | /// non-static member function when the call doesn't have an |
841 | | /// object argument. |
842 | | bool IgnoreObjectArgument : 1; |
843 | | |
844 | | /// True if the candidate was found using ADL. |
845 | | CallExpr::ADLCallKind IsADLCandidate : 1; |
846 | | |
847 | | /// Whether this is a rewritten candidate, and if so, of what kind? |
848 | | unsigned RewriteKind : 2; |
849 | | |
850 | | /// FailureKind - The reason why this candidate is not viable. |
851 | | /// Actually an OverloadFailureKind. |
852 | | unsigned char FailureKind; |
853 | | |
854 | | /// The number of call arguments that were explicitly provided, |
855 | | /// to be used while performing partial ordering of function templates. |
856 | | unsigned ExplicitCallArguments; |
857 | | |
858 | | union { |
859 | | DeductionFailureInfo DeductionFailure; |
860 | | |
861 | | /// FinalConversion - For a conversion function (where Function is |
862 | | /// a CXXConversionDecl), the standard conversion that occurs |
863 | | /// after the call to the overload candidate to convert the result |
864 | | /// of calling the conversion function to the required type. |
865 | | StandardConversionSequence FinalConversion; |
866 | | }; |
867 | | |
868 | | /// Get RewriteKind value in OverloadCandidateRewriteKind type (This |
869 | | /// function is to workaround the spurious GCC bitfield enum warning) |
870 | 804k | OverloadCandidateRewriteKind getRewriteKind() const { |
871 | 804k | return static_cast<OverloadCandidateRewriteKind>(RewriteKind); |
872 | 804k | } |
873 | | |
874 | 789k | bool isReversed() const { return getRewriteKind() & CRK_Reversed; } |
875 | | |
876 | | /// hasAmbiguousConversion - Returns whether this overload |
877 | | /// candidate requires an ambiguous conversion or not. |
878 | 0 | bool hasAmbiguousConversion() const { |
879 | 0 | for (auto &C : Conversions) { |
880 | 0 | if (!C.isInitialized()) return false; |
881 | 0 | if (C.isAmbiguous()) return true; |
882 | 0 | } |
883 | 0 | return false; |
884 | 0 | } |
885 | | |
886 | 10.7k | bool TryToFixBadConversion(unsigned Idx, Sema &S) { |
887 | 10.7k | bool CanFix = Fix.tryToFixConversion( |
888 | 10.7k | Conversions[Idx].Bad.FromExpr, |
889 | 10.7k | Conversions[Idx].Bad.getFromType(), |
890 | 10.7k | Conversions[Idx].Bad.getToType(), S); |
891 | | |
892 | | // If at least one conversion fails, the candidate cannot be fixed. |
893 | 10.7k | if (!CanFix) |
894 | 10.7k | Fix.clear(); |
895 | | |
896 | 10.7k | return CanFix; |
897 | 10.7k | } |
898 | | |
899 | 3.70k | unsigned getNumParams() const { |
900 | 3.70k | if (IsSurrogate) { |
901 | 10 | QualType STy = Surrogate->getConversionType(); |
902 | 20 | while (STy->isPointerType() || STy->isReferenceType()10 ) |
903 | 10 | STy = STy->getPointeeType(); |
904 | 10 | return STy->castAs<FunctionProtoType>()->getNumParams(); |
905 | 10 | } |
906 | 3.69k | if (Function) |
907 | 3.69k | return Function->getNumParams(); |
908 | 0 | return ExplicitCallArguments; |
909 | 0 | } |
910 | | |
911 | | private: |
912 | | friend class OverloadCandidateSet; |
913 | | OverloadCandidate() |
914 | 13.9M | : IsSurrogate(false), IsADLCandidate(CallExpr::NotADL), RewriteKind(CRK_None) {} |
915 | | }; |
916 | | |
917 | | /// OverloadCandidateSet - A set of overload candidates, used in C++ |
918 | | /// overload resolution (C++ 13.3). |
919 | | class OverloadCandidateSet { |
920 | | public: |
921 | | enum CandidateSetKind { |
922 | | /// Normal lookup. |
923 | | CSK_Normal, |
924 | | |
925 | | /// C++ [over.match.oper]: |
926 | | /// Lookup of operator function candidates in a call using operator |
927 | | /// syntax. Candidates that have no parameters of class type will be |
928 | | /// skipped unless there is a parameter of (reference to) enum type and |
929 | | /// the corresponding argument is of the same enum type. |
930 | | CSK_Operator, |
931 | | |
932 | | /// C++ [over.match.copy]: |
933 | | /// Copy-initialization of an object of class type by user-defined |
934 | | /// conversion. |
935 | | CSK_InitByUserDefinedConversion, |
936 | | |
937 | | /// C++ [over.match.ctor], [over.match.list] |
938 | | /// Initialization of an object of class type by constructor, |
939 | | /// using either a parenthesized or braced list of arguments. |
940 | | CSK_InitByConstructor, |
941 | | }; |
942 | | |
943 | | /// Information about operator rewrites to consider when adding operator |
944 | | /// functions to a candidate set. |
945 | | struct OperatorRewriteInfo { |
946 | | OperatorRewriteInfo() |
947 | 16.1M | : OriginalOperator(OO_None), AllowRewrittenCandidates(false) {} |
948 | | OperatorRewriteInfo(OverloadedOperatorKind Op, bool AllowRewritten) |
949 | 110k | : OriginalOperator(Op), AllowRewrittenCandidates(AllowRewritten) {} |
950 | | |
951 | | /// The original operator as written in the source. |
952 | | OverloadedOperatorKind OriginalOperator; |
953 | | /// Whether we should include rewritten candidates in the overload set. |
954 | | bool AllowRewrittenCandidates; |
955 | | |
956 | | /// Would use of this function result in a rewrite using a different |
957 | | /// operator? |
958 | 4.72M | bool isRewrittenOperator(const FunctionDecl *FD) { |
959 | 4.72M | return OriginalOperator && |
960 | 563k | FD->getDeclName().getCXXOverloadedOperator() != OriginalOperator; |
961 | 4.72M | } |
962 | | |
963 | 385k | bool isAcceptableCandidate(const FunctionDecl *FD) { |
964 | 385k | if (!OriginalOperator) |
965 | 10.9k | return true; |
966 | | |
967 | | // For an overloaded operator, we can have candidates with a different |
968 | | // name in our unqualified lookup set. Make sure we only consider the |
969 | | // ones we're supposed to. |
970 | 374k | OverloadedOperatorKind OO = |
971 | 374k | FD->getDeclName().getCXXOverloadedOperator(); |
972 | 374k | return OO && (OO == OriginalOperator || |
973 | 587 | (AllowRewrittenCandidates && |
974 | 467 | OO == getRewrittenOverloadedOperator(OriginalOperator))); |
975 | 374k | } |
976 | | |
977 | | /// Determine the kind of rewrite that should be performed for this |
978 | | /// candidate. |
979 | | OverloadCandidateRewriteKind |
980 | 4.72M | getRewriteKind(const FunctionDecl *FD, OverloadCandidateParamOrder PO) { |
981 | 4.72M | OverloadCandidateRewriteKind CRK = CRK_None; |
982 | 4.72M | if (isRewrittenOperator(FD)) |
983 | 1.62k | CRK = OverloadCandidateRewriteKind(CRK | CRK_DifferentOperator); |
984 | 4.72M | if (PO == OverloadCandidateParamOrder::Reversed) |
985 | 1.10k | CRK = OverloadCandidateRewriteKind(CRK | CRK_Reversed); |
986 | 4.72M | return CRK; |
987 | 4.72M | } |
988 | | |
989 | | /// Determines whether this operator could be implemented by a function |
990 | | /// with reversed parameter order. |
991 | 966 | bool isReversible() { |
992 | 966 | return AllowRewrittenCandidates && OriginalOperator && |
993 | 966 | (getRewrittenOverloadedOperator(OriginalOperator) != OO_None || |
994 | 465 | shouldAddReversed(OriginalOperator)); |
995 | 966 | } |
996 | | |
997 | | /// Determine whether we should consider looking for and adding reversed |
998 | | /// candidates for operator Op. |
999 | | bool shouldAddReversed(OverloadedOperatorKind Op); |
1000 | | |
1001 | | /// Determine whether we should add a rewritten candidate for \p FD with |
1002 | | /// reversed parameter order. |
1003 | | bool shouldAddReversed(ASTContext &Ctx, const FunctionDecl *FD); |
1004 | | }; |
1005 | | |
1006 | | private: |
1007 | | SmallVector<OverloadCandidate, 16> Candidates; |
1008 | | llvm::SmallPtrSet<uintptr_t, 16> Functions; |
1009 | | |
1010 | | // Allocator for ConversionSequenceLists. We store the first few of these |
1011 | | // inline to avoid allocation for small sets. |
1012 | | llvm::BumpPtrAllocator SlabAllocator; |
1013 | | |
1014 | | SourceLocation Loc; |
1015 | | CandidateSetKind Kind; |
1016 | | OperatorRewriteInfo RewriteInfo; |
1017 | | |
1018 | | constexpr static unsigned NumInlineBytes = |
1019 | | 24 * sizeof(ImplicitConversionSequence); |
1020 | | unsigned NumInlineBytesUsed = 0; |
1021 | | alignas(void *) char InlineSpace[NumInlineBytes]; |
1022 | | |
1023 | | // Address space of the object being constructed. |
1024 | | LangAS DestAS = LangAS::Default; |
1025 | | |
1026 | | /// If we have space, allocates from inline storage. Otherwise, allocates |
1027 | | /// from the slab allocator. |
1028 | | /// FIXME: It would probably be nice to have a SmallBumpPtrAllocator |
1029 | | /// instead. |
1030 | | /// FIXME: Now that this only allocates ImplicitConversionSequences, do we |
1031 | | /// want to un-generalize this? |
1032 | | template <typename T> |
1033 | 13.9M | T *slabAllocate(unsigned N) { |
1034 | | // It's simpler if this doesn't need to consider alignment. |
1035 | 13.9M | static_assert(alignof(T) == alignof(void *), |
1036 | 13.9M | "Only works for pointer-aligned types."); |
1037 | 13.9M | static_assert(std::is_trivial<T>::value || |
1038 | 13.9M | std::is_same<ImplicitConversionSequence, T>::value, |
1039 | 13.9M | "Add destruction logic to OverloadCandidateSet::clear()."); |
1040 | | |
1041 | 13.9M | unsigned NBytes = sizeof(T) * N; |
1042 | 13.9M | if (NBytes > NumInlineBytes - NumInlineBytesUsed) |
1043 | 8.42M | return SlabAllocator.Allocate<T>(N); |
1044 | 5.54M | char *FreeSpaceStart = InlineSpace + NumInlineBytesUsed; |
1045 | 5.54M | assert(uintptr_t(FreeSpaceStart) % alignof(void *) == 0 && |
1046 | 5.54M | "Misaligned storage!"); |
1047 | | |
1048 | 5.54M | NumInlineBytesUsed += NBytes; |
1049 | 5.54M | return reinterpret_cast<T *>(FreeSpaceStart); |
1050 | 5.54M | } |
1051 | | |
1052 | | void destroyCandidates(); |
1053 | | |
1054 | | /// Whether diagnostics should be deferred. |
1055 | | bool shouldDeferDiags(Sema &S, ArrayRef<Expr *> Args, SourceLocation OpLoc); |
1056 | | |
1057 | | public: |
1058 | | OverloadCandidateSet(SourceLocation Loc, CandidateSetKind CSK, |
1059 | | OperatorRewriteInfo RewriteInfo = {}) |
1060 | 16.2M | : Loc(Loc), Kind(CSK), RewriteInfo(RewriteInfo) {} |
1061 | | OverloadCandidateSet(const OverloadCandidateSet &) = delete; |
1062 | | OverloadCandidateSet &operator=(const OverloadCandidateSet &) = delete; |
1063 | 16.2M | ~OverloadCandidateSet() { destroyCandidates(); } |
1064 | | |
1065 | 5.29M | SourceLocation getLocation() const { return Loc; } |
1066 | 3.52M | CandidateSetKind getKind() const { return Kind; } |
1067 | 6.22M | OperatorRewriteInfo getRewriteInfo() const { return RewriteInfo; } |
1068 | | |
1069 | | /// Determine when this overload candidate will be new to the |
1070 | | /// overload set. |
1071 | | bool isNewCandidate(Decl *F, OverloadCandidateParamOrder PO = |
1072 | 6.06M | OverloadCandidateParamOrder::Normal) { |
1073 | 6.06M | uintptr_t Key = reinterpret_cast<uintptr_t>(F->getCanonicalDecl()); |
1074 | 6.06M | Key |= static_cast<uintptr_t>(PO); |
1075 | 6.06M | return Functions.insert(Key).second; |
1076 | 6.06M | } |
1077 | | |
1078 | | /// Exclude a function from being considered by overload resolution. |
1079 | 994 | void exclude(Decl *F) { |
1080 | 994 | isNewCandidate(F, OverloadCandidateParamOrder::Normal); |
1081 | 994 | isNewCandidate(F, OverloadCandidateParamOrder::Reversed); |
1082 | 994 | } |
1083 | | |
1084 | | /// Clear out all of the candidates. |
1085 | | void clear(CandidateSetKind CSK); |
1086 | | |
1087 | | using iterator = SmallVectorImpl<OverloadCandidate>::iterator; |
1088 | | |
1089 | 22.5M | iterator begin() { return Candidates.begin(); } |
1090 | 39.9M | iterator end() { return Candidates.end(); } |
1091 | | |
1092 | 3.43M | size_t size() const { return Candidates.size(); } |
1093 | 615k | bool empty() const { return Candidates.empty(); } |
1094 | | |
1095 | | /// Allocate storage for conversion sequences for NumConversions |
1096 | | /// conversions. |
1097 | | ConversionSequenceList |
1098 | 13.9M | allocateConversionSequences(unsigned NumConversions) { |
1099 | 13.9M | ImplicitConversionSequence *Conversions = |
1100 | 13.9M | slabAllocate<ImplicitConversionSequence>(NumConversions); |
1101 | | |
1102 | | // Construct the new objects. |
1103 | 37.4M | for (unsigned I = 0; I != NumConversions; ++I23.4M ) |
1104 | 23.4M | new (&Conversions[I]) ImplicitConversionSequence(); |
1105 | | |
1106 | 13.9M | return ConversionSequenceList(Conversions, NumConversions); |
1107 | 13.9M | } |
1108 | | |
1109 | | /// Add a new candidate with NumConversions conversion sequence slots |
1110 | | /// to the overload set. |
1111 | | OverloadCandidate &addCandidate(unsigned NumConversions = 0, |
1112 | 13.9M | ConversionSequenceList Conversions = None) { |
1113 | 13.9M | assert((Conversions.empty() || Conversions.size() == NumConversions) && |
1114 | 13.9M | "preallocated conversion sequence has wrong length"); |
1115 | | |
1116 | 13.9M | Candidates.push_back(OverloadCandidate()); |
1117 | 13.9M | OverloadCandidate &C = Candidates.back(); |
1118 | 13.9M | C.Conversions = Conversions.empty() |
1119 | 13.5M | ? allocateConversionSequences(NumConversions) |
1120 | 394k | : Conversions; |
1121 | 13.9M | return C; |
1122 | 13.9M | } |
1123 | | |
1124 | | /// Find the best viable function on this overload set, if it exists. |
1125 | | OverloadingResult BestViableFunction(Sema &S, SourceLocation Loc, |
1126 | | OverloadCandidateSet::iterator& Best); |
1127 | | |
1128 | | SmallVector<OverloadCandidate *, 32> CompleteCandidates( |
1129 | | Sema &S, OverloadCandidateDisplayKind OCD, ArrayRef<Expr *> Args, |
1130 | | SourceLocation OpLoc = SourceLocation(), |
1131 | | llvm::function_ref<bool(OverloadCandidate &)> Filter = |
1132 | 867k | [](OverloadCandidate &) { return true; }); |
1133 | | |
1134 | | void NoteCandidates( |
1135 | | PartialDiagnosticAt PA, Sema &S, OverloadCandidateDisplayKind OCD, |
1136 | | ArrayRef<Expr *> Args, StringRef Opc = "", |
1137 | | SourceLocation Loc = SourceLocation(), |
1138 | | llvm::function_ref<bool(OverloadCandidate &)> Filter = |
1139 | 32.4k | [](OverloadCandidate &) { return true; }); |
1140 | | |
1141 | | void NoteCandidates(Sema &S, ArrayRef<Expr *> Args, |
1142 | | ArrayRef<OverloadCandidate *> Cands, |
1143 | | StringRef Opc = "", |
1144 | | SourceLocation OpLoc = SourceLocation()); |
1145 | | |
1146 | 1.66M | LangAS getDestAS() { return DestAS; } |
1147 | | |
1148 | 343k | void setDestAS(LangAS AS) { |
1149 | 343k | assert((Kind == CSK_InitByConstructor || |
1150 | 343k | Kind == CSK_InitByUserDefinedConversion) && |
1151 | 343k | "can't set the destination address space when not constructing an " |
1152 | 343k | "object"); |
1153 | 343k | DestAS = AS; |
1154 | 343k | } |
1155 | | |
1156 | | }; |
1157 | | |
1158 | | bool isBetterOverloadCandidate(Sema &S, |
1159 | | const OverloadCandidate &Cand1, |
1160 | | const OverloadCandidate &Cand2, |
1161 | | SourceLocation Loc, |
1162 | | OverloadCandidateSet::CandidateSetKind Kind); |
1163 | | |
1164 | | struct ConstructorInfo { |
1165 | | DeclAccessPair FoundDecl; |
1166 | | CXXConstructorDecl *Constructor; |
1167 | | FunctionTemplateDecl *ConstructorTmpl; |
1168 | | |
1169 | 993k | explicit operator bool() const { return Constructor; } |
1170 | | }; |
1171 | | |
1172 | | // FIXME: Add an AddOverloadCandidate / AddTemplateOverloadCandidate overload |
1173 | | // that takes one of these. |
1174 | 2.46M | inline ConstructorInfo getConstructorInfo(NamedDecl *ND) { |
1175 | 2.46M | if (isa<UsingDecl>(ND)) |
1176 | 1.57k | return ConstructorInfo{}; |
1177 | | |
1178 | | // For constructors, the access check is performed against the underlying |
1179 | | // declaration, not the found declaration. |
1180 | 2.46M | auto *D = ND->getUnderlyingDecl(); |
1181 | 2.46M | ConstructorInfo Info = {DeclAccessPair::make(ND, D->getAccess()), nullptr, |
1182 | 2.46M | nullptr}; |
1183 | 2.46M | Info.ConstructorTmpl = dyn_cast<FunctionTemplateDecl>(D); |
1184 | 2.46M | if (Info.ConstructorTmpl) |
1185 | 483k | D = Info.ConstructorTmpl->getTemplatedDecl(); |
1186 | 2.46M | Info.Constructor = dyn_cast<CXXConstructorDecl>(D); |
1187 | 2.46M | return Info; |
1188 | 2.46M | } |
1189 | | |
1190 | | } // namespace clang |
1191 | | |
1192 | | #endif // LLVM_CLANG_SEMA_OVERLOAD_H |