File: | tools/clang/lib/Sema/SemaCUDA.cpp |
Warning: | line 837, column 51 Potential leak of memory pointed to by field 'DiagStorage' |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
1 | //===--- SemaCUDA.cpp - Semantic Analysis for CUDA constructs -------------===// | |||
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 | /// \file | |||
10 | /// \brief This file implements semantic analysis for CUDA constructs. | |||
11 | /// | |||
12 | //===----------------------------------------------------------------------===// | |||
13 | ||||
14 | #include "clang/AST/ASTContext.h" | |||
15 | #include "clang/AST/Decl.h" | |||
16 | #include "clang/AST/ExprCXX.h" | |||
17 | #include "clang/Lex/Preprocessor.h" | |||
18 | #include "clang/Sema/Lookup.h" | |||
19 | #include "clang/Sema/Sema.h" | |||
20 | #include "clang/Sema/SemaDiagnostic.h" | |||
21 | #include "clang/Sema/SemaInternal.h" | |||
22 | #include "clang/Sema/Template.h" | |||
23 | #include "llvm/ADT/Optional.h" | |||
24 | #include "llvm/ADT/SmallVector.h" | |||
25 | using namespace clang; | |||
26 | ||||
27 | void Sema::PushForceCUDAHostDevice() { | |||
28 | assert(getLangOpts().CUDA && "Should only be called during CUDA compilation")(static_cast <bool> (getLangOpts().CUDA && "Should only be called during CUDA compilation" ) ? void (0) : __assert_fail ("getLangOpts().CUDA && \"Should only be called during CUDA compilation\"" , "/build/llvm-toolchain-snapshot-7~svn326425/tools/clang/lib/Sema/SemaCUDA.cpp" , 28, __extension__ __PRETTY_FUNCTION__)); | |||
29 | ForceCUDAHostDeviceDepth++; | |||
30 | } | |||
31 | ||||
32 | bool Sema::PopForceCUDAHostDevice() { | |||
33 | assert(getLangOpts().CUDA && "Should only be called during CUDA compilation")(static_cast <bool> (getLangOpts().CUDA && "Should only be called during CUDA compilation" ) ? void (0) : __assert_fail ("getLangOpts().CUDA && \"Should only be called during CUDA compilation\"" , "/build/llvm-toolchain-snapshot-7~svn326425/tools/clang/lib/Sema/SemaCUDA.cpp" , 33, __extension__ __PRETTY_FUNCTION__)); | |||
34 | if (ForceCUDAHostDeviceDepth == 0) | |||
35 | return false; | |||
36 | ForceCUDAHostDeviceDepth--; | |||
37 | return true; | |||
38 | } | |||
39 | ||||
40 | ExprResult Sema::ActOnCUDAExecConfigExpr(Scope *S, SourceLocation LLLLoc, | |||
41 | MultiExprArg ExecConfig, | |||
42 | SourceLocation GGGLoc) { | |||
43 | FunctionDecl *ConfigDecl = Context.getcudaConfigureCallDecl(); | |||
44 | if (!ConfigDecl) | |||
45 | return ExprError(Diag(LLLLoc, diag::err_undeclared_var_use) | |||
46 | << "cudaConfigureCall"); | |||
47 | QualType ConfigQTy = ConfigDecl->getType(); | |||
48 | ||||
49 | DeclRefExpr *ConfigDR = new (Context) | |||
50 | DeclRefExpr(ConfigDecl, false, ConfigQTy, VK_LValue, LLLLoc); | |||
51 | MarkFunctionReferenced(LLLLoc, ConfigDecl); | |||
52 | ||||
53 | return ActOnCallExpr(S, ConfigDR, LLLLoc, ExecConfig, GGGLoc, nullptr, | |||
54 | /*IsExecConfig=*/true); | |||
55 | } | |||
56 | ||||
57 | Sema::CUDAFunctionTarget Sema::IdentifyCUDATarget(const AttributeList *Attr) { | |||
58 | bool HasHostAttr = false; | |||
59 | bool HasDeviceAttr = false; | |||
60 | bool HasGlobalAttr = false; | |||
61 | bool HasInvalidTargetAttr = false; | |||
62 | while (Attr) { | |||
63 | switch(Attr->getKind()){ | |||
64 | case AttributeList::AT_CUDAGlobal: | |||
65 | HasGlobalAttr = true; | |||
66 | break; | |||
67 | case AttributeList::AT_CUDAHost: | |||
68 | HasHostAttr = true; | |||
69 | break; | |||
70 | case AttributeList::AT_CUDADevice: | |||
71 | HasDeviceAttr = true; | |||
72 | break; | |||
73 | case AttributeList::AT_CUDAInvalidTarget: | |||
74 | HasInvalidTargetAttr = true; | |||
75 | break; | |||
76 | default: | |||
77 | break; | |||
78 | } | |||
79 | Attr = Attr->getNext(); | |||
80 | } | |||
81 | if (HasInvalidTargetAttr) | |||
82 | return CFT_InvalidTarget; | |||
83 | ||||
84 | if (HasGlobalAttr) | |||
85 | return CFT_Global; | |||
86 | ||||
87 | if (HasHostAttr && HasDeviceAttr) | |||
88 | return CFT_HostDevice; | |||
89 | ||||
90 | if (HasDeviceAttr) | |||
91 | return CFT_Device; | |||
92 | ||||
93 | return CFT_Host; | |||
94 | } | |||
95 | ||||
96 | template <typename A> | |||
97 | static bool hasAttr(const FunctionDecl *D, bool IgnoreImplicitAttr) { | |||
98 | return D->hasAttrs() && llvm::any_of(D->getAttrs(), [&](Attr *Attribute) { | |||
99 | return isa<A>(Attribute) && | |||
100 | !(IgnoreImplicitAttr && Attribute->isImplicit()); | |||
101 | }); | |||
102 | } | |||
103 | ||||
104 | /// IdentifyCUDATarget - Determine the CUDA compilation target for this function | |||
105 | Sema::CUDAFunctionTarget Sema::IdentifyCUDATarget(const FunctionDecl *D, | |||
106 | bool IgnoreImplicitHDAttr) { | |||
107 | // Code that lives outside a function is run on the host. | |||
108 | if (D == nullptr) | |||
109 | return CFT_Host; | |||
110 | ||||
111 | if (D->hasAttr<CUDAInvalidTargetAttr>()) | |||
112 | return CFT_InvalidTarget; | |||
113 | ||||
114 | if (D->hasAttr<CUDAGlobalAttr>()) | |||
115 | return CFT_Global; | |||
116 | ||||
117 | if (hasAttr<CUDADeviceAttr>(D, IgnoreImplicitHDAttr)) { | |||
118 | if (hasAttr<CUDAHostAttr>(D, IgnoreImplicitHDAttr)) | |||
119 | return CFT_HostDevice; | |||
120 | return CFT_Device; | |||
121 | } else if (hasAttr<CUDAHostAttr>(D, IgnoreImplicitHDAttr)) { | |||
122 | return CFT_Host; | |||
123 | } else if (D->isImplicit() && !IgnoreImplicitHDAttr) { | |||
124 | // Some implicit declarations (like intrinsic functions) are not marked. | |||
125 | // Set the most lenient target on them for maximal flexibility. | |||
126 | return CFT_HostDevice; | |||
127 | } | |||
128 | ||||
129 | return CFT_Host; | |||
130 | } | |||
131 | ||||
132 | // * CUDA Call preference table | |||
133 | // | |||
134 | // F - from, | |||
135 | // T - to | |||
136 | // Ph - preference in host mode | |||
137 | // Pd - preference in device mode | |||
138 | // H - handled in (x) | |||
139 | // Preferences: N:native, SS:same side, HD:host-device, WS:wrong side, --:never. | |||
140 | // | |||
141 | // | F | T | Ph | Pd | H | | |||
142 | // |----+----+-----+-----+-----+ | |||
143 | // | d | d | N | N | (c) | | |||
144 | // | d | g | -- | -- | (a) | | |||
145 | // | d | h | -- | -- | (e) | | |||
146 | // | d | hd | HD | HD | (b) | | |||
147 | // | g | d | N | N | (c) | | |||
148 | // | g | g | -- | -- | (a) | | |||
149 | // | g | h | -- | -- | (e) | | |||
150 | // | g | hd | HD | HD | (b) | | |||
151 | // | h | d | -- | -- | (e) | | |||
152 | // | h | g | N | N | (c) | | |||
153 | // | h | h | N | N | (c) | | |||
154 | // | h | hd | HD | HD | (b) | | |||
155 | // | hd | d | WS | SS | (d) | | |||
156 | // | hd | g | SS | -- |(d/a)| | |||
157 | // | hd | h | SS | WS | (d) | | |||
158 | // | hd | hd | HD | HD | (b) | | |||
159 | ||||
160 | Sema::CUDAFunctionPreference | |||
161 | Sema::IdentifyCUDAPreference(const FunctionDecl *Caller, | |||
162 | const FunctionDecl *Callee) { | |||
163 | assert(Callee && "Callee must be valid.")(static_cast <bool> (Callee && "Callee must be valid." ) ? void (0) : __assert_fail ("Callee && \"Callee must be valid.\"" , "/build/llvm-toolchain-snapshot-7~svn326425/tools/clang/lib/Sema/SemaCUDA.cpp" , 163, __extension__ __PRETTY_FUNCTION__)); | |||
164 | CUDAFunctionTarget CallerTarget = IdentifyCUDATarget(Caller); | |||
165 | CUDAFunctionTarget CalleeTarget = IdentifyCUDATarget(Callee); | |||
166 | ||||
167 | // If one of the targets is invalid, the check always fails, no matter what | |||
168 | // the other target is. | |||
169 | if (CallerTarget == CFT_InvalidTarget || CalleeTarget == CFT_InvalidTarget) | |||
170 | return CFP_Never; | |||
171 | ||||
172 | // (a) Can't call global from some contexts until we support CUDA's | |||
173 | // dynamic parallelism. | |||
174 | if (CalleeTarget == CFT_Global && | |||
175 | (CallerTarget == CFT_Global || CallerTarget == CFT_Device)) | |||
176 | return CFP_Never; | |||
177 | ||||
178 | // (b) Calling HostDevice is OK for everyone. | |||
179 | if (CalleeTarget == CFT_HostDevice) | |||
180 | return CFP_HostDevice; | |||
181 | ||||
182 | // (c) Best case scenarios | |||
183 | if (CalleeTarget == CallerTarget || | |||
184 | (CallerTarget == CFT_Host && CalleeTarget == CFT_Global) || | |||
185 | (CallerTarget == CFT_Global && CalleeTarget == CFT_Device)) | |||
186 | return CFP_Native; | |||
187 | ||||
188 | // (d) HostDevice behavior depends on compilation mode. | |||
189 | if (CallerTarget == CFT_HostDevice) { | |||
190 | // It's OK to call a compilation-mode matching function from an HD one. | |||
191 | if ((getLangOpts().CUDAIsDevice && CalleeTarget == CFT_Device) || | |||
192 | (!getLangOpts().CUDAIsDevice && | |||
193 | (CalleeTarget == CFT_Host || CalleeTarget == CFT_Global))) | |||
194 | return CFP_SameSide; | |||
195 | ||||
196 | // Calls from HD to non-mode-matching functions (i.e., to host functions | |||
197 | // when compiling in device mode or to device functions when compiling in | |||
198 | // host mode) are allowed at the sema level, but eventually rejected if | |||
199 | // they're ever codegened. TODO: Reject said calls earlier. | |||
200 | return CFP_WrongSide; | |||
201 | } | |||
202 | ||||
203 | // (e) Calling across device/host boundary is not something you should do. | |||
204 | if ((CallerTarget == CFT_Host && CalleeTarget == CFT_Device) || | |||
205 | (CallerTarget == CFT_Device && CalleeTarget == CFT_Host) || | |||
206 | (CallerTarget == CFT_Global && CalleeTarget == CFT_Host)) | |||
207 | return CFP_Never; | |||
208 | ||||
209 | llvm_unreachable("All cases should've been handled by now.")::llvm::llvm_unreachable_internal("All cases should've been handled by now." , "/build/llvm-toolchain-snapshot-7~svn326425/tools/clang/lib/Sema/SemaCUDA.cpp" , 209); | |||
210 | } | |||
211 | ||||
212 | void Sema::EraseUnwantedCUDAMatches( | |||
213 | const FunctionDecl *Caller, | |||
214 | SmallVectorImpl<std::pair<DeclAccessPair, FunctionDecl *>> &Matches) { | |||
215 | if (Matches.size() <= 1) | |||
216 | return; | |||
217 | ||||
218 | using Pair = std::pair<DeclAccessPair, FunctionDecl*>; | |||
219 | ||||
220 | // Gets the CUDA function preference for a call from Caller to Match. | |||
221 | auto GetCFP = [&](const Pair &Match) { | |||
222 | return IdentifyCUDAPreference(Caller, Match.second); | |||
223 | }; | |||
224 | ||||
225 | // Find the best call preference among the functions in Matches. | |||
226 | CUDAFunctionPreference BestCFP = GetCFP(*std::max_element( | |||
227 | Matches.begin(), Matches.end(), | |||
228 | [&](const Pair &M1, const Pair &M2) { return GetCFP(M1) < GetCFP(M2); })); | |||
229 | ||||
230 | // Erase all functions with lower priority. | |||
231 | llvm::erase_if(Matches, | |||
232 | [&](const Pair &Match) { return GetCFP(Match) < BestCFP; }); | |||
233 | } | |||
234 | ||||
235 | /// When an implicitly-declared special member has to invoke more than one | |||
236 | /// base/field special member, conflicts may occur in the targets of these | |||
237 | /// members. For example, if one base's member __host__ and another's is | |||
238 | /// __device__, it's a conflict. | |||
239 | /// This function figures out if the given targets \param Target1 and | |||
240 | /// \param Target2 conflict, and if they do not it fills in | |||
241 | /// \param ResolvedTarget with a target that resolves for both calls. | |||
242 | /// \return true if there's a conflict, false otherwise. | |||
243 | static bool | |||
244 | resolveCalleeCUDATargetConflict(Sema::CUDAFunctionTarget Target1, | |||
245 | Sema::CUDAFunctionTarget Target2, | |||
246 | Sema::CUDAFunctionTarget *ResolvedTarget) { | |||
247 | // Only free functions and static member functions may be global. | |||
248 | assert(Target1 != Sema::CFT_Global)(static_cast <bool> (Target1 != Sema::CFT_Global) ? void (0) : __assert_fail ("Target1 != Sema::CFT_Global", "/build/llvm-toolchain-snapshot-7~svn326425/tools/clang/lib/Sema/SemaCUDA.cpp" , 248, __extension__ __PRETTY_FUNCTION__)); | |||
249 | assert(Target2 != Sema::CFT_Global)(static_cast <bool> (Target2 != Sema::CFT_Global) ? void (0) : __assert_fail ("Target2 != Sema::CFT_Global", "/build/llvm-toolchain-snapshot-7~svn326425/tools/clang/lib/Sema/SemaCUDA.cpp" , 249, __extension__ __PRETTY_FUNCTION__)); | |||
250 | ||||
251 | if (Target1 == Sema::CFT_HostDevice) { | |||
252 | *ResolvedTarget = Target2; | |||
253 | } else if (Target2 == Sema::CFT_HostDevice) { | |||
254 | *ResolvedTarget = Target1; | |||
255 | } else if (Target1 != Target2) { | |||
256 | return true; | |||
257 | } else { | |||
258 | *ResolvedTarget = Target1; | |||
259 | } | |||
260 | ||||
261 | return false; | |||
262 | } | |||
263 | ||||
264 | bool Sema::inferCUDATargetForImplicitSpecialMember(CXXRecordDecl *ClassDecl, | |||
265 | CXXSpecialMember CSM, | |||
266 | CXXMethodDecl *MemberDecl, | |||
267 | bool ConstRHS, | |||
268 | bool Diagnose) { | |||
269 | llvm::Optional<CUDAFunctionTarget> InferredTarget; | |||
270 | ||||
271 | // We're going to invoke special member lookup; mark that these special | |||
272 | // members are called from this one, and not from its caller. | |||
273 | ContextRAII MethodContext(*this, MemberDecl); | |||
274 | ||||
275 | // Look for special members in base classes that should be invoked from here. | |||
276 | // Infer the target of this member base on the ones it should call. | |||
277 | // Skip direct and indirect virtual bases for abstract classes. | |||
278 | llvm::SmallVector<const CXXBaseSpecifier *, 16> Bases; | |||
279 | for (const auto &B : ClassDecl->bases()) { | |||
280 | if (!B.isVirtual()) { | |||
281 | Bases.push_back(&B); | |||
282 | } | |||
283 | } | |||
284 | ||||
285 | if (!ClassDecl->isAbstract()) { | |||
286 | for (const auto &VB : ClassDecl->vbases()) { | |||
287 | Bases.push_back(&VB); | |||
288 | } | |||
289 | } | |||
290 | ||||
291 | for (const auto *B : Bases) { | |||
292 | const RecordType *BaseType = B->getType()->getAs<RecordType>(); | |||
293 | if (!BaseType) { | |||
294 | continue; | |||
295 | } | |||
296 | ||||
297 | CXXRecordDecl *BaseClassDecl = cast<CXXRecordDecl>(BaseType->getDecl()); | |||
298 | Sema::SpecialMemberOverloadResult SMOR = | |||
299 | LookupSpecialMember(BaseClassDecl, CSM, | |||
300 | /* ConstArg */ ConstRHS, | |||
301 | /* VolatileArg */ false, | |||
302 | /* RValueThis */ false, | |||
303 | /* ConstThis */ false, | |||
304 | /* VolatileThis */ false); | |||
305 | ||||
306 | if (!SMOR.getMethod()) | |||
307 | continue; | |||
308 | ||||
309 | CUDAFunctionTarget BaseMethodTarget = IdentifyCUDATarget(SMOR.getMethod()); | |||
310 | if (!InferredTarget.hasValue()) { | |||
311 | InferredTarget = BaseMethodTarget; | |||
312 | } else { | |||
313 | bool ResolutionError = resolveCalleeCUDATargetConflict( | |||
314 | InferredTarget.getValue(), BaseMethodTarget, | |||
315 | InferredTarget.getPointer()); | |||
316 | if (ResolutionError) { | |||
317 | if (Diagnose) { | |||
318 | Diag(ClassDecl->getLocation(), | |||
319 | diag::note_implicit_member_target_infer_collision) | |||
320 | << (unsigned)CSM << InferredTarget.getValue() << BaseMethodTarget; | |||
321 | } | |||
322 | MemberDecl->addAttr(CUDAInvalidTargetAttr::CreateImplicit(Context)); | |||
323 | return true; | |||
324 | } | |||
325 | } | |||
326 | } | |||
327 | ||||
328 | // Same as for bases, but now for special members of fields. | |||
329 | for (const auto *F : ClassDecl->fields()) { | |||
330 | if (F->isInvalidDecl()) { | |||
331 | continue; | |||
332 | } | |||
333 | ||||
334 | const RecordType *FieldType = | |||
335 | Context.getBaseElementType(F->getType())->getAs<RecordType>(); | |||
336 | if (!FieldType) { | |||
337 | continue; | |||
338 | } | |||
339 | ||||
340 | CXXRecordDecl *FieldRecDecl = cast<CXXRecordDecl>(FieldType->getDecl()); | |||
341 | Sema::SpecialMemberOverloadResult SMOR = | |||
342 | LookupSpecialMember(FieldRecDecl, CSM, | |||
343 | /* ConstArg */ ConstRHS && !F->isMutable(), | |||
344 | /* VolatileArg */ false, | |||
345 | /* RValueThis */ false, | |||
346 | /* ConstThis */ false, | |||
347 | /* VolatileThis */ false); | |||
348 | ||||
349 | if (!SMOR.getMethod()) | |||
350 | continue; | |||
351 | ||||
352 | CUDAFunctionTarget FieldMethodTarget = | |||
353 | IdentifyCUDATarget(SMOR.getMethod()); | |||
354 | if (!InferredTarget.hasValue()) { | |||
355 | InferredTarget = FieldMethodTarget; | |||
356 | } else { | |||
357 | bool ResolutionError = resolveCalleeCUDATargetConflict( | |||
358 | InferredTarget.getValue(), FieldMethodTarget, | |||
359 | InferredTarget.getPointer()); | |||
360 | if (ResolutionError) { | |||
361 | if (Diagnose) { | |||
362 | Diag(ClassDecl->getLocation(), | |||
363 | diag::note_implicit_member_target_infer_collision) | |||
364 | << (unsigned)CSM << InferredTarget.getValue() | |||
365 | << FieldMethodTarget; | |||
366 | } | |||
367 | MemberDecl->addAttr(CUDAInvalidTargetAttr::CreateImplicit(Context)); | |||
368 | return true; | |||
369 | } | |||
370 | } | |||
371 | } | |||
372 | ||||
373 | if (InferredTarget.hasValue()) { | |||
374 | if (InferredTarget.getValue() == CFT_Device) { | |||
375 | MemberDecl->addAttr(CUDADeviceAttr::CreateImplicit(Context)); | |||
376 | } else if (InferredTarget.getValue() == CFT_Host) { | |||
377 | MemberDecl->addAttr(CUDAHostAttr::CreateImplicit(Context)); | |||
378 | } else { | |||
379 | MemberDecl->addAttr(CUDADeviceAttr::CreateImplicit(Context)); | |||
380 | MemberDecl->addAttr(CUDAHostAttr::CreateImplicit(Context)); | |||
381 | } | |||
382 | } else { | |||
383 | // If no target was inferred, mark this member as __host__ __device__; | |||
384 | // it's the least restrictive option that can be invoked from any target. | |||
385 | MemberDecl->addAttr(CUDADeviceAttr::CreateImplicit(Context)); | |||
386 | MemberDecl->addAttr(CUDAHostAttr::CreateImplicit(Context)); | |||
387 | } | |||
388 | ||||
389 | return false; | |||
390 | } | |||
391 | ||||
392 | bool Sema::isEmptyCudaConstructor(SourceLocation Loc, CXXConstructorDecl *CD) { | |||
393 | if (!CD->isDefined() && CD->isTemplateInstantiation()) | |||
394 | InstantiateFunctionDefinition(Loc, CD->getFirstDecl()); | |||
395 | ||||
396 | // (E.2.3.1, CUDA 7.5) A constructor for a class type is considered | |||
397 | // empty at a point in the translation unit, if it is either a | |||
398 | // trivial constructor | |||
399 | if (CD->isTrivial()) | |||
400 | return true; | |||
401 | ||||
402 | // ... or it satisfies all of the following conditions: | |||
403 | // The constructor function has been defined. | |||
404 | // The constructor function has no parameters, | |||
405 | // and the function body is an empty compound statement. | |||
406 | if (!(CD->hasTrivialBody() && CD->getNumParams() == 0)) | |||
407 | return false; | |||
408 | ||||
409 | // Its class has no virtual functions and no virtual base classes. | |||
410 | if (CD->getParent()->isDynamicClass()) | |||
411 | return false; | |||
412 | ||||
413 | // The only form of initializer allowed is an empty constructor. | |||
414 | // This will recursively check all base classes and member initializers | |||
415 | if (!llvm::all_of(CD->inits(), [&](const CXXCtorInitializer *CI) { | |||
416 | if (const CXXConstructExpr *CE = | |||
417 | dyn_cast<CXXConstructExpr>(CI->getInit())) | |||
418 | return isEmptyCudaConstructor(Loc, CE->getConstructor()); | |||
419 | return false; | |||
420 | })) | |||
421 | return false; | |||
422 | ||||
423 | return true; | |||
424 | } | |||
425 | ||||
426 | bool Sema::isEmptyCudaDestructor(SourceLocation Loc, CXXDestructorDecl *DD) { | |||
427 | // No destructor -> no problem. | |||
428 | if (!DD) | |||
429 | return true; | |||
430 | ||||
431 | if (!DD->isDefined() && DD->isTemplateInstantiation()) | |||
432 | InstantiateFunctionDefinition(Loc, DD->getFirstDecl()); | |||
433 | ||||
434 | // (E.2.3.1, CUDA 7.5) A destructor for a class type is considered | |||
435 | // empty at a point in the translation unit, if it is either a | |||
436 | // trivial constructor | |||
437 | if (DD->isTrivial()) | |||
438 | return true; | |||
439 | ||||
440 | // ... or it satisfies all of the following conditions: | |||
441 | // The destructor function has been defined. | |||
442 | // and the function body is an empty compound statement. | |||
443 | if (!DD->hasTrivialBody()) | |||
444 | return false; | |||
445 | ||||
446 | const CXXRecordDecl *ClassDecl = DD->getParent(); | |||
447 | ||||
448 | // Its class has no virtual functions and no virtual base classes. | |||
449 | if (ClassDecl->isDynamicClass()) | |||
450 | return false; | |||
451 | ||||
452 | // Only empty destructors are allowed. This will recursively check | |||
453 | // destructors for all base classes... | |||
454 | if (!llvm::all_of(ClassDecl->bases(), [&](const CXXBaseSpecifier &BS) { | |||
455 | if (CXXRecordDecl *RD = BS.getType()->getAsCXXRecordDecl()) | |||
456 | return isEmptyCudaDestructor(Loc, RD->getDestructor()); | |||
457 | return true; | |||
458 | })) | |||
459 | return false; | |||
460 | ||||
461 | // ... and member fields. | |||
462 | if (!llvm::all_of(ClassDecl->fields(), [&](const FieldDecl *Field) { | |||
463 | if (CXXRecordDecl *RD = Field->getType() | |||
464 | ->getBaseElementTypeUnsafe() | |||
465 | ->getAsCXXRecordDecl()) | |||
466 | return isEmptyCudaDestructor(Loc, RD->getDestructor()); | |||
467 | return true; | |||
468 | })) | |||
469 | return false; | |||
470 | ||||
471 | return true; | |||
472 | } | |||
473 | ||||
474 | // With -fcuda-host-device-constexpr, an unattributed constexpr function is | |||
475 | // treated as implicitly __host__ __device__, unless: | |||
476 | // * it is a variadic function (device-side variadic functions are not | |||
477 | // allowed), or | |||
478 | // * a __device__ function with this signature was already declared, in which | |||
479 | // case in which case we output an error, unless the __device__ decl is in a | |||
480 | // system header, in which case we leave the constexpr function unattributed. | |||
481 | // | |||
482 | // In addition, all function decls are treated as __host__ __device__ when | |||
483 | // ForceCUDAHostDeviceDepth > 0 (corresponding to code within a | |||
484 | // #pragma clang force_cuda_host_device_begin/end | |||
485 | // pair). | |||
486 | void Sema::maybeAddCUDAHostDeviceAttrs(FunctionDecl *NewD, | |||
487 | const LookupResult &Previous) { | |||
488 | assert(getLangOpts().CUDA && "Should only be called during CUDA compilation")(static_cast <bool> (getLangOpts().CUDA && "Should only be called during CUDA compilation" ) ? void (0) : __assert_fail ("getLangOpts().CUDA && \"Should only be called during CUDA compilation\"" , "/build/llvm-toolchain-snapshot-7~svn326425/tools/clang/lib/Sema/SemaCUDA.cpp" , 488, __extension__ __PRETTY_FUNCTION__)); | |||
489 | ||||
490 | if (ForceCUDAHostDeviceDepth > 0) { | |||
491 | if (!NewD->hasAttr<CUDAHostAttr>()) | |||
492 | NewD->addAttr(CUDAHostAttr::CreateImplicit(Context)); | |||
493 | if (!NewD->hasAttr<CUDADeviceAttr>()) | |||
494 | NewD->addAttr(CUDADeviceAttr::CreateImplicit(Context)); | |||
495 | return; | |||
496 | } | |||
497 | ||||
498 | if (!getLangOpts().CUDAHostDeviceConstexpr || !NewD->isConstexpr() || | |||
499 | NewD->isVariadic() || NewD->hasAttr<CUDAHostAttr>() || | |||
500 | NewD->hasAttr<CUDADeviceAttr>() || NewD->hasAttr<CUDAGlobalAttr>()) | |||
501 | return; | |||
502 | ||||
503 | // Is D a __device__ function with the same signature as NewD, ignoring CUDA | |||
504 | // attributes? | |||
505 | auto IsMatchingDeviceFn = [&](NamedDecl *D) { | |||
506 | if (UsingShadowDecl *Using = dyn_cast<UsingShadowDecl>(D)) | |||
507 | D = Using->getTargetDecl(); | |||
508 | FunctionDecl *OldD = D->getAsFunction(); | |||
509 | return OldD && OldD->hasAttr<CUDADeviceAttr>() && | |||
510 | !OldD->hasAttr<CUDAHostAttr>() && | |||
511 | !IsOverload(NewD, OldD, /* UseMemberUsingDeclRules = */ false, | |||
512 | /* ConsiderCudaAttrs = */ false); | |||
513 | }; | |||
514 | auto It = llvm::find_if(Previous, IsMatchingDeviceFn); | |||
515 | if (It != Previous.end()) { | |||
516 | // We found a __device__ function with the same name and signature as NewD | |||
517 | // (ignoring CUDA attrs). This is an error unless that function is defined | |||
518 | // in a system header, in which case we simply return without making NewD | |||
519 | // host+device. | |||
520 | NamedDecl *Match = *It; | |||
521 | if (!getSourceManager().isInSystemHeader(Match->getLocation())) { | |||
522 | Diag(NewD->getLocation(), | |||
523 | diag::err_cuda_unattributed_constexpr_cannot_overload_device) | |||
524 | << NewD->getName(); | |||
525 | Diag(Match->getLocation(), | |||
526 | diag::note_cuda_conflicting_device_function_declared_here); | |||
527 | } | |||
528 | return; | |||
529 | } | |||
530 | ||||
531 | NewD->addAttr(CUDAHostAttr::CreateImplicit(Context)); | |||
532 | NewD->addAttr(CUDADeviceAttr::CreateImplicit(Context)); | |||
533 | } | |||
534 | ||||
535 | // In CUDA, there are some constructs which may appear in semantically-valid | |||
536 | // code, but trigger errors if we ever generate code for the function in which | |||
537 | // they appear. Essentially every construct you're not allowed to use on the | |||
538 | // device falls into this category, because you are allowed to use these | |||
539 | // constructs in a __host__ __device__ function, but only if that function is | |||
540 | // never codegen'ed on the device. | |||
541 | // | |||
542 | // To handle semantic checking for these constructs, we keep track of the set of | |||
543 | // functions we know will be emitted, either because we could tell a priori that | |||
544 | // they would be emitted, or because they were transitively called by a | |||
545 | // known-emitted function. | |||
546 | // | |||
547 | // We also keep a partial call graph of which not-known-emitted functions call | |||
548 | // which other not-known-emitted functions. | |||
549 | // | |||
550 | // When we see something which is illegal if the current function is emitted | |||
551 | // (usually by way of CUDADiagIfDeviceCode, CUDADiagIfHostCode, or | |||
552 | // CheckCUDACall), we first check if the current function is known-emitted. If | |||
553 | // so, we immediately output the diagnostic. | |||
554 | // | |||
555 | // Otherwise, we "defer" the diagnostic. It sits in Sema::CUDADeferredDiags | |||
556 | // until we discover that the function is known-emitted, at which point we take | |||
557 | // it out of this map and emit the diagnostic. | |||
558 | ||||
559 | Sema::CUDADiagBuilder::CUDADiagBuilder(Kind K, SourceLocation Loc, | |||
560 | unsigned DiagID, FunctionDecl *Fn, | |||
561 | Sema &S) | |||
562 | : S(S), Loc(Loc), DiagID(DiagID), Fn(Fn), | |||
563 | ShowCallStack(K == K_ImmediateWithCallStack || K == K_Deferred) { | |||
564 | switch (K) { | |||
565 | case K_Nop: | |||
566 | break; | |||
567 | case K_Immediate: | |||
568 | case K_ImmediateWithCallStack: | |||
569 | ImmediateDiag.emplace(S.Diag(Loc, DiagID)); | |||
570 | break; | |||
571 | case K_Deferred: | |||
572 | assert(Fn && "Must have a function to attach the deferred diag to.")(static_cast <bool> (Fn && "Must have a function to attach the deferred diag to." ) ? void (0) : __assert_fail ("Fn && \"Must have a function to attach the deferred diag to.\"" , "/build/llvm-toolchain-snapshot-7~svn326425/tools/clang/lib/Sema/SemaCUDA.cpp" , 572, __extension__ __PRETTY_FUNCTION__)); | |||
573 | PartialDiag.emplace(S.PDiag(DiagID)); | |||
574 | break; | |||
575 | } | |||
576 | } | |||
577 | ||||
578 | // Print notes showing how we can reach FD starting from an a priori | |||
579 | // known-callable function. | |||
580 | static void EmitCallStackNotes(Sema &S, FunctionDecl *FD) { | |||
581 | auto FnIt = S.CUDAKnownEmittedFns.find(FD); | |||
582 | while (FnIt != S.CUDAKnownEmittedFns.end()) { | |||
583 | DiagnosticBuilder Builder( | |||
584 | S.Diags.Report(FnIt->second.Loc, diag::note_called_by)); | |||
585 | Builder << FnIt->second.FD; | |||
586 | Builder.setForceEmit(); | |||
587 | ||||
588 | FnIt = S.CUDAKnownEmittedFns.find(FnIt->second.FD); | |||
589 | } | |||
590 | } | |||
591 | ||||
592 | Sema::CUDADiagBuilder::~CUDADiagBuilder() { | |||
593 | if (ImmediateDiag) { | |||
594 | // Emit our diagnostic and, if it was a warning or error, output a callstack | |||
595 | // if Fn isn't a priori known-emitted. | |||
596 | bool IsWarningOrError = S.getDiagnostics().getDiagnosticLevel( | |||
597 | DiagID, Loc) >= DiagnosticsEngine::Warning; | |||
598 | ImmediateDiag.reset(); // Emit the immediate diag. | |||
599 | if (IsWarningOrError && ShowCallStack) | |||
600 | EmitCallStackNotes(S, Fn); | |||
601 | } else if (PartialDiag) { | |||
602 | assert(ShowCallStack && "Must always show call stack for deferred diags.")(static_cast <bool> (ShowCallStack && "Must always show call stack for deferred diags." ) ? void (0) : __assert_fail ("ShowCallStack && \"Must always show call stack for deferred diags.\"" , "/build/llvm-toolchain-snapshot-7~svn326425/tools/clang/lib/Sema/SemaCUDA.cpp" , 602, __extension__ __PRETTY_FUNCTION__)); | |||
603 | S.CUDADeferredDiags[Fn].push_back({Loc, std::move(*PartialDiag)}); | |||
604 | } | |||
605 | } | |||
606 | ||||
607 | // Do we know that we will eventually codegen the given function? | |||
608 | static bool IsKnownEmitted(Sema &S, FunctionDecl *FD) { | |||
609 | // Templates are emitted when they're instantiated. | |||
610 | if (FD->isDependentContext()) | |||
611 | return false; | |||
612 | ||||
613 | // When compiling for device, host functions are never emitted. Similarly, | |||
614 | // when compiling for host, device and global functions are never emitted. | |||
615 | // (Technically, we do emit a host-side stub for global functions, but this | |||
616 | // doesn't count for our purposes here.) | |||
617 | Sema::CUDAFunctionTarget T = S.IdentifyCUDATarget(FD); | |||
618 | if (S.getLangOpts().CUDAIsDevice && T == Sema::CFT_Host) | |||
619 | return false; | |||
620 | if (!S.getLangOpts().CUDAIsDevice && | |||
621 | (T == Sema::CFT_Device || T == Sema::CFT_Global)) | |||
622 | return false; | |||
623 | ||||
624 | // Check whether this function is externally visible -- if so, it's | |||
625 | // known-emitted. | |||
626 | // | |||
627 | // We have to check the GVA linkage of the function's *definition* -- if we | |||
628 | // only have a declaration, we don't know whether or not the function will be | |||
629 | // emitted, because (say) the definition could include "inline". | |||
630 | FunctionDecl *Def = FD->getDefinition(); | |||
631 | ||||
632 | if (Def && | |||
633 | !isDiscardableGVALinkage(S.getASTContext().GetGVALinkageForFunction(Def))) | |||
634 | return true; | |||
635 | ||||
636 | // Otherwise, the function is known-emitted if it's in our set of | |||
637 | // known-emitted functions. | |||
638 | return S.CUDAKnownEmittedFns.count(FD) > 0; | |||
639 | } | |||
640 | ||||
641 | Sema::CUDADiagBuilder Sema::CUDADiagIfDeviceCode(SourceLocation Loc, | |||
642 | unsigned DiagID) { | |||
643 | assert(getLangOpts().CUDA && "Should only be called during CUDA compilation")(static_cast <bool> (getLangOpts().CUDA && "Should only be called during CUDA compilation" ) ? void (0) : __assert_fail ("getLangOpts().CUDA && \"Should only be called during CUDA compilation\"" , "/build/llvm-toolchain-snapshot-7~svn326425/tools/clang/lib/Sema/SemaCUDA.cpp" , 643, __extension__ __PRETTY_FUNCTION__)); | |||
644 | CUDADiagBuilder::Kind DiagKind = [&] { | |||
645 | switch (CurrentCUDATarget()) { | |||
646 | case CFT_Global: | |||
647 | case CFT_Device: | |||
648 | return CUDADiagBuilder::K_Immediate; | |||
649 | case CFT_HostDevice: | |||
650 | // An HD function counts as host code if we're compiling for host, and | |||
651 | // device code if we're compiling for device. Defer any errors in device | |||
652 | // mode until the function is known-emitted. | |||
653 | if (getLangOpts().CUDAIsDevice) { | |||
654 | return IsKnownEmitted(*this, dyn_cast<FunctionDecl>(CurContext)) | |||
655 | ? CUDADiagBuilder::K_ImmediateWithCallStack | |||
656 | : CUDADiagBuilder::K_Deferred; | |||
657 | } | |||
658 | return CUDADiagBuilder::K_Nop; | |||
659 | ||||
660 | default: | |||
661 | return CUDADiagBuilder::K_Nop; | |||
662 | } | |||
663 | }(); | |||
664 | return CUDADiagBuilder(DiagKind, Loc, DiagID, | |||
665 | dyn_cast<FunctionDecl>(CurContext), *this); | |||
666 | } | |||
667 | ||||
668 | Sema::CUDADiagBuilder Sema::CUDADiagIfHostCode(SourceLocation Loc, | |||
669 | unsigned DiagID) { | |||
670 | assert(getLangOpts().CUDA && "Should only be called during CUDA compilation")(static_cast <bool> (getLangOpts().CUDA && "Should only be called during CUDA compilation" ) ? void (0) : __assert_fail ("getLangOpts().CUDA && \"Should only be called during CUDA compilation\"" , "/build/llvm-toolchain-snapshot-7~svn326425/tools/clang/lib/Sema/SemaCUDA.cpp" , 670, __extension__ __PRETTY_FUNCTION__)); | |||
671 | CUDADiagBuilder::Kind DiagKind = [&] { | |||
672 | switch (CurrentCUDATarget()) { | |||
673 | case CFT_Host: | |||
674 | return CUDADiagBuilder::K_Immediate; | |||
675 | case CFT_HostDevice: | |||
676 | // An HD function counts as host code if we're compiling for host, and | |||
677 | // device code if we're compiling for device. Defer any errors in device | |||
678 | // mode until the function is known-emitted. | |||
679 | if (getLangOpts().CUDAIsDevice) | |||
680 | return CUDADiagBuilder::K_Nop; | |||
681 | ||||
682 | return IsKnownEmitted(*this, dyn_cast<FunctionDecl>(CurContext)) | |||
683 | ? CUDADiagBuilder::K_ImmediateWithCallStack | |||
684 | : CUDADiagBuilder::K_Deferred; | |||
685 | default: | |||
686 | return CUDADiagBuilder::K_Nop; | |||
687 | } | |||
688 | }(); | |||
689 | return CUDADiagBuilder(DiagKind, Loc, DiagID, | |||
690 | dyn_cast<FunctionDecl>(CurContext), *this); | |||
691 | } | |||
692 | ||||
693 | // Emit any deferred diagnostics for FD and erase them from the map in which | |||
694 | // they're stored. | |||
695 | static void EmitDeferredDiags(Sema &S, FunctionDecl *FD) { | |||
696 | auto It = S.CUDADeferredDiags.find(FD); | |||
697 | if (It == S.CUDADeferredDiags.end()) | |||
698 | return; | |||
699 | bool HasWarningOrError = false; | |||
700 | for (PartialDiagnosticAt &PDAt : It->second) { | |||
701 | const SourceLocation &Loc = PDAt.first; | |||
702 | const PartialDiagnostic &PD = PDAt.second; | |||
703 | HasWarningOrError |= S.getDiagnostics().getDiagnosticLevel( | |||
704 | PD.getDiagID(), Loc) >= DiagnosticsEngine::Warning; | |||
705 | DiagnosticBuilder Builder(S.Diags.Report(Loc, PD.getDiagID())); | |||
706 | Builder.setForceEmit(); | |||
707 | PD.Emit(Builder); | |||
708 | } | |||
709 | S.CUDADeferredDiags.erase(It); | |||
710 | ||||
711 | // FIXME: Should this be called after every warning/error emitted in the loop | |||
712 | // above, instead of just once per function? That would be consistent with | |||
713 | // how we handle immediate errors, but it also seems like a bit much. | |||
714 | if (HasWarningOrError) | |||
715 | EmitCallStackNotes(S, FD); | |||
716 | } | |||
717 | ||||
718 | // Indicate that this function (and thus everything it transtively calls) will | |||
719 | // be codegen'ed, and emit any deferred diagnostics on this function and its | |||
720 | // (transitive) callees. | |||
721 | static void MarkKnownEmitted(Sema &S, FunctionDecl *OrigCaller, | |||
722 | FunctionDecl *OrigCallee, SourceLocation OrigLoc) { | |||
723 | // Nothing to do if we already know that FD is emitted. | |||
724 | if (IsKnownEmitted(S, OrigCallee)) { | |||
725 | assert(!S.CUDACallGraph.count(OrigCallee))(static_cast <bool> (!S.CUDACallGraph.count(OrigCallee) ) ? void (0) : __assert_fail ("!S.CUDACallGraph.count(OrigCallee)" , "/build/llvm-toolchain-snapshot-7~svn326425/tools/clang/lib/Sema/SemaCUDA.cpp" , 725, __extension__ __PRETTY_FUNCTION__)); | |||
726 | return; | |||
727 | } | |||
728 | ||||
729 | // We've just discovered that OrigCallee is known-emitted. Walk our call | |||
730 | // graph to see what else we can now discover also must be emitted. | |||
731 | ||||
732 | struct CallInfo { | |||
733 | FunctionDecl *Caller; | |||
734 | FunctionDecl *Callee; | |||
735 | SourceLocation Loc; | |||
736 | }; | |||
737 | llvm::SmallVector<CallInfo, 4> Worklist = {{OrigCaller, OrigCallee, OrigLoc}}; | |||
738 | llvm::SmallSet<CanonicalDeclPtr<FunctionDecl>, 4> Seen; | |||
739 | Seen.insert(OrigCallee); | |||
740 | while (!Worklist.empty()) { | |||
741 | CallInfo C = Worklist.pop_back_val(); | |||
742 | assert(!IsKnownEmitted(S, C.Callee) &&(static_cast <bool> (!IsKnownEmitted(S, C.Callee) && "Worklist should not contain known-emitted functions.") ? void (0) : __assert_fail ("!IsKnownEmitted(S, C.Callee) && \"Worklist should not contain known-emitted functions.\"" , "/build/llvm-toolchain-snapshot-7~svn326425/tools/clang/lib/Sema/SemaCUDA.cpp" , 743, __extension__ __PRETTY_FUNCTION__)) | |||
743 | "Worklist should not contain known-emitted functions.")(static_cast <bool> (!IsKnownEmitted(S, C.Callee) && "Worklist should not contain known-emitted functions.") ? void (0) : __assert_fail ("!IsKnownEmitted(S, C.Callee) && \"Worklist should not contain known-emitted functions.\"" , "/build/llvm-toolchain-snapshot-7~svn326425/tools/clang/lib/Sema/SemaCUDA.cpp" , 743, __extension__ __PRETTY_FUNCTION__)); | |||
744 | S.CUDAKnownEmittedFns[C.Callee] = {C.Caller, C.Loc}; | |||
745 | EmitDeferredDiags(S, C.Callee); | |||
746 | ||||
747 | // If this is a template instantiation, explore its callgraph as well: | |||
748 | // Non-dependent calls are part of the template's callgraph, while dependent | |||
749 | // calls are part of to the instantiation's call graph. | |||
750 | if (auto *Templ = C.Callee->getPrimaryTemplate()) { | |||
751 | FunctionDecl *TemplFD = Templ->getAsFunction(); | |||
752 | if (!Seen.count(TemplFD) && !S.CUDAKnownEmittedFns.count(TemplFD)) { | |||
753 | Seen.insert(TemplFD); | |||
754 | Worklist.push_back( | |||
755 | {/* Caller = */ C.Caller, /* Callee = */ TemplFD, C.Loc}); | |||
756 | } | |||
757 | } | |||
758 | ||||
759 | // Add all functions called by Callee to our worklist. | |||
760 | auto CGIt = S.CUDACallGraph.find(C.Callee); | |||
761 | if (CGIt == S.CUDACallGraph.end()) | |||
762 | continue; | |||
763 | ||||
764 | for (std::pair<CanonicalDeclPtr<FunctionDecl>, SourceLocation> FDLoc : | |||
765 | CGIt->second) { | |||
766 | FunctionDecl *NewCallee = FDLoc.first; | |||
767 | SourceLocation CallLoc = FDLoc.second; | |||
768 | if (Seen.count(NewCallee) || IsKnownEmitted(S, NewCallee)) | |||
769 | continue; | |||
770 | Seen.insert(NewCallee); | |||
771 | Worklist.push_back( | |||
772 | {/* Caller = */ C.Callee, /* Callee = */ NewCallee, CallLoc}); | |||
773 | } | |||
774 | ||||
775 | // C.Callee is now known-emitted, so we no longer need to maintain its list | |||
776 | // of callees in CUDACallGraph. | |||
777 | S.CUDACallGraph.erase(CGIt); | |||
778 | } | |||
779 | } | |||
780 | ||||
781 | bool Sema::CheckCUDACall(SourceLocation Loc, FunctionDecl *Callee) { | |||
782 | assert(getLangOpts().CUDA && "Should only be called during CUDA compilation")(static_cast <bool> (getLangOpts().CUDA && "Should only be called during CUDA compilation" ) ? void (0) : __assert_fail ("getLangOpts().CUDA && \"Should only be called during CUDA compilation\"" , "/build/llvm-toolchain-snapshot-7~svn326425/tools/clang/lib/Sema/SemaCUDA.cpp" , 782, __extension__ __PRETTY_FUNCTION__)); | |||
783 | assert(Callee && "Callee may not be null.")(static_cast <bool> (Callee && "Callee may not be null." ) ? void (0) : __assert_fail ("Callee && \"Callee may not be null.\"" , "/build/llvm-toolchain-snapshot-7~svn326425/tools/clang/lib/Sema/SemaCUDA.cpp" , 783, __extension__ __PRETTY_FUNCTION__)); | |||
784 | // FIXME: Is bailing out early correct here? Should we instead assume that | |||
785 | // the caller is a global initializer? | |||
786 | FunctionDecl *Caller = dyn_cast<FunctionDecl>(CurContext); | |||
787 | if (!Caller) | |||
| ||||
788 | return true; | |||
789 | ||||
790 | // If the caller is known-emitted, mark the callee as known-emitted. | |||
791 | // Otherwise, mark the call in our call graph so we can traverse it later. | |||
792 | bool CallerKnownEmitted = IsKnownEmitted(*this, Caller); | |||
793 | if (CallerKnownEmitted) | |||
794 | MarkKnownEmitted(*this, Caller, Callee, Loc); | |||
795 | else { | |||
796 | // If we have | |||
797 | // host fn calls kernel fn calls host+device, | |||
798 | // the HD function does not get instantiated on the host. We model this by | |||
799 | // omitting at the call to the kernel from the callgraph. This ensures | |||
800 | // that, when compiling for host, only HD functions actually called from the | |||
801 | // host get marked as known-emitted. | |||
802 | if (getLangOpts().CUDAIsDevice || IdentifyCUDATarget(Callee) != CFT_Global) | |||
803 | CUDACallGraph[Caller].insert({Callee, Loc}); | |||
804 | } | |||
805 | ||||
806 | CUDADiagBuilder::Kind DiagKind = [&] { | |||
807 | switch (IdentifyCUDAPreference(Caller, Callee)) { | |||
808 | case CFP_Never: | |||
809 | return CUDADiagBuilder::K_Immediate; | |||
810 | case CFP_WrongSide: | |||
811 | assert(Caller && "WrongSide calls require a non-null caller")(static_cast <bool> (Caller && "WrongSide calls require a non-null caller" ) ? void (0) : __assert_fail ("Caller && \"WrongSide calls require a non-null caller\"" , "/build/llvm-toolchain-snapshot-7~svn326425/tools/clang/lib/Sema/SemaCUDA.cpp" , 811, __extension__ __PRETTY_FUNCTION__)); | |||
812 | // If we know the caller will be emitted, we know this wrong-side call | |||
813 | // will be emitted, so it's an immediate error. Otherwise, defer the | |||
814 | // error until we know the caller is emitted. | |||
815 | return CallerKnownEmitted ? CUDADiagBuilder::K_ImmediateWithCallStack | |||
816 | : CUDADiagBuilder::K_Deferred; | |||
817 | default: | |||
818 | return CUDADiagBuilder::K_Nop; | |||
819 | } | |||
820 | }(); | |||
821 | ||||
822 | if (DiagKind == CUDADiagBuilder::K_Nop) | |||
823 | return true; | |||
824 | ||||
825 | // Avoid emitting this error twice for the same location. Using a hashtable | |||
826 | // like this is unfortunate, but because we must continue parsing as normal | |||
827 | // after encountering a deferred error, it's otherwise very tricky for us to | |||
828 | // ensure that we only emit this deferred error once. | |||
829 | if (!LocsWithCUDACallDiags.insert({Caller, Loc}).second) | |||
830 | return true; | |||
831 | ||||
832 | CUDADiagBuilder(DiagKind, Loc, diag::err_ref_bad_target, Caller, *this) | |||
833 | << IdentifyCUDATarget(Callee) << Callee << IdentifyCUDATarget(Caller); | |||
834 | CUDADiagBuilder(DiagKind, Callee->getLocation(), diag::note_previous_decl, | |||
835 | Caller, *this) | |||
836 | << Callee; | |||
837 | return DiagKind != CUDADiagBuilder::K_Immediate && | |||
| ||||
838 | DiagKind != CUDADiagBuilder::K_ImmediateWithCallStack; | |||
839 | } | |||
840 | ||||
841 | void Sema::CUDASetLambdaAttrs(CXXMethodDecl *Method) { | |||
842 | assert(getLangOpts().CUDA && "Should only be called during CUDA compilation")(static_cast <bool> (getLangOpts().CUDA && "Should only be called during CUDA compilation" ) ? void (0) : __assert_fail ("getLangOpts().CUDA && \"Should only be called during CUDA compilation\"" , "/build/llvm-toolchain-snapshot-7~svn326425/tools/clang/lib/Sema/SemaCUDA.cpp" , 842, __extension__ __PRETTY_FUNCTION__)); | |||
843 | if (Method->hasAttr<CUDAHostAttr>() || Method->hasAttr<CUDADeviceAttr>()) | |||
844 | return; | |||
845 | FunctionDecl *CurFn = dyn_cast<FunctionDecl>(CurContext); | |||
846 | if (!CurFn) | |||
847 | return; | |||
848 | CUDAFunctionTarget Target = IdentifyCUDATarget(CurFn); | |||
849 | if (Target == CFT_Global || Target == CFT_Device) { | |||
850 | Method->addAttr(CUDADeviceAttr::CreateImplicit(Context)); | |||
851 | } else if (Target == CFT_HostDevice) { | |||
852 | Method->addAttr(CUDADeviceAttr::CreateImplicit(Context)); | |||
853 | Method->addAttr(CUDAHostAttr::CreateImplicit(Context)); | |||
854 | } | |||
855 | } | |||
856 | ||||
857 | void Sema::checkCUDATargetOverload(FunctionDecl *NewFD, | |||
858 | const LookupResult &Previous) { | |||
859 | assert(getLangOpts().CUDA && "Should only be called during CUDA compilation")(static_cast <bool> (getLangOpts().CUDA && "Should only be called during CUDA compilation" ) ? void (0) : __assert_fail ("getLangOpts().CUDA && \"Should only be called during CUDA compilation\"" , "/build/llvm-toolchain-snapshot-7~svn326425/tools/clang/lib/Sema/SemaCUDA.cpp" , 859, __extension__ __PRETTY_FUNCTION__)); | |||
860 | CUDAFunctionTarget NewTarget = IdentifyCUDATarget(NewFD); | |||
861 | for (NamedDecl *OldND : Previous) { | |||
862 | FunctionDecl *OldFD = OldND->getAsFunction(); | |||
863 | if (!OldFD) | |||
864 | continue; | |||
865 | ||||
866 | CUDAFunctionTarget OldTarget = IdentifyCUDATarget(OldFD); | |||
867 | // Don't allow HD and global functions to overload other functions with the | |||
868 | // same signature. We allow overloading based on CUDA attributes so that | |||
869 | // functions can have different implementations on the host and device, but | |||
870 | // HD/global functions "exist" in some sense on both the host and device, so | |||
871 | // should have the same implementation on both sides. | |||
872 | if (NewTarget != OldTarget && | |||
873 | ((NewTarget == CFT_HostDevice) || (OldTarget == CFT_HostDevice) || | |||
874 | (NewTarget == CFT_Global) || (OldTarget == CFT_Global)) && | |||
875 | !IsOverload(NewFD, OldFD, /* UseMemberUsingDeclRules = */ false, | |||
876 | /* ConsiderCudaAttrs = */ false)) { | |||
877 | Diag(NewFD->getLocation(), diag::err_cuda_ovl_target) | |||
878 | << NewTarget << NewFD->getDeclName() << OldTarget << OldFD; | |||
879 | Diag(OldFD->getLocation(), diag::note_previous_declaration); | |||
880 | NewFD->setInvalidDecl(); | |||
881 | break; | |||
882 | } | |||
883 | } | |||
884 | } | |||
885 | ||||
886 | template <typename AttrTy> | |||
887 | static void copyAttrIfPresent(Sema &S, FunctionDecl *FD, | |||
888 | const FunctionDecl &TemplateFD) { | |||
889 | if (AttrTy *Attribute = TemplateFD.getAttr<AttrTy>()) { | |||
890 | AttrTy *Clone = Attribute->clone(S.Context); | |||
891 | Clone->setInherited(true); | |||
892 | FD->addAttr(Clone); | |||
893 | } | |||
894 | } | |||
895 | ||||
896 | void Sema::inheritCUDATargetAttrs(FunctionDecl *FD, | |||
897 | const FunctionTemplateDecl &TD) { | |||
898 | const FunctionDecl &TemplateFD = *TD.getTemplatedDecl(); | |||
899 | copyAttrIfPresent<CUDAGlobalAttr>(*this, FD, TemplateFD); | |||
900 | copyAttrIfPresent<CUDAHostAttr>(*this, FD, TemplateFD); | |||
901 | copyAttrIfPresent<CUDADeviceAttr>(*this, FD, TemplateFD); | |||
902 | } |
1 | //===--- Sema.h - Semantic Analysis & AST Building --------------*- 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 defines the Sema class, which performs semantic analysis and |
11 | // builds ASTs. |
12 | // |
13 | //===----------------------------------------------------------------------===// |
14 | |
15 | #ifndef LLVM_CLANG_SEMA_SEMA_H |
16 | #define LLVM_CLANG_SEMA_SEMA_H |
17 | |
18 | #include "clang/AST/Attr.h" |
19 | #include "clang/AST/Availability.h" |
20 | #include "clang/AST/DeclarationName.h" |
21 | #include "clang/AST/DeclTemplate.h" |
22 | #include "clang/AST/Expr.h" |
23 | #include "clang/AST/ExprObjC.h" |
24 | #include "clang/AST/ExternalASTSource.h" |
25 | #include "clang/AST/LocInfoType.h" |
26 | #include "clang/AST/MangleNumberingContext.h" |
27 | #include "clang/AST/NSAPI.h" |
28 | #include "clang/AST/PrettyPrinter.h" |
29 | #include "clang/AST/StmtCXX.h" |
30 | #include "clang/AST/TypeLoc.h" |
31 | #include "clang/AST/TypeOrdering.h" |
32 | #include "clang/Basic/ExpressionTraits.h" |
33 | #include "clang/Basic/LangOptions.h" |
34 | #include "clang/Basic/Module.h" |
35 | #include "clang/Basic/OpenMPKinds.h" |
36 | #include "clang/Basic/PragmaKinds.h" |
37 | #include "clang/Basic/Specifiers.h" |
38 | #include "clang/Basic/TemplateKinds.h" |
39 | #include "clang/Basic/TypeTraits.h" |
40 | #include "clang/Sema/AnalysisBasedWarnings.h" |
41 | #include "clang/Sema/CleanupInfo.h" |
42 | #include "clang/Sema/DeclSpec.h" |
43 | #include "clang/Sema/ExternalSemaSource.h" |
44 | #include "clang/Sema/IdentifierResolver.h" |
45 | #include "clang/Sema/ObjCMethodList.h" |
46 | #include "clang/Sema/Ownership.h" |
47 | #include "clang/Sema/Scope.h" |
48 | #include "clang/Sema/ScopeInfo.h" |
49 | #include "clang/Sema/TypoCorrection.h" |
50 | #include "clang/Sema/Weak.h" |
51 | #include "llvm/ADT/ArrayRef.h" |
52 | #include "llvm/ADT/Optional.h" |
53 | #include "llvm/ADT/SetVector.h" |
54 | #include "llvm/ADT/SmallPtrSet.h" |
55 | #include "llvm/ADT/SmallVector.h" |
56 | #include "llvm/ADT/TinyPtrVector.h" |
57 | #include <deque> |
58 | #include <memory> |
59 | #include <string> |
60 | #include <vector> |
61 | |
62 | namespace llvm { |
63 | class APSInt; |
64 | template <typename ValueT> struct DenseMapInfo; |
65 | template <typename ValueT, typename ValueInfoT> class DenseSet; |
66 | class SmallBitVector; |
67 | struct InlineAsmIdentifierInfo; |
68 | } |
69 | |
70 | namespace clang { |
71 | class ADLResult; |
72 | class ASTConsumer; |
73 | class ASTContext; |
74 | class ASTMutationListener; |
75 | class ASTReader; |
76 | class ASTWriter; |
77 | class ArrayType; |
78 | class AttributeList; |
79 | class BindingDecl; |
80 | class BlockDecl; |
81 | class CapturedDecl; |
82 | class CXXBasePath; |
83 | class CXXBasePaths; |
84 | class CXXBindTemporaryExpr; |
85 | typedef SmallVector<CXXBaseSpecifier*, 4> CXXCastPath; |
86 | class CXXConstructorDecl; |
87 | class CXXConversionDecl; |
88 | class CXXDeleteExpr; |
89 | class CXXDestructorDecl; |
90 | class CXXFieldCollector; |
91 | class CXXMemberCallExpr; |
92 | class CXXMethodDecl; |
93 | class CXXScopeSpec; |
94 | class CXXTemporary; |
95 | class CXXTryStmt; |
96 | class CallExpr; |
97 | class ClassTemplateDecl; |
98 | class ClassTemplatePartialSpecializationDecl; |
99 | class ClassTemplateSpecializationDecl; |
100 | class VarTemplatePartialSpecializationDecl; |
101 | class CodeCompleteConsumer; |
102 | class CodeCompletionAllocator; |
103 | class CodeCompletionTUInfo; |
104 | class CodeCompletionResult; |
105 | class CoroutineBodyStmt; |
106 | class Decl; |
107 | class DeclAccessPair; |
108 | class DeclContext; |
109 | class DeclRefExpr; |
110 | class DeclaratorDecl; |
111 | class DeducedTemplateArgument; |
112 | class DependentDiagnostic; |
113 | class DesignatedInitExpr; |
114 | class Designation; |
115 | class EnableIfAttr; |
116 | class EnumConstantDecl; |
117 | class Expr; |
118 | class ExtVectorType; |
119 | class FormatAttr; |
120 | class FriendDecl; |
121 | class FunctionDecl; |
122 | class FunctionProtoType; |
123 | class FunctionTemplateDecl; |
124 | class ImplicitConversionSequence; |
125 | typedef MutableArrayRef<ImplicitConversionSequence> ConversionSequenceList; |
126 | class InitListExpr; |
127 | class InitializationKind; |
128 | class InitializationSequence; |
129 | class InitializedEntity; |
130 | class IntegerLiteral; |
131 | class LabelStmt; |
132 | class LambdaExpr; |
133 | class LangOptions; |
134 | class LocalInstantiationScope; |
135 | class LookupResult; |
136 | class MacroInfo; |
137 | typedef ArrayRef<std::pair<IdentifierInfo *, SourceLocation>> ModuleIdPath; |
138 | class ModuleLoader; |
139 | class MultiLevelTemplateArgumentList; |
140 | class NamedDecl; |
141 | class ObjCCategoryDecl; |
142 | class ObjCCategoryImplDecl; |
143 | class ObjCCompatibleAliasDecl; |
144 | class ObjCContainerDecl; |
145 | class ObjCImplDecl; |
146 | class ObjCImplementationDecl; |
147 | class ObjCInterfaceDecl; |
148 | class ObjCIvarDecl; |
149 | template <class T> class ObjCList; |
150 | class ObjCMessageExpr; |
151 | class ObjCMethodDecl; |
152 | class ObjCPropertyDecl; |
153 | class ObjCProtocolDecl; |
154 | class OMPThreadPrivateDecl; |
155 | class OMPDeclareReductionDecl; |
156 | class OMPDeclareSimdDecl; |
157 | class OMPClause; |
158 | struct OverloadCandidate; |
159 | class OverloadCandidateSet; |
160 | class OverloadExpr; |
161 | class ParenListExpr; |
162 | class ParmVarDecl; |
163 | class Preprocessor; |
164 | class PseudoDestructorTypeStorage; |
165 | class PseudoObjectExpr; |
166 | class QualType; |
167 | class StandardConversionSequence; |
168 | class Stmt; |
169 | class StringLiteral; |
170 | class SwitchStmt; |
171 | class TemplateArgument; |
172 | class TemplateArgumentList; |
173 | class TemplateArgumentLoc; |
174 | class TemplateDecl; |
175 | class TemplateInstantiationCallback; |
176 | class TemplateParameterList; |
177 | class TemplatePartialOrderingContext; |
178 | class TemplateTemplateParmDecl; |
179 | class Token; |
180 | class TypeAliasDecl; |
181 | class TypedefDecl; |
182 | class TypedefNameDecl; |
183 | class TypeLoc; |
184 | class TypoCorrectionConsumer; |
185 | class UnqualifiedId; |
186 | class UnresolvedLookupExpr; |
187 | class UnresolvedMemberExpr; |
188 | class UnresolvedSetImpl; |
189 | class UnresolvedSetIterator; |
190 | class UsingDecl; |
191 | class UsingShadowDecl; |
192 | class ValueDecl; |
193 | class VarDecl; |
194 | class VarTemplateSpecializationDecl; |
195 | class VisibilityAttr; |
196 | class VisibleDeclConsumer; |
197 | class IndirectFieldDecl; |
198 | struct DeductionFailureInfo; |
199 | class TemplateSpecCandidateSet; |
200 | |
201 | namespace sema { |
202 | class AccessedEntity; |
203 | class BlockScopeInfo; |
204 | class CapturedRegionScopeInfo; |
205 | class CapturingScopeInfo; |
206 | class CompoundScopeInfo; |
207 | class DelayedDiagnostic; |
208 | class DelayedDiagnosticPool; |
209 | class FunctionScopeInfo; |
210 | class LambdaScopeInfo; |
211 | class PossiblyUnreachableDiag; |
212 | class SemaPPCallbacks; |
213 | class TemplateDeductionInfo; |
214 | } |
215 | |
216 | namespace threadSafety { |
217 | class BeforeSet; |
218 | void threadSafetyCleanup(BeforeSet* Cache); |
219 | } |
220 | |
221 | // FIXME: No way to easily map from TemplateTypeParmTypes to |
222 | // TemplateTypeParmDecls, so we have this horrible PointerUnion. |
223 | typedef std::pair<llvm::PointerUnion<const TemplateTypeParmType*, NamedDecl*>, |
224 | SourceLocation> UnexpandedParameterPack; |
225 | |
226 | /// Describes whether we've seen any nullability information for the given |
227 | /// file. |
228 | struct FileNullability { |
229 | /// The first pointer declarator (of any pointer kind) in the file that does |
230 | /// not have a corresponding nullability annotation. |
231 | SourceLocation PointerLoc; |
232 | |
233 | /// The end location for the first pointer declarator in the file. Used for |
234 | /// placing fix-its. |
235 | SourceLocation PointerEndLoc; |
236 | |
237 | /// Which kind of pointer declarator we saw. |
238 | uint8_t PointerKind; |
239 | |
240 | /// Whether we saw any type nullability annotations in the given file. |
241 | bool SawTypeNullability = false; |
242 | }; |
243 | |
244 | /// A mapping from file IDs to a record of whether we've seen nullability |
245 | /// information in that file. |
246 | class FileNullabilityMap { |
247 | /// A mapping from file IDs to the nullability information for each file ID. |
248 | llvm::DenseMap<FileID, FileNullability> Map; |
249 | |
250 | /// A single-element cache based on the file ID. |
251 | struct { |
252 | FileID File; |
253 | FileNullability Nullability; |
254 | } Cache; |
255 | |
256 | public: |
257 | FileNullability &operator[](FileID file) { |
258 | // Check the single-element cache. |
259 | if (file == Cache.File) |
260 | return Cache.Nullability; |
261 | |
262 | // It's not in the single-element cache; flush the cache if we have one. |
263 | if (!Cache.File.isInvalid()) { |
264 | Map[Cache.File] = Cache.Nullability; |
265 | } |
266 | |
267 | // Pull this entry into the cache. |
268 | Cache.File = file; |
269 | Cache.Nullability = Map[file]; |
270 | return Cache.Nullability; |
271 | } |
272 | }; |
273 | |
274 | /// Sema - This implements semantic analysis and AST building for C. |
275 | class Sema { |
276 | Sema(const Sema &) = delete; |
277 | void operator=(const Sema &) = delete; |
278 | |
279 | ///\brief Source of additional semantic information. |
280 | ExternalSemaSource *ExternalSource; |
281 | |
282 | ///\brief Whether Sema has generated a multiplexer and has to delete it. |
283 | bool isMultiplexExternalSource; |
284 | |
285 | static bool mightHaveNonExternalLinkage(const DeclaratorDecl *FD); |
286 | |
287 | bool isVisibleSlow(const NamedDecl *D); |
288 | |
289 | /// Determine whether two declarations should be linked together, given that |
290 | /// the old declaration might not be visible and the new declaration might |
291 | /// not have external linkage. |
292 | bool shouldLinkPossiblyHiddenDecl(const NamedDecl *Old, |
293 | const NamedDecl *New) { |
294 | if (isVisible(Old)) |
295 | return true; |
296 | // See comment in below overload for why it's safe to compute the linkage |
297 | // of the new declaration here. |
298 | if (New->isExternallyDeclarable()) { |
299 | assert(Old->isExternallyDeclarable() &&(static_cast <bool> (Old->isExternallyDeclarable() && "should not have found a non-externally-declarable previous decl" ) ? void (0) : __assert_fail ("Old->isExternallyDeclarable() && \"should not have found a non-externally-declarable previous decl\"" , "/build/llvm-toolchain-snapshot-7~svn326425/tools/clang/include/clang/Sema/Sema.h" , 300, __extension__ __PRETTY_FUNCTION__)) |
300 | "should not have found a non-externally-declarable previous decl")(static_cast <bool> (Old->isExternallyDeclarable() && "should not have found a non-externally-declarable previous decl" ) ? void (0) : __assert_fail ("Old->isExternallyDeclarable() && \"should not have found a non-externally-declarable previous decl\"" , "/build/llvm-toolchain-snapshot-7~svn326425/tools/clang/include/clang/Sema/Sema.h" , 300, __extension__ __PRETTY_FUNCTION__)); |
301 | return true; |
302 | } |
303 | return false; |
304 | } |
305 | bool shouldLinkPossiblyHiddenDecl(LookupResult &Old, const NamedDecl *New); |
306 | |
307 | public: |
308 | typedef OpaquePtr<DeclGroupRef> DeclGroupPtrTy; |
309 | typedef OpaquePtr<TemplateName> TemplateTy; |
310 | typedef OpaquePtr<QualType> TypeTy; |
311 | |
312 | OpenCLOptions OpenCLFeatures; |
313 | FPOptions FPFeatures; |
314 | |
315 | const LangOptions &LangOpts; |
316 | Preprocessor &PP; |
317 | ASTContext &Context; |
318 | ASTConsumer &Consumer; |
319 | DiagnosticsEngine &Diags; |
320 | SourceManager &SourceMgr; |
321 | |
322 | /// \brief Flag indicating whether or not to collect detailed statistics. |
323 | bool CollectStats; |
324 | |
325 | /// \brief Code-completion consumer. |
326 | CodeCompleteConsumer *CodeCompleter; |
327 | |
328 | /// CurContext - This is the current declaration context of parsing. |
329 | DeclContext *CurContext; |
330 | |
331 | /// \brief Generally null except when we temporarily switch decl contexts, |
332 | /// like in \see ActOnObjCTemporaryExitContainerContext. |
333 | DeclContext *OriginalLexicalContext; |
334 | |
335 | /// VAListTagName - The declaration name corresponding to __va_list_tag. |
336 | /// This is used as part of a hack to omit that class from ADL results. |
337 | DeclarationName VAListTagName; |
338 | |
339 | bool MSStructPragmaOn; // True when \#pragma ms_struct on |
340 | |
341 | /// \brief Controls member pointer representation format under the MS ABI. |
342 | LangOptions::PragmaMSPointersToMembersKind |
343 | MSPointerToMemberRepresentationMethod; |
344 | |
345 | /// Stack of active SEH __finally scopes. Can be empty. |
346 | SmallVector<Scope*, 2> CurrentSEHFinally; |
347 | |
348 | /// \brief Source location for newly created implicit MSInheritanceAttrs |
349 | SourceLocation ImplicitMSInheritanceAttrLoc; |
350 | |
351 | /// \brief pragma clang section kind |
352 | enum PragmaClangSectionKind { |
353 | PCSK_Invalid = 0, |
354 | PCSK_BSS = 1, |
355 | PCSK_Data = 2, |
356 | PCSK_Rodata = 3, |
357 | PCSK_Text = 4 |
358 | }; |
359 | |
360 | enum PragmaClangSectionAction { |
361 | PCSA_Set = 0, |
362 | PCSA_Clear = 1 |
363 | }; |
364 | |
365 | struct PragmaClangSection { |
366 | std::string SectionName; |
367 | bool Valid = false; |
368 | SourceLocation PragmaLocation; |
369 | |
370 | void Act(SourceLocation PragmaLocation, |
371 | PragmaClangSectionAction Action, |
372 | StringLiteral* Name); |
373 | }; |
374 | |
375 | PragmaClangSection PragmaClangBSSSection; |
376 | PragmaClangSection PragmaClangDataSection; |
377 | PragmaClangSection PragmaClangRodataSection; |
378 | PragmaClangSection PragmaClangTextSection; |
379 | |
380 | enum PragmaMsStackAction { |
381 | PSK_Reset = 0x0, // #pragma () |
382 | PSK_Set = 0x1, // #pragma (value) |
383 | PSK_Push = 0x2, // #pragma (push[, id]) |
384 | PSK_Pop = 0x4, // #pragma (pop[, id]) |
385 | PSK_Show = 0x8, // #pragma (show) -- only for "pack"! |
386 | PSK_Push_Set = PSK_Push | PSK_Set, // #pragma (push[, id], value) |
387 | PSK_Pop_Set = PSK_Pop | PSK_Set, // #pragma (pop[, id], value) |
388 | }; |
389 | |
390 | template<typename ValueType> |
391 | struct PragmaStack { |
392 | struct Slot { |
393 | llvm::StringRef StackSlotLabel; |
394 | ValueType Value; |
395 | SourceLocation PragmaLocation; |
396 | SourceLocation PragmaPushLocation; |
397 | Slot(llvm::StringRef StackSlotLabel, ValueType Value, |
398 | SourceLocation PragmaLocation, SourceLocation PragmaPushLocation) |
399 | : StackSlotLabel(StackSlotLabel), Value(Value), |
400 | PragmaLocation(PragmaLocation), |
401 | PragmaPushLocation(PragmaPushLocation) {} |
402 | }; |
403 | void Act(SourceLocation PragmaLocation, |
404 | PragmaMsStackAction Action, |
405 | llvm::StringRef StackSlotLabel, |
406 | ValueType Value); |
407 | |
408 | // MSVC seems to add artificial slots to #pragma stacks on entering a C++ |
409 | // method body to restore the stacks on exit, so it works like this: |
410 | // |
411 | // struct S { |
412 | // #pragma <name>(push, InternalPragmaSlot, <current_pragma_value>) |
413 | // void Method {} |
414 | // #pragma <name>(pop, InternalPragmaSlot) |
415 | // }; |
416 | // |
417 | // It works even with #pragma vtordisp, although MSVC doesn't support |
418 | // #pragma vtordisp(push [, id], n) |
419 | // syntax. |
420 | // |
421 | // Push / pop a named sentinel slot. |
422 | void SentinelAction(PragmaMsStackAction Action, StringRef Label) { |
423 | assert((Action == PSK_Push || Action == PSK_Pop) &&(static_cast <bool> ((Action == PSK_Push || Action == PSK_Pop ) && "Can only push / pop #pragma stack sentinels!") ? void (0) : __assert_fail ("(Action == PSK_Push || Action == PSK_Pop) && \"Can only push / pop #pragma stack sentinels!\"" , "/build/llvm-toolchain-snapshot-7~svn326425/tools/clang/include/clang/Sema/Sema.h" , 424, __extension__ __PRETTY_FUNCTION__)) |
424 | "Can only push / pop #pragma stack sentinels!")(static_cast <bool> ((Action == PSK_Push || Action == PSK_Pop ) && "Can only push / pop #pragma stack sentinels!") ? void (0) : __assert_fail ("(Action == PSK_Push || Action == PSK_Pop) && \"Can only push / pop #pragma stack sentinels!\"" , "/build/llvm-toolchain-snapshot-7~svn326425/tools/clang/include/clang/Sema/Sema.h" , 424, __extension__ __PRETTY_FUNCTION__)); |
425 | Act(CurrentPragmaLocation, Action, Label, CurrentValue); |
426 | } |
427 | |
428 | // Constructors. |
429 | explicit PragmaStack(const ValueType &Default) |
430 | : DefaultValue(Default), CurrentValue(Default) {} |
431 | |
432 | bool hasValue() const { return CurrentValue != DefaultValue; } |
433 | |
434 | SmallVector<Slot, 2> Stack; |
435 | ValueType DefaultValue; // Value used for PSK_Reset action. |
436 | ValueType CurrentValue; |
437 | SourceLocation CurrentPragmaLocation; |
438 | }; |
439 | // FIXME: We should serialize / deserialize these if they occur in a PCH (but |
440 | // we shouldn't do so if they're in a module). |
441 | |
442 | /// \brief Whether to insert vtordisps prior to virtual bases in the Microsoft |
443 | /// C++ ABI. Possible values are 0, 1, and 2, which mean: |
444 | /// |
445 | /// 0: Suppress all vtordisps |
446 | /// 1: Insert vtordisps in the presence of vbase overrides and non-trivial |
447 | /// structors |
448 | /// 2: Always insert vtordisps to support RTTI on partially constructed |
449 | /// objects |
450 | PragmaStack<MSVtorDispAttr::Mode> VtorDispStack; |
451 | // #pragma pack. |
452 | // Sentinel to represent when the stack is set to mac68k alignment. |
453 | static const unsigned kMac68kAlignmentSentinel = ~0U; |
454 | PragmaStack<unsigned> PackStack; |
455 | // The current #pragma pack values and locations at each #include. |
456 | struct PackIncludeState { |
457 | unsigned CurrentValue; |
458 | SourceLocation CurrentPragmaLocation; |
459 | bool HasNonDefaultValue, ShouldWarnOnInclude; |
460 | }; |
461 | SmallVector<PackIncludeState, 8> PackIncludeStack; |
462 | // Segment #pragmas. |
463 | PragmaStack<StringLiteral *> DataSegStack; |
464 | PragmaStack<StringLiteral *> BSSSegStack; |
465 | PragmaStack<StringLiteral *> ConstSegStack; |
466 | PragmaStack<StringLiteral *> CodeSegStack; |
467 | |
468 | // RAII object to push / pop sentinel slots for all MS #pragma stacks. |
469 | // Actions should be performed only if we enter / exit a C++ method body. |
470 | class PragmaStackSentinelRAII { |
471 | public: |
472 | PragmaStackSentinelRAII(Sema &S, StringRef SlotLabel, bool ShouldAct); |
473 | ~PragmaStackSentinelRAII(); |
474 | |
475 | private: |
476 | Sema &S; |
477 | StringRef SlotLabel; |
478 | bool ShouldAct; |
479 | }; |
480 | |
481 | /// A mapping that describes the nullability we've seen in each header file. |
482 | FileNullabilityMap NullabilityMap; |
483 | |
484 | /// Last section used with #pragma init_seg. |
485 | StringLiteral *CurInitSeg; |
486 | SourceLocation CurInitSegLoc; |
487 | |
488 | /// VisContext - Manages the stack for \#pragma GCC visibility. |
489 | void *VisContext; // Really a "PragmaVisStack*" |
490 | |
491 | /// \brief This represents the stack of attributes that were pushed by |
492 | /// \#pragma clang attribute. |
493 | struct PragmaAttributeEntry { |
494 | SourceLocation Loc; |
495 | AttributeList *Attribute; |
496 | SmallVector<attr::SubjectMatchRule, 4> MatchRules; |
497 | bool IsUsed; |
498 | }; |
499 | SmallVector<PragmaAttributeEntry, 2> PragmaAttributeStack; |
500 | |
501 | /// \brief The declaration that is currently receiving an attribute from the |
502 | /// #pragma attribute stack. |
503 | const Decl *PragmaAttributeCurrentTargetDecl; |
504 | |
505 | /// \brief This represents the last location of a "#pragma clang optimize off" |
506 | /// directive if such a directive has not been closed by an "on" yet. If |
507 | /// optimizations are currently "on", this is set to an invalid location. |
508 | SourceLocation OptimizeOffPragmaLocation; |
509 | |
510 | /// \brief Flag indicating if Sema is building a recovery call expression. |
511 | /// |
512 | /// This flag is used to avoid building recovery call expressions |
513 | /// if Sema is already doing so, which would cause infinite recursions. |
514 | bool IsBuildingRecoveryCallExpr; |
515 | |
516 | /// Used to control the generation of ExprWithCleanups. |
517 | CleanupInfo Cleanup; |
518 | |
519 | /// ExprCleanupObjects - This is the stack of objects requiring |
520 | /// cleanup that are created by the current full expression. The |
521 | /// element type here is ExprWithCleanups::Object. |
522 | SmallVector<BlockDecl*, 8> ExprCleanupObjects; |
523 | |
524 | /// \brief Store a list of either DeclRefExprs or MemberExprs |
525 | /// that contain a reference to a variable (constant) that may or may not |
526 | /// be odr-used in this Expr, and we won't know until all lvalue-to-rvalue |
527 | /// and discarded value conversions have been applied to all subexpressions |
528 | /// of the enclosing full expression. This is cleared at the end of each |
529 | /// full expression. |
530 | llvm::SmallPtrSet<Expr*, 2> MaybeODRUseExprs; |
531 | |
532 | /// \brief Stack containing information about each of the nested |
533 | /// function, block, and method scopes that are currently active. |
534 | /// |
535 | /// This array is never empty. Clients should ignore the first |
536 | /// element, which is used to cache a single FunctionScopeInfo |
537 | /// that's used to parse every top-level function. |
538 | SmallVector<sema::FunctionScopeInfo *, 4> FunctionScopes; |
539 | |
540 | typedef LazyVector<TypedefNameDecl *, ExternalSemaSource, |
541 | &ExternalSemaSource::ReadExtVectorDecls, 2, 2> |
542 | ExtVectorDeclsType; |
543 | |
544 | /// ExtVectorDecls - This is a list all the extended vector types. This allows |
545 | /// us to associate a raw vector type with one of the ext_vector type names. |
546 | /// This is only necessary for issuing pretty diagnostics. |
547 | ExtVectorDeclsType ExtVectorDecls; |
548 | |
549 | /// FieldCollector - Collects CXXFieldDecls during parsing of C++ classes. |
550 | std::unique_ptr<CXXFieldCollector> FieldCollector; |
551 | |
552 | typedef llvm::SmallSetVector<const NamedDecl*, 16> NamedDeclSetType; |
553 | |
554 | /// \brief Set containing all declared private fields that are not used. |
555 | NamedDeclSetType UnusedPrivateFields; |
556 | |
557 | /// \brief Set containing all typedefs that are likely unused. |
558 | llvm::SmallSetVector<const TypedefNameDecl *, 4> |
559 | UnusedLocalTypedefNameCandidates; |
560 | |
561 | /// \brief Delete-expressions to be analyzed at the end of translation unit |
562 | /// |
563 | /// This list contains class members, and locations of delete-expressions |
564 | /// that could not be proven as to whether they mismatch with new-expression |
565 | /// used in initializer of the field. |
566 | typedef std::pair<SourceLocation, bool> DeleteExprLoc; |
567 | typedef llvm::SmallVector<DeleteExprLoc, 4> DeleteLocs; |
568 | llvm::MapVector<FieldDecl *, DeleteLocs> DeleteExprs; |
569 | |
570 | typedef llvm::SmallPtrSet<const CXXRecordDecl*, 8> RecordDeclSetTy; |
571 | |
572 | /// PureVirtualClassDiagSet - a set of class declarations which we have |
573 | /// emitted a list of pure virtual functions. Used to prevent emitting the |
574 | /// same list more than once. |
575 | std::unique_ptr<RecordDeclSetTy> PureVirtualClassDiagSet; |
576 | |
577 | /// ParsingInitForAutoVars - a set of declarations with auto types for which |
578 | /// we are currently parsing the initializer. |
579 | llvm::SmallPtrSet<const Decl*, 4> ParsingInitForAutoVars; |
580 | |
581 | /// \brief Look for a locally scoped extern "C" declaration by the given name. |
582 | NamedDecl *findLocallyScopedExternCDecl(DeclarationName Name); |
583 | |
584 | typedef LazyVector<VarDecl *, ExternalSemaSource, |
585 | &ExternalSemaSource::ReadTentativeDefinitions, 2, 2> |
586 | TentativeDefinitionsType; |
587 | |
588 | /// \brief All the tentative definitions encountered in the TU. |
589 | TentativeDefinitionsType TentativeDefinitions; |
590 | |
591 | typedef LazyVector<const DeclaratorDecl *, ExternalSemaSource, |
592 | &ExternalSemaSource::ReadUnusedFileScopedDecls, 2, 2> |
593 | UnusedFileScopedDeclsType; |
594 | |
595 | /// \brief The set of file scoped decls seen so far that have not been used |
596 | /// and must warn if not used. Only contains the first declaration. |
597 | UnusedFileScopedDeclsType UnusedFileScopedDecls; |
598 | |
599 | typedef LazyVector<CXXConstructorDecl *, ExternalSemaSource, |
600 | &ExternalSemaSource::ReadDelegatingConstructors, 2, 2> |
601 | DelegatingCtorDeclsType; |
602 | |
603 | /// \brief All the delegating constructors seen so far in the file, used for |
604 | /// cycle detection at the end of the TU. |
605 | DelegatingCtorDeclsType DelegatingCtorDecls; |
606 | |
607 | /// \brief All the overriding functions seen during a class definition |
608 | /// that had their exception spec checks delayed, plus the overridden |
609 | /// function. |
610 | SmallVector<std::pair<const CXXMethodDecl*, const CXXMethodDecl*>, 2> |
611 | DelayedExceptionSpecChecks; |
612 | |
613 | /// \brief All the members seen during a class definition which were both |
614 | /// explicitly defaulted and had explicitly-specified exception |
615 | /// specifications, along with the function type containing their |
616 | /// user-specified exception specification. Those exception specifications |
617 | /// were overridden with the default specifications, but we still need to |
618 | /// check whether they are compatible with the default specification, and |
619 | /// we can't do that until the nesting set of class definitions is complete. |
620 | SmallVector<std::pair<CXXMethodDecl*, const FunctionProtoType*>, 2> |
621 | DelayedDefaultedMemberExceptionSpecs; |
622 | |
623 | typedef llvm::MapVector<const FunctionDecl *, |
624 | std::unique_ptr<LateParsedTemplate>> |
625 | LateParsedTemplateMapT; |
626 | LateParsedTemplateMapT LateParsedTemplateMap; |
627 | |
628 | /// \brief Callback to the parser to parse templated functions when needed. |
629 | typedef void LateTemplateParserCB(void *P, LateParsedTemplate &LPT); |
630 | typedef void LateTemplateParserCleanupCB(void *P); |
631 | LateTemplateParserCB *LateTemplateParser; |
632 | LateTemplateParserCleanupCB *LateTemplateParserCleanup; |
633 | void *OpaqueParser; |
634 | |
635 | void SetLateTemplateParser(LateTemplateParserCB *LTP, |
636 | LateTemplateParserCleanupCB *LTPCleanup, |
637 | void *P) { |
638 | LateTemplateParser = LTP; |
639 | LateTemplateParserCleanup = LTPCleanup; |
640 | OpaqueParser = P; |
641 | } |
642 | |
643 | class DelayedDiagnostics; |
644 | |
645 | class DelayedDiagnosticsState { |
646 | sema::DelayedDiagnosticPool *SavedPool; |
647 | friend class Sema::DelayedDiagnostics; |
648 | }; |
649 | typedef DelayedDiagnosticsState ParsingDeclState; |
650 | typedef DelayedDiagnosticsState ProcessingContextState; |
651 | |
652 | /// A class which encapsulates the logic for delaying diagnostics |
653 | /// during parsing and other processing. |
654 | class DelayedDiagnostics { |
655 | /// \brief The current pool of diagnostics into which delayed |
656 | /// diagnostics should go. |
657 | sema::DelayedDiagnosticPool *CurPool; |
658 | |
659 | public: |
660 | DelayedDiagnostics() : CurPool(nullptr) {} |
661 | |
662 | /// Adds a delayed diagnostic. |
663 | void add(const sema::DelayedDiagnostic &diag); // in DelayedDiagnostic.h |
664 | |
665 | /// Determines whether diagnostics should be delayed. |
666 | bool shouldDelayDiagnostics() { return CurPool != nullptr; } |
667 | |
668 | /// Returns the current delayed-diagnostics pool. |
669 | sema::DelayedDiagnosticPool *getCurrentPool() const { |
670 | return CurPool; |
671 | } |
672 | |
673 | /// Enter a new scope. Access and deprecation diagnostics will be |
674 | /// collected in this pool. |
675 | DelayedDiagnosticsState push(sema::DelayedDiagnosticPool &pool) { |
676 | DelayedDiagnosticsState state; |
677 | state.SavedPool = CurPool; |
678 | CurPool = &pool; |
679 | return state; |
680 | } |
681 | |
682 | /// Leave a delayed-diagnostic state that was previously pushed. |
683 | /// Do not emit any of the diagnostics. This is performed as part |
684 | /// of the bookkeeping of popping a pool "properly". |
685 | void popWithoutEmitting(DelayedDiagnosticsState state) { |
686 | CurPool = state.SavedPool; |
687 | } |
688 | |
689 | /// Enter a new scope where access and deprecation diagnostics are |
690 | /// not delayed. |
691 | DelayedDiagnosticsState pushUndelayed() { |
692 | DelayedDiagnosticsState state; |
693 | state.SavedPool = CurPool; |
694 | CurPool = nullptr; |
695 | return state; |
696 | } |
697 | |
698 | /// Undo a previous pushUndelayed(). |
699 | void popUndelayed(DelayedDiagnosticsState state) { |
700 | assert(CurPool == nullptr)(static_cast <bool> (CurPool == nullptr) ? void (0) : __assert_fail ("CurPool == nullptr", "/build/llvm-toolchain-snapshot-7~svn326425/tools/clang/include/clang/Sema/Sema.h" , 700, __extension__ __PRETTY_FUNCTION__)); |
701 | CurPool = state.SavedPool; |
702 | } |
703 | } DelayedDiagnostics; |
704 | |
705 | /// A RAII object to temporarily push a declaration context. |
706 | class ContextRAII { |
707 | private: |
708 | Sema &S; |
709 | DeclContext *SavedContext; |
710 | ProcessingContextState SavedContextState; |
711 | QualType SavedCXXThisTypeOverride; |
712 | |
713 | public: |
714 | ContextRAII(Sema &S, DeclContext *ContextToPush, bool NewThisContext = true) |
715 | : S(S), SavedContext(S.CurContext), |
716 | SavedContextState(S.DelayedDiagnostics.pushUndelayed()), |
717 | SavedCXXThisTypeOverride(S.CXXThisTypeOverride) |
718 | { |
719 | assert(ContextToPush && "pushing null context")(static_cast <bool> (ContextToPush && "pushing null context" ) ? void (0) : __assert_fail ("ContextToPush && \"pushing null context\"" , "/build/llvm-toolchain-snapshot-7~svn326425/tools/clang/include/clang/Sema/Sema.h" , 719, __extension__ __PRETTY_FUNCTION__)); |
720 | S.CurContext = ContextToPush; |
721 | if (NewThisContext) |
722 | S.CXXThisTypeOverride = QualType(); |
723 | } |
724 | |
725 | void pop() { |
726 | if (!SavedContext) return; |
727 | S.CurContext = SavedContext; |
728 | S.DelayedDiagnostics.popUndelayed(SavedContextState); |
729 | S.CXXThisTypeOverride = SavedCXXThisTypeOverride; |
730 | SavedContext = nullptr; |
731 | } |
732 | |
733 | ~ContextRAII() { |
734 | pop(); |
735 | } |
736 | }; |
737 | |
738 | /// \brief RAII object to handle the state changes required to synthesize |
739 | /// a function body. |
740 | class SynthesizedFunctionScope { |
741 | Sema &S; |
742 | Sema::ContextRAII SavedContext; |
743 | bool PushedCodeSynthesisContext = false; |
744 | |
745 | public: |
746 | SynthesizedFunctionScope(Sema &S, DeclContext *DC) |
747 | : S(S), SavedContext(S, DC) { |
748 | S.PushFunctionScope(); |
749 | S.PushExpressionEvaluationContext( |
750 | Sema::ExpressionEvaluationContext::PotentiallyEvaluated); |
751 | if (auto *FD = dyn_cast<FunctionDecl>(DC)) |
752 | FD->setWillHaveBody(true); |
753 | else |
754 | assert(isa<ObjCMethodDecl>(DC))(static_cast <bool> (isa<ObjCMethodDecl>(DC)) ? void (0) : __assert_fail ("isa<ObjCMethodDecl>(DC)", "/build/llvm-toolchain-snapshot-7~svn326425/tools/clang/include/clang/Sema/Sema.h" , 754, __extension__ __PRETTY_FUNCTION__)); |
755 | } |
756 | |
757 | void addContextNote(SourceLocation UseLoc) { |
758 | assert(!PushedCodeSynthesisContext)(static_cast <bool> (!PushedCodeSynthesisContext) ? void (0) : __assert_fail ("!PushedCodeSynthesisContext", "/build/llvm-toolchain-snapshot-7~svn326425/tools/clang/include/clang/Sema/Sema.h" , 758, __extension__ __PRETTY_FUNCTION__)); |
759 | |
760 | Sema::CodeSynthesisContext Ctx; |
761 | Ctx.Kind = Sema::CodeSynthesisContext::DefiningSynthesizedFunction; |
762 | Ctx.PointOfInstantiation = UseLoc; |
763 | Ctx.Entity = cast<Decl>(S.CurContext); |
764 | S.pushCodeSynthesisContext(Ctx); |
765 | |
766 | PushedCodeSynthesisContext = true; |
767 | } |
768 | |
769 | ~SynthesizedFunctionScope() { |
770 | if (PushedCodeSynthesisContext) |
771 | S.popCodeSynthesisContext(); |
772 | if (auto *FD = dyn_cast<FunctionDecl>(S.CurContext)) |
773 | FD->setWillHaveBody(false); |
774 | S.PopExpressionEvaluationContext(); |
775 | S.PopFunctionScopeInfo(); |
776 | } |
777 | }; |
778 | |
779 | /// WeakUndeclaredIdentifiers - Identifiers contained in |
780 | /// \#pragma weak before declared. rare. may alias another |
781 | /// identifier, declared or undeclared |
782 | llvm::MapVector<IdentifierInfo *, WeakInfo> WeakUndeclaredIdentifiers; |
783 | |
784 | /// ExtnameUndeclaredIdentifiers - Identifiers contained in |
785 | /// \#pragma redefine_extname before declared. Used in Solaris system headers |
786 | /// to define functions that occur in multiple standards to call the version |
787 | /// in the currently selected standard. |
788 | llvm::DenseMap<IdentifierInfo*,AsmLabelAttr*> ExtnameUndeclaredIdentifiers; |
789 | |
790 | |
791 | /// \brief Load weak undeclared identifiers from the external source. |
792 | void LoadExternalWeakUndeclaredIdentifiers(); |
793 | |
794 | /// WeakTopLevelDecl - Translation-unit scoped declarations generated by |
795 | /// \#pragma weak during processing of other Decls. |
796 | /// I couldn't figure out a clean way to generate these in-line, so |
797 | /// we store them here and handle separately -- which is a hack. |
798 | /// It would be best to refactor this. |
799 | SmallVector<Decl*,2> WeakTopLevelDecl; |
800 | |
801 | IdentifierResolver IdResolver; |
802 | |
803 | /// Translation Unit Scope - useful to Objective-C actions that need |
804 | /// to lookup file scope declarations in the "ordinary" C decl namespace. |
805 | /// For example, user-defined classes, built-in "id" type, etc. |
806 | Scope *TUScope; |
807 | |
808 | /// \brief The C++ "std" namespace, where the standard library resides. |
809 | LazyDeclPtr StdNamespace; |
810 | |
811 | /// \brief The C++ "std::bad_alloc" class, which is defined by the C++ |
812 | /// standard library. |
813 | LazyDeclPtr StdBadAlloc; |
814 | |
815 | /// \brief The C++ "std::align_val_t" enum class, which is defined by the C++ |
816 | /// standard library. |
817 | LazyDeclPtr StdAlignValT; |
818 | |
819 | /// \brief The C++ "std::experimental" namespace, where the experimental parts |
820 | /// of the standard library resides. |
821 | NamespaceDecl *StdExperimentalNamespaceCache; |
822 | |
823 | /// \brief The C++ "std::initializer_list" template, which is defined in |
824 | /// \<initializer_list>. |
825 | ClassTemplateDecl *StdInitializerList; |
826 | |
827 | /// \brief The C++ "type_info" declaration, which is defined in \<typeinfo>. |
828 | RecordDecl *CXXTypeInfoDecl; |
829 | |
830 | /// \brief The MSVC "_GUID" struct, which is defined in MSVC header files. |
831 | RecordDecl *MSVCGuidDecl; |
832 | |
833 | /// \brief Caches identifiers/selectors for NSFoundation APIs. |
834 | std::unique_ptr<NSAPI> NSAPIObj; |
835 | |
836 | /// \brief The declaration of the Objective-C NSNumber class. |
837 | ObjCInterfaceDecl *NSNumberDecl; |
838 | |
839 | /// \brief The declaration of the Objective-C NSValue class. |
840 | ObjCInterfaceDecl *NSValueDecl; |
841 | |
842 | /// \brief Pointer to NSNumber type (NSNumber *). |
843 | QualType NSNumberPointer; |
844 | |
845 | /// \brief Pointer to NSValue type (NSValue *). |
846 | QualType NSValuePointer; |
847 | |
848 | /// \brief The Objective-C NSNumber methods used to create NSNumber literals. |
849 | ObjCMethodDecl *NSNumberLiteralMethods[NSAPI::NumNSNumberLiteralMethods]; |
850 | |
851 | /// \brief The declaration of the Objective-C NSString class. |
852 | ObjCInterfaceDecl *NSStringDecl; |
853 | |
854 | /// \brief Pointer to NSString type (NSString *). |
855 | QualType NSStringPointer; |
856 | |
857 | /// \brief The declaration of the stringWithUTF8String: method. |
858 | ObjCMethodDecl *StringWithUTF8StringMethod; |
859 | |
860 | /// \brief The declaration of the valueWithBytes:objCType: method. |
861 | ObjCMethodDecl *ValueWithBytesObjCTypeMethod; |
862 | |
863 | /// \brief The declaration of the Objective-C NSArray class. |
864 | ObjCInterfaceDecl *NSArrayDecl; |
865 | |
866 | /// \brief The declaration of the arrayWithObjects:count: method. |
867 | ObjCMethodDecl *ArrayWithObjectsMethod; |
868 | |
869 | /// \brief The declaration of the Objective-C NSDictionary class. |
870 | ObjCInterfaceDecl *NSDictionaryDecl; |
871 | |
872 | /// \brief The declaration of the dictionaryWithObjects:forKeys:count: method. |
873 | ObjCMethodDecl *DictionaryWithObjectsMethod; |
874 | |
875 | /// \brief id<NSCopying> type. |
876 | QualType QIDNSCopying; |
877 | |
878 | /// \brief will hold 'respondsToSelector:' |
879 | Selector RespondsToSelectorSel; |
880 | |
881 | /// A flag to remember whether the implicit forms of operator new and delete |
882 | /// have been declared. |
883 | bool GlobalNewDeleteDeclared; |
884 | |
885 | /// A flag to indicate that we're in a context that permits abstract |
886 | /// references to fields. This is really a |
887 | bool AllowAbstractFieldReference; |
888 | |
889 | /// \brief Describes how the expressions currently being parsed are |
890 | /// evaluated at run-time, if at all. |
891 | enum class ExpressionEvaluationContext { |
892 | /// \brief The current expression and its subexpressions occur within an |
893 | /// unevaluated operand (C++11 [expr]p7), such as the subexpression of |
894 | /// \c sizeof, where the type of the expression may be significant but |
895 | /// no code will be generated to evaluate the value of the expression at |
896 | /// run time. |
897 | Unevaluated, |
898 | |
899 | /// \brief The current expression occurs within a braced-init-list within |
900 | /// an unevaluated operand. This is mostly like a regular unevaluated |
901 | /// context, except that we still instantiate constexpr functions that are |
902 | /// referenced here so that we can perform narrowing checks correctly. |
903 | UnevaluatedList, |
904 | |
905 | /// \brief The current expression occurs within a discarded statement. |
906 | /// This behaves largely similarly to an unevaluated operand in preventing |
907 | /// definitions from being required, but not in other ways. |
908 | DiscardedStatement, |
909 | |
910 | /// \brief The current expression occurs within an unevaluated |
911 | /// operand that unconditionally permits abstract references to |
912 | /// fields, such as a SIZE operator in MS-style inline assembly. |
913 | UnevaluatedAbstract, |
914 | |
915 | /// \brief The current context is "potentially evaluated" in C++11 terms, |
916 | /// but the expression is evaluated at compile-time (like the values of |
917 | /// cases in a switch statement). |
918 | ConstantEvaluated, |
919 | |
920 | /// \brief The current expression is potentially evaluated at run time, |
921 | /// which means that code may be generated to evaluate the value of the |
922 | /// expression at run time. |
923 | PotentiallyEvaluated, |
924 | |
925 | /// \brief The current expression is potentially evaluated, but any |
926 | /// declarations referenced inside that expression are only used if |
927 | /// in fact the current expression is used. |
928 | /// |
929 | /// This value is used when parsing default function arguments, for which |
930 | /// we would like to provide diagnostics (e.g., passing non-POD arguments |
931 | /// through varargs) but do not want to mark declarations as "referenced" |
932 | /// until the default argument is used. |
933 | PotentiallyEvaluatedIfUsed |
934 | }; |
935 | |
936 | /// \brief Data structure used to record current or nested |
937 | /// expression evaluation contexts. |
938 | struct ExpressionEvaluationContextRecord { |
939 | /// \brief The expression evaluation context. |
940 | ExpressionEvaluationContext Context; |
941 | |
942 | /// \brief Whether the enclosing context needed a cleanup. |
943 | CleanupInfo ParentCleanup; |
944 | |
945 | /// \brief Whether we are in a decltype expression. |
946 | bool IsDecltype; |
947 | |
948 | /// \brief The number of active cleanup objects when we entered |
949 | /// this expression evaluation context. |
950 | unsigned NumCleanupObjects; |
951 | |
952 | /// \brief The number of typos encountered during this expression evaluation |
953 | /// context (i.e. the number of TypoExprs created). |
954 | unsigned NumTypos; |
955 | |
956 | llvm::SmallPtrSet<Expr*, 2> SavedMaybeODRUseExprs; |
957 | |
958 | /// \brief The lambdas that are present within this context, if it |
959 | /// is indeed an unevaluated context. |
960 | SmallVector<LambdaExpr *, 2> Lambdas; |
961 | |
962 | /// \brief The declaration that provides context for lambda expressions |
963 | /// and block literals if the normal declaration context does not |
964 | /// suffice, e.g., in a default function argument. |
965 | Decl *ManglingContextDecl; |
966 | |
967 | /// \brief The context information used to mangle lambda expressions |
968 | /// and block literals within this context. |
969 | /// |
970 | /// This mangling information is allocated lazily, since most contexts |
971 | /// do not have lambda expressions or block literals. |
972 | std::unique_ptr<MangleNumberingContext> MangleNumbering; |
973 | |
974 | /// \brief If we are processing a decltype type, a set of call expressions |
975 | /// for which we have deferred checking the completeness of the return type. |
976 | SmallVector<CallExpr *, 8> DelayedDecltypeCalls; |
977 | |
978 | /// \brief If we are processing a decltype type, a set of temporary binding |
979 | /// expressions for which we have deferred checking the destructor. |
980 | SmallVector<CXXBindTemporaryExpr *, 8> DelayedDecltypeBinds; |
981 | |
982 | ExpressionEvaluationContextRecord(ExpressionEvaluationContext Context, |
983 | unsigned NumCleanupObjects, |
984 | CleanupInfo ParentCleanup, |
985 | Decl *ManglingContextDecl, |
986 | bool IsDecltype) |
987 | : Context(Context), ParentCleanup(ParentCleanup), |
988 | IsDecltype(IsDecltype), NumCleanupObjects(NumCleanupObjects), |
989 | NumTypos(0), |
990 | ManglingContextDecl(ManglingContextDecl), MangleNumbering() { } |
991 | |
992 | /// \brief Retrieve the mangling numbering context, used to consistently |
993 | /// number constructs like lambdas for mangling. |
994 | MangleNumberingContext &getMangleNumberingContext(ASTContext &Ctx); |
995 | |
996 | bool isUnevaluated() const { |
997 | return Context == ExpressionEvaluationContext::Unevaluated || |
998 | Context == ExpressionEvaluationContext::UnevaluatedAbstract || |
999 | Context == ExpressionEvaluationContext::UnevaluatedList; |
1000 | } |
1001 | bool isConstantEvaluated() const { |
1002 | return Context == ExpressionEvaluationContext::ConstantEvaluated; |
1003 | } |
1004 | }; |
1005 | |
1006 | /// A stack of expression evaluation contexts. |
1007 | SmallVector<ExpressionEvaluationContextRecord, 8> ExprEvalContexts; |
1008 | |
1009 | /// \brief Compute the mangling number context for a lambda expression or |
1010 | /// block literal. |
1011 | /// |
1012 | /// \param DC - The DeclContext containing the lambda expression or |
1013 | /// block literal. |
1014 | /// \param[out] ManglingContextDecl - Returns the ManglingContextDecl |
1015 | /// associated with the context, if relevant. |
1016 | MangleNumberingContext *getCurrentMangleNumberContext( |
1017 | const DeclContext *DC, |
1018 | Decl *&ManglingContextDecl); |
1019 | |
1020 | |
1021 | /// SpecialMemberOverloadResult - The overloading result for a special member |
1022 | /// function. |
1023 | /// |
1024 | /// This is basically a wrapper around PointerIntPair. The lowest bits of the |
1025 | /// integer are used to determine whether overload resolution succeeded. |
1026 | class SpecialMemberOverloadResult { |
1027 | public: |
1028 | enum Kind { |
1029 | NoMemberOrDeleted, |
1030 | Ambiguous, |
1031 | Success |
1032 | }; |
1033 | |
1034 | private: |
1035 | llvm::PointerIntPair<CXXMethodDecl*, 2> Pair; |
1036 | |
1037 | public: |
1038 | SpecialMemberOverloadResult() : Pair() {} |
1039 | SpecialMemberOverloadResult(CXXMethodDecl *MD) |
1040 | : Pair(MD, MD->isDeleted() ? NoMemberOrDeleted : Success) {} |
1041 | |
1042 | CXXMethodDecl *getMethod() const { return Pair.getPointer(); } |
1043 | void setMethod(CXXMethodDecl *MD) { Pair.setPointer(MD); } |
1044 | |
1045 | Kind getKind() const { return static_cast<Kind>(Pair.getInt()); } |
1046 | void setKind(Kind K) { Pair.setInt(K); } |
1047 | }; |
1048 | |
1049 | class SpecialMemberOverloadResultEntry |
1050 | : public llvm::FastFoldingSetNode, |
1051 | public SpecialMemberOverloadResult { |
1052 | public: |
1053 | SpecialMemberOverloadResultEntry(const llvm::FoldingSetNodeID &ID) |
1054 | : FastFoldingSetNode(ID) |
1055 | {} |
1056 | }; |
1057 | |
1058 | /// \brief A cache of special member function overload resolution results |
1059 | /// for C++ records. |
1060 | llvm::FoldingSet<SpecialMemberOverloadResultEntry> SpecialMemberCache; |
1061 | |
1062 | /// \brief A cache of the flags available in enumerations with the flag_bits |
1063 | /// attribute. |
1064 | mutable llvm::DenseMap<const EnumDecl*, llvm::APInt> FlagBitsCache; |
1065 | |
1066 | /// \brief The kind of translation unit we are processing. |
1067 | /// |
1068 | /// When we're processing a complete translation unit, Sema will perform |
1069 | /// end-of-translation-unit semantic tasks (such as creating |
1070 | /// initializers for tentative definitions in C) once parsing has |
1071 | /// completed. Modules and precompiled headers perform different kinds of |
1072 | /// checks. |
1073 | TranslationUnitKind TUKind; |
1074 | |
1075 | llvm::BumpPtrAllocator BumpAlloc; |
1076 | |
1077 | /// \brief The number of SFINAE diagnostics that have been trapped. |
1078 | unsigned NumSFINAEErrors; |
1079 | |
1080 | typedef llvm::DenseMap<ParmVarDecl *, llvm::TinyPtrVector<ParmVarDecl *>> |
1081 | UnparsedDefaultArgInstantiationsMap; |
1082 | |
1083 | /// \brief A mapping from parameters with unparsed default arguments to the |
1084 | /// set of instantiations of each parameter. |
1085 | /// |
1086 | /// This mapping is a temporary data structure used when parsing |
1087 | /// nested class templates or nested classes of class templates, |
1088 | /// where we might end up instantiating an inner class before the |
1089 | /// default arguments of its methods have been parsed. |
1090 | UnparsedDefaultArgInstantiationsMap UnparsedDefaultArgInstantiations; |
1091 | |
1092 | // Contains the locations of the beginning of unparsed default |
1093 | // argument locations. |
1094 | llvm::DenseMap<ParmVarDecl *, SourceLocation> UnparsedDefaultArgLocs; |
1095 | |
1096 | /// UndefinedInternals - all the used, undefined objects which require a |
1097 | /// definition in this translation unit. |
1098 | llvm::MapVector<NamedDecl *, SourceLocation> UndefinedButUsed; |
1099 | |
1100 | /// Determine if VD, which must be a variable or function, is an external |
1101 | /// symbol that nonetheless can't be referenced from outside this translation |
1102 | /// unit because its type has no linkage and it's not extern "C". |
1103 | bool isExternalWithNoLinkageType(ValueDecl *VD); |
1104 | |
1105 | /// Obtain a sorted list of functions that are undefined but ODR-used. |
1106 | void getUndefinedButUsed( |
1107 | SmallVectorImpl<std::pair<NamedDecl *, SourceLocation> > &Undefined); |
1108 | |
1109 | /// Retrieves list of suspicious delete-expressions that will be checked at |
1110 | /// the end of translation unit. |
1111 | const llvm::MapVector<FieldDecl *, DeleteLocs> & |
1112 | getMismatchingDeleteExpressions() const; |
1113 | |
1114 | typedef std::pair<ObjCMethodList, ObjCMethodList> GlobalMethods; |
1115 | typedef llvm::DenseMap<Selector, GlobalMethods> GlobalMethodPool; |
1116 | |
1117 | /// Method Pool - allows efficient lookup when typechecking messages to "id". |
1118 | /// We need to maintain a list, since selectors can have differing signatures |
1119 | /// across classes. In Cocoa, this happens to be extremely uncommon (only 1% |
1120 | /// of selectors are "overloaded"). |
1121 | /// At the head of the list it is recorded whether there were 0, 1, or >= 2 |
1122 | /// methods inside categories with a particular selector. |
1123 | GlobalMethodPool MethodPool; |
1124 | |
1125 | /// Method selectors used in a \@selector expression. Used for implementation |
1126 | /// of -Wselector. |
1127 | llvm::MapVector<Selector, SourceLocation> ReferencedSelectors; |
1128 | |
1129 | /// Kinds of C++ special members. |
1130 | enum CXXSpecialMember { |
1131 | CXXDefaultConstructor, |
1132 | CXXCopyConstructor, |
1133 | CXXMoveConstructor, |
1134 | CXXCopyAssignment, |
1135 | CXXMoveAssignment, |
1136 | CXXDestructor, |
1137 | CXXInvalid |
1138 | }; |
1139 | |
1140 | typedef llvm::PointerIntPair<CXXRecordDecl *, 3, CXXSpecialMember> |
1141 | SpecialMemberDecl; |
1142 | |
1143 | /// The C++ special members which we are currently in the process of |
1144 | /// declaring. If this process recursively triggers the declaration of the |
1145 | /// same special member, we should act as if it is not yet declared. |
1146 | llvm::SmallPtrSet<SpecialMemberDecl, 4> SpecialMembersBeingDeclared; |
1147 | |
1148 | /// The function definitions which were renamed as part of typo-correction |
1149 | /// to match their respective declarations. We want to keep track of them |
1150 | /// to ensure that we don't emit a "redefinition" error if we encounter a |
1151 | /// correctly named definition after the renamed definition. |
1152 | llvm::SmallPtrSet<const NamedDecl *, 4> TypoCorrectedFunctionDefinitions; |
1153 | |
1154 | /// Stack of types that correspond to the parameter entities that are |
1155 | /// currently being copy-initialized. Can be empty. |
1156 | llvm::SmallVector<QualType, 4> CurrentParameterCopyTypes; |
1157 | |
1158 | void ReadMethodPool(Selector Sel); |
1159 | void updateOutOfDateSelector(Selector Sel); |
1160 | |
1161 | /// Private Helper predicate to check for 'self'. |
1162 | bool isSelfExpr(Expr *RExpr); |
1163 | bool isSelfExpr(Expr *RExpr, const ObjCMethodDecl *Method); |
1164 | |
1165 | /// \brief Cause the active diagnostic on the DiagosticsEngine to be |
1166 | /// emitted. This is closely coupled to the SemaDiagnosticBuilder class and |
1167 | /// should not be used elsewhere. |
1168 | void EmitCurrentDiagnostic(unsigned DiagID); |
1169 | |
1170 | /// Records and restores the FP_CONTRACT state on entry/exit of compound |
1171 | /// statements. |
1172 | class FPContractStateRAII { |
1173 | public: |
1174 | FPContractStateRAII(Sema &S) : S(S), OldFPFeaturesState(S.FPFeatures) {} |
1175 | ~FPContractStateRAII() { S.FPFeatures = OldFPFeaturesState; } |
1176 | |
1177 | private: |
1178 | Sema& S; |
1179 | FPOptions OldFPFeaturesState; |
1180 | }; |
1181 | |
1182 | void addImplicitTypedef(StringRef Name, QualType T); |
1183 | |
1184 | public: |
1185 | Sema(Preprocessor &pp, ASTContext &ctxt, ASTConsumer &consumer, |
1186 | TranslationUnitKind TUKind = TU_Complete, |
1187 | CodeCompleteConsumer *CompletionConsumer = nullptr); |
1188 | ~Sema(); |
1189 | |
1190 | /// \brief Perform initialization that occurs after the parser has been |
1191 | /// initialized but before it parses anything. |
1192 | void Initialize(); |
1193 | |
1194 | const LangOptions &getLangOpts() const { return LangOpts; } |
1195 | OpenCLOptions &getOpenCLOptions() { return OpenCLFeatures; } |
1196 | FPOptions &getFPOptions() { return FPFeatures; } |
1197 | |
1198 | DiagnosticsEngine &getDiagnostics() const { return Diags; } |
1199 | SourceManager &getSourceManager() const { return SourceMgr; } |
1200 | Preprocessor &getPreprocessor() const { return PP; } |
1201 | ASTContext &getASTContext() const { return Context; } |
1202 | ASTConsumer &getASTConsumer() const { return Consumer; } |
1203 | ASTMutationListener *getASTMutationListener() const; |
1204 | ExternalSemaSource* getExternalSource() const { return ExternalSource; } |
1205 | |
1206 | ///\brief Registers an external source. If an external source already exists, |
1207 | /// creates a multiplex external source and appends to it. |
1208 | /// |
1209 | ///\param[in] E - A non-null external sema source. |
1210 | /// |
1211 | void addExternalSource(ExternalSemaSource *E); |
1212 | |
1213 | void PrintStats() const; |
1214 | |
1215 | /// \brief Helper class that creates diagnostics with optional |
1216 | /// template instantiation stacks. |
1217 | /// |
1218 | /// This class provides a wrapper around the basic DiagnosticBuilder |
1219 | /// class that emits diagnostics. SemaDiagnosticBuilder is |
1220 | /// responsible for emitting the diagnostic (as DiagnosticBuilder |
1221 | /// does) and, if the diagnostic comes from inside a template |
1222 | /// instantiation, printing the template instantiation stack as |
1223 | /// well. |
1224 | class SemaDiagnosticBuilder : public DiagnosticBuilder { |
1225 | Sema &SemaRef; |
1226 | unsigned DiagID; |
1227 | |
1228 | public: |
1229 | SemaDiagnosticBuilder(DiagnosticBuilder &DB, Sema &SemaRef, unsigned DiagID) |
1230 | : DiagnosticBuilder(DB), SemaRef(SemaRef), DiagID(DiagID) { } |
1231 | |
1232 | // This is a cunning lie. DiagnosticBuilder actually performs move |
1233 | // construction in its copy constructor (but due to varied uses, it's not |
1234 | // possible to conveniently express this as actual move construction). So |
1235 | // the default copy ctor here is fine, because the base class disables the |
1236 | // source anyway, so the user-defined ~SemaDiagnosticBuilder is a safe no-op |
1237 | // in that case anwyay. |
1238 | SemaDiagnosticBuilder(const SemaDiagnosticBuilder&) = default; |
1239 | |
1240 | ~SemaDiagnosticBuilder() { |
1241 | // If we aren't active, there is nothing to do. |
1242 | if (!isActive()) return; |
1243 | |
1244 | // Otherwise, we need to emit the diagnostic. First flush the underlying |
1245 | // DiagnosticBuilder data, and clear the diagnostic builder itself so it |
1246 | // won't emit the diagnostic in its own destructor. |
1247 | // |
1248 | // This seems wasteful, in that as written the DiagnosticBuilder dtor will |
1249 | // do its own needless checks to see if the diagnostic needs to be |
1250 | // emitted. However, because we take care to ensure that the builder |
1251 | // objects never escape, a sufficiently smart compiler will be able to |
1252 | // eliminate that code. |
1253 | FlushCounts(); |
1254 | Clear(); |
1255 | |
1256 | // Dispatch to Sema to emit the diagnostic. |
1257 | SemaRef.EmitCurrentDiagnostic(DiagID); |
1258 | } |
1259 | |
1260 | /// Teach operator<< to produce an object of the correct type. |
1261 | template<typename T> |
1262 | friend const SemaDiagnosticBuilder &operator<<( |
1263 | const SemaDiagnosticBuilder &Diag, const T &Value) { |
1264 | const DiagnosticBuilder &BaseDiag = Diag; |
1265 | BaseDiag << Value; |
1266 | return Diag; |
1267 | } |
1268 | }; |
1269 | |
1270 | /// \brief Emit a diagnostic. |
1271 | SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID) { |
1272 | DiagnosticBuilder DB = Diags.Report(Loc, DiagID); |
1273 | return SemaDiagnosticBuilder(DB, *this, DiagID); |
1274 | } |
1275 | |
1276 | /// \brief Emit a partial diagnostic. |
1277 | SemaDiagnosticBuilder Diag(SourceLocation Loc, const PartialDiagnostic& PD); |
1278 | |
1279 | /// \brief Build a partial diagnostic. |
1280 | PartialDiagnostic PDiag(unsigned DiagID = 0); // in SemaInternal.h |
1281 | |
1282 | bool findMacroSpelling(SourceLocation &loc, StringRef name); |
1283 | |
1284 | /// \brief Get a string to suggest for zero-initialization of a type. |
1285 | std::string |
1286 | getFixItZeroInitializerForType(QualType T, SourceLocation Loc) const; |
1287 | std::string getFixItZeroLiteralForType(QualType T, SourceLocation Loc) const; |
1288 | |
1289 | /// \brief Calls \c Lexer::getLocForEndOfToken() |
1290 | SourceLocation getLocForEndOfToken(SourceLocation Loc, unsigned Offset = 0); |
1291 | |
1292 | /// \brief Retrieve the module loader associated with the preprocessor. |
1293 | ModuleLoader &getModuleLoader() const; |
1294 | |
1295 | void emitAndClearUnusedLocalTypedefWarnings(); |
1296 | |
1297 | void ActOnStartOfTranslationUnit(); |
1298 | void ActOnEndOfTranslationUnit(); |
1299 | |
1300 | void CheckDelegatingCtorCycles(); |
1301 | |
1302 | Scope *getScopeForContext(DeclContext *Ctx); |
1303 | |
1304 | void PushFunctionScope(); |
1305 | void PushBlockScope(Scope *BlockScope, BlockDecl *Block); |
1306 | sema::LambdaScopeInfo *PushLambdaScope(); |
1307 | |
1308 | /// \brief This is used to inform Sema what the current TemplateParameterDepth |
1309 | /// is during Parsing. Currently it is used to pass on the depth |
1310 | /// when parsing generic lambda 'auto' parameters. |
1311 | void RecordParsingTemplateParameterDepth(unsigned Depth); |
1312 | |
1313 | void PushCapturedRegionScope(Scope *RegionScope, CapturedDecl *CD, |
1314 | RecordDecl *RD, |
1315 | CapturedRegionKind K); |
1316 | void |
1317 | PopFunctionScopeInfo(const sema::AnalysisBasedWarnings::Policy *WP = nullptr, |
1318 | const Decl *D = nullptr, |
1319 | const BlockExpr *blkExpr = nullptr); |
1320 | |
1321 | sema::FunctionScopeInfo *getCurFunction() const { |
1322 | return FunctionScopes.back(); |
1323 | } |
1324 | |
1325 | sema::FunctionScopeInfo *getEnclosingFunction() const { |
1326 | if (FunctionScopes.empty()) |
1327 | return nullptr; |
1328 | |
1329 | for (int e = FunctionScopes.size()-1; e >= 0; --e) { |
1330 | if (isa<sema::BlockScopeInfo>(FunctionScopes[e])) |
1331 | continue; |
1332 | return FunctionScopes[e]; |
1333 | } |
1334 | return nullptr; |
1335 | } |
1336 | |
1337 | template <typename ExprT> |
1338 | void recordUseOfEvaluatedWeak(const ExprT *E, bool IsRead=true) { |
1339 | if (!isUnevaluatedContext()) |
1340 | getCurFunction()->recordUseOfWeak(E, IsRead); |
1341 | } |
1342 | |
1343 | void PushCompoundScope(bool IsStmtExpr); |
1344 | void PopCompoundScope(); |
1345 | |
1346 | sema::CompoundScopeInfo &getCurCompoundScope() const; |
1347 | |
1348 | bool hasAnyUnrecoverableErrorsInThisFunction() const; |
1349 | |
1350 | /// \brief Retrieve the current block, if any. |
1351 | sema::BlockScopeInfo *getCurBlock(); |
1352 | |
1353 | /// Retrieve the current lambda scope info, if any. |
1354 | /// \param IgnoreNonLambdaCapturingScope true if should find the top-most |
1355 | /// lambda scope info ignoring all inner capturing scopes that are not |
1356 | /// lambda scopes. |
1357 | sema::LambdaScopeInfo * |
1358 | getCurLambda(bool IgnoreNonLambdaCapturingScope = false); |
1359 | |
1360 | /// \brief Retrieve the current generic lambda info, if any. |
1361 | sema::LambdaScopeInfo *getCurGenericLambda(); |
1362 | |
1363 | /// \brief Retrieve the current captured region, if any. |
1364 | sema::CapturedRegionScopeInfo *getCurCapturedRegion(); |
1365 | |
1366 | /// WeakTopLevelDeclDecls - access to \#pragma weak-generated Decls |
1367 | SmallVectorImpl<Decl *> &WeakTopLevelDecls() { return WeakTopLevelDecl; } |
1368 | |
1369 | void ActOnComment(SourceRange Comment); |
1370 | |
1371 | //===--------------------------------------------------------------------===// |
1372 | // Type Analysis / Processing: SemaType.cpp. |
1373 | // |
1374 | |
1375 | QualType BuildQualifiedType(QualType T, SourceLocation Loc, Qualifiers Qs, |
1376 | const DeclSpec *DS = nullptr); |
1377 | QualType BuildQualifiedType(QualType T, SourceLocation Loc, unsigned CVRA, |
1378 | const DeclSpec *DS = nullptr); |
1379 | QualType BuildPointerType(QualType T, |
1380 | SourceLocation Loc, DeclarationName Entity); |
1381 | QualType BuildReferenceType(QualType T, bool LValueRef, |
1382 | SourceLocation Loc, DeclarationName Entity); |
1383 | QualType BuildArrayType(QualType T, ArrayType::ArraySizeModifier ASM, |
1384 | Expr *ArraySize, unsigned Quals, |
1385 | SourceRange Brackets, DeclarationName Entity); |
1386 | QualType BuildExtVectorType(QualType T, Expr *ArraySize, |
1387 | SourceLocation AttrLoc); |
1388 | QualType BuildAddressSpaceAttr(QualType &T, Expr *AddrSpace, |
1389 | SourceLocation AttrLoc); |
1390 | |
1391 | bool CheckFunctionReturnType(QualType T, SourceLocation Loc); |
1392 | |
1393 | /// \brief Build a function type. |
1394 | /// |
1395 | /// This routine checks the function type according to C++ rules and |
1396 | /// under the assumption that the result type and parameter types have |
1397 | /// just been instantiated from a template. It therefore duplicates |
1398 | /// some of the behavior of GetTypeForDeclarator, but in a much |
1399 | /// simpler form that is only suitable for this narrow use case. |
1400 | /// |
1401 | /// \param T The return type of the function. |
1402 | /// |
1403 | /// \param ParamTypes The parameter types of the function. This array |
1404 | /// will be modified to account for adjustments to the types of the |
1405 | /// function parameters. |
1406 | /// |
1407 | /// \param Loc The location of the entity whose type involves this |
1408 | /// function type or, if there is no such entity, the location of the |
1409 | /// type that will have function type. |
1410 | /// |
1411 | /// \param Entity The name of the entity that involves the function |
1412 | /// type, if known. |
1413 | /// |
1414 | /// \param EPI Extra information about the function type. Usually this will |
1415 | /// be taken from an existing function with the same prototype. |
1416 | /// |
1417 | /// \returns A suitable function type, if there are no errors. The |
1418 | /// unqualified type will always be a FunctionProtoType. |
1419 | /// Otherwise, returns a NULL type. |
1420 | QualType BuildFunctionType(QualType T, |
1421 | MutableArrayRef<QualType> ParamTypes, |
1422 | SourceLocation Loc, DeclarationName Entity, |
1423 | const FunctionProtoType::ExtProtoInfo &EPI); |
1424 | |
1425 | QualType BuildMemberPointerType(QualType T, QualType Class, |
1426 | SourceLocation Loc, |
1427 | DeclarationName Entity); |
1428 | QualType BuildBlockPointerType(QualType T, |
1429 | SourceLocation Loc, DeclarationName Entity); |
1430 | QualType BuildParenType(QualType T); |
1431 | QualType BuildAtomicType(QualType T, SourceLocation Loc); |
1432 | QualType BuildReadPipeType(QualType T, |
1433 | SourceLocation Loc); |
1434 | QualType BuildWritePipeType(QualType T, |
1435 | SourceLocation Loc); |
1436 | |
1437 | TypeSourceInfo *GetTypeForDeclarator(Declarator &D, Scope *S); |
1438 | TypeSourceInfo *GetTypeForDeclaratorCast(Declarator &D, QualType FromTy); |
1439 | TypeSourceInfo *GetTypeSourceInfoForDeclarator(Declarator &D, QualType T, |
1440 | TypeSourceInfo *ReturnTypeInfo); |
1441 | |
1442 | /// \brief Package the given type and TSI into a ParsedType. |
1443 | ParsedType CreateParsedType(QualType T, TypeSourceInfo *TInfo); |
1444 | DeclarationNameInfo GetNameForDeclarator(Declarator &D); |
1445 | DeclarationNameInfo GetNameFromUnqualifiedId(const UnqualifiedId &Name); |
1446 | static QualType GetTypeFromParser(ParsedType Ty, |
1447 | TypeSourceInfo **TInfo = nullptr); |
1448 | CanThrowResult canThrow(const Expr *E); |
1449 | const FunctionProtoType *ResolveExceptionSpec(SourceLocation Loc, |
1450 | const FunctionProtoType *FPT); |
1451 | void UpdateExceptionSpec(FunctionDecl *FD, |
1452 | const FunctionProtoType::ExceptionSpecInfo &ESI); |
1453 | bool CheckSpecifiedExceptionType(QualType &T, SourceRange Range); |
1454 | bool CheckDistantExceptionSpec(QualType T); |
1455 | bool CheckEquivalentExceptionSpec(FunctionDecl *Old, FunctionDecl *New); |
1456 | bool CheckEquivalentExceptionSpec( |
1457 | const FunctionProtoType *Old, SourceLocation OldLoc, |
1458 | const FunctionProtoType *New, SourceLocation NewLoc); |
1459 | bool CheckEquivalentExceptionSpec( |
1460 | const PartialDiagnostic &DiagID, const PartialDiagnostic & NoteID, |
1461 | const FunctionProtoType *Old, SourceLocation OldLoc, |
1462 | const FunctionProtoType *New, SourceLocation NewLoc); |
1463 | bool handlerCanCatch(QualType HandlerType, QualType ExceptionType); |
1464 | bool CheckExceptionSpecSubset(const PartialDiagnostic &DiagID, |
1465 | const PartialDiagnostic &NestedDiagID, |
1466 | const PartialDiagnostic &NoteID, |
1467 | const FunctionProtoType *Superset, |
1468 | SourceLocation SuperLoc, |
1469 | const FunctionProtoType *Subset, |
1470 | SourceLocation SubLoc); |
1471 | bool CheckParamExceptionSpec(const PartialDiagnostic &NestedDiagID, |
1472 | const PartialDiagnostic &NoteID, |
1473 | const FunctionProtoType *Target, |
1474 | SourceLocation TargetLoc, |
1475 | const FunctionProtoType *Source, |
1476 | SourceLocation SourceLoc); |
1477 | |
1478 | TypeResult ActOnTypeName(Scope *S, Declarator &D); |
1479 | |
1480 | /// \brief The parser has parsed the context-sensitive type 'instancetype' |
1481 | /// in an Objective-C message declaration. Return the appropriate type. |
1482 | ParsedType ActOnObjCInstanceType(SourceLocation Loc); |
1483 | |
1484 | /// \brief Abstract class used to diagnose incomplete types. |
1485 | struct TypeDiagnoser { |
1486 | TypeDiagnoser() {} |
1487 | |
1488 | virtual void diagnose(Sema &S, SourceLocation Loc, QualType T) = 0; |
1489 | virtual ~TypeDiagnoser() {} |
1490 | }; |
1491 | |
1492 | static int getPrintable(int I) { return I; } |
1493 | static unsigned getPrintable(unsigned I) { return I; } |
1494 | static bool getPrintable(bool B) { return B; } |
1495 | static const char * getPrintable(const char *S) { return S; } |
1496 | static StringRef getPrintable(StringRef S) { return S; } |
1497 | static const std::string &getPrintable(const std::string &S) { return S; } |
1498 | static const IdentifierInfo *getPrintable(const IdentifierInfo *II) { |
1499 | return II; |
1500 | } |
1501 | static DeclarationName getPrintable(DeclarationName N) { return N; } |
1502 | static QualType getPrintable(QualType T) { return T; } |
1503 | static SourceRange getPrintable(SourceRange R) { return R; } |
1504 | static SourceRange getPrintable(SourceLocation L) { return L; } |
1505 | static SourceRange getPrintable(const Expr *E) { return E->getSourceRange(); } |
1506 | static SourceRange getPrintable(TypeLoc TL) { return TL.getSourceRange();} |
1507 | |
1508 | template <typename... Ts> class BoundTypeDiagnoser : public TypeDiagnoser { |
1509 | unsigned DiagID; |
1510 | std::tuple<const Ts &...> Args; |
1511 | |
1512 | template <std::size_t... Is> |
1513 | void emit(const SemaDiagnosticBuilder &DB, |
1514 | llvm::index_sequence<Is...>) const { |
1515 | // Apply all tuple elements to the builder in order. |
1516 | bool Dummy[] = {false, (DB << getPrintable(std::get<Is>(Args)))...}; |
1517 | (void)Dummy; |
1518 | } |
1519 | |
1520 | public: |
1521 | BoundTypeDiagnoser(unsigned DiagID, const Ts &...Args) |
1522 | : TypeDiagnoser(), DiagID(DiagID), Args(Args...) { |
1523 | assert(DiagID != 0 && "no diagnostic for type diagnoser")(static_cast <bool> (DiagID != 0 && "no diagnostic for type diagnoser" ) ? void (0) : __assert_fail ("DiagID != 0 && \"no diagnostic for type diagnoser\"" , "/build/llvm-toolchain-snapshot-7~svn326425/tools/clang/include/clang/Sema/Sema.h" , 1523, __extension__ __PRETTY_FUNCTION__)); |
1524 | } |
1525 | |
1526 | void diagnose(Sema &S, SourceLocation Loc, QualType T) override { |
1527 | const SemaDiagnosticBuilder &DB = S.Diag(Loc, DiagID); |
1528 | emit(DB, llvm::index_sequence_for<Ts...>()); |
1529 | DB << T; |
1530 | } |
1531 | }; |
1532 | |
1533 | private: |
1534 | bool RequireCompleteTypeImpl(SourceLocation Loc, QualType T, |
1535 | TypeDiagnoser *Diagnoser); |
1536 | |
1537 | struct ModuleScope { |
1538 | clang::Module *Module = nullptr; |
1539 | bool ModuleInterface = false; |
1540 | VisibleModuleSet OuterVisibleModules; |
1541 | }; |
1542 | /// The modules we're currently parsing. |
1543 | llvm::SmallVector<ModuleScope, 16> ModuleScopes; |
1544 | |
1545 | /// Get the module whose scope we are currently within. |
1546 | Module *getCurrentModule() const { |
1547 | return ModuleScopes.empty() ? nullptr : ModuleScopes.back().Module; |
1548 | } |
1549 | |
1550 | VisibleModuleSet VisibleModules; |
1551 | |
1552 | public: |
1553 | /// \brief Get the module owning an entity. |
1554 | Module *getOwningModule(Decl *Entity) { return Entity->getOwningModule(); } |
1555 | |
1556 | /// \brief Make a merged definition of an existing hidden definition \p ND |
1557 | /// visible at the specified location. |
1558 | void makeMergedDefinitionVisible(NamedDecl *ND); |
1559 | |
1560 | bool isModuleVisible(const Module *M) { return VisibleModules.isVisible(M); } |
1561 | |
1562 | /// Determine whether a declaration is visible to name lookup. |
1563 | bool isVisible(const NamedDecl *D) { |
1564 | return !D->isHidden() || isVisibleSlow(D); |
1565 | } |
1566 | |
1567 | /// Determine whether any declaration of an entity is visible. |
1568 | bool |
1569 | hasVisibleDeclaration(const NamedDecl *D, |
1570 | llvm::SmallVectorImpl<Module *> *Modules = nullptr) { |
1571 | return isVisible(D) || hasVisibleDeclarationSlow(D, Modules); |
1572 | } |
1573 | bool hasVisibleDeclarationSlow(const NamedDecl *D, |
1574 | llvm::SmallVectorImpl<Module *> *Modules); |
1575 | |
1576 | bool hasVisibleMergedDefinition(NamedDecl *Def); |
1577 | bool hasMergedDefinitionInCurrentModule(NamedDecl *Def); |
1578 | |
1579 | /// Determine if \p D and \p Suggested have a structurally compatible |
1580 | /// layout as described in C11 6.2.7/1. |
1581 | bool hasStructuralCompatLayout(Decl *D, Decl *Suggested); |
1582 | |
1583 | /// Determine if \p D has a visible definition. If not, suggest a declaration |
1584 | /// that should be made visible to expose the definition. |
1585 | bool hasVisibleDefinition(NamedDecl *D, NamedDecl **Suggested, |
1586 | bool OnlyNeedComplete = false); |
1587 | bool hasVisibleDefinition(const NamedDecl *D) { |
1588 | NamedDecl *Hidden; |
1589 | return hasVisibleDefinition(const_cast<NamedDecl*>(D), &Hidden); |
1590 | } |
1591 | |
1592 | /// Determine if the template parameter \p D has a visible default argument. |
1593 | bool |
1594 | hasVisibleDefaultArgument(const NamedDecl *D, |
1595 | llvm::SmallVectorImpl<Module *> *Modules = nullptr); |
1596 | |
1597 | /// Determine if there is a visible declaration of \p D that is an explicit |
1598 | /// specialization declaration for a specialization of a template. (For a |
1599 | /// member specialization, use hasVisibleMemberSpecialization.) |
1600 | bool hasVisibleExplicitSpecialization( |
1601 | const NamedDecl *D, llvm::SmallVectorImpl<Module *> *Modules = nullptr); |
1602 | |
1603 | /// Determine if there is a visible declaration of \p D that is a member |
1604 | /// specialization declaration (as opposed to an instantiated declaration). |
1605 | bool hasVisibleMemberSpecialization( |
1606 | const NamedDecl *D, llvm::SmallVectorImpl<Module *> *Modules = nullptr); |
1607 | |
1608 | /// Determine if \p A and \p B are equivalent internal linkage declarations |
1609 | /// from different modules, and thus an ambiguity error can be downgraded to |
1610 | /// an extension warning. |
1611 | bool isEquivalentInternalLinkageDeclaration(const NamedDecl *A, |
1612 | const NamedDecl *B); |
1613 | void diagnoseEquivalentInternalLinkageDeclarations( |
1614 | SourceLocation Loc, const NamedDecl *D, |
1615 | ArrayRef<const NamedDecl *> Equiv); |
1616 | |
1617 | bool isCompleteType(SourceLocation Loc, QualType T) { |
1618 | return !RequireCompleteTypeImpl(Loc, T, nullptr); |
1619 | } |
1620 | bool RequireCompleteType(SourceLocation Loc, QualType T, |
1621 | TypeDiagnoser &Diagnoser); |
1622 | bool RequireCompleteType(SourceLocation Loc, QualType T, |
1623 | unsigned DiagID); |
1624 | |
1625 | template <typename... Ts> |
1626 | bool RequireCompleteType(SourceLocation Loc, QualType T, unsigned DiagID, |
1627 | const Ts &...Args) { |
1628 | BoundTypeDiagnoser<Ts...> Diagnoser(DiagID, Args...); |
1629 | return RequireCompleteType(Loc, T, Diagnoser); |
1630 | } |
1631 | |
1632 | void completeExprArrayBound(Expr *E); |
1633 | bool RequireCompleteExprType(Expr *E, TypeDiagnoser &Diagnoser); |
1634 | bool RequireCompleteExprType(Expr *E, unsigned DiagID); |
1635 | |
1636 | template <typename... Ts> |
1637 | bool RequireCompleteExprType(Expr *E, unsigned DiagID, const Ts &...Args) { |
1638 | BoundTypeDiagnoser<Ts...> Diagnoser(DiagID, Args...); |
1639 | return RequireCompleteExprType(E, Diagnoser); |
1640 | } |
1641 | |
1642 | bool RequireLiteralType(SourceLocation Loc, QualType T, |
1643 | TypeDiagnoser &Diagnoser); |
1644 | bool RequireLiteralType(SourceLocation Loc, QualType T, unsigned DiagID); |
1645 | |
1646 | template <typename... Ts> |
1647 | bool RequireLiteralType(SourceLocation Loc, QualType T, unsigned DiagID, |
1648 | const Ts &...Args) { |
1649 | BoundTypeDiagnoser<Ts...> Diagnoser(DiagID, Args...); |
1650 | return RequireLiteralType(Loc, T, Diagnoser); |
1651 | } |
1652 | |
1653 | QualType getElaboratedType(ElaboratedTypeKeyword Keyword, |
1654 | const CXXScopeSpec &SS, QualType T); |
1655 | |
1656 | QualType BuildTypeofExprType(Expr *E, SourceLocation Loc); |
1657 | /// If AsUnevaluated is false, E is treated as though it were an evaluated |
1658 | /// context, such as when building a type for decltype(auto). |
1659 | QualType BuildDecltypeType(Expr *E, SourceLocation Loc, |
1660 | bool AsUnevaluated = true); |
1661 | QualType BuildUnaryTransformType(QualType BaseType, |
1662 | UnaryTransformType::UTTKind UKind, |
1663 | SourceLocation Loc); |
1664 | |
1665 | //===--------------------------------------------------------------------===// |
1666 | // Symbol table / Decl tracking callbacks: SemaDecl.cpp. |
1667 | // |
1668 | |
1669 | struct SkipBodyInfo { |
1670 | SkipBodyInfo() |
1671 | : ShouldSkip(false), CheckSameAsPrevious(false), Previous(nullptr), |
1672 | New(nullptr) {} |
1673 | bool ShouldSkip; |
1674 | bool CheckSameAsPrevious; |
1675 | NamedDecl *Previous; |
1676 | NamedDecl *New; |
1677 | }; |
1678 | |
1679 | DeclGroupPtrTy ConvertDeclToDeclGroup(Decl *Ptr, Decl *OwnedType = nullptr); |
1680 | |
1681 | void DiagnoseUseOfUnimplementedSelectors(); |
1682 | |
1683 | bool isSimpleTypeSpecifier(tok::TokenKind Kind) const; |
1684 | |
1685 | ParsedType getTypeName(const IdentifierInfo &II, SourceLocation NameLoc, |
1686 | Scope *S, CXXScopeSpec *SS = nullptr, |
1687 | bool isClassName = false, bool HasTrailingDot = false, |
1688 | ParsedType ObjectType = nullptr, |
1689 | bool IsCtorOrDtorName = false, |
1690 | bool WantNontrivialTypeSourceInfo = false, |
1691 | bool IsClassTemplateDeductionContext = true, |
1692 | IdentifierInfo **CorrectedII = nullptr); |
1693 | TypeSpecifierType isTagName(IdentifierInfo &II, Scope *S); |
1694 | bool isMicrosoftMissingTypename(const CXXScopeSpec *SS, Scope *S); |
1695 | void DiagnoseUnknownTypeName(IdentifierInfo *&II, |
1696 | SourceLocation IILoc, |
1697 | Scope *S, |
1698 | CXXScopeSpec *SS, |
1699 | ParsedType &SuggestedType, |
1700 | bool IsTemplateName = false); |
1701 | |
1702 | /// Attempt to behave like MSVC in situations where lookup of an unqualified |
1703 | /// type name has failed in a dependent context. In these situations, we |
1704 | /// automatically form a DependentTypeName that will retry lookup in a related |
1705 | /// scope during instantiation. |
1706 | ParsedType ActOnMSVCUnknownTypeName(const IdentifierInfo &II, |
1707 | SourceLocation NameLoc, |
1708 | bool IsTemplateTypeArg); |
1709 | |
1710 | /// \brief Describes the result of the name lookup and resolution performed |
1711 | /// by \c ClassifyName(). |
1712 | enum NameClassificationKind { |
1713 | NC_Unknown, |
1714 | NC_Error, |
1715 | NC_Keyword, |
1716 | NC_Type, |
1717 | NC_Expression, |
1718 | NC_NestedNameSpecifier, |
1719 | NC_TypeTemplate, |
1720 | NC_VarTemplate, |
1721 | NC_FunctionTemplate |
1722 | }; |
1723 | |
1724 | class NameClassification { |
1725 | NameClassificationKind Kind; |
1726 | ExprResult Expr; |
1727 | TemplateName Template; |
1728 | ParsedType Type; |
1729 | |
1730 | explicit NameClassification(NameClassificationKind Kind) : Kind(Kind) {} |
1731 | |
1732 | public: |
1733 | NameClassification(ExprResult Expr) : Kind(NC_Expression), Expr(Expr) {} |
1734 | |
1735 | NameClassification(ParsedType Type) : Kind(NC_Type), Type(Type) {} |
1736 | |
1737 | NameClassification(const IdentifierInfo *Keyword) : Kind(NC_Keyword) {} |
1738 | |
1739 | static NameClassification Error() { |
1740 | return NameClassification(NC_Error); |
1741 | } |
1742 | |
1743 | static NameClassification Unknown() { |
1744 | return NameClassification(NC_Unknown); |
1745 | } |
1746 | |
1747 | static NameClassification NestedNameSpecifier() { |
1748 | return NameClassification(NC_NestedNameSpecifier); |
1749 | } |
1750 | |
1751 | static NameClassification TypeTemplate(TemplateName Name) { |
1752 | NameClassification Result(NC_TypeTemplate); |
1753 | Result.Template = Name; |
1754 | return Result; |
1755 | } |
1756 | |
1757 | static NameClassification VarTemplate(TemplateName Name) { |
1758 | NameClassification Result(NC_VarTemplate); |
1759 | Result.Template = Name; |
1760 | return Result; |
1761 | } |
1762 | |
1763 | static NameClassification FunctionTemplate(TemplateName Name) { |
1764 | NameClassification Result(NC_FunctionTemplate); |
1765 | Result.Template = Name; |
1766 | return Result; |
1767 | } |
1768 | |
1769 | NameClassificationKind getKind() const { return Kind; } |
1770 | |
1771 | ParsedType getType() const { |
1772 | assert(Kind == NC_Type)(static_cast <bool> (Kind == NC_Type) ? void (0) : __assert_fail ("Kind == NC_Type", "/build/llvm-toolchain-snapshot-7~svn326425/tools/clang/include/clang/Sema/Sema.h" , 1772, __extension__ __PRETTY_FUNCTION__)); |
1773 | return Type; |
1774 | } |
1775 | |
1776 | ExprResult getExpression() const { |
1777 | assert(Kind == NC_Expression)(static_cast <bool> (Kind == NC_Expression) ? void (0) : __assert_fail ("Kind == NC_Expression", "/build/llvm-toolchain-snapshot-7~svn326425/tools/clang/include/clang/Sema/Sema.h" , 1777, __extension__ __PRETTY_FUNCTION__)); |
1778 | return Expr; |
1779 | } |
1780 | |
1781 | TemplateName getTemplateName() const { |
1782 | assert(Kind == NC_TypeTemplate || Kind == NC_FunctionTemplate ||(static_cast <bool> (Kind == NC_TypeTemplate || Kind == NC_FunctionTemplate || Kind == NC_VarTemplate) ? void (0) : __assert_fail ("Kind == NC_TypeTemplate || Kind == NC_FunctionTemplate || Kind == NC_VarTemplate" , "/build/llvm-toolchain-snapshot-7~svn326425/tools/clang/include/clang/Sema/Sema.h" , 1783, __extension__ __PRETTY_FUNCTION__)) |
1783 | Kind == NC_VarTemplate)(static_cast <bool> (Kind == NC_TypeTemplate || Kind == NC_FunctionTemplate || Kind == NC_VarTemplate) ? void (0) : __assert_fail ("Kind == NC_TypeTemplate || Kind == NC_FunctionTemplate || Kind == NC_VarTemplate" , "/build/llvm-toolchain-snapshot-7~svn326425/tools/clang/include/clang/Sema/Sema.h" , 1783, __extension__ __PRETTY_FUNCTION__)); |
1784 | return Template; |
1785 | } |
1786 | |
1787 | TemplateNameKind getTemplateNameKind() const { |
1788 | switch (Kind) { |
1789 | case NC_TypeTemplate: |
1790 | return TNK_Type_template; |
1791 | case NC_FunctionTemplate: |
1792 | return TNK_Function_template; |
1793 | case NC_VarTemplate: |
1794 | return TNK_Var_template; |
1795 | default: |
1796 | llvm_unreachable("unsupported name classification.")::llvm::llvm_unreachable_internal("unsupported name classification." , "/build/llvm-toolchain-snapshot-7~svn326425/tools/clang/include/clang/Sema/Sema.h" , 1796); |
1797 | } |
1798 | } |
1799 | }; |
1800 | |
1801 | /// \brief Perform name lookup on the given name, classifying it based on |
1802 | /// the results of name lookup and the following token. |
1803 | /// |
1804 | /// This routine is used by the parser to resolve identifiers and help direct |
1805 | /// parsing. When the identifier cannot be found, this routine will attempt |
1806 | /// to correct the typo and classify based on the resulting name. |
1807 | /// |
1808 | /// \param S The scope in which we're performing name lookup. |
1809 | /// |
1810 | /// \param SS The nested-name-specifier that precedes the name. |
1811 | /// |
1812 | /// \param Name The identifier. If typo correction finds an alternative name, |
1813 | /// this pointer parameter will be updated accordingly. |
1814 | /// |
1815 | /// \param NameLoc The location of the identifier. |
1816 | /// |
1817 | /// \param NextToken The token following the identifier. Used to help |
1818 | /// disambiguate the name. |
1819 | /// |
1820 | /// \param IsAddressOfOperand True if this name is the operand of a unary |
1821 | /// address of ('&') expression, assuming it is classified as an |
1822 | /// expression. |
1823 | /// |
1824 | /// \param CCC The correction callback, if typo correction is desired. |
1825 | NameClassification |
1826 | ClassifyName(Scope *S, CXXScopeSpec &SS, IdentifierInfo *&Name, |
1827 | SourceLocation NameLoc, const Token &NextToken, |
1828 | bool IsAddressOfOperand, |
1829 | std::unique_ptr<CorrectionCandidateCallback> CCC = nullptr); |
1830 | |
1831 | /// Describes the detailed kind of a template name. Used in diagnostics. |
1832 | enum class TemplateNameKindForDiagnostics { |
1833 | ClassTemplate, |
1834 | FunctionTemplate, |
1835 | VarTemplate, |
1836 | AliasTemplate, |
1837 | TemplateTemplateParam, |
1838 | DependentTemplate |
1839 | }; |
1840 | TemplateNameKindForDiagnostics |
1841 | getTemplateNameKindForDiagnostics(TemplateName Name); |
1842 | |
1843 | /// Determine whether it's plausible that E was intended to be a |
1844 | /// template-name. |
1845 | bool mightBeIntendedToBeTemplateName(ExprResult E) { |
1846 | if (!getLangOpts().CPlusPlus || E.isInvalid()) |
1847 | return false; |
1848 | if (auto *DRE = dyn_cast<DeclRefExpr>(E.get())) |
1849 | return !DRE->hasExplicitTemplateArgs(); |
1850 | if (auto *ME = dyn_cast<MemberExpr>(E.get())) |
1851 | return !ME->hasExplicitTemplateArgs(); |
1852 | // Any additional cases recognized here should also be handled by |
1853 | // diagnoseExprIntendedAsTemplateName. |
1854 | return false; |
1855 | } |
1856 | void diagnoseExprIntendedAsTemplateName(Scope *S, ExprResult TemplateName, |
1857 | SourceLocation Less, |
1858 | SourceLocation Greater); |
1859 | |
1860 | Decl *ActOnDeclarator(Scope *S, Declarator &D); |
1861 | |
1862 | NamedDecl *HandleDeclarator(Scope *S, Declarator &D, |
1863 | MultiTemplateParamsArg TemplateParameterLists); |
1864 | void RegisterLocallyScopedExternCDecl(NamedDecl *ND, Scope *S); |
1865 | bool DiagnoseClassNameShadow(DeclContext *DC, DeclarationNameInfo Info); |
1866 | bool diagnoseQualifiedDeclaration(CXXScopeSpec &SS, DeclContext *DC, |
1867 | DeclarationName Name, |
1868 | SourceLocation Loc); |
1869 | void |
1870 | diagnoseIgnoredQualifiers(unsigned DiagID, unsigned Quals, |
1871 | SourceLocation FallbackLoc, |
1872 | SourceLocation ConstQualLoc = SourceLocation(), |
1873 | SourceLocation VolatileQualLoc = SourceLocation(), |
1874 | SourceLocation RestrictQualLoc = SourceLocation(), |
1875 | SourceLocation AtomicQualLoc = SourceLocation(), |
1876 | SourceLocation UnalignedQualLoc = SourceLocation()); |
1877 | |
1878 | static bool adjustContextForLocalExternDecl(DeclContext *&DC); |
1879 | void DiagnoseFunctionSpecifiers(const DeclSpec &DS); |
1880 | NamedDecl *getShadowedDeclaration(const TypedefNameDecl *D, |
1881 | const LookupResult &R); |
1882 | NamedDecl *getShadowedDeclaration(const VarDecl *D, const LookupResult &R); |
1883 | void CheckShadow(NamedDecl *D, NamedDecl *ShadowedDecl, |
1884 | const LookupResult &R); |
1885 | void CheckShadow(Scope *S, VarDecl *D); |
1886 | |
1887 | /// Warn if 'E', which is an expression that is about to be modified, refers |
1888 | /// to a shadowing declaration. |
1889 | void CheckShadowingDeclModification(Expr *E, SourceLocation Loc); |
1890 | |
1891 | void DiagnoseShadowingLambdaDecls(const sema::LambdaScopeInfo *LSI); |
1892 | |
1893 | private: |
1894 | /// Map of current shadowing declarations to shadowed declarations. Warn if |
1895 | /// it looks like the user is trying to modify the shadowing declaration. |
1896 | llvm::DenseMap<const NamedDecl *, const NamedDecl *> ShadowingDecls; |
1897 | |
1898 | public: |
1899 | void CheckCastAlign(Expr *Op, QualType T, SourceRange TRange); |
1900 | void handleTagNumbering(const TagDecl *Tag, Scope *TagScope); |
1901 | void setTagNameForLinkagePurposes(TagDecl *TagFromDeclSpec, |
1902 | TypedefNameDecl *NewTD); |
1903 | void CheckTypedefForVariablyModifiedType(Scope *S, TypedefNameDecl *D); |
1904 | NamedDecl* ActOnTypedefDeclarator(Scope* S, Declarator& D, DeclContext* DC, |
1905 | TypeSourceInfo *TInfo, |
1906 | LookupResult &Previous); |
1907 | NamedDecl* ActOnTypedefNameDecl(Scope* S, DeclContext* DC, TypedefNameDecl *D, |
1908 | LookupResult &Previous, bool &Redeclaration); |
1909 | NamedDecl *ActOnVariableDeclarator(Scope *S, Declarator &D, DeclContext *DC, |
1910 | TypeSourceInfo *TInfo, |
1911 | LookupResult &Previous, |
1912 | MultiTemplateParamsArg TemplateParamLists, |
1913 | bool &AddToScope, |
1914 | ArrayRef<BindingDecl *> Bindings = None); |
1915 | NamedDecl * |
1916 | ActOnDecompositionDeclarator(Scope *S, Declarator &D, |
1917 | MultiTemplateParamsArg TemplateParamLists); |
1918 | // Returns true if the variable declaration is a redeclaration |
1919 | bool CheckVariableDeclaration(VarDecl *NewVD, LookupResult &Previous); |
1920 | void CheckVariableDeclarationType(VarDecl *NewVD); |
1921 | bool DeduceVariableDeclarationType(VarDecl *VDecl, bool DirectInit, |
1922 | Expr *Init); |
1923 | void CheckCompleteVariableDeclaration(VarDecl *VD); |
1924 | void CheckCompleteDecompositionDeclaration(DecompositionDecl *DD); |
1925 | void MaybeSuggestAddingStaticToDecl(const FunctionDecl *D); |
1926 | |
1927 | NamedDecl* ActOnFunctionDeclarator(Scope* S, Declarator& D, DeclContext* DC, |
1928 | TypeSourceInfo *TInfo, |
1929 | LookupResult &Previous, |
1930 | MultiTemplateParamsArg TemplateParamLists, |
1931 | bool &AddToScope); |
1932 | bool AddOverriddenMethods(CXXRecordDecl *DC, CXXMethodDecl *MD); |
1933 | |
1934 | bool CheckConstexprFunctionDecl(const FunctionDecl *FD); |
1935 | bool CheckConstexprFunctionBody(const FunctionDecl *FD, Stmt *Body); |
1936 | |
1937 | void DiagnoseHiddenVirtualMethods(CXXMethodDecl *MD); |
1938 | void FindHiddenVirtualMethods(CXXMethodDecl *MD, |
1939 | SmallVectorImpl<CXXMethodDecl*> &OverloadedMethods); |
1940 | void NoteHiddenVirtualMethods(CXXMethodDecl *MD, |
1941 | SmallVectorImpl<CXXMethodDecl*> &OverloadedMethods); |
1942 | // Returns true if the function declaration is a redeclaration |
1943 | bool CheckFunctionDeclaration(Scope *S, |
1944 | FunctionDecl *NewFD, LookupResult &Previous, |
1945 | bool IsMemberSpecialization); |
1946 | bool shouldLinkDependentDeclWithPrevious(Decl *D, Decl *OldDecl); |
1947 | void CheckMain(FunctionDecl *FD, const DeclSpec &D); |
1948 | void CheckMSVCRTEntryPoint(FunctionDecl *FD); |
1949 | Decl *ActOnParamDeclarator(Scope *S, Declarator &D); |
1950 | ParmVarDecl *BuildParmVarDeclForTypedef(DeclContext *DC, |
1951 | SourceLocation Loc, |
1952 | QualType T); |
1953 | ParmVarDecl *CheckParameter(DeclContext *DC, SourceLocation StartLoc, |
1954 | SourceLocation NameLoc, IdentifierInfo *Name, |
1955 | QualType T, TypeSourceInfo *TSInfo, |
1956 | StorageClass SC); |
1957 | void ActOnParamDefaultArgument(Decl *param, |
1958 | SourceLocation EqualLoc, |
1959 | Expr *defarg); |
1960 | void ActOnParamUnparsedDefaultArgument(Decl *param, |
1961 | SourceLocation EqualLoc, |
1962 | SourceLocation ArgLoc); |
1963 | void ActOnParamDefaultArgumentError(Decl *param, SourceLocation EqualLoc); |
1964 | bool SetParamDefaultArgument(ParmVarDecl *Param, Expr *DefaultArg, |
1965 | SourceLocation EqualLoc); |
1966 | |
1967 | void AddInitializerToDecl(Decl *dcl, Expr *init, bool DirectInit); |
1968 | void ActOnUninitializedDecl(Decl *dcl); |
1969 | void ActOnInitializerError(Decl *Dcl); |
1970 | |
1971 | void ActOnPureSpecifier(Decl *D, SourceLocation PureSpecLoc); |
1972 | void ActOnCXXForRangeDecl(Decl *D); |
1973 | StmtResult ActOnCXXForRangeIdentifier(Scope *S, SourceLocation IdentLoc, |
1974 | IdentifierInfo *Ident, |
1975 | ParsedAttributes &Attrs, |
1976 | SourceLocation AttrEnd); |
1977 | void SetDeclDeleted(Decl *dcl, SourceLocation DelLoc); |
1978 | void SetDeclDefaulted(Decl *dcl, SourceLocation DefaultLoc); |
1979 | void FinalizeDeclaration(Decl *D); |
1980 | DeclGroupPtrTy FinalizeDeclaratorGroup(Scope *S, const DeclSpec &DS, |
1981 | ArrayRef<Decl *> Group); |
1982 | DeclGroupPtrTy BuildDeclaratorGroup(MutableArrayRef<Decl *> Group); |
1983 | |
1984 | /// Should be called on all declarations that might have attached |
1985 | /// documentation comments. |
1986 | void ActOnDocumentableDecl(Decl *D); |
1987 | void ActOnDocumentableDecls(ArrayRef<Decl *> Group); |
1988 | |
1989 | void ActOnFinishKNRParamDeclarations(Scope *S, Declarator &D, |
1990 | SourceLocation LocAfterDecls); |
1991 | void CheckForFunctionRedefinition( |
1992 | FunctionDecl *FD, const FunctionDecl *EffectiveDefinition = nullptr, |
1993 | SkipBodyInfo *SkipBody = nullptr); |
1994 | Decl *ActOnStartOfFunctionDef(Scope *S, Declarator &D, |
1995 | MultiTemplateParamsArg TemplateParamLists, |
1996 | SkipBodyInfo *SkipBody = nullptr); |
1997 | Decl *ActOnStartOfFunctionDef(Scope *S, Decl *D, |
1998 | SkipBodyInfo *SkipBody = nullptr); |
1999 | void ActOnStartOfObjCMethodDef(Scope *S, Decl *D); |
2000 | bool isObjCMethodDecl(Decl *D) { |
2001 | return D && isa<ObjCMethodDecl>(D); |
2002 | } |
2003 | |
2004 | /// \brief Determine whether we can delay parsing the body of a function or |
2005 | /// function template until it is used, assuming we don't care about emitting |
2006 | /// code for that function. |
2007 | /// |
2008 | /// This will be \c false if we may need the body of the function in the |
2009 | /// middle of parsing an expression (where it's impractical to switch to |
2010 | /// parsing a different function), for instance, if it's constexpr in C++11 |
2011 | /// or has an 'auto' return type in C++14. These cases are essentially bugs. |
2012 | bool canDelayFunctionBody(const Declarator &D); |
2013 | |
2014 | /// \brief Determine whether we can skip parsing the body of a function |
2015 | /// definition, assuming we don't care about analyzing its body or emitting |
2016 | /// code for that function. |
2017 | /// |
2018 | /// This will be \c false only if we may need the body of the function in |
2019 | /// order to parse the rest of the program (for instance, if it is |
2020 | /// \c constexpr in C++11 or has an 'auto' return type in C++14). |
2021 | bool canSkipFunctionBody(Decl *D); |
2022 | |
2023 | void computeNRVO(Stmt *Body, sema::FunctionScopeInfo *Scope); |
2024 | Decl *ActOnFinishFunctionBody(Decl *Decl, Stmt *Body); |
2025 | Decl *ActOnFinishFunctionBody(Decl *Decl, Stmt *Body, bool IsInstantiation); |
2026 | Decl *ActOnSkippedFunctionBody(Decl *Decl); |
2027 | void ActOnFinishInlineFunctionDef(FunctionDecl *D); |
2028 | |
2029 | /// ActOnFinishDelayedAttribute - Invoked when we have finished parsing an |
2030 | /// attribute for which parsing is delayed. |
2031 | void ActOnFinishDelayedAttribute(Scope *S, Decl *D, ParsedAttributes &Attrs); |
2032 | |
2033 | /// \brief Diagnose any unused parameters in the given sequence of |
2034 | /// ParmVarDecl pointers. |
2035 | void DiagnoseUnusedParameters(ArrayRef<ParmVarDecl *> Parameters); |
2036 | |
2037 | /// \brief Diagnose whether the size of parameters or return value of a |
2038 | /// function or obj-c method definition is pass-by-value and larger than a |
2039 | /// specified threshold. |
2040 | void |
2041 | DiagnoseSizeOfParametersAndReturnValue(ArrayRef<ParmVarDecl *> Parameters, |
2042 | QualType ReturnTy, NamedDecl *D); |
2043 | |
2044 | void DiagnoseInvalidJumps(Stmt *Body); |
2045 | Decl *ActOnFileScopeAsmDecl(Expr *expr, |
2046 | SourceLocation AsmLoc, |
2047 | SourceLocation RParenLoc); |
2048 | |
2049 | /// \brief Handle a C++11 empty-declaration and attribute-declaration. |
2050 | Decl *ActOnEmptyDeclaration(Scope *S, |
2051 | AttributeList *AttrList, |
2052 | SourceLocation SemiLoc); |
2053 | |
2054 | enum class ModuleDeclKind { |
2055 | Interface, ///< 'export module X;' |
2056 | Implementation, ///< 'module X;' |
2057 | Partition, ///< 'module partition X;' |
2058 | }; |
2059 | |
2060 | /// The parser has processed a module-declaration that begins the definition |
2061 | /// of a module interface or implementation. |
2062 | DeclGroupPtrTy ActOnModuleDecl(SourceLocation StartLoc, |
2063 | SourceLocation ModuleLoc, ModuleDeclKind MDK, |
2064 | ModuleIdPath Path); |
2065 | |
2066 | /// \brief The parser has processed a module import declaration. |
2067 | /// |
2068 | /// \param AtLoc The location of the '@' symbol, if any. |
2069 | /// |
2070 | /// \param ImportLoc The location of the 'import' keyword. |
2071 | /// |
2072 | /// \param Path The module access path. |
2073 | DeclResult ActOnModuleImport(SourceLocation AtLoc, SourceLocation ImportLoc, |
2074 | ModuleIdPath Path); |
2075 | |
2076 | /// \brief The parser has processed a module import translated from a |
2077 | /// #include or similar preprocessing directive. |
2078 | void ActOnModuleInclude(SourceLocation DirectiveLoc, Module *Mod); |
2079 | void BuildModuleInclude(SourceLocation DirectiveLoc, Module *Mod); |
2080 | |
2081 | /// \brief The parsed has entered a submodule. |
2082 | void ActOnModuleBegin(SourceLocation DirectiveLoc, Module *Mod); |
2083 | /// \brief The parser has left a submodule. |
2084 | void ActOnModuleEnd(SourceLocation DirectiveLoc, Module *Mod); |
2085 | |
2086 | /// \brief Create an implicit import of the given module at the given |
2087 | /// source location, for error recovery, if possible. |
2088 | /// |
2089 | /// This routine is typically used when an entity found by name lookup |
2090 | /// is actually hidden within a module that we know about but the user |
2091 | /// has forgotten to import. |
2092 | void createImplicitModuleImportForErrorRecovery(SourceLocation Loc, |
2093 | Module *Mod); |
2094 | |
2095 | /// Kinds of missing import. Note, the values of these enumerators correspond |
2096 | /// to %select values in diagnostics. |
2097 | enum class MissingImportKind { |
2098 | Declaration, |
2099 | Definition, |
2100 | DefaultArgument, |
2101 | ExplicitSpecialization, |
2102 | PartialSpecialization |
2103 | }; |
2104 | |
2105 | /// \brief Diagnose that the specified declaration needs to be visible but |
2106 | /// isn't, and suggest a module import that would resolve the problem. |
2107 | void diagnoseMissingImport(SourceLocation Loc, NamedDecl *Decl, |
2108 | MissingImportKind MIK, bool Recover = true); |
2109 | void diagnoseMissingImport(SourceLocation Loc, NamedDecl *Decl, |
2110 | SourceLocation DeclLoc, ArrayRef<Module *> Modules, |
2111 | MissingImportKind MIK, bool Recover); |
2112 | |
2113 | Decl *ActOnStartExportDecl(Scope *S, SourceLocation ExportLoc, |
2114 | SourceLocation LBraceLoc); |
2115 | Decl *ActOnFinishExportDecl(Scope *S, Decl *ExportDecl, |
2116 | SourceLocation RBraceLoc); |
2117 | |
2118 | /// \brief We've found a use of a templated declaration that would trigger an |
2119 | /// implicit instantiation. Check that any relevant explicit specializations |
2120 | /// and partial specializations are visible, and diagnose if not. |
2121 | void checkSpecializationVisibility(SourceLocation Loc, NamedDecl *Spec); |
2122 | |
2123 | /// \brief We've found a use of a template specialization that would select a |
2124 | /// partial specialization. Check that the partial specialization is visible, |
2125 | /// and diagnose if not. |
2126 | void checkPartialSpecializationVisibility(SourceLocation Loc, |
2127 | NamedDecl *Spec); |
2128 | |
2129 | /// \brief Retrieve a suitable printing policy. |
2130 | PrintingPolicy getPrintingPolicy() const { |
2131 | return getPrintingPolicy(Context, PP); |
2132 | } |
2133 | |
2134 | /// \brief Retrieve a suitable printing policy. |
2135 | static PrintingPolicy getPrintingPolicy(const ASTContext &Ctx, |
2136 | const Preprocessor &PP); |
2137 | |
2138 | /// Scope actions. |
2139 | void ActOnPopScope(SourceLocation Loc, Scope *S); |
2140 | void ActOnTranslationUnitScope(Scope *S); |
2141 | |
2142 | Decl *ParsedFreeStandingDeclSpec(Scope *S, AccessSpecifier AS, DeclSpec &DS, |
2143 | RecordDecl *&AnonRecord); |
2144 | Decl *ParsedFreeStandingDeclSpec(Scope *S, AccessSpecifier AS, DeclSpec &DS, |
2145 | MultiTemplateParamsArg TemplateParams, |
2146 | bool IsExplicitInstantiation, |
2147 | RecordDecl *&AnonRecord); |
2148 | |
2149 | Decl *BuildAnonymousStructOrUnion(Scope *S, DeclSpec &DS, |
2150 | AccessSpecifier AS, |
2151 | RecordDecl *Record, |
2152 | const PrintingPolicy &Policy); |
2153 | |
2154 | Decl *BuildMicrosoftCAnonymousStruct(Scope *S, DeclSpec &DS, |
2155 | RecordDecl *Record); |
2156 | |
2157 | /// Common ways to introduce type names without a tag for use in diagnostics. |
2158 | /// Keep in sync with err_tag_reference_non_tag. |
2159 | enum NonTagKind { |
2160 | NTK_NonStruct, |
2161 | NTK_NonClass, |
2162 | NTK_NonUnion, |
2163 | NTK_NonEnum, |
2164 | NTK_Typedef, |
2165 | NTK_TypeAlias, |
2166 | NTK_Template, |
2167 | NTK_TypeAliasTemplate, |
2168 | NTK_TemplateTemplateArgument, |
2169 | }; |
2170 | |
2171 | /// Given a non-tag type declaration, returns an enum useful for indicating |
2172 | /// what kind of non-tag type this is. |
2173 | NonTagKind getNonTagTypeDeclKind(const Decl *D, TagTypeKind TTK); |
2174 | |
2175 | bool isAcceptableTagRedeclaration(const TagDecl *Previous, |
2176 | TagTypeKind NewTag, bool isDefinition, |
2177 | SourceLocation NewTagLoc, |
2178 | const IdentifierInfo *Name); |
2179 | |
2180 | enum TagUseKind { |
2181 | TUK_Reference, // Reference to a tag: 'struct foo *X;' |
2182 | TUK_Declaration, // Fwd decl of a tag: 'struct foo;' |
2183 | TUK_Definition, // Definition of a tag: 'struct foo { int X; } Y;' |
2184 | TUK_Friend // Friend declaration: 'friend struct foo;' |
2185 | }; |
2186 | |
2187 | Decl *ActOnTag(Scope *S, unsigned TagSpec, TagUseKind TUK, |
2188 | SourceLocation KWLoc, CXXScopeSpec &SS, IdentifierInfo *Name, |
2189 | SourceLocation NameLoc, AttributeList *Attr, |
2190 | AccessSpecifier AS, SourceLocation ModulePrivateLoc, |
2191 | MultiTemplateParamsArg TemplateParameterLists, bool &OwnedDecl, |
2192 | bool &IsDependent, SourceLocation ScopedEnumKWLoc, |
2193 | bool ScopedEnumUsesClassTag, TypeResult UnderlyingType, |
2194 | bool IsTypeSpecifier, bool IsTemplateParamOrArg, |
2195 | SkipBodyInfo *SkipBody = nullptr); |
2196 | |
2197 | Decl *ActOnTemplatedFriendTag(Scope *S, SourceLocation FriendLoc, |
2198 | unsigned TagSpec, SourceLocation TagLoc, |
2199 | CXXScopeSpec &SS, |
2200 | IdentifierInfo *Name, SourceLocation NameLoc, |
2201 | AttributeList *Attr, |
2202 | MultiTemplateParamsArg TempParamLists); |
2203 | |
2204 | TypeResult ActOnDependentTag(Scope *S, |
2205 | unsigned TagSpec, |
2206 | TagUseKind TUK, |
2207 | const CXXScopeSpec &SS, |
2208 | IdentifierInfo *Name, |
2209 | SourceLocation TagLoc, |
2210 | SourceLocation NameLoc); |
2211 | |
2212 | void ActOnDefs(Scope *S, Decl *TagD, SourceLocation DeclStart, |
2213 | IdentifierInfo *ClassName, |
2214 | SmallVectorImpl<Decl *> &Decls); |
2215 | Decl *ActOnField(Scope *S, Decl *TagD, SourceLocation DeclStart, |
2216 | Declarator &D, Expr *BitfieldWidth); |
2217 | |
2218 | FieldDecl *HandleField(Scope *S, RecordDecl *TagD, SourceLocation DeclStart, |
2219 | Declarator &D, Expr *BitfieldWidth, |
2220 | InClassInitStyle InitStyle, |
2221 | AccessSpecifier AS); |
2222 | MSPropertyDecl *HandleMSProperty(Scope *S, RecordDecl *TagD, |
2223 | SourceLocation DeclStart, |
2224 | Declarator &D, Expr *BitfieldWidth, |
2225 | InClassInitStyle InitStyle, |
2226 | AccessSpecifier AS, |
2227 | AttributeList *MSPropertyAttr); |
2228 | |
2229 | FieldDecl *CheckFieldDecl(DeclarationName Name, QualType T, |
2230 | TypeSourceInfo *TInfo, |
2231 | RecordDecl *Record, SourceLocation Loc, |
2232 | bool Mutable, Expr *BitfieldWidth, |
2233 | InClassInitStyle InitStyle, |
2234 | SourceLocation TSSL, |
2235 | AccessSpecifier AS, NamedDecl *PrevDecl, |
2236 | Declarator *D = nullptr); |
2237 | |
2238 | bool CheckNontrivialField(FieldDecl *FD); |
2239 | void DiagnoseNontrivial(const CXXRecordDecl *Record, CXXSpecialMember CSM); |
2240 | |
2241 | enum TrivialABIHandling { |
2242 | /// The triviality of a method unaffected by "trivial_abi". |
2243 | TAH_IgnoreTrivialABI, |
2244 | |
2245 | /// The triviality of a method affected by "trivial_abi". |
2246 | TAH_ConsiderTrivialABI |
2247 | }; |
2248 | |
2249 | bool SpecialMemberIsTrivial(CXXMethodDecl *MD, CXXSpecialMember CSM, |
2250 | TrivialABIHandling TAH = TAH_IgnoreTrivialABI, |
2251 | bool Diagnose = false); |
2252 | CXXSpecialMember getSpecialMember(const CXXMethodDecl *MD); |
2253 | void ActOnLastBitfield(SourceLocation DeclStart, |
2254 | SmallVectorImpl<Decl *> &AllIvarDecls); |
2255 | Decl *ActOnIvar(Scope *S, SourceLocation DeclStart, |
2256 | Declarator &D, Expr *BitfieldWidth, |
2257 | tok::ObjCKeywordKind visibility); |
2258 | |
2259 | // This is used for both record definitions and ObjC interface declarations. |
2260 | void ActOnFields(Scope* S, SourceLocation RecLoc, Decl *TagDecl, |
2261 | ArrayRef<Decl *> Fields, |
2262 | SourceLocation LBrac, SourceLocation RBrac, |
2263 | AttributeList *AttrList); |
2264 | |
2265 | /// ActOnTagStartDefinition - Invoked when we have entered the |
2266 | /// scope of a tag's definition (e.g., for an enumeration, class, |
2267 | /// struct, or union). |
2268 | void ActOnTagStartDefinition(Scope *S, Decl *TagDecl); |
2269 | |
2270 | /// Perform ODR-like check for C/ObjC when merging tag types from modules. |
2271 | /// Differently from C++, actually parse the body and reject / error out |
2272 | /// in case of a structural mismatch. |
2273 | bool ActOnDuplicateDefinition(DeclSpec &DS, Decl *Prev, |
2274 | SkipBodyInfo &SkipBody); |
2275 | |
2276 | typedef void *SkippedDefinitionContext; |
2277 | |
2278 | /// \brief Invoked when we enter a tag definition that we're skipping. |
2279 | SkippedDefinitionContext ActOnTagStartSkippedDefinition(Scope *S, Decl *TD); |
2280 | |
2281 | Decl *ActOnObjCContainerStartDefinition(Decl *IDecl); |
2282 | |
2283 | /// ActOnStartCXXMemberDeclarations - Invoked when we have parsed a |
2284 | /// C++ record definition's base-specifiers clause and are starting its |
2285 | /// member declarations. |
2286 | void ActOnStartCXXMemberDeclarations(Scope *S, Decl *TagDecl, |
2287 | SourceLocation FinalLoc, |
2288 | bool IsFinalSpelledSealed, |
2289 | SourceLocation LBraceLoc); |
2290 | |
2291 | /// ActOnTagFinishDefinition - Invoked once we have finished parsing |
2292 | /// the definition of a tag (enumeration, class, struct, or union). |
2293 | void ActOnTagFinishDefinition(Scope *S, Decl *TagDecl, |
2294 | SourceRange BraceRange); |
2295 | |
2296 | void ActOnTagFinishSkippedDefinition(SkippedDefinitionContext Context); |
2297 | |
2298 | void ActOnObjCContainerFinishDefinition(); |
2299 | |
2300 | /// \brief Invoked when we must temporarily exit the objective-c container |
2301 | /// scope for parsing/looking-up C constructs. |
2302 | /// |
2303 | /// Must be followed by a call to \see ActOnObjCReenterContainerContext |
2304 | void ActOnObjCTemporaryExitContainerContext(DeclContext *DC); |
2305 | void ActOnObjCReenterContainerContext(DeclContext *DC); |
2306 | |
2307 | /// ActOnTagDefinitionError - Invoked when there was an unrecoverable |
2308 | /// error parsing the definition of a tag. |
2309 | void ActOnTagDefinitionError(Scope *S, Decl *TagDecl); |
2310 | |
2311 | EnumConstantDecl *CheckEnumConstant(EnumDecl *Enum, |
2312 | EnumConstantDecl *LastEnumConst, |
2313 | SourceLocation IdLoc, |
2314 | IdentifierInfo *Id, |
2315 | Expr *val); |
2316 | bool CheckEnumUnderlyingType(TypeSourceInfo *TI); |
2317 | bool CheckEnumRedeclaration(SourceLocation EnumLoc, bool IsScoped, |
2318 | QualType EnumUnderlyingTy, bool IsFixed, |
2319 | const EnumDecl *Prev); |
2320 | |
2321 | /// Determine whether the body of an anonymous enumeration should be skipped. |
2322 | /// \param II The name of the first enumerator. |
2323 | SkipBodyInfo shouldSkipAnonEnumBody(Scope *S, IdentifierInfo *II, |
2324 | SourceLocation IILoc); |
2325 | |
2326 | Decl *ActOnEnumConstant(Scope *S, Decl *EnumDecl, Decl *LastEnumConstant, |
2327 | SourceLocation IdLoc, IdentifierInfo *Id, |
2328 | AttributeList *Attrs, SourceLocation EqualLoc, |
2329 | Expr *Val); |
2330 | void ActOnEnumBody(SourceLocation EnumLoc, SourceRange BraceRange, |
2331 | Decl *EnumDecl, |
2332 | ArrayRef<Decl *> Elements, |
2333 | Scope *S, AttributeList *Attr); |
2334 | |
2335 | DeclContext *getContainingDC(DeclContext *DC); |
2336 | |
2337 | /// Set the current declaration context until it gets popped. |
2338 | void PushDeclContext(Scope *S, DeclContext *DC); |
2339 | void PopDeclContext(); |
2340 | |
2341 | /// EnterDeclaratorContext - Used when we must lookup names in the context |
2342 | /// of a declarator's nested name specifier. |
2343 | void EnterDeclaratorContext(Scope *S, DeclContext *DC); |
2344 | void ExitDeclaratorContext(Scope *S); |
2345 | |
2346 | /// Push the parameters of D, which must be a function, into scope. |
2347 | void ActOnReenterFunctionContext(Scope* S, Decl* D); |
2348 | void ActOnExitFunctionContext(); |
2349 | |
2350 | DeclContext *getFunctionLevelDeclContext(); |
2351 | |
2352 | /// getCurFunctionDecl - If inside of a function body, this returns a pointer |
2353 | /// to the function decl for the function being parsed. If we're currently |
2354 | /// in a 'block', this returns the containing context. |
2355 | FunctionDecl *getCurFunctionDecl(); |
2356 | |
2357 | /// getCurMethodDecl - If inside of a method body, this returns a pointer to |
2358 | /// the method decl for the method being parsed. If we're currently |
2359 | /// in a 'block', this returns the containing context. |
2360 | ObjCMethodDecl *getCurMethodDecl(); |
2361 | |
2362 | /// getCurFunctionOrMethodDecl - Return the Decl for the current ObjC method |
2363 | /// or C function we're in, otherwise return null. If we're currently |
2364 | /// in a 'block', this returns the containing context. |
2365 | NamedDecl *getCurFunctionOrMethodDecl(); |
2366 | |
2367 | /// Add this decl to the scope shadowed decl chains. |
2368 | void PushOnScopeChains(NamedDecl *D, Scope *S, bool AddToContext = true); |
2369 | |
2370 | /// \brief Make the given externally-produced declaration visible at the |
2371 | /// top level scope. |
2372 | /// |
2373 | /// \param D The externally-produced declaration to push. |
2374 | /// |
2375 | /// \param Name The name of the externally-produced declaration. |
2376 | void pushExternalDeclIntoScope(NamedDecl *D, DeclarationName Name); |
2377 | |
2378 | /// isDeclInScope - If 'Ctx' is a function/method, isDeclInScope returns true |
2379 | /// if 'D' is in Scope 'S', otherwise 'S' is ignored and isDeclInScope returns |
2380 | /// true if 'D' belongs to the given declaration context. |
2381 | /// |
2382 | /// \param AllowInlineNamespace If \c true, allow the declaration to be in the |
2383 | /// enclosing namespace set of the context, rather than contained |
2384 | /// directly within it. |
2385 | bool isDeclInScope(NamedDecl *D, DeclContext *Ctx, Scope *S = nullptr, |
2386 | bool AllowInlineNamespace = false); |
2387 | |
2388 | /// Finds the scope corresponding to the given decl context, if it |
2389 | /// happens to be an enclosing scope. Otherwise return NULL. |
2390 | static Scope *getScopeForDeclContext(Scope *S, DeclContext *DC); |
2391 | |
2392 | /// Subroutines of ActOnDeclarator(). |
2393 | TypedefDecl *ParseTypedefDecl(Scope *S, Declarator &D, QualType T, |
2394 | TypeSourceInfo *TInfo); |
2395 | bool isIncompatibleTypedef(TypeDecl *Old, TypedefNameDecl *New); |
2396 | |
2397 | /// \brief Describes the kind of merge to perform for availability |
2398 | /// attributes (including "deprecated", "unavailable", and "availability"). |
2399 | enum AvailabilityMergeKind { |
2400 | /// \brief Don't merge availability attributes at all. |
2401 | AMK_None, |
2402 | /// \brief Merge availability attributes for a redeclaration, which requires |
2403 | /// an exact match. |
2404 | AMK_Redeclaration, |
2405 | /// \brief Merge availability attributes for an override, which requires |
2406 | /// an exact match or a weakening of constraints. |
2407 | AMK_Override, |
2408 | /// \brief Merge availability attributes for an implementation of |
2409 | /// a protocol requirement. |
2410 | AMK_ProtocolImplementation, |
2411 | }; |
2412 | |
2413 | /// Attribute merging methods. Return true if a new attribute was added. |
2414 | AvailabilityAttr *mergeAvailabilityAttr(NamedDecl *D, SourceRange Range, |
2415 | IdentifierInfo *Platform, |
2416 | bool Implicit, |
2417 | VersionTuple Introduced, |
2418 | VersionTuple Deprecated, |
2419 | VersionTuple Obsoleted, |
2420 | bool IsUnavailable, |
2421 | StringRef Message, |
2422 | bool IsStrict, StringRef Replacement, |
2423 | AvailabilityMergeKind AMK, |
2424 | unsigned AttrSpellingListIndex); |
2425 | TypeVisibilityAttr *mergeTypeVisibilityAttr(Decl *D, SourceRange Range, |
2426 | TypeVisibilityAttr::VisibilityType Vis, |
2427 | unsigned AttrSpellingListIndex); |
2428 | VisibilityAttr *mergeVisibilityAttr(Decl *D, SourceRange Range, |
2429 | VisibilityAttr::VisibilityType Vis, |
2430 | unsigned AttrSpellingListIndex); |
2431 | UuidAttr *mergeUuidAttr(Decl *D, SourceRange Range, |
2432 | unsigned AttrSpellingListIndex, StringRef Uuid); |
2433 | DLLImportAttr *mergeDLLImportAttr(Decl *D, SourceRange Range, |
2434 | unsigned AttrSpellingListIndex); |
2435 | DLLExportAttr *mergeDLLExportAttr(Decl *D, SourceRange Range, |
2436 | unsigned AttrSpellingListIndex); |
2437 | MSInheritanceAttr * |
2438 | mergeMSInheritanceAttr(Decl *D, SourceRange Range, bool BestCase, |
2439 | unsigned AttrSpellingListIndex, |
2440 | MSInheritanceAttr::Spelling SemanticSpelling); |
2441 | FormatAttr *mergeFormatAttr(Decl *D, SourceRange Range, |
2442 | IdentifierInfo *Format, int FormatIdx, |
2443 | int FirstArg, unsigned AttrSpellingListIndex); |
2444 | SectionAttr *mergeSectionAttr(Decl *D, SourceRange Range, StringRef Name, |
2445 | unsigned AttrSpellingListIndex); |
2446 | AlwaysInlineAttr *mergeAlwaysInlineAttr(Decl *D, SourceRange Range, |
2447 | IdentifierInfo *Ident, |
2448 | unsigned AttrSpellingListIndex); |
2449 | MinSizeAttr *mergeMinSizeAttr(Decl *D, SourceRange Range, |
2450 | unsigned AttrSpellingListIndex); |
2451 | OptimizeNoneAttr *mergeOptimizeNoneAttr(Decl *D, SourceRange Range, |
2452 | unsigned AttrSpellingListIndex); |
2453 | InternalLinkageAttr *mergeInternalLinkageAttr(Decl *D, SourceRange Range, |
2454 | IdentifierInfo *Ident, |
2455 | unsigned AttrSpellingListIndex); |
2456 | CommonAttr *mergeCommonAttr(Decl *D, SourceRange Range, IdentifierInfo *Ident, |
2457 | unsigned AttrSpellingListIndex); |
2458 | |
2459 | void mergeDeclAttributes(NamedDecl *New, Decl *Old, |
2460 | AvailabilityMergeKind AMK = AMK_Redeclaration); |
2461 | void MergeTypedefNameDecl(Scope *S, TypedefNameDecl *New, |
2462 | LookupResult &OldDecls); |
2463 | bool MergeFunctionDecl(FunctionDecl *New, NamedDecl *&Old, Scope *S, |
2464 | bool MergeTypeWithOld); |
2465 | bool MergeCompatibleFunctionDecls(FunctionDecl *New, FunctionDecl *Old, |
2466 | Scope *S, bool MergeTypeWithOld); |
2467 | void mergeObjCMethodDecls(ObjCMethodDecl *New, ObjCMethodDecl *Old); |
2468 | void MergeVarDecl(VarDecl *New, LookupResult &Previous); |
2469 | void MergeVarDeclTypes(VarDecl *New, VarDecl *Old, bool MergeTypeWithOld); |
2470 | void MergeVarDeclExceptionSpecs(VarDecl *New, VarDecl *Old); |
2471 | bool checkVarDeclRedefinition(VarDecl *OldDefn, VarDecl *NewDefn); |
2472 | void notePreviousDefinition(const NamedDecl *Old, SourceLocation New); |
2473 | bool MergeCXXFunctionDecl(FunctionDecl *New, FunctionDecl *Old, Scope *S); |
2474 | |
2475 | // AssignmentAction - This is used by all the assignment diagnostic functions |
2476 | // to represent what is actually causing the operation |
2477 | enum AssignmentAction { |
2478 | AA_Assigning, |
2479 | AA_Passing, |
2480 | AA_Returning, |
2481 | AA_Converting, |
2482 | AA_Initializing, |
2483 | AA_Sending, |
2484 | AA_Casting, |
2485 | AA_Passing_CFAudited |
2486 | }; |
2487 | |
2488 | /// C++ Overloading. |
2489 | enum OverloadKind { |
2490 | /// This is a legitimate overload: the existing declarations are |
2491 | /// functions or function templates with different signatures. |
2492 | Ovl_Overload, |
2493 | |
2494 | /// This is not an overload because the signature exactly matches |
2495 | /// an existing declaration. |
2496 | Ovl_Match, |
2497 | |
2498 | /// This is not an overload because the lookup results contain a |
2499 | /// non-function. |
2500 | Ovl_NonFunction |
2501 | }; |
2502 | OverloadKind CheckOverload(Scope *S, |
2503 | FunctionDecl *New, |
2504 | const LookupResult &OldDecls, |
2505 | NamedDecl *&OldDecl, |
2506 | bool IsForUsingDecl); |
2507 | bool IsOverload(FunctionDecl *New, FunctionDecl *Old, bool IsForUsingDecl, |
2508 | bool ConsiderCudaAttrs = true); |
2509 | |
2510 | /// \brief Checks availability of the function depending on the current |
2511 | /// function context.Inside an unavailable function,unavailability is ignored. |
2512 | /// |
2513 | /// \returns true if \p FD is unavailable and current context is inside |
2514 | /// an available function, false otherwise. |
2515 | bool isFunctionConsideredUnavailable(FunctionDecl *FD); |
2516 | |
2517 | ImplicitConversionSequence |
2518 | TryImplicitConversion(Expr *From, QualType ToType, |
2519 | bool SuppressUserConversions, |
2520 | bool AllowExplicit, |
2521 | bool InOverloadResolution, |
2522 | bool CStyle, |
2523 | bool AllowObjCWritebackConversion); |
2524 | |
2525 | bool IsIntegralPromotion(Expr *From, QualType FromType, QualType ToType); |
2526 | bool IsFloatingPointPromotion(QualType FromType, QualType ToType); |
2527 | bool IsComplexPromotion(QualType FromType, QualType ToType); |
2528 | bool IsPointerConversion(Expr *From, QualType FromType, QualType ToType, |
2529 | bool InOverloadResolution, |
2530 | QualType& ConvertedType, bool &IncompatibleObjC); |
2531 | bool isObjCPointerConversion(QualType FromType, QualType ToType, |
2532 | QualType& ConvertedType, bool &IncompatibleObjC); |
2533 | bool isObjCWritebackConversion(QualType FromType, QualType ToType, |
2534 | QualType &ConvertedType); |
2535 | bool IsBlockPointerConversion(QualType FromType, QualType ToType, |
2536 | QualType& ConvertedType); |
2537 | bool FunctionParamTypesAreEqual(const FunctionProtoType *OldType, |
2538 | const FunctionProtoType *NewType, |
2539 | unsigned *ArgPos = nullptr); |
2540 | void HandleFunctionTypeMismatch(PartialDiagnostic &PDiag, |
2541 | QualType FromType, QualType ToType); |
2542 | |
2543 | void maybeExtendBlockObject(ExprResult &E); |
2544 | CastKind PrepareCastToObjCObjectPointer(ExprResult &E); |
2545 | bool CheckPointerConversion(Expr *From, QualType ToType, |
2546 | CastKind &Kind, |
2547 | CXXCastPath& BasePath, |
2548 | bool IgnoreBaseAccess, |
2549 | bool Diagnose = true); |
2550 | bool IsMemberPointerConversion(Expr *From, QualType FromType, QualType ToType, |
2551 | bool InOverloadResolution, |
2552 | QualType &ConvertedType); |
2553 | bool CheckMemberPointerConversion(Expr *From, QualType ToType, |
2554 | CastKind &Kind, |
2555 | CXXCastPath &BasePath, |
2556 | bool IgnoreBaseAccess); |
2557 | bool IsQualificationConversion(QualType FromType, QualType ToType, |
2558 | bool CStyle, bool &ObjCLifetimeConversion); |
2559 | bool IsFunctionConversion(QualType FromType, QualType ToType, |
2560 | QualType &ResultTy); |
2561 | bool DiagnoseMultipleUserDefinedConversion(Expr *From, QualType ToType); |
2562 | bool isSameOrCompatibleFunctionType(CanQualType Param, CanQualType Arg); |
2563 | |
2564 | ExprResult PerformMoveOrCopyInitialization(const InitializedEntity &Entity, |
2565 | const VarDecl *NRVOCandidate, |
2566 | QualType ResultType, |
2567 | Expr *Value, |
2568 | bool AllowNRVO = true); |
2569 | |
2570 | bool CanPerformCopyInitialization(const InitializedEntity &Entity, |
2571 | ExprResult Init); |
2572 | ExprResult PerformCopyInitialization(const InitializedEntity &Entity, |
2573 | SourceLocation EqualLoc, |
2574 | ExprResult Init, |
2575 | bool TopLevelOfInitList = false, |
2576 | bool AllowExplicit = false); |
2577 | ExprResult PerformObjectArgumentInitialization(Expr *From, |
2578 | NestedNameSpecifier *Qualifier, |
2579 | NamedDecl *FoundDecl, |
2580 | CXXMethodDecl *Method); |
2581 | |
2582 | ExprResult PerformContextuallyConvertToBool(Expr *From); |
2583 | ExprResult PerformContextuallyConvertToObjCPointer(Expr *From); |
2584 | |
2585 | /// Contexts in which a converted constant expression is required. |
2586 | enum CCEKind { |
2587 | CCEK_CaseValue, ///< Expression in a case label. |
2588 | CCEK_Enumerator, ///< Enumerator value with fixed underlying type. |
2589 | CCEK_TemplateArg, ///< Value of a non-type template parameter. |
2590 | CCEK_NewExpr, ///< Constant expression in a noptr-new-declarator. |
2591 | CCEK_ConstexprIf ///< Condition in a constexpr if statement. |
2592 | }; |
2593 | ExprResult CheckConvertedConstantExpression(Expr *From, QualType T, |
2594 | llvm::APSInt &Value, CCEKind CCE); |
2595 | ExprResult CheckConvertedConstantExpression(Expr *From, QualType T, |
2596 | APValue &Value, CCEKind CCE); |
2597 | |
2598 | /// \brief Abstract base class used to perform a contextual implicit |
2599 | /// conversion from an expression to any type passing a filter. |
2600 | class ContextualImplicitConverter { |
2601 | public: |
2602 | bool Suppress; |
2603 | bool SuppressConversion; |
2604 | |
2605 | ContextualImplicitConverter(bool Suppress = false, |
2606 | bool SuppressConversion = false) |
2607 | : Suppress(Suppress), SuppressConversion(SuppressConversion) {} |
2608 | |
2609 | /// \brief Determine whether the specified type is a valid destination type |
2610 | /// for this conversion. |
2611 | virtual bool match(QualType T) = 0; |
2612 | |
2613 | /// \brief Emits a diagnostic complaining that the expression does not have |
2614 | /// integral or enumeration type. |
2615 | virtual SemaDiagnosticBuilder |
2616 | diagnoseNoMatch(Sema &S, SourceLocation Loc, QualType T) = 0; |
2617 | |
2618 | /// \brief Emits a diagnostic when the expression has incomplete class type. |
2619 | virtual SemaDiagnosticBuilder |
2620 | diagnoseIncomplete(Sema &S, SourceLocation Loc, QualType T) = 0; |
2621 | |
2622 | /// \brief Emits a diagnostic when the only matching conversion function |
2623 | /// is explicit. |
2624 | virtual SemaDiagnosticBuilder diagnoseExplicitConv( |
2625 | Sema &S, SourceLocation Loc, QualType T, QualType ConvTy) = 0; |
2626 | |
2627 | /// \brief Emits a note for the explicit conversion function. |
2628 | virtual SemaDiagnosticBuilder |
2629 | noteExplicitConv(Sema &S, CXXConversionDecl *Conv, QualType ConvTy) = 0; |
2630 | |
2631 | /// \brief Emits a diagnostic when there are multiple possible conversion |
2632 | /// functions. |
2633 | virtual SemaDiagnosticBuilder |
2634 | diagnoseAmbiguous(Sema &S, SourceLocation Loc, QualType T) = 0; |
2635 | |
2636 | /// \brief Emits a note for one of the candidate conversions. |
2637 | virtual SemaDiagnosticBuilder |
2638 | noteAmbiguous(Sema &S, CXXConversionDecl *Conv, QualType ConvTy) = 0; |
2639 | |
2640 | /// \brief Emits a diagnostic when we picked a conversion function |
2641 | /// (for cases when we are not allowed to pick a conversion function). |
2642 | virtual SemaDiagnosticBuilder diagnoseConversion( |
2643 | Sema &S, SourceLocation Loc, QualType T, QualType ConvTy) = 0; |
2644 | |
2645 | virtual ~ContextualImplicitConverter() {} |
2646 | }; |
2647 | |
2648 | class ICEConvertDiagnoser : public ContextualImplicitConverter { |
2649 | bool AllowScopedEnumerations; |
2650 | |
2651 | public: |
2652 | ICEConvertDiagnoser(bool AllowScopedEnumerations, |
2653 | bool Suppress, bool SuppressConversion) |
2654 | : ContextualImplicitConverter(Suppress, SuppressConversion), |
2655 | AllowScopedEnumerations(AllowScopedEnumerations) {} |
2656 | |
2657 | /// Match an integral or (possibly scoped) enumeration type. |
2658 | bool match(QualType T) override; |
2659 | |
2660 | SemaDiagnosticBuilder |
2661 | diagnoseNoMatch(Sema &S, SourceLocation Loc, QualType T) override { |
2662 | return diagnoseNotInt(S, Loc, T); |
2663 | } |
2664 | |
2665 | /// \brief Emits a diagnostic complaining that the expression does not have |
2666 | /// integral or enumeration type. |
2667 | virtual SemaDiagnosticBuilder |
2668 | diagnoseNotInt(Sema &S, SourceLocation Loc, QualType T) = 0; |
2669 | }; |
2670 | |
2671 | /// Perform a contextual implicit conversion. |
2672 | ExprResult PerformContextualImplicitConversion( |
2673 | SourceLocation Loc, Expr *FromE, ContextualImplicitConverter &Converter); |
2674 | |
2675 | |
2676 | enum ObjCSubscriptKind { |
2677 | OS_Array, |
2678 | OS_Dictionary, |
2679 | OS_Error |
2680 | }; |
2681 | ObjCSubscriptKind CheckSubscriptingKind(Expr *FromE); |
2682 | |
2683 | // Note that LK_String is intentionally after the other literals, as |
2684 | // this is used for diagnostics logic. |
2685 | enum ObjCLiteralKind { |
2686 | LK_Array, |
2687 | LK_Dictionary, |
2688 | LK_Numeric, |
2689 | LK_Boxed, |
2690 | LK_String, |
2691 | LK_Block, |
2692 | LK_None |
2693 | }; |
2694 | ObjCLiteralKind CheckLiteralKind(Expr *FromE); |
2695 | |
2696 | ExprResult PerformObjectMemberConversion(Expr *From, |
2697 | NestedNameSpecifier *Qualifier, |
2698 | NamedDecl *FoundDecl, |
2699 | NamedDecl *Member); |
2700 | |
2701 | // Members have to be NamespaceDecl* or TranslationUnitDecl*. |
2702 | // TODO: make this is a typesafe union. |
2703 | typedef llvm::SmallSetVector<DeclContext *, 16> AssociatedNamespaceSet; |
2704 | typedef llvm::SmallSetVector<CXXRecordDecl *, 16> AssociatedClassSet; |
2705 | |
2706 | void AddOverloadCandidate(FunctionDecl *Function, |
2707 | DeclAccessPair FoundDecl, |
2708 | ArrayRef<Expr *> Args, |
2709 | OverloadCandidateSet &CandidateSet, |
2710 | bool SuppressUserConversions = false, |
2711 | bool PartialOverloading = false, |
2712 | bool AllowExplicit = false, |
2713 | ConversionSequenceList EarlyConversions = None); |
2714 | void AddFunctionCandidates(const UnresolvedSetImpl &Functions, |
2715 | ArrayRef<Expr *> Args, |
2716 | OverloadCandidateSet &CandidateSet, |
2717 | TemplateArgumentListInfo *ExplicitTemplateArgs = nullptr, |
2718 | bool SuppressUserConversions = false, |
2719 | bool PartialOverloading = false, |
2720 | bool FirstArgumentIsBase = false); |
2721 | void AddMethodCandidate(DeclAccessPair FoundDecl, |
2722 | QualType ObjectType, |
2723 | Expr::Classification ObjectClassification, |
2724 | ArrayRef<Expr *> Args, |
2725 | OverloadCandidateSet& CandidateSet, |
2726 | bool SuppressUserConversion = false); |
2727 | void AddMethodCandidate(CXXMethodDecl *Method, |
2728 | DeclAccessPair FoundDecl, |
2729 | CXXRecordDecl *ActingContext, QualType ObjectType, |
2730 | Expr::Classification ObjectClassification, |
2731 | ArrayRef<Expr *> Args, |
2732 | OverloadCandidateSet& CandidateSet, |
2733 | bool SuppressUserConversions = false, |
2734 | bool PartialOverloading = false, |
2735 | ConversionSequenceList EarlyConversions = None); |
2736 | void AddMethodTemplateCandidate(FunctionTemplateDecl *MethodTmpl, |
2737 | DeclAccessPair FoundDecl, |
2738 | CXXRecordDecl *ActingContext, |
2739 | TemplateArgumentListInfo *ExplicitTemplateArgs, |
2740 | QualType ObjectType, |
2741 | Expr::Classification ObjectClassification, |
2742 | ArrayRef<Expr *> Args, |
2743 | OverloadCandidateSet& CandidateSet, |
2744 | bool SuppressUserConversions = false, |
2745 | bool PartialOverloading = false); |
2746 | void AddTemplateOverloadCandidate(FunctionTemplateDecl *FunctionTemplate, |
2747 | DeclAccessPair FoundDecl, |
2748 | TemplateArgumentListInfo *ExplicitTemplateArgs, |
2749 | ArrayRef<Expr *> Args, |
2750 | OverloadCandidateSet& CandidateSet, |
2751 | bool SuppressUserConversions = false, |
2752 | bool PartialOverloading = false); |
2753 | bool CheckNonDependentConversions(FunctionTemplateDecl *FunctionTemplate, |
2754 | ArrayRef<QualType> ParamTypes, |
2755 | ArrayRef<Expr *> Args, |
2756 | OverloadCandidateSet &CandidateSet, |
2757 | ConversionSequenceList &Conversions, |
2758 | bool SuppressUserConversions, |
2759 | CXXRecordDecl *ActingContext = nullptr, |
2760 | QualType ObjectType = QualType(), |
2761 | Expr::Classification |
2762 | ObjectClassification = {}); |
2763 | void AddConversionCandidate(CXXConversionDecl *Conversion, |
2764 | DeclAccessPair FoundDecl, |
2765 | CXXRecordDecl *ActingContext, |
2766 | Expr *From, QualType ToType, |
2767 | OverloadCandidateSet& CandidateSet, |
2768 | bool AllowObjCConversionOnExplicit, |
2769 | bool AllowResultConversion = true); |
2770 | void AddTemplateConversionCandidate(FunctionTemplateDecl *FunctionTemplate, |
2771 | DeclAccessPair FoundDecl, |
2772 | CXXRecordDecl *ActingContext, |
2773 | Expr *From, QualType ToType, |
2774 | OverloadCandidateSet &CandidateSet, |
2775 | bool AllowObjCConversionOnExplicit, |
2776 | bool AllowResultConversion = true); |
2777 | void AddSurrogateCandidate(CXXConversionDecl *Conversion, |
2778 | DeclAccessPair FoundDecl, |
2779 | CXXRecordDecl *ActingContext, |
2780 | const FunctionProtoType *Proto, |
2781 | Expr *Object, ArrayRef<Expr *> Args, |
2782 | OverloadCandidateSet& CandidateSet); |
2783 | void AddMemberOperatorCandidates(OverloadedOperatorKind Op, |
2784 | SourceLocation OpLoc, ArrayRef<Expr *> Args, |
2785 | OverloadCandidateSet& CandidateSet, |
2786 | SourceRange OpRange = SourceRange()); |
2787 | void AddBuiltinCandidate(QualType *ParamTys, ArrayRef<Expr *> Args, |
2788 | OverloadCandidateSet& CandidateSet, |
2789 | bool IsAssignmentOperator = false, |
2790 | unsigned NumContextualBoolArguments = 0); |
2791 | void AddBuiltinOperatorCandidates(OverloadedOperatorKind Op, |
2792 | SourceLocation OpLoc, ArrayRef<Expr *> Args, |
2793 | OverloadCandidateSet& CandidateSet); |
2794 | void AddArgumentDependentLookupCandidates(DeclarationName Name, |
2795 | SourceLocation Loc, |
2796 | ArrayRef<Expr *> Args, |
2797 | TemplateArgumentListInfo *ExplicitTemplateArgs, |
2798 | OverloadCandidateSet& CandidateSet, |
2799 | bool PartialOverloading = false); |
2800 | |
2801 | // Emit as a 'note' the specific overload candidate |
2802 | void NoteOverloadCandidate(NamedDecl *Found, FunctionDecl *Fn, |
2803 | QualType DestType = QualType(), |
2804 | bool TakingAddress = false); |
2805 | |
2806 | // Emit as a series of 'note's all template and non-templates identified by |
2807 | // the expression Expr |
2808 | void NoteAllOverloadCandidates(Expr *E, QualType DestType = QualType(), |
2809 | bool TakingAddress = false); |
2810 | |
2811 | /// Check the enable_if expressions on the given function. Returns the first |
2812 | /// failing attribute, or NULL if they were all successful. |
2813 | EnableIfAttr *CheckEnableIf(FunctionDecl *Function, ArrayRef<Expr *> Args, |
2814 | bool MissingImplicitThis = false); |
2815 | |
2816 | /// Find the failed Boolean condition within a given Boolean |
2817 | /// constant expression, and describe it with a string. |
2818 | /// |
2819 | /// \param AllowTopLevelCond Whether to allow the result to be the |
2820 | /// complete top-level condition. |
2821 | std::pair<Expr *, std::string> |
2822 | findFailedBooleanCondition(Expr *Cond, bool AllowTopLevelCond); |
2823 | |
2824 | /// Emit diagnostics for the diagnose_if attributes on Function, ignoring any |
2825 | /// non-ArgDependent DiagnoseIfAttrs. |
2826 | /// |
2827 | /// Argument-dependent diagnose_if attributes should be checked each time a |
2828 | /// function is used as a direct callee of a function call. |
2829 | /// |
2830 | /// Returns true if any errors were emitted. |
2831 | bool diagnoseArgDependentDiagnoseIfAttrs(const FunctionDecl *Function, |
2832 | const Expr *ThisArg, |
2833 | ArrayRef<const Expr *> Args, |
2834 | SourceLocation Loc); |
2835 | |
2836 | /// Emit diagnostics for the diagnose_if attributes on Function, ignoring any |
2837 | /// ArgDependent DiagnoseIfAttrs. |
2838 | /// |
2839 | /// Argument-independent diagnose_if attributes should be checked on every use |
2840 | /// of a function. |
2841 | /// |
2842 | /// Returns true if any errors were emitted. |
2843 | bool diagnoseArgIndependentDiagnoseIfAttrs(const NamedDecl *ND, |
2844 | SourceLocation Loc); |
2845 | |
2846 | /// Returns whether the given function's address can be taken or not, |
2847 | /// optionally emitting a diagnostic if the address can't be taken. |
2848 | /// |
2849 | /// Returns false if taking the address of the function is illegal. |
2850 | bool checkAddressOfFunctionIsAvailable(const FunctionDecl *Function, |
2851 | bool Complain = false, |
2852 | SourceLocation Loc = SourceLocation()); |
2853 | |
2854 | // [PossiblyAFunctionType] --> [Return] |
2855 | // NonFunctionType --> NonFunctionType |
2856 | // R (A) --> R(A) |
2857 | // R (*)(A) --> R (A) |
2858 | // R (&)(A) --> R (A) |
2859 | // R (S::*)(A) --> R (A) |
2860 | QualType ExtractUnqualifiedFunctionType(QualType PossiblyAFunctionType); |
2861 | |
2862 | FunctionDecl * |
2863 | ResolveAddressOfOverloadedFunction(Expr *AddressOfExpr, |
2864 | QualType TargetType, |
2865 | bool Complain, |
2866 | DeclAccessPair &Found, |
2867 | bool *pHadMultipleCandidates = nullptr); |
2868 | |
2869 | FunctionDecl * |
2870 | resolveAddressOfOnlyViableOverloadCandidate(Expr *E, |
2871 | DeclAccessPair &FoundResult); |
2872 | |
2873 | bool resolveAndFixAddressOfOnlyViableOverloadCandidate( |
2874 | ExprResult &SrcExpr, bool DoFunctionPointerConversion = false); |
2875 | |
2876 | FunctionDecl * |
2877 | ResolveSingleFunctionTemplateSpecialization(OverloadExpr *ovl, |
2878 | bool Complain = false, |
2879 | DeclAccessPair *Found = nullptr); |
2880 | |
2881 | bool ResolveAndFixSingleFunctionTemplateSpecialization( |
2882 | ExprResult &SrcExpr, |
2883 | bool DoFunctionPointerConverion = false, |
2884 | bool Complain = false, |
2885 | SourceRange OpRangeForComplaining = SourceRange(), |
2886 | QualType DestTypeForComplaining = QualType(), |
2887 | unsigned DiagIDForComplaining = 0); |
2888 | |
2889 | |
2890 | Expr *FixOverloadedFunctionReference(Expr *E, |
2891 | DeclAccessPair FoundDecl, |
2892 | FunctionDecl *Fn); |
2893 | ExprResult FixOverloadedFunctionReference(ExprResult, |
2894 | DeclAccessPair FoundDecl, |
2895 | FunctionDecl *Fn); |
2896 | |
2897 | void AddOverloadedCallCandidates(UnresolvedLookupExpr *ULE, |
2898 | ArrayRef<Expr *> Args, |
2899 | OverloadCandidateSet &CandidateSet, |
2900 | bool PartialOverloading = false); |
2901 | |
2902 | // An enum used to represent the different possible results of building a |
2903 | // range-based for loop. |
2904 | enum ForRangeStatus { |
2905 | FRS_Success, |
2906 | FRS_NoViableFunction, |
2907 | FRS_DiagnosticIssued |
2908 | }; |
2909 | |
2910 | ForRangeStatus BuildForRangeBeginEndCall(SourceLocation Loc, |
2911 | SourceLocation RangeLoc, |
2912 | const DeclarationNameInfo &NameInfo, |
2913 | LookupResult &MemberLookup, |
2914 | OverloadCandidateSet *CandidateSet, |
2915 | Expr *Range, ExprResult *CallExpr); |
2916 | |
2917 | ExprResult BuildOverloadedCallExpr(Scope *S, Expr *Fn, |
2918 | UnresolvedLookupExpr *ULE, |
2919 | SourceLocation LParenLoc, |
2920 | MultiExprArg Args, |
2921 | SourceLocation RParenLoc, |
2922 | Expr *ExecConfig, |
2923 | bool AllowTypoCorrection=true, |
2924 | bool CalleesAddressIsTaken=false); |
2925 | |
2926 | bool buildOverloadedCallSet(Scope *S, Expr *Fn, UnresolvedLookupExpr *ULE, |
2927 | MultiExprArg Args, SourceLocation RParenLoc, |
2928 | OverloadCandidateSet *CandidateSet, |
2929 | ExprResult *Result); |
2930 | |
2931 | ExprResult CreateOverloadedUnaryOp(SourceLocation OpLoc, |
2932 | UnaryOperatorKind Opc, |
2933 | const UnresolvedSetImpl &Fns, |
2934 | Expr *input, bool RequiresADL = true); |
2935 | |
2936 | ExprResult CreateOverloadedBinOp(SourceLocation OpLoc, |
2937 | BinaryOperatorKind Opc, |
2938 | const UnresolvedSetImpl &Fns, |
2939 | Expr *LHS, Expr *RHS, |
2940 | bool RequiresADL = true); |
2941 | |
2942 | ExprResult CreateOverloadedArraySubscriptExpr(SourceLocation LLoc, |
2943 | SourceLocation RLoc, |
2944 | Expr *Base,Expr *Idx); |
2945 | |
2946 | ExprResult |
2947 | BuildCallToMemberFunction(Scope *S, Expr *MemExpr, |
2948 | SourceLocation LParenLoc, |
2949 | MultiExprArg Args, |
2950 | SourceLocation RParenLoc); |
2951 | ExprResult |
2952 | BuildCallToObjectOfClassType(Scope *S, Expr *Object, SourceLocation LParenLoc, |
2953 | MultiExprArg Args, |
2954 | SourceLocation RParenLoc); |
2955 | |
2956 | ExprResult BuildOverloadedArrowExpr(Scope *S, Expr *Base, |
2957 | SourceLocation OpLoc, |
2958 | bool *NoArrowOperatorFound = nullptr); |
2959 | |
2960 | /// CheckCallReturnType - Checks that a call expression's return type is |
2961 | /// complete. Returns true on failure. The location passed in is the location |
2962 | /// that best represents the call. |
2963 | bool CheckCallReturnType(QualType ReturnType, SourceLocation Loc, |
2964 | CallExpr *CE, FunctionDecl *FD); |
2965 | |
2966 | /// Helpers for dealing with blocks and functions. |
2967 | bool CheckParmsForFunctionDef(ArrayRef<ParmVarDecl *> Parameters, |
2968 | bool CheckParameterNames); |
2969 | void CheckCXXDefaultArguments(FunctionDecl *FD); |
2970 | void CheckExtraCXXDefaultArguments(Declarator &D); |
2971 | Scope *getNonFieldDeclScope(Scope *S); |
2972 | |
2973 | /// \name Name lookup |
2974 | /// |
2975 | /// These routines provide name lookup that is used during semantic |
2976 | /// analysis to resolve the various kinds of names (identifiers, |
2977 | /// overloaded operator names, constructor names, etc.) into zero or |
2978 | /// more declarations within a particular scope. The major entry |
2979 | /// points are LookupName, which performs unqualified name lookup, |
2980 | /// and LookupQualifiedName, which performs qualified name lookup. |
2981 | /// |
2982 | /// All name lookup is performed based on some specific criteria, |
2983 | /// which specify what names will be visible to name lookup and how |
2984 | /// far name lookup should work. These criteria are important both |
2985 | /// for capturing language semantics (certain lookups will ignore |
2986 | /// certain names, for example) and for performance, since name |
2987 | /// lookup is often a bottleneck in the compilation of C++. Name |
2988 | /// lookup criteria is specified via the LookupCriteria enumeration. |
2989 | /// |
2990 | /// The results of name lookup can vary based on the kind of name |
2991 | /// lookup performed, the current language, and the translation |
2992 | /// unit. In C, for example, name lookup will either return nothing |
2993 | /// (no entity found) or a single declaration. In C++, name lookup |
2994 | /// can additionally refer to a set of overloaded functions or |
2995 | /// result in an ambiguity. All of the possible results of name |
2996 | /// lookup are captured by the LookupResult class, which provides |
2997 | /// the ability to distinguish among them. |
2998 | //@{ |
2999 | |
3000 | /// @brief Describes the kind of name lookup to perform. |
3001 | enum LookupNameKind { |
3002 | /// Ordinary name lookup, which finds ordinary names (functions, |
3003 | /// variables, typedefs, etc.) in C and most kinds of names |
3004 | /// (functions, variables, members, types, etc.) in C++. |
3005 | LookupOrdinaryName = 0, |
3006 | /// Tag name lookup, which finds the names of enums, classes, |
3007 | /// structs, and unions. |
3008 | LookupTagName, |
3009 | /// Label name lookup. |
3010 | LookupLabel, |
3011 | /// Member name lookup, which finds the names of |
3012 | /// class/struct/union members. |
3013 | LookupMemberName, |
3014 | /// Look up of an operator name (e.g., operator+) for use with |
3015 | /// operator overloading. This lookup is similar to ordinary name |
3016 | /// lookup, but will ignore any declarations that are class members. |
3017 | LookupOperatorName, |
3018 | /// Look up of a name that precedes the '::' scope resolution |
3019 | /// operator in C++. This lookup completely ignores operator, object, |
3020 | /// function, and enumerator names (C++ [basic.lookup.qual]p1). |
3021 | LookupNestedNameSpecifierName, |
3022 | /// Look up a namespace name within a C++ using directive or |
3023 | /// namespace alias definition, ignoring non-namespace names (C++ |
3024 | /// [basic.lookup.udir]p1). |
3025 | LookupNamespaceName, |
3026 | /// Look up all declarations in a scope with the given name, |
3027 | /// including resolved using declarations. This is appropriate |
3028 | /// for checking redeclarations for a using declaration. |
3029 | LookupUsingDeclName, |
3030 | /// Look up an ordinary name that is going to be redeclared as a |
3031 | /// name with linkage. This lookup ignores any declarations that |
3032 | /// are outside of the current scope unless they have linkage. See |
3033 | /// C99 6.2.2p4-5 and C++ [basic.link]p6. |
3034 | LookupRedeclarationWithLinkage, |
3035 | /// Look up a friend of a local class. This lookup does not look |
3036 | /// outside the innermost non-class scope. See C++11 [class.friend]p11. |
3037 | LookupLocalFriendName, |
3038 | /// Look up the name of an Objective-C protocol. |
3039 | LookupObjCProtocolName, |
3040 | /// Look up implicit 'self' parameter of an objective-c method. |
3041 | LookupObjCImplicitSelfParam, |
3042 | /// \brief Look up the name of an OpenMP user-defined reduction operation. |
3043 | LookupOMPReductionName, |
3044 | /// \brief Look up any declaration with any name. |
3045 | LookupAnyName |
3046 | }; |
3047 | |
3048 | /// \brief Specifies whether (or how) name lookup is being performed for a |
3049 | /// redeclaration (vs. a reference). |
3050 | enum RedeclarationKind { |
3051 | /// \brief The lookup is a reference to this name that is not for the |
3052 | /// purpose of redeclaring the name. |
3053 | NotForRedeclaration = 0, |
3054 | /// \brief The lookup results will be used for redeclaration of a name, |
3055 | /// if an entity by that name already exists and is visible. |
3056 | ForVisibleRedeclaration, |
3057 | /// \brief The lookup results will be used for redeclaration of a name |
3058 | /// with external linkage; non-visible lookup results with external linkage |
3059 | /// may also be found. |
3060 | ForExternalRedeclaration |
3061 | }; |
3062 | |
3063 | RedeclarationKind forRedeclarationInCurContext() { |
3064 | // A declaration with an owning module for linkage can never link against |
3065 | // anything that is not visible. We don't need to check linkage here; if |
3066 | // the context has internal linkage, redeclaration lookup won't find things |
3067 | // from other TUs, and we can't safely compute linkage yet in general. |
3068 | if (cast<Decl>(CurContext) |
3069 | ->getOwningModuleForLinkage(/*IgnoreLinkage*/true)) |
3070 | return ForVisibleRedeclaration; |
3071 | return ForExternalRedeclaration; |
3072 | } |
3073 | |
3074 | /// \brief The possible outcomes of name lookup for a literal operator. |
3075 | enum LiteralOperatorLookupResult { |
3076 | /// \brief The lookup resulted in an error. |
3077 | LOLR_Error, |
3078 | /// \brief The lookup found no match but no diagnostic was issued. |
3079 | LOLR_ErrorNoDiagnostic, |
3080 | /// \brief The lookup found a single 'cooked' literal operator, which |
3081 | /// expects a normal literal to be built and passed to it. |
3082 | LOLR_Cooked, |
3083 | /// \brief The lookup found a single 'raw' literal operator, which expects |
3084 | /// a string literal containing the spelling of the literal token. |
3085 | LOLR_Raw, |
3086 | /// \brief The lookup found an overload set of literal operator templates, |
3087 | /// which expect the characters of the spelling of the literal token to be |
3088 | /// passed as a non-type template argument pack. |
3089 | LOLR_Template, |
3090 | /// \brief The lookup found an overload set of literal operator templates, |
3091 | /// which expect the character type and characters of the spelling of the |
3092 | /// string literal token to be passed as template arguments. |
3093 | LOLR_StringTemplate |
3094 | }; |
3095 | |
3096 | SpecialMemberOverloadResult LookupSpecialMember(CXXRecordDecl *D, |
3097 | CXXSpecialMember SM, |
3098 | bool ConstArg, |
3099 | bool VolatileArg, |
3100 | bool RValueThis, |
3101 | bool ConstThis, |
3102 | bool VolatileThis); |
3103 | |
3104 | typedef std::function<void(const TypoCorrection &)> TypoDiagnosticGenerator; |
3105 | typedef std::function<ExprResult(Sema &, TypoExpr *, TypoCorrection)> |
3106 | TypoRecoveryCallback; |
3107 | |
3108 | private: |
3109 | bool CppLookupName(LookupResult &R, Scope *S); |
3110 | |
3111 | struct TypoExprState { |
3112 | std::unique_ptr<TypoCorrectionConsumer> Consumer; |
3113 | TypoDiagnosticGenerator DiagHandler; |
3114 | TypoRecoveryCallback RecoveryHandler; |
3115 | TypoExprState(); |
3116 | TypoExprState(TypoExprState &&other) noexcept; |
3117 | TypoExprState &operator=(TypoExprState &&other) noexcept; |
3118 | }; |
3119 | |
3120 | /// \brief The set of unhandled TypoExprs and their associated state. |
3121 | llvm::MapVector<TypoExpr *, TypoExprState> DelayedTypos; |
3122 | |
3123 | /// \brief Creates a new TypoExpr AST node. |
3124 | TypoExpr *createDelayedTypo(std::unique_ptr<TypoCorrectionConsumer> TCC, |
3125 | TypoDiagnosticGenerator TDG, |
3126 | TypoRecoveryCallback TRC); |
3127 | |
3128 | // \brief The set of known/encountered (unique, canonicalized) NamespaceDecls. |
3129 | // |
3130 | // The boolean value will be true to indicate that the namespace was loaded |
3131 | // from an AST/PCH file, or false otherwise. |
3132 | llvm::MapVector<NamespaceDecl*, bool> KnownNamespaces; |
3133 | |
3134 | /// \brief Whether we have already loaded known namespaces from an extenal |
3135 | /// source. |
3136 | bool LoadedExternalKnownNamespaces; |
3137 | |
3138 | /// \brief Helper for CorrectTypo and CorrectTypoDelayed used to create and |
3139 | /// populate a new TypoCorrectionConsumer. Returns nullptr if typo correction |
3140 | /// should be skipped entirely. |
3141 | std::unique_ptr<TypoCorrectionConsumer> |
3142 | makeTypoCorrectionConsumer(const DeclarationNameInfo &Typo, |
3143 | Sema::LookupNameKind LookupKind, Scope *S, |
3144 | CXXScopeSpec *SS, |
3145 | std::unique_ptr<CorrectionCandidateCallback> CCC, |
3146 | DeclContext *MemberContext, bool EnteringContext, |
3147 | const ObjCObjectPointerType *OPT, |
3148 | bool ErrorRecovery); |
3149 | |
3150 | public: |
3151 | const TypoExprState &getTypoExprState(TypoExpr *TE) const; |
3152 | |
3153 | /// \brief Clears the state of the given TypoExpr. |
3154 | void clearDelayedTypo(TypoExpr *TE); |
3155 | |
3156 | /// \brief Look up a name, looking for a single declaration. Return |
3157 | /// null if the results were absent, ambiguous, or overloaded. |
3158 | /// |
3159 | /// It is preferable to use the elaborated form and explicitly handle |
3160 | /// ambiguity and overloaded. |
3161 | NamedDecl *LookupSingleName(Scope *S, DeclarationName Name, |
3162 | SourceLocation Loc, |
3163 | LookupNameKind NameKind, |
3164 | RedeclarationKind Redecl |
3165 | = NotForRedeclaration); |
3166 | bool LookupName(LookupResult &R, Scope *S, |
3167 | bool AllowBuiltinCreation = false); |
3168 | bool LookupQualifiedName(LookupResult &R, DeclContext *LookupCtx, |
3169 | bool InUnqualifiedLookup = false); |
3170 | bool LookupQualifiedName(LookupResult &R, DeclContext *LookupCtx, |
3171 | CXXScopeSpec &SS); |
3172 | bool LookupParsedName(LookupResult &R, Scope *S, CXXScopeSpec *SS, |
3173 | bool AllowBuiltinCreation = false, |
3174 | bool EnteringContext = false); |
3175 | ObjCProtocolDecl *LookupProtocol(IdentifierInfo *II, SourceLocation IdLoc, |
3176 | RedeclarationKind Redecl |
3177 | = NotForRedeclaration); |
3178 | bool LookupInSuper(LookupResult &R, CXXRecordDecl *Class); |
3179 | |
3180 | void LookupOverloadedOperatorName(OverloadedOperatorKind Op, Scope *S, |
3181 | QualType T1, QualType T2, |
3182 | UnresolvedSetImpl &Functions); |
3183 | |
3184 | LabelDecl *LookupOrCreateLabel(IdentifierInfo *II, SourceLocation IdentLoc, |
3185 | SourceLocation GnuLabelLoc = SourceLocation()); |
3186 | |
3187 | DeclContextLookupResult LookupConstructors(CXXRecordDecl *Class); |
3188 | CXXConstructorDecl *LookupDefaultConstructor(CXXRecordDecl *Class); |
3189 | CXXConstructorDecl *LookupCopyingConstructor(CXXRecordDecl *Class, |
3190 | unsigned Quals); |
3191 | CXXMethodDecl *LookupCopyingAssignment(CXXRecordDecl *Class, unsigned Quals, |
3192 | bool RValueThis, unsigned ThisQuals); |
3193 | CXXConstructorDecl *LookupMovingConstructor(CXXRecordDecl *Class, |
3194 | unsigned Quals); |
3195 | CXXMethodDecl *LookupMovingAssignment(CXXRecordDecl *Class, unsigned Quals, |
3196 | bool RValueThis, unsigned ThisQuals); |
3197 | CXXDestructorDecl *LookupDestructor(CXXRecordDecl *Class); |
3198 | |
3199 | bool checkLiteralOperatorId(const CXXScopeSpec &SS, const UnqualifiedId &Id); |
3200 | LiteralOperatorLookupResult LookupLiteralOperator(Scope *S, LookupResult &R, |
3201 | ArrayRef<QualType> ArgTys, |
3202 | bool AllowRaw, |
3203 | bool AllowTemplate, |
3204 | bool AllowStringTemplate, |
3205 | bool DiagnoseMissing); |
3206 | bool isKnownName(StringRef name); |
3207 | |
3208 | void ArgumentDependentLookup(DeclarationName Name, SourceLocation Loc, |
3209 | ArrayRef<Expr *> Args, ADLResult &Functions); |
3210 | |
3211 | void LookupVisibleDecls(Scope *S, LookupNameKind Kind, |
3212 | VisibleDeclConsumer &Consumer, |
3213 | bool IncludeGlobalScope = true, |
3214 | bool LoadExternal = true); |
3215 | void LookupVisibleDecls(DeclContext *Ctx, LookupNameKind Kind, |
3216 | VisibleDeclConsumer &Consumer, |
3217 | bool IncludeGlobalScope = true, |
3218 | bool IncludeDependentBases = false, |
3219 | bool LoadExternal = true); |
3220 | |
3221 | enum CorrectTypoKind { |
3222 | CTK_NonError, // CorrectTypo used in a non error recovery situation. |
3223 | CTK_ErrorRecovery // CorrectTypo used in normal error recovery. |
3224 | }; |
3225 | |
3226 | TypoCorrection CorrectTypo(const DeclarationNameInfo &Typo, |
3227 | Sema::LookupNameKind LookupKind, |
3228 | Scope *S, CXXScopeSpec *SS, |
3229 | std::unique_ptr<CorrectionCandidateCallback> CCC, |
3230 | CorrectTypoKind Mode, |
3231 | DeclContext *MemberContext = nullptr, |
3232 | bool EnteringContext = false, |
3233 | const ObjCObjectPointerType *OPT = nullptr, |
3234 | bool RecordFailure = true); |
3235 | |
3236 | TypoExpr *CorrectTypoDelayed(const DeclarationNameInfo &Typo, |
3237 | Sema::LookupNameKind LookupKind, Scope *S, |
3238 | CXXScopeSpec *SS, |
3239 | std::unique_ptr<CorrectionCandidateCallback> CCC, |
3240 | TypoDiagnosticGenerator TDG, |
3241 | TypoRecoveryCallback TRC, CorrectTypoKind Mode, |
3242 | DeclContext *MemberContext = nullptr, |
3243 | bool EnteringContext = false, |
3244 | const ObjCObjectPointerType *OPT = nullptr); |
3245 | |
3246 | /// \brief Process any TypoExprs in the given Expr and its children, |
3247 | /// generating diagnostics as appropriate and returning a new Expr if there |
3248 | /// were typos that were all successfully corrected and ExprError if one or |
3249 | /// more typos could not be corrected. |
3250 | /// |
3251 | /// \param E The Expr to check for TypoExprs. |
3252 | /// |
3253 | /// \param InitDecl A VarDecl to avoid because the Expr being corrected is its |
3254 | /// initializer. |
3255 | /// |
3256 | /// \param Filter A function applied to a newly rebuilt Expr to determine if |
3257 | /// it is an acceptable/usable result from a single combination of typo |
3258 | /// corrections. As long as the filter returns ExprError, different |
3259 | /// combinations of corrections will be tried until all are exhausted. |
3260 | ExprResult |
3261 | CorrectDelayedTyposInExpr(Expr *E, VarDecl *InitDecl = nullptr, |
3262 | llvm::function_ref<ExprResult(Expr *)> Filter = |
3263 | [](Expr *E) -> ExprResult { return E; }); |
3264 | |
3265 | ExprResult |
3266 | CorrectDelayedTyposInExpr(Expr *E, |
3267 | llvm::function_ref<ExprResult(Expr *)> Filter) { |
3268 | return CorrectDelayedTyposInExpr(E, nullptr, Filter); |
3269 | } |
3270 | |
3271 | ExprResult |
3272 | CorrectDelayedTyposInExpr(ExprResult ER, VarDecl *InitDecl = nullptr, |
3273 | llvm::function_ref<ExprResult(Expr *)> Filter = |
3274 | [](Expr *E) -> ExprResult { return E; }) { |
3275 | return ER.isInvalid() ? ER : CorrectDelayedTyposInExpr(ER.get(), Filter); |
3276 | } |
3277 | |
3278 | ExprResult |
3279 | CorrectDelayedTyposInExpr(ExprResult ER, |
3280 | llvm::function_ref<ExprResult(Expr *)> Filter) { |
3281 | return CorrectDelayedTyposInExpr(ER, nullptr, Filter); |
3282 | } |
3283 | |
3284 | void diagnoseTypo(const TypoCorrection &Correction, |
3285 | const PartialDiagnostic &TypoDiag, |
3286 | bool ErrorRecovery = true); |
3287 | |
3288 | void diagnoseTypo(const TypoCorrection &Correction, |
3289 | const PartialDiagnostic &TypoDiag, |
3290 | const PartialDiagnostic &PrevNote, |
3291 | bool ErrorRecovery = true); |
3292 | |
3293 | void MarkTypoCorrectedFunctionDefinition(const NamedDecl *F); |
3294 | |
3295 | void FindAssociatedClassesAndNamespaces(SourceLocation InstantiationLoc, |
3296 | ArrayRef<Expr *> Args, |
3297 | AssociatedNamespaceSet &AssociatedNamespaces, |
3298 | AssociatedClassSet &AssociatedClasses); |
3299 | |
3300 | void FilterLookupForScope(LookupResult &R, DeclContext *Ctx, Scope *S, |
3301 | bool ConsiderLinkage, bool AllowInlineNamespace); |
3302 | |
3303 | bool CheckRedeclarationModuleOwnership(NamedDecl *New, NamedDecl *Old); |
3304 | |
3305 | void DiagnoseAmbiguousLookup(LookupResult &Result); |
3306 | //@} |
3307 | |
3308 | ObjCInterfaceDecl *getObjCInterfaceDecl(IdentifierInfo *&Id, |
3309 | SourceLocation IdLoc, |
3310 | bool TypoCorrection = false); |
3311 | NamedDecl *LazilyCreateBuiltin(IdentifierInfo *II, unsigned ID, |
3312 | Scope *S, bool ForRedeclaration, |
3313 | SourceLocation Loc); |
3314 | NamedDecl *ImplicitlyDefineFunction(SourceLocation Loc, IdentifierInfo &II, |
3315 | Scope *S); |
3316 | void AddKnownFunctionAttributes(FunctionDecl *FD); |
3317 | |
3318 | // More parsing and symbol table subroutines. |
3319 | |
3320 | void ProcessPragmaWeak(Scope *S, Decl *D); |
3321 | // Decl attributes - this routine is the top level dispatcher. |
3322 | void ProcessDeclAttributes(Scope *S, Decl *D, const Declarator &PD); |
3323 | // Helper for delayed processing of attributes. |
3324 | void ProcessDeclAttributeDelayed(Decl *D, const AttributeList *AttrList); |
3325 | void ProcessDeclAttributeList(Scope *S, Decl *D, const AttributeList *AL, |
3326 | bool IncludeCXX11Attributes = true); |
3327 | bool ProcessAccessDeclAttributeList(AccessSpecDecl *ASDecl, |
3328 | const AttributeList *AttrList); |
3329 | |
3330 | void checkUnusedDeclAttributes(Declarator &D); |
3331 | |
3332 | /// Determine if type T is a valid subject for a nonnull and similar |
3333 | /// attributes. By default, we look through references (the behavior used by |
3334 | /// nonnull), but if the second parameter is true, then we treat a reference |
3335 | /// type as valid. |
3336 | bool isValidPointerAttrType(QualType T, bool RefOkay = false); |
3337 | |
3338 | bool CheckRegparmAttr(const AttributeList &attr, unsigned &value); |
3339 | bool CheckCallingConvAttr(const AttributeList &attr, CallingConv &CC, |
3340 | const FunctionDecl *FD = nullptr); |
3341 | bool CheckNoReturnAttr(const AttributeList &attr); |
3342 | bool CheckNoCallerSavedRegsAttr(const AttributeList &attr); |
3343 | bool checkStringLiteralArgumentAttr(const AttributeList &Attr, |
3344 | unsigned ArgNum, StringRef &Str, |
3345 | SourceLocation *ArgLocation = nullptr); |
3346 | bool checkSectionName(SourceLocation LiteralLoc, StringRef Str); |
3347 | bool checkTargetAttr(SourceLocation LiteralLoc, StringRef Str); |
3348 | bool checkMSInheritanceAttrOnDefinition( |
3349 | CXXRecordDecl *RD, SourceRange Range, bool BestCase, |
3350 | MSInheritanceAttr::Spelling SemanticSpelling); |
3351 | |
3352 | void CheckAlignasUnderalignment(Decl *D); |
3353 | |
3354 | /// Adjust the calling convention of a method to be the ABI default if it |
3355 | /// wasn't specified explicitly. This handles method types formed from |
3356 | /// function type typedefs and typename template arguments. |
3357 | void adjustMemberFunctionCC(QualType &T, bool IsStatic, bool IsCtorOrDtor, |
3358 | SourceLocation Loc); |
3359 | |
3360 | // Check if there is an explicit attribute, but only look through parens. |
3361 | // The intent is to look for an attribute on the current declarator, but not |
3362 | // one that came from a typedef. |
3363 | bool hasExplicitCallingConv(QualType &T); |
3364 | |
3365 | /// Get the outermost AttributedType node that sets a calling convention. |
3366 | /// Valid types should not have multiple attributes with different CCs. |
3367 | const AttributedType *getCallingConvAttributedType(QualType T) const; |
3368 | |
3369 | /// Check whether a nullability type specifier can be added to the given |
3370 | /// type. |
3371 | /// |
3372 | /// \param type The type to which the nullability specifier will be |
3373 | /// added. On success, this type will be updated appropriately. |
3374 | /// |
3375 | /// \param nullability The nullability specifier to add. |
3376 | /// |
3377 | /// \param nullabilityLoc The location of the nullability specifier. |
3378 | /// |
3379 | /// \param isContextSensitive Whether this nullability specifier was |
3380 | /// written as a context-sensitive keyword (in an Objective-C |
3381 | /// method) or an Objective-C property attribute, rather than as an |
3382 | /// underscored type specifier. |
3383 | /// |
3384 | /// \param allowArrayTypes Whether to accept nullability specifiers on an |
3385 | /// array type (e.g., because it will decay to a pointer). |
3386 | /// |
3387 | /// \returns true if nullability cannot be applied, false otherwise. |
3388 | bool checkNullabilityTypeSpecifier(QualType &type, NullabilityKind nullability, |
3389 | SourceLocation nullabilityLoc, |
3390 | bool isContextSensitive, |
3391 | bool allowArrayTypes); |
3392 | |
3393 | /// \brief Stmt attributes - this routine is the top level dispatcher. |
3394 | StmtResult ProcessStmtAttributes(Stmt *Stmt, AttributeList *Attrs, |
3395 | SourceRange Range); |
3396 | |
3397 | void WarnConflictingTypedMethods(ObjCMethodDecl *Method, |
3398 | ObjCMethodDecl *MethodDecl, |
3399 | bool IsProtocolMethodDecl); |
3400 | |
3401 | void CheckConflictingOverridingMethod(ObjCMethodDecl *Method, |
3402 | ObjCMethodDecl *Overridden, |
3403 | bool IsProtocolMethodDecl); |
3404 | |
3405 | /// WarnExactTypedMethods - This routine issues a warning if method |
3406 | /// implementation declaration matches exactly that of its declaration. |
3407 | void WarnExactTypedMethods(ObjCMethodDecl *Method, |
3408 | ObjCMethodDecl *MethodDecl, |
3409 | bool IsProtocolMethodDecl); |
3410 | |
3411 | typedef llvm::SmallPtrSet<Selector, 8> SelectorSet; |
3412 | |
3413 | /// CheckImplementationIvars - This routine checks if the instance variables |
3414 | /// listed in the implelementation match those listed in the interface. |
3415 | void CheckImplementationIvars(ObjCImplementationDecl *ImpDecl, |
3416 | ObjCIvarDecl **Fields, unsigned nIvars, |
3417 | SourceLocation Loc); |
3418 | |
3419 | /// ImplMethodsVsClassMethods - This is main routine to warn if any method |
3420 | /// remains unimplemented in the class or category \@implementation. |
3421 | void ImplMethodsVsClassMethods(Scope *S, ObjCImplDecl* IMPDecl, |
3422 | ObjCContainerDecl* IDecl, |
3423 | bool IncompleteImpl = false); |
3424 | |
3425 | /// DiagnoseUnimplementedProperties - This routine warns on those properties |
3426 | /// which must be implemented by this implementation. |
3427 | void DiagnoseUnimplementedProperties(Scope *S, ObjCImplDecl* IMPDecl, |
3428 | ObjCContainerDecl *CDecl, |
3429 | bool SynthesizeProperties); |
3430 | |
3431 | /// Diagnose any null-resettable synthesized setters. |
3432 | void diagnoseNullResettableSynthesizedSetters(const ObjCImplDecl *impDecl); |
3433 | |
3434 | /// DefaultSynthesizeProperties - This routine default synthesizes all |
3435 | /// properties which must be synthesized in the class's \@implementation. |
3436 | void DefaultSynthesizeProperties(Scope *S, ObjCImplDecl *IMPDecl, |
3437 | ObjCInterfaceDecl *IDecl, |
3438 | SourceLocation AtEnd); |
3439 | void DefaultSynthesizeProperties(Scope *S, Decl *D, SourceLocation AtEnd); |
3440 | |
3441 | /// IvarBacksCurrentMethodAccessor - This routine returns 'true' if 'IV' is |
3442 | /// an ivar synthesized for 'Method' and 'Method' is a property accessor |
3443 | /// declared in class 'IFace'. |
3444 | bool IvarBacksCurrentMethodAccessor(ObjCInterfaceDecl *IFace, |
3445 | ObjCMethodDecl *Method, ObjCIvarDecl *IV); |
3446 | |
3447 | /// DiagnoseUnusedBackingIvarInAccessor - Issue an 'unused' warning if ivar which |
3448 | /// backs the property is not used in the property's accessor. |
3449 | void DiagnoseUnusedBackingIvarInAccessor(Scope *S, |
3450 | const ObjCImplementationDecl *ImplD); |
3451 | |
3452 | /// GetIvarBackingPropertyAccessor - If method is a property setter/getter and |
3453 | /// it property has a backing ivar, returns this ivar; otherwise, returns NULL. |
3454 | /// It also returns ivar's property on success. |
3455 | ObjCIvarDecl *GetIvarBackingPropertyAccessor(const ObjCMethodDecl *Method, |
3456 | const ObjCPropertyDecl *&PDecl) const; |
3457 | |
3458 | /// Called by ActOnProperty to handle \@property declarations in |
3459 | /// class extensions. |
3460 | ObjCPropertyDecl *HandlePropertyInClassExtension(Scope *S, |
3461 | SourceLocation AtLoc, |
3462 | SourceLocation LParenLoc, |
3463 | FieldDeclarator &FD, |
3464 | Selector GetterSel, |
3465 | SourceLocation GetterNameLoc, |
3466 | Selector SetterSel, |
3467 | SourceLocation SetterNameLoc, |
3468 | const bool isReadWrite, |
3469 | unsigned &Attributes, |
3470 | const unsigned AttributesAsWritten, |
3471 | QualType T, |
3472 | TypeSourceInfo *TSI, |
3473 | tok::ObjCKeywordKind MethodImplKind); |
3474 | |
3475 | /// Called by ActOnProperty and HandlePropertyInClassExtension to |
3476 | /// handle creating the ObjcPropertyDecl for a category or \@interface. |
3477 | ObjCPropertyDecl *CreatePropertyDecl(Scope *S, |
3478 | ObjCContainerDecl *CDecl, |
3479 | SourceLocation AtLoc, |
3480 | SourceLocation LParenLoc, |
3481 | FieldDeclarator &FD, |
3482 | Selector GetterSel, |
3483 | SourceLocation GetterNameLoc, |
3484 | Selector SetterSel, |
3485 | SourceLocation SetterNameLoc, |
3486 | const bool isReadWrite, |
3487 | const unsigned Attributes, |
3488 | const unsigned AttributesAsWritten, |
3489 | QualType T, |
3490 | TypeSourceInfo *TSI, |
3491 | tok::ObjCKeywordKind MethodImplKind, |
3492 | DeclContext *lexicalDC = nullptr); |
3493 | |
3494 | /// AtomicPropertySetterGetterRules - This routine enforces the rule (via |
3495 | /// warning) when atomic property has one but not the other user-declared |
3496 | /// setter or getter. |
3497 | void AtomicPropertySetterGetterRules(ObjCImplDecl* IMPDecl, |
3498 | ObjCInterfaceDecl* IDecl); |
3499 | |
3500 | void DiagnoseOwningPropertyGetterSynthesis(const ObjCImplementationDecl *D); |
3501 | |
3502 | void DiagnoseMissingDesignatedInitOverrides( |
3503 | const ObjCImplementationDecl *ImplD, |
3504 | const ObjCInterfaceDecl *IFD); |
3505 | |
3506 | void DiagnoseDuplicateIvars(ObjCInterfaceDecl *ID, ObjCInterfaceDecl *SID); |
3507 | |
3508 | enum MethodMatchStrategy { |
3509 | MMS_loose, |
3510 | MMS_strict |
3511 | }; |
3512 | |
3513 | /// MatchTwoMethodDeclarations - Checks if two methods' type match and returns |
3514 | /// true, or false, accordingly. |
3515 | bool MatchTwoMethodDeclarations(const ObjCMethodDecl *Method, |
3516 | const ObjCMethodDecl *PrevMethod, |
3517 | MethodMatchStrategy strategy = MMS_strict); |
3518 | |
3519 | /// MatchAllMethodDeclarations - Check methods declaraed in interface or |
3520 | /// or protocol against those declared in their implementations. |
3521 | void MatchAllMethodDeclarations(const SelectorSet &InsMap, |
3522 | const SelectorSet &ClsMap, |
3523 | SelectorSet &InsMapSeen, |
3524 | SelectorSet &ClsMapSeen, |
3525 | ObjCImplDecl* IMPDecl, |
3526 | ObjCContainerDecl* IDecl, |
3527 | bool &IncompleteImpl, |
3528 | bool ImmediateClass, |
3529 | bool WarnCategoryMethodImpl=false); |
3530 | |
3531 | /// CheckCategoryVsClassMethodMatches - Checks that methods implemented in |
3532 | /// category matches with those implemented in its primary class and |
3533 | /// warns each time an exact match is found. |
3534 | void CheckCategoryVsClassMethodMatches(ObjCCategoryImplDecl *CatIMP); |
3535 | |
3536 | /// \brief Add the given method to the list of globally-known methods. |
3537 | void addMethodToGlobalList(ObjCMethodList *List, ObjCMethodDecl *Method); |
3538 | |
3539 | private: |
3540 | /// AddMethodToGlobalPool - Add an instance or factory method to the global |
3541 | /// pool. See descriptoin of AddInstanceMethodToGlobalPool. |
3542 | void AddMethodToGlobalPool(ObjCMethodDecl *Method, bool impl, bool instance); |
3543 | |
3544 | /// LookupMethodInGlobalPool - Returns the instance or factory method and |
3545 | /// optionally warns if there are multiple signatures. |
3546 | ObjCMethodDecl *LookupMethodInGlobalPool(Selector Sel, SourceRange R, |
3547 | bool receiverIdOrClass, |
3548 | bool instance); |
3549 | |
3550 | public: |
3551 | /// \brief - Returns instance or factory methods in global method pool for |
3552 | /// given selector. It checks the desired kind first, if none is found, and |
3553 | /// parameter checkTheOther is set, it then checks the other kind. If no such |
3554 | /// method or only one method is found, function returns false; otherwise, it |
3555 | /// returns true. |
3556 | bool |
3557 | CollectMultipleMethodsInGlobalPool(Selector Sel, |
3558 | SmallVectorImpl<ObjCMethodDecl*>& Methods, |
3559 | bool InstanceFirst, bool CheckTheOther, |
3560 | const ObjCObjectType *TypeBound = nullptr); |
3561 | |
3562 | bool |
3563 | AreMultipleMethodsInGlobalPool(Selector Sel, ObjCMethodDecl *BestMethod, |
3564 | SourceRange R, bool receiverIdOrClass, |
3565 | SmallVectorImpl<ObjCMethodDecl*>& Methods); |
3566 | |
3567 | void |
3568 | DiagnoseMultipleMethodInGlobalPool(SmallVectorImpl<ObjCMethodDecl*> &Methods, |
3569 | Selector Sel, SourceRange R, |
3570 | bool receiverIdOrClass); |
3571 | |
3572 | private: |
3573 | /// \brief - Returns a selector which best matches given argument list or |
3574 | /// nullptr if none could be found |
3575 | ObjCMethodDecl *SelectBestMethod(Selector Sel, MultiExprArg Args, |
3576 | bool IsInstance, |
3577 | SmallVectorImpl<ObjCMethodDecl*>& Methods); |
3578 | |
3579 | |
3580 | /// \brief Record the typo correction failure and return an empty correction. |
3581 | TypoCorrection FailedCorrection(IdentifierInfo *Typo, SourceLocation TypoLoc, |
3582 | bool RecordFailure = true) { |
3583 | if (RecordFailure) |
3584 | TypoCorrectionFailures[Typo].insert(TypoLoc); |
3585 | return TypoCorrection(); |
3586 | } |
3587 | |
3588 | public: |
3589 | /// AddInstanceMethodToGlobalPool - All instance methods in a translation |
3590 | /// unit are added to a global pool. This allows us to efficiently associate |
3591 | /// a selector with a method declaraation for purposes of typechecking |
3592 | /// messages sent to "id" (where the class of the object is unknown). |
3593 | void AddInstanceMethodToGlobalPool(ObjCMethodDecl *Method, bool impl=false) { |
3594 | AddMethodToGlobalPool(Method, impl, /*instance*/true); |
3595 | } |
3596 | |
3597 | /// AddFactoryMethodToGlobalPool - Same as above, but for factory methods. |
3598 | void AddFactoryMethodToGlobalPool(ObjCMethodDecl *Method, bool impl=false) { |
3599 | AddMethodToGlobalPool(Method, impl, /*instance*/false); |
3600 | } |
3601 | |
3602 | /// AddAnyMethodToGlobalPool - Add any method, instance or factory to global |
3603 | /// pool. |
3604 | void AddAnyMethodToGlobalPool(Decl *D); |
3605 | |
3606 | /// LookupInstanceMethodInGlobalPool - Returns the method and warns if |
3607 | /// there are multiple signatures. |
3608 | ObjCMethodDecl *LookupInstanceMethodInGlobalPool(Selector Sel, SourceRange R, |
3609 | bool receiverIdOrClass=false) { |
3610 | return LookupMethodInGlobalPool(Sel, R, receiverIdOrClass, |
3611 | /*instance*/true); |
3612 | } |
3613 | |
3614 | /// LookupFactoryMethodInGlobalPool - Returns the method and warns if |
3615 | /// there are multiple signatures. |
3616 | ObjCMethodDecl *LookupFactoryMethodInGlobalPool(Selector Sel, SourceRange R, |
3617 | bool receiverIdOrClass=false) { |
3618 | return LookupMethodInGlobalPool(Sel, R, receiverIdOrClass, |
3619 | /*instance*/false); |
3620 | } |
3621 | |
3622 | const ObjCMethodDecl *SelectorsForTypoCorrection(Selector Sel, |
3623 | QualType ObjectType=QualType()); |
3624 | /// LookupImplementedMethodInGlobalPool - Returns the method which has an |
3625 | /// implementation. |
3626 | ObjCMethodDecl *LookupImplementedMethodInGlobalPool(Selector Sel); |
3627 | |
3628 | /// CollectIvarsToConstructOrDestruct - Collect those ivars which require |
3629 | /// initialization. |
3630 | void CollectIvarsToConstructOrDestruct(ObjCInterfaceDecl *OI, |
3631 | SmallVectorImpl<ObjCIvarDecl*> &Ivars); |
3632 | |
3633 | //===--------------------------------------------------------------------===// |
3634 | // Statement Parsing Callbacks: SemaStmt.cpp. |
3635 | public: |
3636 | class FullExprArg { |
3637 | public: |
3638 | FullExprArg() : E(nullptr) { } |
3639 | FullExprArg(Sema &actions) : E(nullptr) { } |
3640 | |
3641 | ExprResult release() { |
3642 | return E; |
3643 | } |
3644 | |
3645 | Expr *get() const { return E; } |
3646 | |
3647 | Expr *operator->() { |
3648 | return E; |
3649 | } |
3650 | |
3651 | private: |
3652 | // FIXME: No need to make the entire Sema class a friend when it's just |
3653 | // Sema::MakeFullExpr that needs access to the constructor below. |
3654 | friend class Sema; |
3655 | |
3656 | explicit FullExprArg(Expr *expr) : E(expr) {} |
3657 | |
3658 | Expr *E; |
3659 | }; |
3660 | |
3661 | FullExprArg MakeFullExpr(Expr *Arg) { |
3662 | return MakeFullExpr(Arg, Arg ? Arg->getExprLoc() : SourceLocation()); |
3663 | } |
3664 | FullExprArg MakeFullExpr(Expr *Arg, SourceLocation CC) { |
3665 | return FullExprArg(ActOnFinishFullExpr(Arg, CC).get()); |
3666 | } |
3667 | FullExprArg MakeFullDiscardedValueExpr(Expr *Arg) { |
3668 | ExprResult FE = |
3669 | ActOnFinishFullExpr(Arg, Arg ? Arg->getExprLoc() : SourceLocation(), |
3670 | /*DiscardedValue*/ true); |
3671 | return FullExprArg(FE.get()); |
3672 | } |
3673 | |
3674 | StmtResult ActOnExprStmt(ExprResult Arg); |
3675 | StmtResult ActOnExprStmtError(); |
3676 | |
3677 | StmtResult ActOnNullStmt(SourceLocation SemiLoc, |
3678 | bool HasLeadingEmptyMacro = false); |
3679 | |
3680 | void ActOnStartOfCompoundStmt(bool IsStmtExpr); |
3681 | void ActOnFinishOfCompoundStmt(); |
3682 | StmtResult ActOnCompoundStmt(SourceLocation L, SourceLocation R, |
3683 | ArrayRef<Stmt *> Elts, bool isStmtExpr); |
3684 | |
3685 | /// \brief A RAII object to enter scope of a compound statement. |
3686 | class CompoundScopeRAII { |
3687 | public: |
3688 | CompoundScopeRAII(Sema &S, bool IsStmtExpr = false) : S(S) { |
3689 | S.ActOnStartOfCompoundStmt(IsStmtExpr); |
3690 | } |
3691 | |
3692 | ~CompoundScopeRAII() { |
3693 | S.ActOnFinishOfCompoundStmt(); |
3694 | } |
3695 | |
3696 | private: |
3697 | Sema &S; |
3698 | }; |
3699 | |
3700 | /// An RAII helper that pops function a function scope on exit. |
3701 | struct FunctionScopeRAII { |
3702 | Sema &S; |
3703 | bool Active; |
3704 | FunctionScopeRAII(Sema &S) : S(S), Active(true) {} |
3705 | ~FunctionScopeRAII() { |
3706 | if (Active) |
3707 | S.PopFunctionScopeInfo(); |
3708 | } |
3709 | void disable() { Active = false; } |
3710 | }; |
3711 | |
3712 | StmtResult ActOnDeclStmt(DeclGroupPtrTy Decl, |
3713 | SourceLocation StartLoc, |
3714 | SourceLocation EndLoc); |
3715 | void ActOnForEachDeclStmt(DeclGroupPtrTy Decl); |
3716 | StmtResult ActOnForEachLValueExpr(Expr *E); |
3717 | StmtResult ActOnCaseStmt(SourceLocation CaseLoc, Expr *LHSVal, |
3718 | SourceLocation DotDotDotLoc, Expr *RHSVal, |
3719 | SourceLocation ColonLoc); |
3720 | void ActOnCaseStmtBody(Stmt *CaseStmt, Stmt *SubStmt); |
3721 | |
3722 | StmtResult ActOnDefaultStmt(SourceLocation DefaultLoc, |
3723 | SourceLocation ColonLoc, |
3724 | Stmt *SubStmt, Scope *CurScope); |
3725 | StmtResult ActOnLabelStmt(SourceLocation IdentLoc, LabelDecl *TheDecl, |
3726 | SourceLocation ColonLoc, Stmt *SubStmt); |
3727 | |
3728 | StmtResult ActOnAttributedStmt(SourceLocation AttrLoc, |
3729 | ArrayRef<const Attr*> Attrs, |
3730 | Stmt *SubStmt); |
3731 | |
3732 | class ConditionResult; |
3733 | StmtResult ActOnIfStmt(SourceLocation IfLoc, bool IsConstexpr, |
3734 | Stmt *InitStmt, |
3735 | ConditionResult Cond, Stmt *ThenVal, |
3736 | SourceLocation ElseLoc, Stmt *ElseVal); |
3737 | StmtResult BuildIfStmt(SourceLocation IfLoc, bool IsConstexpr, |
3738 | Stmt *InitStmt, |
3739 | ConditionResult Cond, Stmt *ThenVal, |
3740 | SourceLocation ElseLoc, Stmt *ElseVal); |
3741 | StmtResult ActOnStartOfSwitchStmt(SourceLocation SwitchLoc, |
3742 | Stmt *InitStmt, |
3743 | ConditionResult Cond); |
3744 | StmtResult ActOnFinishSwitchStmt(SourceLocation SwitchLoc, |
3745 | Stmt *Switch, Stmt *Body); |
3746 | StmtResult ActOnWhileStmt(SourceLocation WhileLoc, ConditionResult Cond, |
3747 | Stmt *Body); |
3748 | StmtResult ActOnDoStmt(SourceLocation DoLoc, Stmt *Body, |
3749 | SourceLocation WhileLoc, SourceLocation CondLParen, |
3750 | Expr *Cond, SourceLocation CondRParen); |
3751 | |
3752 | StmtResult ActOnForStmt(SourceLocation ForLoc, |
3753 | SourceLocation LParenLoc, |
3754 | Stmt *First, |
3755 | ConditionResult Second, |
3756 | FullExprArg Third, |
3757 | SourceLocation RParenLoc, |
3758 | Stmt *Body); |
3759 | ExprResult CheckObjCForCollectionOperand(SourceLocation forLoc, |
3760 | Expr *collection); |
3761 | StmtResult ActOnObjCForCollectionStmt(SourceLocation ForColLoc, |
3762 | Stmt *First, Expr *collection, |
3763 | SourceLocation RParenLoc); |
3764 | StmtResult FinishObjCForCollectionStmt(Stmt *ForCollection, Stmt *Body); |
3765 | |
3766 | enum BuildForRangeKind { |
3767 | /// Initial building of a for-range statement. |
3768 | BFRK_Build, |
3769 | /// Instantiation or recovery rebuild of a for-range statement. Don't |
3770 | /// attempt any typo-correction. |
3771 | BFRK_Rebuild, |
3772 | /// Determining whether a for-range statement could be built. Avoid any |
3773 | /// unnecessary or irreversible actions. |
3774 | BFRK_Check |
3775 | }; |
3776 | |
3777 | StmtResult ActOnCXXForRangeStmt(Scope *S, SourceLocation ForLoc, |
3778 | SourceLocation CoawaitLoc, |
3779 | Stmt *LoopVar, |
3780 | SourceLocation ColonLoc, Expr *Collection, |
3781 | SourceLocation RParenLoc, |
3782 | BuildForRangeKind Kind); |
3783 | StmtResult BuildCXXForRangeStmt(SourceLocation ForLoc, |
3784 | SourceLocation CoawaitLoc, |
3785 | SourceLocation ColonLoc, |
3786 | Stmt *RangeDecl, Stmt *Begin, Stmt *End, |
3787 | Expr *Cond, Expr *Inc, |
3788 | Stmt *LoopVarDecl, |
3789 | SourceLocation RParenLoc, |
3790 | BuildForRangeKind Kind); |
3791 | StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body); |
3792 | |
3793 | StmtResult ActOnGotoStmt(SourceLocation GotoLoc, |
3794 | SourceLocation LabelLoc, |
3795 | LabelDecl *TheDecl); |
3796 | StmtResult ActOnIndirectGotoStmt(SourceLocation GotoLoc, |
3797 | SourceLocation StarLoc, |
3798 | Expr *DestExp); |
3799 | StmtResult ActOnContinueStmt(SourceLocation ContinueLoc, Scope *CurScope); |
3800 | StmtResult ActOnBreakStmt(SourceLocation BreakLoc, Scope *CurScope); |
3801 | |
3802 | void ActOnCapturedRegionStart(SourceLocation Loc, Scope *CurScope, |
3803 | CapturedRegionKind Kind, unsigned NumParams); |
3804 | typedef std::pair<StringRef, QualType> CapturedParamNameType; |
3805 | void ActOnCapturedRegionStart(SourceLocation Loc, Scope *CurScope, |
3806 | CapturedRegionKind Kind, |
3807 | ArrayRef<CapturedParamNameType> Params); |
3808 | StmtResult ActOnCapturedRegionEnd(Stmt *S); |
3809 | void ActOnCapturedRegionError(); |
3810 | RecordDecl *CreateCapturedStmtRecordDecl(CapturedDecl *&CD, |
3811 | SourceLocation Loc, |
3812 | unsigned NumParams); |
3813 | VarDecl *getCopyElisionCandidate(QualType ReturnType, Expr *E, |
3814 | bool AllowParamOrMoveConstructible); |
3815 | bool isCopyElisionCandidate(QualType ReturnType, const VarDecl *VD, |
3816 | bool AllowParamOrMoveConstructible); |
3817 | |
3818 | StmtResult ActOnReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp, |
3819 | Scope *CurScope); |
3820 | StmtResult BuildReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp); |
3821 | StmtResult ActOnCapScopeReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp); |
3822 | |
3823 | StmtResult ActOnGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple, |
3824 | bool IsVolatile, unsigned NumOutputs, |
3825 | unsigned NumInputs, IdentifierInfo **Names, |
3826 | MultiExprArg Constraints, MultiExprArg Exprs, |
3827 | Expr *AsmString, MultiExprArg Clobbers, |
3828 | SourceLocation RParenLoc); |
3829 | |
3830 | void FillInlineAsmIdentifierInfo(Expr *Res, |
3831 | llvm::InlineAsmIdentifierInfo &Info); |
3832 | ExprResult LookupInlineAsmIdentifier(CXXScopeSpec &SS, |
3833 | SourceLocation TemplateKWLoc, |
3834 | UnqualifiedId &Id, |
3835 | bool IsUnevaluatedContext); |
3836 | bool LookupInlineAsmField(StringRef Base, StringRef Member, |
3837 | unsigned &Offset, SourceLocation AsmLoc); |
3838 | ExprResult LookupInlineAsmVarDeclField(Expr *RefExpr, StringRef Member, |
3839 | SourceLocation AsmLoc); |
3840 | StmtResult ActOnMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc, |
3841 | ArrayRef<Token> AsmToks, |
3842 | StringRef AsmString, |
3843 | unsigned NumOutputs, unsigned NumInputs, |
3844 | ArrayRef<StringRef> Constraints, |
3845 | ArrayRef<StringRef> Clobbers, |
3846 | ArrayRef<Expr*> Exprs, |
3847 | SourceLocation EndLoc); |
3848 | LabelDecl *GetOrCreateMSAsmLabel(StringRef ExternalLabelName, |
3849 | SourceLocation Location, |
3850 | bool AlwaysCreate); |
3851 | |
3852 | VarDecl *BuildObjCExceptionDecl(TypeSourceInfo *TInfo, QualType ExceptionType, |
3853 | SourceLocation StartLoc, |
3854 | SourceLocation IdLoc, IdentifierInfo *Id, |
3855 | bool Invalid = false); |
3856 | |
3857 | Decl *ActOnObjCExceptionDecl(Scope *S, Declarator &D); |
3858 | |
3859 | StmtResult ActOnObjCAtCatchStmt(SourceLocation AtLoc, SourceLocation RParen, |
3860 | Decl *Parm, Stmt *Body); |
3861 | |
3862 | StmtResult ActOnObjCAtFinallyStmt(SourceLocation AtLoc, Stmt *Body); |
3863 | |
3864 | StmtResult ActOnObjCAtTryStmt(SourceLocation AtLoc, Stmt *Try, |
3865 | MultiStmtArg Catch, Stmt *Finally); |
3866 | |
3867 | StmtResult BuildObjCAtThrowStmt(SourceLocation AtLoc, Expr *Throw); |
3868 | StmtResult ActOnObjCAtThrowStmt(SourceLocation AtLoc, Expr *Throw, |
3869 | Scope *CurScope); |
3870 | ExprResult ActOnObjCAtSynchronizedOperand(SourceLocation atLoc, |
3871 | Expr *operand); |
3872 | StmtResult ActOnObjCAtSynchronizedStmt(SourceLocation AtLoc, |
3873 | Expr *SynchExpr, |
3874 | Stmt *SynchBody); |
3875 | |
3876 | StmtResult ActOnObjCAutoreleasePoolStmt(SourceLocation AtLoc, Stmt *Body); |
3877 | |
3878 | VarDecl *BuildExceptionDeclaration(Scope *S, TypeSourceInfo *TInfo, |
3879 | SourceLocation StartLoc, |
3880 | SourceLocation IdLoc, |
3881 | IdentifierInfo *Id); |
3882 | |
3883 | Decl *ActOnExceptionDeclarator(Scope *S, Declarator &D); |
3884 | |
3885 | StmtResult ActOnCXXCatchBlock(SourceLocation CatchLoc, |
3886 | Decl *ExDecl, Stmt *HandlerBlock); |
3887 | StmtResult ActOnCXXTryBlock(SourceLocation TryLoc, Stmt *TryBlock, |
3888 | ArrayRef<Stmt *> Handlers); |
3889 | |
3890 | StmtResult ActOnSEHTryBlock(bool IsCXXTry, // try (true) or __try (false) ? |
3891 | SourceLocation TryLoc, Stmt *TryBlock, |
3892 | Stmt *Handler); |
3893 | StmtResult ActOnSEHExceptBlock(SourceLocation Loc, |
3894 | Expr *FilterExpr, |
3895 | Stmt *Block); |
3896 | void ActOnStartSEHFinallyBlock(); |
3897 | void ActOnAbortSEHFinallyBlock(); |
3898 | StmtResult ActOnFinishSEHFinallyBlock(SourceLocation Loc, Stmt *Block); |
3899 | StmtResult ActOnSEHLeaveStmt(SourceLocation Loc, Scope *CurScope); |
3900 | |
3901 | void DiagnoseReturnInConstructorExceptionHandler(CXXTryStmt *TryBlock); |
3902 | |
3903 | bool ShouldWarnIfUnusedFileScopedDecl(const DeclaratorDecl *D) const; |
3904 | |
3905 | /// \brief If it's a file scoped decl that must warn if not used, keep track |
3906 | /// of it. |
3907 | void MarkUnusedFileScopedDecl(const DeclaratorDecl *D); |
3908 | |
3909 | /// DiagnoseUnusedExprResult - If the statement passed in is an expression |
3910 | /// whose result is unused, warn. |
3911 | void DiagnoseUnusedExprResult(const Stmt *S); |
3912 | void DiagnoseUnusedNestedTypedefs(const RecordDecl *D); |
3913 | void DiagnoseUnusedDecl(const NamedDecl *ND); |
3914 | |
3915 | /// Emit \p DiagID if statement located on \p StmtLoc has a suspicious null |
3916 | /// statement as a \p Body, and it is located on the same line. |
3917 | /// |
3918 | /// This helps prevent bugs due to typos, such as: |
3919 | /// if (condition); |
3920 | /// do_stuff(); |
3921 | void DiagnoseEmptyStmtBody(SourceLocation StmtLoc, |
3922 | const Stmt *Body, |
3923 | unsigned DiagID); |
3924 | |
3925 | /// Warn if a for/while loop statement \p S, which is followed by |
3926 | /// \p PossibleBody, has a suspicious null statement as a body. |
3927 | void DiagnoseEmptyLoopBody(const Stmt *S, |
3928 | const Stmt *PossibleBody); |
3929 | |
3930 | /// Warn if a value is moved to itself. |
3931 | void DiagnoseSelfMove(const Expr *LHSExpr, const Expr *RHSExpr, |
3932 | SourceLocation OpLoc); |
3933 | |
3934 | /// \brief Warn if we're implicitly casting from a _Nullable pointer type to a |
3935 | /// _Nonnull one. |
3936 | void diagnoseNullableToNonnullConversion(QualType DstType, QualType SrcType, |
3937 | SourceLocation Loc); |
3938 | |
3939 | /// Warn when implicitly casting 0 to nullptr. |
3940 | void diagnoseZeroToNullptrConversion(CastKind Kind, const Expr *E); |
3941 | |
3942 | ParsingDeclState PushParsingDeclaration(sema::DelayedDiagnosticPool &pool) { |
3943 | return DelayedDiagnostics.push(pool); |
3944 | } |
3945 | void PopParsingDeclaration(ParsingDeclState state, Decl *decl); |
3946 | |
3947 | typedef ProcessingContextState ParsingClassState; |
3948 | ParsingClassState PushParsingClass() { |
3949 | return DelayedDiagnostics.pushUndelayed(); |
3950 | } |
3951 | void PopParsingClass(ParsingClassState state) { |
3952 | DelayedDiagnostics.popUndelayed(state); |
3953 | } |
3954 | |
3955 | void redelayDiagnostics(sema::DelayedDiagnosticPool &pool); |
3956 | |
3957 | void DiagnoseAvailabilityOfDecl(NamedDecl *D, SourceLocation Loc, |
3958 | const ObjCInterfaceDecl *UnknownObjCClass, |
3959 | bool ObjCPropertyAccess, |
3960 | bool AvoidPartialAvailabilityChecks = false); |
3961 | |
3962 | bool makeUnavailableInSystemHeader(SourceLocation loc, |
3963 | UnavailableAttr::ImplicitReason reason); |
3964 | |
3965 | /// \brief Issue any -Wunguarded-availability warnings in \c FD |
3966 | void DiagnoseUnguardedAvailabilityViolations(Decl *FD); |
3967 | |
3968 | //===--------------------------------------------------------------------===// |
3969 | // Expression Parsing Callbacks: SemaExpr.cpp. |
3970 | |
3971 | bool CanUseDecl(NamedDecl *D, bool TreatUnavailableAsInvalid); |
3972 | bool DiagnoseUseOfDecl(NamedDecl *D, SourceLocation Loc, |
3973 | const ObjCInterfaceDecl *UnknownObjCClass = nullptr, |
3974 | bool ObjCPropertyAccess = false, |
3975 | bool AvoidPartialAvailabilityChecks = false); |
3976 | void NoteDeletedFunction(FunctionDecl *FD); |
3977 | void NoteDeletedInheritingConstructor(CXXConstructorDecl *CD); |
3978 | std::string getDeletedOrUnavailableSuffix(const FunctionDecl *FD); |
3979 | bool DiagnosePropertyAccessorMismatch(ObjCPropertyDecl *PD, |
3980 | ObjCMethodDecl *Getter, |
3981 | SourceLocation Loc); |
3982 | void DiagnoseSentinelCalls(NamedDecl *D, SourceLocation Loc, |
3983 | ArrayRef<Expr *> Args); |
3984 | |
3985 | void PushExpressionEvaluationContext(ExpressionEvaluationContext NewContext, |
3986 | Decl *LambdaContextDecl = nullptr, |
3987 | bool IsDecltype = false); |
3988 | enum ReuseLambdaContextDecl_t { ReuseLambdaContextDecl }; |
3989 | void PushExpressionEvaluationContext(ExpressionEvaluationContext NewContext, |
3990 | ReuseLambdaContextDecl_t, |
3991 | bool IsDecltype = false); |
3992 | void PopExpressionEvaluationContext(); |
3993 | |
3994 | void DiscardCleanupsInEvaluationContext(); |
3995 | |
3996 | ExprResult TransformToPotentiallyEvaluated(Expr *E); |
3997 | ExprResult HandleExprEvaluationContextForTypeof(Expr *E); |
3998 | |
3999 | ExprResult ActOnConstantExpression(ExprResult Res); |
4000 | |
4001 | // Functions for marking a declaration referenced. These functions also |
4002 | // contain the relevant logic for marking if a reference to a function or |
4003 | // variable is an odr-use (in the C++11 sense). There are separate variants |
4004 | // for expressions referring to a decl; these exist because odr-use marking |
4005 | // needs to be delayed for some constant variables when we build one of the |
4006 | // named expressions. |
4007 | // |
4008 | // MightBeOdrUse indicates whether the use could possibly be an odr-use, and |
4009 | // should usually be true. This only needs to be set to false if the lack of |
4010 | // odr-use cannot be determined from the current context (for instance, |
4011 | // because the name denotes a virtual function and was written without an |
4012 | // explicit nested-name-specifier). |
4013 | void MarkAnyDeclReferenced(SourceLocation Loc, Decl *D, bool MightBeOdrUse); |
4014 | void MarkFunctionReferenced(SourceLocation Loc, FunctionDecl *Func, |
4015 | bool MightBeOdrUse = true); |
4016 | void MarkVariableReferenced(SourceLocation Loc, VarDecl *Var); |
4017 | void MarkDeclRefReferenced(DeclRefExpr *E, const Expr *Base = nullptr); |
4018 | void MarkMemberReferenced(MemberExpr *E); |
4019 | |
4020 | void UpdateMarkingForLValueToRValue(Expr *E); |
4021 | void CleanupVarDeclMarking(); |
4022 | |
4023 | enum TryCaptureKind { |
4024 | TryCapture_Implicit, TryCapture_ExplicitByVal, TryCapture_ExplicitByRef |
4025 | }; |
4026 | |
4027 | /// \brief Try to capture the given variable. |
4028 | /// |
4029 | /// \param Var The variable to capture. |
4030 | /// |
4031 | /// \param Loc The location at which the capture occurs. |
4032 | /// |
4033 | /// \param Kind The kind of capture, which may be implicit (for either a |
4034 | /// block or a lambda), or explicit by-value or by-reference (for a lambda). |
4035 | /// |
4036 | /// \param EllipsisLoc The location of the ellipsis, if one is provided in |
4037 | /// an explicit lambda capture. |
4038 | /// |
4039 | /// \param BuildAndDiagnose Whether we are actually supposed to add the |
4040 | /// captures or diagnose errors. If false, this routine merely check whether |
4041 | /// the capture can occur without performing the capture itself or complaining |
4042 | /// if the variable cannot be captured. |
4043 | /// |
4044 | /// \param CaptureType Will be set to the type of the field used to capture |
4045 | /// this variable in the innermost block or lambda. Only valid when the |
4046 | /// variable can be captured. |
4047 | /// |
4048 | /// \param DeclRefType Will be set to the type of a reference to the capture |
4049 | /// from within the current scope. Only valid when the variable can be |
4050 | /// captured. |
4051 | /// |
4052 | /// \param FunctionScopeIndexToStopAt If non-null, it points to the index |
4053 | /// of the FunctionScopeInfo stack beyond which we do not attempt to capture. |
4054 | /// This is useful when enclosing lambdas must speculatively capture |
4055 | /// variables that may or may not be used in certain specializations of |
4056 | /// a nested generic lambda. |
4057 | /// |
4058 | /// \returns true if an error occurred (i.e., the variable cannot be |
4059 | /// captured) and false if the capture succeeded. |
4060 | bool tryCaptureVariable(VarDecl *Var, SourceLocation Loc, TryCaptureKind Kind, |
4061 | SourceLocation EllipsisLoc, bool BuildAndDiagnose, |
4062 | QualType &CaptureType, |
4063 | QualType &DeclRefType, |
4064 | const unsigned *const FunctionScopeIndexToStopAt); |
4065 | |
4066 | /// \brief Try to capture the given variable. |
4067 | bool tryCaptureVariable(VarDecl *Var, SourceLocation Loc, |
4068 | TryCaptureKind Kind = TryCapture_Implicit, |
4069 | SourceLocation EllipsisLoc = SourceLocation()); |
4070 | |
4071 | /// \brief Checks if the variable must be captured. |
4072 | bool NeedToCaptureVariable(VarDecl *Var, SourceLocation Loc); |
4073 | |
4074 | /// \brief Given a variable, determine the type that a reference to that |
4075 | /// variable will have in the given scope. |
4076 | QualType getCapturedDeclRefType(VarDecl *Var, SourceLocation Loc); |
4077 | |
4078 | /// Mark all of the declarations referenced within a particular AST node as |
4079 | /// referenced. Used when template instantiation instantiates a non-dependent |
4080 | /// type -- entities referenced by the type are now referenced. |
4081 | void MarkDeclarationsReferencedInType(SourceLocation Loc, QualType T); |
4082 | void MarkDeclarationsReferencedInExpr(Expr *E, |
4083 | bool SkipLocalVariables = false); |
4084 | |
4085 | /// \brief Try to recover by turning the given expression into a |
4086 | /// call. Returns true if recovery was attempted or an error was |
4087 | /// emitted; this may also leave the ExprResult invalid. |
4088 | bool tryToRecoverWithCall(ExprResult &E, const PartialDiagnostic &PD, |
4089 | bool ForceComplain = false, |
4090 | bool (*IsPlausibleResult)(QualType) = nullptr); |
4091 | |
4092 | /// \brief Figure out if an expression could be turned into a call. |
4093 | bool tryExprAsCall(Expr &E, QualType &ZeroArgCallReturnTy, |
4094 | UnresolvedSetImpl &NonTemplateOverloads); |
4095 | |
4096 | /// \brief Conditionally issue a diagnostic based on the current |
4097 | /// evaluation context. |
4098 | /// |
4099 | /// \param Statement If Statement is non-null, delay reporting the |
4100 | /// diagnostic until the function body is parsed, and then do a basic |
4101 | /// reachability analysis to determine if the statement is reachable. |
4102 | /// If it is unreachable, the diagnostic will not be emitted. |
4103 | bool DiagRuntimeBehavior(SourceLocation Loc, const Stmt *Statement, |
4104 | const PartialDiagnostic &PD); |
4105 | |
4106 | // Primary Expressions. |
4107 | SourceRange getExprRange(Expr *E) const; |
4108 | |
4109 | ExprResult ActOnIdExpression( |
4110 | Scope *S, CXXScopeSpec &SS, SourceLocation TemplateKWLoc, |
4111 | UnqualifiedId &Id, bool HasTrailingLParen, bool IsAddressOfOperand, |
4112 | std::unique_ptr<CorrectionCandidateCallback> CCC = nullptr, |
4113 | bool IsInlineAsmIdentifier = false, Token *KeywordReplacement = nullptr); |
4114 | |
4115 | void DecomposeUnqualifiedId(const UnqualifiedId &Id, |
4116 | TemplateArgumentListInfo &Buffer, |
4117 | DeclarationNameInfo &NameInfo, |
4118 | const TemplateArgumentListInfo *&TemplateArgs); |
4119 | |
4120 | bool |
4121 | DiagnoseEmptyLookup(Scope *S, CXXScopeSpec &SS, LookupResult &R, |
4122 | std::unique_ptr<CorrectionCandidateCallback> CCC, |
4123 | TemplateArgumentListInfo *ExplicitTemplateArgs = nullptr, |
4124 | ArrayRef<Expr *> Args = None, TypoExpr **Out = nullptr); |
4125 | |
4126 | ExprResult LookupInObjCMethod(LookupResult &LookUp, Scope *S, |
4127 | IdentifierInfo *II, |
4128 | bool AllowBuiltinCreation=false); |
4129 | |
4130 | ExprResult ActOnDependentIdExpression(const CXXScopeSpec &SS, |
4131 | SourceLocation TemplateKWLoc, |
4132 | const DeclarationNameInfo &NameInfo, |
4133 | bool isAddressOfOperand, |
4134 | const TemplateArgumentListInfo *TemplateArgs); |
4135 | |
4136 | ExprResult BuildDeclRefExpr(ValueDecl *D, QualType Ty, |
4137 | ExprValueKind VK, |
4138 | SourceLocation Loc, |
4139 | const CXXScopeSpec *SS = nullptr); |
4140 | ExprResult |
4141 | BuildDeclRefExpr(ValueDecl *D, QualType Ty, ExprValueKind VK, |
4142 | const DeclarationNameInfo &NameInfo, |
4143 | const CXXScopeSpec *SS = nullptr, |
4144 | NamedDecl *FoundD = nullptr, |
4145 | const TemplateArgumentListInfo *TemplateArgs = nullptr); |
4146 | ExprResult |
4147 | BuildAnonymousStructUnionMemberReference( |
4148 | const CXXScopeSpec &SS, |
4149 | SourceLocation nameLoc, |
4150 | IndirectFieldDecl *indirectField, |
4151 | DeclAccessPair FoundDecl = DeclAccessPair::make(nullptr, AS_none), |
4152 | Expr *baseObjectExpr = nullptr, |
4153 | SourceLocation opLoc = SourceLocation()); |
4154 | |
4155 | ExprResult BuildPossibleImplicitMemberExpr(const CXXScopeSpec &SS, |
4156 | SourceLocation TemplateKWLoc, |
4157 | LookupResult &R, |
4158 | const TemplateArgumentListInfo *TemplateArgs, |
4159 | const Scope *S); |
4160 | ExprResult BuildImplicitMemberExpr(const CXXScopeSpec &SS, |
4161 | SourceLocation TemplateKWLoc, |
4162 | LookupResult &R, |
4163 | const TemplateArgumentListInfo *TemplateArgs, |
4164 | bool IsDefiniteInstance, |
4165 | const Scope *S); |
4166 | bool UseArgumentDependentLookup(const CXXScopeSpec &SS, |
4167 | const LookupResult &R, |
4168 | bool HasTrailingLParen); |
4169 | |
4170 | ExprResult |
4171 | BuildQualifiedDeclarationNameExpr(CXXScopeSpec &SS, |
4172 | const DeclarationNameInfo &NameInfo, |
4173 | bool IsAddressOfOperand, const Scope *S, |
4174 | TypeSourceInfo **RecoveryTSI = nullptr); |
4175 | |
4176 | ExprResult BuildDependentDeclRefExpr(const CXXScopeSpec &SS, |
4177 | SourceLocation TemplateKWLoc, |
4178 | const DeclarationNameInfo &NameInfo, |
4179 | const TemplateArgumentListInfo *TemplateArgs); |
4180 | |
4181 | ExprResult BuildDeclarationNameExpr(const CXXScopeSpec &SS, |
4182 | LookupResult &R, |
4183 | bool NeedsADL, |
4184 | bool AcceptInvalidDecl = false); |
4185 | ExprResult BuildDeclarationNameExpr( |
4186 | const CXXScopeSpec &SS, const DeclarationNameInfo &NameInfo, NamedDecl *D, |
4187 | NamedDecl *FoundD = nullptr, |
4188 | const TemplateArgumentListInfo *TemplateArgs = nullptr, |
4189 | bool AcceptInvalidDecl = false); |
4190 | |
4191 | ExprResult BuildLiteralOperatorCall(LookupResult &R, |
4192 | DeclarationNameInfo &SuffixInfo, |
4193 | ArrayRef<Expr *> Args, |
4194 | SourceLocation LitEndLoc, |
4195 | TemplateArgumentListInfo *ExplicitTemplateArgs = nullptr); |
4196 | |
4197 | ExprResult BuildPredefinedExpr(SourceLocation Loc, |
4198 | PredefinedExpr::IdentType IT); |
4199 | ExprResult ActOnPredefinedExpr(SourceLocation Loc, tok::TokenKind Kind); |
4200 | ExprResult ActOnIntegerConstant(SourceLocation Loc, uint64_t Val); |
4201 | |
4202 | bool CheckLoopHintExpr(Expr *E, SourceLocation Loc); |
4203 | |
4204 | ExprResult ActOnNumericConstant(const Token &Tok, Scope *UDLScope = nullptr); |
4205 | ExprResult ActOnCharacterConstant(const Token &Tok, |
4206 | Scope *UDLScope = nullptr); |
4207 | ExprResult ActOnParenExpr(SourceLocation L, SourceLocation R, Expr *E); |
4208 | ExprResult ActOnParenListExpr(SourceLocation L, |
4209 | SourceLocation R, |
4210 | MultiExprArg Val); |
4211 | |
4212 | /// ActOnStringLiteral - The specified tokens were lexed as pasted string |
4213 | /// fragments (e.g. "foo" "bar" L"baz"). |
4214 | ExprResult ActOnStringLiteral(ArrayRef<Token> StringToks, |
4215 | Scope *UDLScope = nullptr); |
4216 | |
4217 | ExprResult ActOnGenericSelectionExpr(SourceLocation KeyLoc, |
4218 | SourceLocation DefaultLoc, |
4219 | SourceLocation RParenLoc, |
4220 | Expr *ControllingExpr, |
4221 | ArrayRef<ParsedType> ArgTypes, |
4222 | ArrayRef<Expr *> ArgExprs); |
4223 | ExprResult CreateGenericSelectionExpr(SourceLocation KeyLoc, |
4224 | SourceLocation DefaultLoc, |
4225 | SourceLocation RParenLoc, |
4226 | Expr *ControllingExpr, |
4227 | ArrayRef<TypeSourceInfo *> Types, |
4228 | ArrayRef<Expr *> Exprs); |
4229 | |
4230 | // Binary/Unary Operators. 'Tok' is the token for the operator. |
4231 | ExprResult CreateBuiltinUnaryOp(SourceLocation OpLoc, UnaryOperatorKind Opc, |
4232 | Expr *InputExpr); |
4233 | ExprResult BuildUnaryOp(Scope *S, SourceLocation OpLoc, |
4234 | UnaryOperatorKind Opc, Expr *Input); |
4235 | ExprResult ActOnUnaryOp(Scope *S, SourceLocation OpLoc, |
4236 | tok::TokenKind Op, Expr *Input); |
4237 | |
4238 | QualType CheckAddressOfOperand(ExprResult &Operand, SourceLocation OpLoc); |
4239 | |
4240 | ExprResult CreateUnaryExprOrTypeTraitExpr(TypeSourceInfo *TInfo, |
4241 | SourceLocation OpLoc, |
4242 | UnaryExprOrTypeTrait ExprKind, |
4243 | SourceRange R); |
4244 | ExprResult CreateUnaryExprOrTypeTraitExpr(Expr *E, SourceLocation OpLoc, |
4245 | UnaryExprOrTypeTrait ExprKind); |
4246 | ExprResult |
4247 | ActOnUnaryExprOrTypeTraitExpr(SourceLocation OpLoc, |
4248 | UnaryExprOrTypeTrait ExprKind, |
4249 | bool IsType, void *TyOrEx, |
4250 | SourceRange ArgRange); |
4251 | |
4252 | ExprResult CheckPlaceholderExpr(Expr *E); |
4253 | bool CheckVecStepExpr(Expr *E); |
4254 | |
4255 | bool CheckUnaryExprOrTypeTraitOperand(Expr *E, UnaryExprOrTypeTrait ExprKind); |
4256 | bool CheckUnaryExprOrTypeTraitOperand(QualType ExprType, SourceLocation OpLoc, |
4257 | SourceRange ExprRange, |
4258 | UnaryExprOrTypeTrait ExprKind); |
4259 | ExprResult ActOnSizeofParameterPackExpr(Scope *S, |
4260 | SourceLocation OpLoc, |
4261 | IdentifierInfo &Name, |
4262 | SourceLocation NameLoc, |
4263 | SourceLocation RParenLoc); |
4264 | ExprResult ActOnPostfixUnaryOp(Scope *S, SourceLocation OpLoc, |
4265 | tok::TokenKind Kind, Expr *Input); |
4266 | |
4267 | ExprResult ActOnArraySubscriptExpr(Scope *S, Expr *Base, SourceLocation LLoc, |
4268 | Expr *Idx, SourceLocation RLoc); |
4269 | ExprResult CreateBuiltinArraySubscriptExpr(Expr *Base, SourceLocation LLoc, |
4270 | Expr *Idx, SourceLocation RLoc); |
4271 | ExprResult ActOnOMPArraySectionExpr(Expr *Base, SourceLocation LBLoc, |
4272 | Expr *LowerBound, SourceLocation ColonLoc, |
4273 | Expr *Length, SourceLocation RBLoc); |
4274 | |
4275 | // This struct is for use by ActOnMemberAccess to allow |
4276 | // BuildMemberReferenceExpr to be able to reinvoke ActOnMemberAccess after |
4277 | // changing the access operator from a '.' to a '->' (to see if that is the |
4278 | // change needed to fix an error about an unknown member, e.g. when the class |
4279 | // defines a custom operator->). |
4280 | struct ActOnMemberAccessExtraArgs { |
4281 | Scope *S; |
4282 | UnqualifiedId &Id; |
4283 | Decl *ObjCImpDecl; |
4284 | }; |
4285 | |
4286 | ExprResult BuildMemberReferenceExpr( |
4287 | Expr *Base, QualType BaseType, SourceLocation OpLoc, bool IsArrow, |
4288 | CXXScopeSpec &SS, SourceLocation TemplateKWLoc, |
4289 | NamedDecl *FirstQualifierInScope, const DeclarationNameInfo &NameInfo, |
4290 | const TemplateArgumentListInfo *TemplateArgs, |
4291 | const Scope *S, |
4292 | ActOnMemberAccessExtraArgs *ExtraArgs = nullptr); |
4293 | |
4294 | ExprResult |
4295 | BuildMemberReferenceExpr(Expr *Base, QualType BaseType, SourceLocation OpLoc, |
4296 | bool IsArrow, const CXXScopeSpec &SS, |
4297 | SourceLocation TemplateKWLoc, |
4298 | NamedDecl *FirstQualifierInScope, LookupResult &R, |
4299 | const TemplateArgumentListInfo *TemplateArgs, |
4300 | const Scope *S, |
4301 | bool SuppressQualifierCheck = false, |
4302 | ActOnMemberAccessExtraArgs *ExtraArgs = nullptr); |
4303 | |
4304 | ExprResult BuildFieldReferenceExpr(Expr *BaseExpr, bool IsArrow, |
4305 | SourceLocation OpLoc, |
4306 | const CXXScopeSpec &SS, FieldDecl *Field, |
4307 | DeclAccessPair FoundDecl, |
4308 | const DeclarationNameInfo &MemberNameInfo); |
4309 | |
4310 | ExprResult PerformMemberExprBaseConversion(Expr *Base, bool IsArrow); |
4311 | |
4312 | bool CheckQualifiedMemberReference(Expr *BaseExpr, QualType BaseType, |
4313 | const CXXScopeSpec &SS, |
4314 | const LookupResult &R); |
4315 | |
4316 | ExprResult ActOnDependentMemberExpr(Expr *Base, QualType BaseType, |
4317 | bool IsArrow, SourceLocation OpLoc, |
4318 | const CXXScopeSpec &SS, |
4319 | SourceLocation TemplateKWLoc, |
4320 | NamedDecl *FirstQualifierInScope, |
4321 | const DeclarationNameInfo &NameInfo, |
4322 | const TemplateArgumentListInfo *TemplateArgs); |
4323 | |
4324 | ExprResult ActOnMemberAccessExpr(Scope *S, Expr *Base, |
4325 | SourceLocation OpLoc, |
4326 | tok::TokenKind OpKind, |
4327 | CXXScopeSpec &SS, |
4328 | SourceLocation TemplateKWLoc, |
4329 | UnqualifiedId &Member, |
4330 | Decl *ObjCImpDecl); |
4331 | |
4332 | void ActOnDefaultCtorInitializers(Decl *CDtorDecl); |
4333 | bool ConvertArgumentsForCall(CallExpr *Call, Expr *Fn, |
4334 | FunctionDecl *FDecl, |
4335 | const FunctionProtoType *Proto, |
4336 | ArrayRef<Expr *> Args, |
4337 | SourceLocation RParenLoc, |
4338 | bool ExecConfig = false); |
4339 | void CheckStaticArrayArgument(SourceLocation CallLoc, |
4340 | ParmVarDecl *Param, |
4341 | const Expr *ArgExpr); |
4342 | |
4343 | /// ActOnCallExpr - Handle a call to Fn with the specified array of arguments. |
4344 | /// This provides the location of the left/right parens and a list of comma |
4345 | /// locations. |
4346 | ExprResult ActOnCallExpr(Scope *S, Expr *Fn, SourceLocation LParenLoc, |
4347 | MultiExprArg ArgExprs, SourceLocation RParenLoc, |
4348 | Expr *ExecConfig = nullptr, |
4349 | bool IsExecConfig = false); |
4350 | ExprResult BuildResolvedCallExpr(Expr *Fn, NamedDecl *NDecl, |
4351 | SourceLocation LParenLoc, |
4352 | ArrayRef<Expr *> Arg, |
4353 | SourceLocation RParenLoc, |
4354 | Expr *Config = nullptr, |
4355 | bool IsExecConfig = false); |
4356 | |
4357 | ExprResult ActOnCUDAExecConfigExpr(Scope *S, SourceLocation LLLLoc, |
4358 | MultiExprArg ExecConfig, |
4359 | SourceLocation GGGLoc); |
4360 | |
4361 | ExprResult ActOnCastExpr(Scope *S, SourceLocation LParenLoc, |
4362 | Declarator &D, ParsedType &Ty, |
4363 | SourceLocation RParenLoc, Expr *CastExpr); |
4364 | ExprResult BuildCStyleCastExpr(SourceLocation LParenLoc, |
4365 | TypeSourceInfo *Ty, |
4366 | SourceLocation RParenLoc, |
4367 | Expr *Op); |
4368 | CastKind PrepareScalarCast(ExprResult &src, QualType destType); |
4369 | |
4370 | /// \brief Build an altivec or OpenCL literal. |
4371 | ExprResult BuildVectorLiteral(SourceLocation LParenLoc, |
4372 | SourceLocation RParenLoc, Expr *E, |
4373 | TypeSourceInfo *TInfo); |
4374 | |
4375 | ExprResult MaybeConvertParenListExprToParenExpr(Scope *S, Expr *ME); |
4376 | |
4377 | ExprResult ActOnCompoundLiteral(SourceLocation LParenLoc, |
4378 | ParsedType Ty, |
4379 | SourceLocation RParenLoc, |
4380 | Expr *InitExpr); |
4381 | |
4382 | ExprResult BuildCompoundLiteralExpr(SourceLocation LParenLoc, |
4383 | TypeSourceInfo *TInfo, |
4384 | SourceLocation RParenLoc, |
4385 | Expr *LiteralExpr); |
4386 | |
4387 | ExprResult ActOnInitList(SourceLocation LBraceLoc, |
4388 | MultiExprArg InitArgList, |
4389 | SourceLocation RBraceLoc); |
4390 | |
4391 | ExprResult ActOnDesignatedInitializer(Designation &Desig, |
4392 | SourceLocation Loc, |
4393 | bool GNUSyntax, |
4394 | ExprResult Init); |
4395 | |
4396 | private: |
4397 | static BinaryOperatorKind ConvertTokenKindToBinaryOpcode(tok::TokenKind Kind); |
4398 | |
4399 | public: |
4400 | ExprResult ActOnBinOp(Scope *S, SourceLocation TokLoc, |
4401 | tok::TokenKind Kind, Expr *LHSExpr, Expr *RHSExpr); |
4402 | ExprResult BuildBinOp(Scope *S, SourceLocation OpLoc, |
4403 | BinaryOperatorKind Opc, Expr *LHSExpr, Expr *RHSExpr); |
4404 | ExprResult CreateBuiltinBinOp(SourceLocation OpLoc, BinaryOperatorKind Opc, |
4405 | Expr *LHSExpr, Expr *RHSExpr); |
4406 | |
4407 | void DiagnoseCommaOperator(const Expr *LHS, SourceLocation Loc); |
4408 | |
4409 | /// ActOnConditionalOp - Parse a ?: operation. Note that 'LHS' may be null |
4410 | /// in the case of a the GNU conditional expr extension. |
4411 | ExprResult ActOnConditionalOp(SourceLocation QuestionLoc, |
4412 | SourceLocation ColonLoc, |
4413 | Expr *CondExpr, Expr *LHSExpr, Expr *RHSExpr); |
4414 | |
4415 | /// ActOnAddrLabel - Parse the GNU address of label extension: "&&foo". |
4416 | ExprResult ActOnAddrLabel(SourceLocation OpLoc, SourceLocation LabLoc, |
4417 | LabelDecl *TheDecl); |
4418 | |
4419 | void ActOnStartStmtExpr(); |
4420 | ExprResult ActOnStmtExpr(SourceLocation LPLoc, Stmt *SubStmt, |
4421 | SourceLocation RPLoc); // "({..})" |
4422 | void ActOnStmtExprError(); |
4423 | |
4424 | // __builtin_offsetof(type, identifier(.identifier|[expr])*) |
4425 | struct OffsetOfComponent { |
4426 | SourceLocation LocStart, LocEnd; |
4427 | bool isBrackets; // true if [expr], false if .ident |
4428 | union { |
4429 | IdentifierInfo *IdentInfo; |
4430 | Expr *E; |
4431 | } U; |
4432 | }; |
4433 | |
4434 | /// __builtin_offsetof(type, a.b[123][456].c) |
4435 | ExprResult BuildBuiltinOffsetOf(SourceLocation BuiltinLoc, |
4436 | TypeSourceInfo *TInfo, |
4437 | ArrayRef<OffsetOfComponent> Components, |
4438 | SourceLocation RParenLoc); |
4439 | ExprResult ActOnBuiltinOffsetOf(Scope *S, |
4440 | SourceLocation BuiltinLoc, |
4441 | SourceLocation TypeLoc, |
4442 | ParsedType ParsedArgTy, |
4443 | ArrayRef<OffsetOfComponent> Components, |
4444 | SourceLocation RParenLoc); |
4445 | |
4446 | // __builtin_choose_expr(constExpr, expr1, expr2) |
4447 | ExprResult ActOnChooseExpr(SourceLocation BuiltinLoc, |
4448 | Expr *CondExpr, Expr *LHSExpr, |
4449 | Expr *RHSExpr, SourceLocation RPLoc); |
4450 | |
4451 | // __builtin_va_arg(expr, type) |
4452 | ExprResult ActOnVAArg(SourceLocation BuiltinLoc, Expr *E, ParsedType Ty, |
4453 | SourceLocation RPLoc); |
4454 | ExprResult BuildVAArgExpr(SourceLocation BuiltinLoc, Expr *E, |
4455 | TypeSourceInfo *TInfo, SourceLocation RPLoc); |
4456 | |
4457 | // __null |
4458 | ExprResult ActOnGNUNullExpr(SourceLocation TokenLoc); |
4459 | |
4460 | bool CheckCaseExpression(Expr *E); |
4461 | |
4462 | /// \brief Describes the result of an "if-exists" condition check. |
4463 | enum IfExistsResult { |
4464 | /// \brief The symbol exists. |
4465 | IER_Exists, |
4466 | |
4467 | /// \brief The symbol does not exist. |
4468 | IER_DoesNotExist, |
4469 | |
4470 | /// \brief The name is a dependent name, so the results will differ |
4471 | /// from one instantiation to the next. |
4472 | IER_Dependent, |
4473 | |
4474 | /// \brief An error occurred. |
4475 | IER_Error |
4476 | }; |
4477 | |
4478 | IfExistsResult |
4479 | CheckMicrosoftIfExistsSymbol(Scope *S, CXXScopeSpec &SS, |
4480 | const DeclarationNameInfo &TargetNameInfo); |
4481 | |
4482 | IfExistsResult |
4483 | CheckMicrosoftIfExistsSymbol(Scope *S, SourceLocation KeywordLoc, |
4484 | bool IsIfExists, CXXScopeSpec &SS, |
4485 | UnqualifiedId &Name); |
4486 | |
4487 | StmtResult BuildMSDependentExistsStmt(SourceLocation KeywordLoc, |
4488 | bool IsIfExists, |
4489 | NestedNameSpecifierLoc QualifierLoc, |
4490 | DeclarationNameInfo NameInfo, |
4491 | Stmt *Nested); |
4492 | StmtResult ActOnMSDependentExistsStmt(SourceLocation KeywordLoc, |
4493 | bool IsIfExists, |
4494 | CXXScopeSpec &SS, UnqualifiedId &Name, |
4495 | Stmt *Nested); |
4496 | |
4497 | //===------------------------- "Block" Extension ------------------------===// |
4498 | |
4499 | /// ActOnBlockStart - This callback is invoked when a block literal is |
4500 | /// started. |
4501 | void ActOnBlockStart(SourceLocation CaretLoc, Scope *CurScope); |
4502 | |
4503 | /// ActOnBlockArguments - This callback allows processing of block arguments. |
4504 | /// If there are no arguments, this is still invoked. |
4505 | void ActOnBlockArguments(SourceLocation CaretLoc, Declarator &ParamInfo, |
4506 | Scope *CurScope); |
4507 | |
4508 | /// ActOnBlockError - If there is an error parsing a block, this callback |
4509 | /// is invoked to pop the information about the block from the action impl. |
4510 | void ActOnBlockError(SourceLocation CaretLoc, Scope *CurScope); |
4511 | |
4512 | /// ActOnBlockStmtExpr - This is called when the body of a block statement |
4513 | /// literal was successfully completed. ^(int x){...} |
4514 | ExprResult ActOnBlockStmtExpr(SourceLocation CaretLoc, Stmt *Body, |
4515 | Scope *CurScope); |
4516 | |
4517 | //===---------------------------- Clang Extensions ----------------------===// |
4518 | |
4519 | /// __builtin_convertvector(...) |
4520 | ExprResult ActOnConvertVectorExpr(Expr *E, ParsedType ParsedDestTy, |
4521 | SourceLocation BuiltinLoc, |
4522 | SourceLocation RParenLoc); |
4523 | |
4524 | //===---------------------------- OpenCL Features -----------------------===// |
4525 | |
4526 | /// __builtin_astype(...) |
4527 | ExprResult ActOnAsTypeExpr(Expr *E, ParsedType ParsedDestTy, |
4528 | SourceLocation BuiltinLoc, |
4529 | SourceLocation RParenLoc); |
4530 | |
4531 | //===---------------------------- C++ Features --------------------------===// |
4532 | |
4533 | // Act on C++ namespaces |
4534 | Decl *ActOnStartNamespaceDef(Scope *S, SourceLocation InlineLoc, |
4535 | SourceLocation NamespaceLoc, |
4536 | SourceLocation IdentLoc, |
4537 | IdentifierInfo *Ident, |
4538 | SourceLocation LBrace, |
4539 | AttributeList *AttrList, |
4540 | UsingDirectiveDecl * &UsingDecl); |
4541 | void ActOnFinishNamespaceDef(Decl *Dcl, SourceLocation RBrace); |
4542 | |
4543 | NamespaceDecl *getStdNamespace() const; |
4544 | NamespaceDecl *getOrCreateStdNamespace(); |
4545 | |
4546 | NamespaceDecl *lookupStdExperimentalNamespace(); |
4547 | |
4548 | CXXRecordDecl *getStdBadAlloc() const; |
4549 | EnumDecl *getStdAlignValT() const; |
4550 | |
4551 | /// \brief Tests whether Ty is an instance of std::initializer_list and, if |
4552 | /// it is and Element is not NULL, assigns the element type to Element. |
4553 | bool isStdInitializerList(QualType Ty, QualType *Element); |
4554 | |
4555 | /// \brief Looks for the std::initializer_list template and instantiates it |
4556 | /// with Element, or emits an error if it's not found. |
4557 | /// |
4558 | /// \returns The instantiated template, or null on error. |
4559 | QualType BuildStdInitializerList(QualType Element, SourceLocation Loc); |
4560 | |
4561 | /// \brief Determine whether Ctor is an initializer-list constructor, as |
4562 | /// defined in [dcl.init.list]p2. |
4563 | bool isInitListConstructor(const FunctionDecl *Ctor); |
4564 | |
4565 | Decl *ActOnUsingDirective(Scope *CurScope, |
4566 | SourceLocation UsingLoc, |
4567 | SourceLocation NamespcLoc, |
4568 | CXXScopeSpec &SS, |
4569 | SourceLocation IdentLoc, |
4570 | IdentifierInfo *NamespcName, |
4571 | AttributeList *AttrList); |
4572 | |
4573 | void PushUsingDirective(Scope *S, UsingDirectiveDecl *UDir); |
4574 | |
4575 | Decl *ActOnNamespaceAliasDef(Scope *CurScope, |
4576 | SourceLocation NamespaceLoc, |
4577 | SourceLocation AliasLoc, |
4578 | IdentifierInfo *Alias, |
4579 | CXXScopeSpec &SS, |
4580 | SourceLocation IdentLoc, |
4581 | IdentifierInfo *Ident); |
4582 | |
4583 | void HideUsingShadowDecl(Scope *S, UsingShadowDecl *Shadow); |
4584 | bool CheckUsingShadowDecl(UsingDecl *UD, NamedDecl *Target, |
4585 | const LookupResult &PreviousDecls, |
4586 | UsingShadowDecl *&PrevShadow); |
4587 | UsingShadowDecl *BuildUsingShadowDecl(Scope *S, UsingDecl *UD, |
4588 | NamedDecl *Target, |
4589 | UsingShadowDecl *PrevDecl); |
4590 | |
4591 | bool CheckUsingDeclRedeclaration(SourceLocation UsingLoc, |
4592 | bool HasTypenameKeyword, |
4593 | const CXXScopeSpec &SS, |
4594 | SourceLocation NameLoc, |
4595 | const LookupResult &Previous); |
4596 | bool CheckUsingDeclQualifier(SourceLocation UsingLoc, |
4597 | bool HasTypename, |
4598 | const CXXScopeSpec &SS, |
4599 | const DeclarationNameInfo &NameInfo, |
4600 | SourceLocation NameLoc); |
4601 | |
4602 | NamedDecl *BuildUsingDeclaration(Scope *S, AccessSpecifier AS, |
4603 | SourceLocation UsingLoc, |
4604 | bool HasTypenameKeyword, |
4605 | SourceLocation TypenameLoc, |
4606 | CXXScopeSpec &SS, |
4607 | DeclarationNameInfo NameInfo, |
4608 | SourceLocation EllipsisLoc, |
4609 | AttributeList *AttrList, |
4610 | bool IsInstantiation); |
4611 | NamedDecl *BuildUsingPackDecl(NamedDecl *InstantiatedFrom, |
4612 | ArrayRef<NamedDecl *> Expansions); |
4613 | |
4614 | bool CheckInheritingConstructorUsingDecl(UsingDecl *UD); |
4615 | |
4616 | /// Given a derived-class using shadow declaration for a constructor and the |
4617 | /// correspnding base class constructor, find or create the implicit |
4618 | /// synthesized derived class constructor to use for this initialization. |
4619 | CXXConstructorDecl * |
4620 | findInheritingConstructor(SourceLocation Loc, CXXConstructorDecl *BaseCtor, |
4621 | ConstructorUsingShadowDecl *DerivedShadow); |
4622 | |
4623 | Decl *ActOnUsingDeclaration(Scope *CurScope, |
4624 | AccessSpecifier AS, |
4625 | SourceLocation UsingLoc, |
4626 | SourceLocation TypenameLoc, |
4627 | CXXScopeSpec &SS, |
4628 | UnqualifiedId &Name, |
4629 | SourceLocation EllipsisLoc, |
4630 | AttributeList *AttrList); |
4631 | Decl *ActOnAliasDeclaration(Scope *CurScope, |
4632 | AccessSpecifier AS, |
4633 | MultiTemplateParamsArg TemplateParams, |
4634 | SourceLocation UsingLoc, |
4635 | UnqualifiedId &Name, |
4636 | AttributeList *AttrList, |
4637 | TypeResult Type, |
4638 | Decl *DeclFromDeclSpec); |
4639 | |
4640 | /// BuildCXXConstructExpr - Creates a complete call to a constructor, |
4641 | /// including handling of its default argument expressions. |
4642 | /// |
4643 | /// \param ConstructKind - a CXXConstructExpr::ConstructionKind |
4644 | ExprResult |
4645 | BuildCXXConstructExpr(SourceLocation ConstructLoc, QualType DeclInitType, |
4646 | NamedDecl *FoundDecl, |
4647 | CXXConstructorDecl *Constructor, MultiExprArg Exprs, |
4648 | bool HadMultipleCandidates, bool IsListInitialization, |
4649 | bool IsStdInitListInitialization, |
4650 | bool RequiresZeroInit, unsigned ConstructKind, |
4651 | SourceRange ParenRange); |
4652 | |
4653 | /// Build a CXXConstructExpr whose constructor has already been resolved if |
4654 | /// it denotes an inherited constructor. |
4655 | ExprResult |
4656 | BuildCXXConstructExpr(SourceLocation ConstructLoc, QualType DeclInitType, |
4657 | CXXConstructorDecl *Constructor, bool Elidable, |
4658 | MultiExprArg Exprs, |
4659 | bool HadMultipleCandidates, bool IsListInitialization, |
4660 | bool IsStdInitListInitialization, |
4661 | bool RequiresZeroInit, unsigned ConstructKind, |
4662 | SourceRange ParenRange); |
4663 | |
4664 | // FIXME: Can we remove this and have the above BuildCXXConstructExpr check if |
4665 | // the constructor can be elidable? |
4666 | ExprResult |
4667 | BuildCXXConstructExpr(SourceLocation ConstructLoc, QualType DeclInitType, |
4668 | NamedDecl *FoundDecl, |
4669 | CXXConstructorDecl *Constructor, bool Elidable, |
4670 | MultiExprArg Exprs, bool HadMultipleCandidates, |
4671 | bool IsListInitialization, |
4672 | bool IsStdInitListInitialization, bool RequiresZeroInit, |
4673 | unsigned ConstructKind, SourceRange ParenRange); |
4674 | |
4675 | ExprResult BuildCXXDefaultInitExpr(SourceLocation Loc, FieldDecl *Field); |
4676 | |
4677 | |
4678 | /// Instantiate or parse a C++ default argument expression as necessary. |
4679 | /// Return true on error. |
4680 | bool CheckCXXDefaultArgExpr(SourceLocation CallLoc, FunctionDecl *FD, |
4681 | ParmVarDecl *Param); |
4682 | |
4683 | /// BuildCXXDefaultArgExpr - Creates a CXXDefaultArgExpr, instantiating |
4684 | /// the default expr if needed. |
4685 | ExprResult BuildCXXDefaultArgExpr(SourceLocation CallLoc, |
4686 | FunctionDecl *FD, |
4687 | ParmVarDecl *Param); |
4688 | |
4689 | /// FinalizeVarWithDestructor - Prepare for calling destructor on the |
4690 | /// constructed variable. |
4691 | void FinalizeVarWithDestructor(VarDecl *VD, const RecordType *DeclInitType); |
4692 | |
4693 | /// \brief Helper class that collects exception specifications for |
4694 | /// implicitly-declared special member functions. |
4695 | class ImplicitExceptionSpecification { |
4696 | // Pointer to allow copying |
4697 | Sema *Self; |
4698 | // We order exception specifications thus: |
4699 | // noexcept is the most restrictive, but is only used in C++11. |
4700 | // throw() comes next. |
4701 | // Then a throw(collected exceptions) |
4702 | // Finally no specification, which is expressed as noexcept(false). |
4703 | // throw(...) is used instead if any called function uses it. |
4704 | ExceptionSpecificationType ComputedEST; |
4705 | llvm::SmallPtrSet<CanQualType, 4> ExceptionsSeen; |
4706 | SmallVector<QualType, 4> Exceptions; |
4707 | |
4708 | void ClearExceptions() { |
4709 | ExceptionsSeen.clear(); |
4710 | Exceptions.clear(); |
4711 | } |
4712 | |
4713 | public: |
4714 | explicit ImplicitExceptionSpecification(Sema &Self) |
4715 | : Self(&Self), ComputedEST(EST_BasicNoexcept) { |
4716 | if (!Self.getLangOpts().CPlusPlus11) |
4717 | ComputedEST = EST_DynamicNone; |
4718 | } |
4719 | |
4720 | /// \brief Get the computed exception specification type. |
4721 | ExceptionSpecificationType getExceptionSpecType() const { |
4722 | assert(ComputedEST != EST_ComputedNoexcept &&(static_cast <bool> (ComputedEST != EST_ComputedNoexcept && "noexcept(expr) should not be a possible result") ? void (0) : __assert_fail ("ComputedEST != EST_ComputedNoexcept && \"noexcept(expr) should not be a possible result\"" , "/build/llvm-toolchain-snapshot-7~svn326425/tools/clang/include/clang/Sema/Sema.h" , 4723, __extension__ __PRETTY_FUNCTION__)) |
4723 | "noexcept(expr) should not be a possible result")(static_cast <bool> (ComputedEST != EST_ComputedNoexcept && "noexcept(expr) should not be a possible result") ? void (0) : __assert_fail ("ComputedEST != EST_ComputedNoexcept && \"noexcept(expr) should not be a possible result\"" , "/build/llvm-toolchain-snapshot-7~svn326425/tools/clang/include/clang/Sema/Sema.h" , 4723, __extension__ __PRETTY_FUNCTION__)); |
4724 | return ComputedEST; |
4725 | } |
4726 | |
4727 | /// \brief The number of exceptions in the exception specification. |
4728 | unsigned size() const { return Exceptions.size(); } |
4729 | |
4730 | /// \brief The set of exceptions in the exception specification. |
4731 | const QualType *data() const { return Exceptions.data(); } |
4732 | |
4733 | /// \brief Integrate another called method into the collected data. |
4734 | void CalledDecl(SourceLocation CallLoc, const CXXMethodDecl *Method); |
4735 | |
4736 | /// \brief Integrate an invoked expression into the collected data. |
4737 | void CalledExpr(Expr *E); |
4738 | |
4739 | /// \brief Overwrite an EPI's exception specification with this |
4740 | /// computed exception specification. |
4741 | FunctionProtoType::ExceptionSpecInfo getExceptionSpec() const { |
4742 | FunctionProtoType::ExceptionSpecInfo ESI; |
4743 | ESI.Type = getExceptionSpecType(); |
4744 | if (ESI.Type == EST_Dynamic) { |
4745 | ESI.Exceptions = Exceptions; |
4746 | } else if (ESI.Type == EST_None) { |
4747 | /// C++11 [except.spec]p14: |
4748 | /// The exception-specification is noexcept(false) if the set of |
4749 | /// potential exceptions of the special member function contains "any" |
4750 | ESI.Type = EST_ComputedNoexcept; |
4751 | ESI.NoexceptExpr = Self->ActOnCXXBoolLiteral(SourceLocation(), |
4752 | tok::kw_false).get(); |
4753 | } |
4754 | return ESI; |
4755 | } |
4756 | }; |
4757 | |
4758 | /// \brief Determine what sort of exception specification a defaulted |
4759 | /// copy constructor of a class will have. |
4760 | ImplicitExceptionSpecification |
4761 | ComputeDefaultedDefaultCtorExceptionSpec(SourceLocation Loc, |
4762 | CXXMethodDecl *MD); |
4763 | |
4764 | /// \brief Determine what sort of exception specification a defaulted |
4765 | /// default constructor of a class will have, and whether the parameter |
4766 | /// will be const. |
4767 | ImplicitExceptionSpecification |
4768 | ComputeDefaultedCopyCtorExceptionSpec(CXXMethodDecl *MD); |
4769 | |
4770 | /// \brief Determine what sort of exception specification a defautled |
4771 | /// copy assignment operator of a class will have, and whether the |
4772 | /// parameter will be const. |
4773 | ImplicitExceptionSpecification |
4774 | ComputeDefaultedCopyAssignmentExceptionSpec(CXXMethodDecl *MD); |
4775 | |
4776 | /// \brief Determine what sort of exception specification a defaulted move |
4777 | /// constructor of a class will have. |
4778 | ImplicitExceptionSpecification |
4779 | ComputeDefaultedMoveCtorExceptionSpec(CXXMethodDecl *MD); |
4780 | |
4781 | /// \brief Determine what sort of exception specification a defaulted move |
4782 | /// assignment operator of a class will have. |
4783 | ImplicitExceptionSpecification |
4784 | ComputeDefaultedMoveAssignmentExceptionSpec(CXXMethodDecl *MD); |
4785 | |
4786 | /// \brief Determine what sort of exception specification a defaulted |
4787 | /// destructor of a class will have. |
4788 | ImplicitExceptionSpecification |
4789 | ComputeDefaultedDtorExceptionSpec(CXXMethodDecl *MD); |
4790 | |
4791 | /// \brief Determine what sort of exception specification an inheriting |
4792 | /// constructor of a class will have. |
4793 | ImplicitExceptionSpecification |
4794 | ComputeInheritingCtorExceptionSpec(SourceLocation Loc, |
4795 | CXXConstructorDecl *CD); |
4796 | |
4797 | /// \brief Evaluate the implicit exception specification for a defaulted |
4798 | /// special member function. |
4799 | void EvaluateImplicitExceptionSpec(SourceLocation Loc, CXXMethodDecl *MD); |
4800 | |
4801 | /// \brief Check the given exception-specification and update the |
4802 | /// exception specification information with the results. |
4803 | void checkExceptionSpecification(bool IsTopLevel, |
4804 | ExceptionSpecificationType EST, |
4805 | ArrayRef<ParsedType> DynamicExceptions, |
4806 | ArrayRef<SourceRange> DynamicExceptionRanges, |
4807 | Expr *NoexceptExpr, |
4808 | SmallVectorImpl<QualType> &Exceptions, |
4809 | FunctionProtoType::ExceptionSpecInfo &ESI); |
4810 | |
4811 | /// \brief Determine if we're in a case where we need to (incorrectly) eagerly |
4812 | /// parse an exception specification to work around a libstdc++ bug. |
4813 | bool isLibstdcxxEagerExceptionSpecHack(const Declarator &D); |
4814 | |
4815 | /// \brief Add an exception-specification to the given member function |
4816 | /// (or member function template). The exception-specification was parsed |
4817 | /// after the method itself was declared. |
4818 | void actOnDelayedExceptionSpecification(Decl *Method, |
4819 | ExceptionSpecificationType EST, |
4820 | SourceRange SpecificationRange, |
4821 | ArrayRef<ParsedType> DynamicExceptions, |
4822 | ArrayRef<SourceRange> DynamicExceptionRanges, |
4823 | Expr *NoexceptExpr); |
4824 | |
4825 | class InheritedConstructorInfo; |
4826 | |
4827 | /// \brief Determine if a special member function should have a deleted |
4828 | /// definition when it is defaulted. |
4829 | bool ShouldDeleteSpecialMember(CXXMethodDecl *MD, CXXSpecialMember CSM, |
4830 | InheritedConstructorInfo *ICI = nullptr, |
4831 | bool Diagnose = false); |
4832 | |
4833 | /// \brief Declare the implicit default constructor for the given class. |
4834 | /// |
4835 | /// \param ClassDecl The class declaration into which the implicit |
4836 | /// default constructor will be added. |
4837 | /// |
4838 | /// \returns The implicitly-declared default constructor. |
4839 | CXXConstructorDecl *DeclareImplicitDefaultConstructor( |
4840 | CXXRecordDecl *ClassDecl); |
4841 | |
4842 | /// DefineImplicitDefaultConstructor - Checks for feasibility of |
4843 | /// defining this constructor as the default constructor. |
4844 | void DefineImplicitDefaultConstructor(SourceLocation CurrentLocation, |
4845 | CXXConstructorDecl *Constructor); |
4846 | |
4847 | /// \brief Declare the implicit destructor for the given class. |
4848 | /// |
4849 | /// \param ClassDecl The class declaration into which the implicit |
4850 | /// destructor will be added. |
4851 | /// |
4852 | /// \returns The implicitly-declared destructor. |
4853 | CXXDestructorDecl *DeclareImplicitDestructor(CXXRecordDecl *ClassDecl); |
4854 | |
4855 | /// DefineImplicitDestructor - Checks for feasibility of |
4856 | /// defining this destructor as the default destructor. |
4857 | void DefineImplicitDestructor(SourceLocation CurrentLocation, |
4858 | CXXDestructorDecl *Destructor); |
4859 | |
4860 | /// \brief Build an exception spec for destructors that don't have one. |
4861 | /// |
4862 | /// C++11 says that user-defined destructors with no exception spec get one |
4863 | /// that looks as if the destructor was implicitly declared. |
4864 | void AdjustDestructorExceptionSpec(CXXRecordDecl *ClassDecl, |
4865 | CXXDestructorDecl *Destructor); |
4866 | |
4867 | /// \brief Define the specified inheriting constructor. |
4868 | void DefineInheritingConstructor(SourceLocation UseLoc, |
4869 | CXXConstructorDecl *Constructor); |
4870 | |
4871 | /// \brief Declare the implicit copy constructor for the given class. |
4872 | /// |
4873 | /// \param ClassDecl The class declaration into which the implicit |
4874 | /// copy constructor will be added. |
4875 | /// |
4876 | /// \returns The implicitly-declared copy constructor. |
4877 | CXXConstructorDecl *DeclareImplicitCopyConstructor(CXXRecordDecl *ClassDecl); |
4878 | |
4879 | /// DefineImplicitCopyConstructor - Checks for feasibility of |
4880 | /// defining this constructor as the copy constructor. |
4881 | void DefineImplicitCopyConstructor(SourceLocation CurrentLocation, |
4882 | CXXConstructorDecl *Constructor); |
4883 | |
4884 | /// \brief Declare the implicit move constructor for the given class. |
4885 | /// |
4886 | /// \param ClassDecl The Class declaration into which the implicit |
4887 | /// move constructor will be added. |
4888 | /// |
4889 | /// \returns The implicitly-declared move constructor, or NULL if it wasn't |
4890 | /// declared. |
4891 | CXXConstructorDecl *DeclareImplicitMoveConstructor(CXXRecordDecl *ClassDecl); |
4892 | |
4893 | /// DefineImplicitMoveConstructor - Checks for feasibility of |
4894 | /// defining this constructor as the move constructor. |
4895 | void DefineImplicitMoveConstructor(SourceLocation CurrentLocation, |
4896 | CXXConstructorDecl *Constructor); |
4897 | |
4898 | /// \brief Declare the implicit copy assignment operator for the given class. |
4899 | /// |
4900 | /// \param ClassDecl The class declaration into which the implicit |
4901 | /// copy assignment operator will be added. |
4902 | /// |
4903 | /// \returns The implicitly-declared copy assignment operator. |
4904 | CXXMethodDecl *DeclareImplicitCopyAssignment(CXXRecordDecl *ClassDecl); |
4905 | |
4906 | /// \brief Defines an implicitly-declared copy assignment operator. |
4907 | void DefineImplicitCopyAssignment(SourceLocation CurrentLocation, |
4908 | CXXMethodDecl *MethodDecl); |
4909 | |
4910 | /// \brief Declare the implicit move assignment operator for the given class. |
4911 | /// |
4912 | /// \param ClassDecl The Class declaration into which the implicit |
4913 | /// move assignment operator will be added. |
4914 | /// |
4915 | /// \returns The implicitly-declared move assignment operator, or NULL if it |
4916 | /// wasn't declared. |
4917 | CXXMethodDecl *DeclareImplicitMoveAssignment(CXXRecordDecl *ClassDecl); |
4918 | |
4919 | /// \brief Defines an implicitly-declared move assignment operator. |
4920 | void DefineImplicitMoveAssignment(SourceLocation CurrentLocation, |
4921 | CXXMethodDecl *MethodDecl); |
4922 | |
4923 | /// \brief Force the declaration of any implicitly-declared members of this |
4924 | /// class. |
4925 | void ForceDeclarationOfImplicitMembers(CXXRecordDecl *Class); |
4926 | |
4927 | /// \brief Check a completed declaration of an implicit special member. |
4928 | void CheckImplicitSpecialMemberDeclaration(Scope *S, FunctionDecl *FD); |
4929 | |
4930 | /// \brief Determine whether the given function is an implicitly-deleted |
4931 | /// special member function. |
4932 | bool isImplicitlyDeleted(FunctionDecl *FD); |
4933 | |
4934 | /// \brief Check whether 'this' shows up in the type of a static member |
4935 | /// function after the (naturally empty) cv-qualifier-seq would be. |
4936 | /// |
4937 | /// \returns true if an error occurred. |
4938 | bool checkThisInStaticMemberFunctionType(CXXMethodDecl *Method); |
4939 | |
4940 | /// \brief Whether this' shows up in the exception specification of a static |
4941 | /// member function. |
4942 | bool checkThisInStaticMemberFunctionExceptionSpec(CXXMethodDecl *Method); |
4943 | |
4944 | /// \brief Check whether 'this' shows up in the attributes of the given |
4945 | /// static member function. |
4946 | /// |
4947 | /// \returns true if an error occurred. |
4948 | bool checkThisInStaticMemberFunctionAttributes(CXXMethodDecl *Method); |
4949 | |
4950 | /// MaybeBindToTemporary - If the passed in expression has a record type with |
4951 | /// a non-trivial destructor, this will return CXXBindTemporaryExpr. Otherwise |
4952 | /// it simply returns the passed in expression. |
4953 | ExprResult MaybeBindToTemporary(Expr *E); |
4954 | |
4955 | bool CompleteConstructorCall(CXXConstructorDecl *Constructor, |
4956 | MultiExprArg ArgsPtr, |
4957 | SourceLocation Loc, |
4958 | SmallVectorImpl<Expr*> &ConvertedArgs, |
4959 | bool AllowExplicit = false, |
4960 | bool IsListInitialization = false); |
4961 | |
4962 | ParsedType getInheritingConstructorName(CXXScopeSpec &SS, |
4963 | SourceLocation NameLoc, |
4964 | IdentifierInfo &Name); |
4965 | |
4966 | ParsedType getDestructorName(SourceLocation TildeLoc, |
4967 | IdentifierInfo &II, SourceLocation NameLoc, |
4968 | Scope *S, CXXScopeSpec &SS, |
4969 | ParsedType ObjectType, |
4970 | bool EnteringContext); |
4971 | |
4972 | ParsedType getDestructorTypeForDecltype(const DeclSpec &DS, |
4973 | ParsedType ObjectType); |
4974 | |
4975 | // Checks that reinterpret casts don't have undefined behavior. |
4976 | void CheckCompatibleReinterpretCast(QualType SrcType, QualType DestType, |
4977 | bool IsDereference, SourceRange Range); |
4978 | |
4979 | /// ActOnCXXNamedCast - Parse {dynamic,static,reinterpret,const}_cast's. |
4980 | ExprResult ActOnCXXNamedCast(SourceLocation OpLoc, |
4981 | tok::TokenKind Kind, |
4982 | SourceLocation LAngleBracketLoc, |
4983 | Declarator &D, |
4984 | SourceLocation RAngleBracketLoc, |
4985 | SourceLocation LParenLoc, |
4986 | Expr *E, |
4987 | SourceLocation RParenLoc); |
4988 | |
4989 | ExprResult BuildCXXNamedCast(SourceLocation OpLoc, |
4990 | tok::TokenKind Kind, |
4991 | TypeSourceInfo *Ty, |
4992 | Expr *E, |
4993 | SourceRange AngleBrackets, |
4994 | SourceRange Parens); |
4995 | |
4996 | ExprResult BuildCXXTypeId(QualType TypeInfoType, |
4997 | SourceLocation TypeidLoc, |
4998 | TypeSourceInfo *Operand, |
4999 | SourceLocation RParenLoc); |
5000 | ExprResult BuildCXXTypeId(QualType TypeInfoType, |
5001 | SourceLocation TypeidLoc, |
5002 | Expr *Operand, |
5003 | SourceLocation RParenLoc); |
5004 | |
5005 | /// ActOnCXXTypeid - Parse typeid( something ). |
5006 | ExprResult ActOnCXXTypeid(SourceLocation OpLoc, |
5007 | SourceLocation LParenLoc, bool isType, |
5008 | void *TyOrExpr, |
5009 | SourceLocation RParenLoc); |
5010 | |
5011 | ExprResult BuildCXXUuidof(QualType TypeInfoType, |
5012 | SourceLocation TypeidLoc, |
5013 | TypeSourceInfo *Operand, |
5014 | SourceLocation RParenLoc); |
5015 | ExprResult BuildCXXUuidof(QualType TypeInfoType, |
5016 | SourceLocation TypeidLoc, |
5017 | Expr *Operand, |
5018 | SourceLocation RParenLoc); |
5019 | |
5020 | /// ActOnCXXUuidof - Parse __uuidof( something ). |
5021 | ExprResult ActOnCXXUuidof(SourceLocation OpLoc, |
5022 | SourceLocation LParenLoc, bool isType, |
5023 | void *TyOrExpr, |
5024 | SourceLocation RParenLoc); |
5025 | |
5026 | /// \brief Handle a C++1z fold-expression: ( expr op ... op expr ). |
5027 | ExprResult ActOnCXXFoldExpr(SourceLocation LParenLoc, Expr *LHS, |
5028 | tok::TokenKind Operator, |
5029 | SourceLocation EllipsisLoc, Expr *RHS, |
5030 | SourceLocation RParenLoc); |
5031 | ExprResult BuildCXXFoldExpr(SourceLocation LParenLoc, Expr *LHS, |
5032 | BinaryOperatorKind Operator, |
5033 | SourceLocation EllipsisLoc, Expr *RHS, |
5034 | SourceLocation RParenLoc); |
5035 | ExprResult BuildEmptyCXXFoldExpr(SourceLocation EllipsisLoc, |
5036 | BinaryOperatorKind Operator); |
5037 | |
5038 | //// ActOnCXXThis - Parse 'this' pointer. |
5039 | ExprResult ActOnCXXThis(SourceLocation loc); |
5040 | |
5041 | /// \brief Try to retrieve the type of the 'this' pointer. |
5042 | /// |
5043 | /// \returns The type of 'this', if possible. Otherwise, returns a NULL type. |
5044 | QualType getCurrentThisType(); |
5045 | |
5046 | /// \brief When non-NULL, the C++ 'this' expression is allowed despite the |
5047 | /// current context not being a non-static member function. In such cases, |
5048 | /// this provides the type used for 'this'. |
5049 | QualType CXXThisTypeOverride; |
5050 | |
5051 | /// \brief RAII object used to temporarily allow the C++ 'this' expression |
5052 | /// to be used, with the given qualifiers on the current class type. |
5053 | class CXXThisScopeRAII { |
5054 | Sema &S; |
5055 | QualType OldCXXThisTypeOverride; |
5056 | bool Enabled; |
5057 | |
5058 | public: |
5059 | /// \brief Introduce a new scope where 'this' may be allowed (when enabled), |
5060 | /// using the given declaration (which is either a class template or a |
5061 | /// class) along with the given qualifiers. |
5062 | /// along with the qualifiers placed on '*this'. |
5063 | CXXThisScopeRAII(Sema &S, Decl *ContextDecl, unsigned CXXThisTypeQuals, |
5064 | bool Enabled = true); |
5065 | |
5066 | ~CXXThisScopeRAII(); |
5067 | }; |
5068 | |
5069 | /// \brief Make sure the value of 'this' is actually available in the current |
5070 | /// context, if it is a potentially evaluated context. |
5071 | /// |
5072 | /// \param Loc The location at which the capture of 'this' occurs. |
5073 | /// |
5074 | /// \param Explicit Whether 'this' is explicitly captured in a lambda |
5075 | /// capture list. |
5076 | /// |
5077 | /// \param FunctionScopeIndexToStopAt If non-null, it points to the index |
5078 | /// of the FunctionScopeInfo stack beyond which we do not attempt to capture. |
5079 | /// This is useful when enclosing lambdas must speculatively capture |
5080 | /// 'this' that may or may not be used in certain specializations of |
5081 | /// a nested generic lambda (depending on whether the name resolves to |
5082 | /// a non-static member function or a static function). |
5083 | /// \return returns 'true' if failed, 'false' if success. |
5084 | bool CheckCXXThisCapture(SourceLocation Loc, bool Explicit = false, |
5085 | bool BuildAndDiagnose = true, |
5086 | const unsigned *const FunctionScopeIndexToStopAt = nullptr, |