clang 24.0.0git
SemaCUDA.cpp
Go to the documentation of this file.
1//===--- SemaCUDA.cpp - Semantic Analysis for CUDA constructs -------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8/// \file
9/// This file implements semantic analysis for CUDA constructs.
10///
11//===----------------------------------------------------------------------===//
12
13#include "clang/Sema/SemaCUDA.h"
15#include "clang/AST/Decl.h"
18#include "clang/AST/ExprCXX.h"
19#include "clang/Basic/Cuda.h"
22#include "clang/Sema/Lookup.h"
23#include "clang/Sema/Overload.h"
25#include "clang/Sema/Sema.h"
26#include "clang/Sema/Template.h"
27#include "llvm/ADT/SmallVector.h"
28#include <optional>
29using namespace clang;
30
32
33template <typename AttrT> static bool hasExplicitAttr(const VarDecl *D) {
34 if (!D)
35 return false;
36 if (auto *A = D->getAttr<AttrT>())
37 return !A->isImplicit();
38 return false;
39}
40
42 assert(getLangOpts().CUDA && "Should only be called during CUDA compilation");
43 ForceHostDeviceDepth++;
44}
45
47 assert(getLangOpts().CUDA && "Should only be called during CUDA compilation");
48 if (ForceHostDeviceDepth == 0)
49 return false;
50 ForceHostDeviceDepth--;
51 return true;
52}
53
55 MultiExprArg ExecConfig,
56 SourceLocation GGGLoc) {
57 bool IsDeviceKernelCall = false;
58 switch (CurrentTarget()) {
61 IsDeviceKernelCall = true;
62 break;
64 if (getLangOpts().CUDAIsDevice) {
65 IsDeviceKernelCall = true;
66 FunctionDecl *Caller = SemaRef.getCurFunctionDecl(/*AllowLambda=*/true);
67 if (Caller && isImplicitHostDeviceFunction(Caller)) {
68 // Under the device compilation, config call under an HD function should
69 // be treated as a device kernel call. But, for implicit HD ones (such
70 // as lambdas), need to check whether RDC is enabled or not.
71 if (!getLangOpts().GPURelocatableDeviceCode)
72 IsDeviceKernelCall = false;
73 // HIP doesn't support device-side kernel call yet. Still treat it as
74 // the host-side kernel call.
75 if (getLangOpts().HIP)
76 IsDeviceKernelCall = false;
77 } else if (getLangOpts().HIP && getLangOpts().IncrementalExtensions &&
78 isa<TopLevelStmtDecl>(SemaRef.getCurLexicalContext())) {
79 IsDeviceKernelCall = false;
80 }
81 }
82 break;
83 default:
84 break;
85 }
86
87 if (IsDeviceKernelCall && getLangOpts().HIP)
88 return ExprError(
89 Diag(LLLLoc, diag::err_cuda_device_kernel_launch_not_supported));
90
91 FunctionDecl *ConfigDecl = IsDeviceKernelCall
94 if (!ConfigDecl)
95 return ExprError(Diag(LLLLoc, diag::err_undeclared_var_use)
96 << (IsDeviceKernelCall ? getLaunchDeviceFuncName()
98 // Additional check on the launch function if it's a device kernel call.
99 if (IsDeviceKernelCall) {
100 auto *GetParamBuf = getASTContext().getcudaGetParameterBufferDecl();
101 if (!GetParamBuf)
102 return ExprError(Diag(LLLLoc, diag::err_undeclared_var_use)
104 }
105
106 QualType ConfigQTy = ConfigDecl->getType();
107
108 DeclRefExpr *ConfigDR = new (getASTContext()) DeclRefExpr(
109 getASTContext(), ConfigDecl, false, ConfigQTy, VK_LValue, LLLLoc);
110 SemaRef.MarkFunctionReferenced(LLLLoc, ConfigDecl);
111
112 if (IsDeviceKernelCall) {
114 // Use a null pointer as the kernel function, which may not be resolvable
115 // here. For example, resolving that kernel function may need additional
116 // kernel arguments.
117 llvm::APInt Zero(SemaRef.Context.getTypeSize(SemaRef.Context.IntTy), 0);
118 Args.push_back(IntegerLiteral::Create(SemaRef.Context, Zero,
119 SemaRef.Context.IntTy, LLLLoc));
120 // Use a null pointer as the placeholder of the parameter buffer, which
121 // should be replaced with the actual allocation later, in the codegen.
122 Args.push_back(IntegerLiteral::Create(SemaRef.Context, Zero,
123 SemaRef.Context.IntTy, LLLLoc));
124 // Add the original config arguments.
125 llvm::append_range(Args, ExecConfig);
126 // Add the default blockDim if it's missing.
127 if (Args.size() < 4) {
128 llvm::APInt One(SemaRef.Context.getTypeSize(SemaRef.Context.IntTy), 1);
129 Args.push_back(IntegerLiteral::Create(SemaRef.Context, One,
130 SemaRef.Context.IntTy, LLLLoc));
131 }
132 // Add the default sharedMemSize if it's missing.
133 if (Args.size() < 5)
134 Args.push_back(IntegerLiteral::Create(SemaRef.Context, Zero,
135 SemaRef.Context.IntTy, LLLLoc));
136 // Add the default stream if it's missing.
137 if (Args.size() < 6)
138 Args.push_back(new (SemaRef.Context) CXXNullPtrLiteralExpr(
139 SemaRef.Context.NullPtrTy, LLLLoc));
140 return SemaRef.BuildCallExpr(S, ConfigDR, LLLLoc, Args, GGGLoc, nullptr,
141 /*IsExecConfig=*/true);
142 }
143 return SemaRef.BuildCallExpr(S, ConfigDR, LLLLoc, ExecConfig, GGGLoc, nullptr,
144 /*IsExecConfig=*/true);
145}
146
148 bool HasHostAttr = false;
149 bool HasDeviceAttr = false;
150 bool HasGlobalAttr = false;
151 bool HasInvalidTargetAttr = false;
152 for (const ParsedAttr &AL : Attrs) {
153 switch (AL.getKind()) {
154 case ParsedAttr::AT_CUDAGlobal:
155 HasGlobalAttr = true;
156 break;
157 case ParsedAttr::AT_CUDAHost:
158 HasHostAttr = true;
159 break;
160 case ParsedAttr::AT_CUDADevice:
161 HasDeviceAttr = true;
162 break;
163 case ParsedAttr::AT_CUDAInvalidTarget:
164 HasInvalidTargetAttr = true;
165 break;
166 default:
167 break;
168 }
169 }
170
171 if (HasInvalidTargetAttr)
173
174 if (HasGlobalAttr)
176
177 if (HasHostAttr && HasDeviceAttr)
179
180 if (HasDeviceAttr)
182
184}
185
186template <typename A>
187static bool hasAttr(const Decl *D, bool IgnoreImplicitAttr) {
188 return D->hasAttrs() && llvm::any_of(D->getAttrs(), [&](Attr *Attribute) {
189 return isa<A>(Attribute) &&
190 !(IgnoreImplicitAttr && Attribute->isImplicit());
191 });
192}
193
196 : S(S_) {
197 SavedCtx = S.CurCUDATargetCtx;
198 assert(K == SemaCUDA::CTCK_InitGlobalVar);
199 auto *VD = dyn_cast_or_null<VarDecl>(D);
200 if (VD && VD->hasGlobalStorage() && !VD->isStaticLocal()) {
202 if ((hasAttr<CUDADeviceAttr>(VD, /*IgnoreImplicit=*/true) &&
203 !hasAttr<CUDAHostAttr>(VD, /*IgnoreImplicit=*/true)) ||
204 hasAttr<CUDASharedAttr>(VD, /*IgnoreImplicit=*/true) ||
205 hasAttr<CUDAConstantAttr>(VD, /*IgnoreImplicit=*/true))
207 S.CurCUDATargetCtx = {Target, K, VD};
208 }
209}
210
211/// IdentifyTarget - Determine the CUDA compilation target for this function
213 bool IgnoreImplicitHDAttr) {
214 // Code that lives outside a function gets the target from CurCUDATargetCtx.
215 if (D == nullptr)
216 return CurCUDATargetCtx.Target;
217
218 // C++ deduction guides are never codegen'ed and only participate in template
219 // argument deduction. Treat them as if they were always host+device so that
220 // CUDA/HIP target checking never rejects their use based solely on target.
223
224 if (D->hasAttr<CUDAInvalidTargetAttr>())
226
227 if (D->hasAttr<CUDAGlobalAttr>())
229
230 if (D->isConsteval())
232
233 if (hasAttr<CUDADeviceAttr>(D, IgnoreImplicitHDAttr)) {
234 if (hasAttr<CUDAHostAttr>(D, IgnoreImplicitHDAttr))
237 } else if (hasAttr<CUDAHostAttr>(D, IgnoreImplicitHDAttr)) {
239 } else if ((D->isImplicit() || !D->isUserProvided()) &&
240 !IgnoreImplicitHDAttr) {
241 // Some implicit declarations (like intrinsic functions) are not marked.
242 // Set the most lenient target on them for maximal flexibility.
244 }
245
247}
248
249/// IdentifyTarget - Determine the CUDA compilation target for this variable.
251 if (Var->hasAttr<HIPManagedAttr>())
252 return CVT_Unified;
253 // Only constexpr and const variabless with implicit constant attribute
254 // are emitted on both sides. Such variables are promoted to device side
255 // only if they have static constant initializers on device side.
256 if ((Var->isConstexpr() || Var->getType().isConstQualified()) &&
257 Var->hasAttr<CUDAConstantAttr>() &&
259 return CVT_Both;
260 if (Var->hasAttr<CUDADeviceAttr>() || Var->hasAttr<CUDAConstantAttr>() ||
261 Var->hasAttr<CUDASharedAttr>() ||
264 return CVT_Device;
265 // Function-scope static variable without explicit device or constant
266 // attribute are emitted
267 // - on both sides in host device functions
268 // - on device side in device or global functions
269 if (auto *FD = dyn_cast<FunctionDecl>(Var->getDeclContext())) {
270 switch (IdentifyTarget(FD)) {
272 return CVT_Both;
275 return CVT_Device;
276 default:
277 return CVT_Host;
278 }
279 }
280 return CVT_Host;
281}
282
283// * CUDA Call preference table
284//
285// F - from,
286// T - to
287// Ph - preference in host mode
288// Pd - preference in device mode
289// H - handled in (x)
290// Preferences: N:native, SS:same side, HD:host-device, WS:wrong side, --:never.
291//
292// | F | T | Ph | Pd | H |
293// |----+----+-----+-----+-----+
294// | d | d | N | N | (c) |
295// | d | g | -- | -- | (a) |
296// | d | h | -- | -- | (e) |
297// | d | hd | HD | HD | (b) |
298// | g | d | N | N | (c) |
299// | g | g | -- | -- | (a) |
300// | g | h | -- | -- | (e) |
301// | g | hd | HD | HD | (b) |
302// | h | d | -- | -- | (e) |
303// | h | g | N | N | (c) |
304// | h | h | N | N | (c) |
305// | h | hd | HD | HD | (b) |
306// | hd | d | WS | SS | (d) |
307// | hd | g | SS | -- |(d/a)|
308// | hd | h | SS | WS | (d) |
309// | hd | hd | HD | HD | (b) |
310
313 const FunctionDecl *Callee) {
314 assert(Callee && "Callee must be valid.");
315
316 // Treat ctor/dtor as host device function in device var initializer to allow
317 // trivial ctor/dtor without device attr to be used. Non-trivial ctor/dtor
318 // will be diagnosed by checkAllowedInitializer.
319 if (Caller == nullptr && CurCUDATargetCtx.Kind == CTCK_InitGlobalVar &&
322 return CFP_HostDevice;
323
324 CUDAFunctionTarget CallerTarget = IdentifyTarget(Caller);
325 CUDAFunctionTarget CalleeTarget = IdentifyTarget(Callee);
326
327 // If one of the targets is invalid, the check always fails, no matter what
328 // the other target is.
329 if (CallerTarget == CUDAFunctionTarget::InvalidTarget ||
330 CalleeTarget == CUDAFunctionTarget::InvalidTarget)
331 return CFP_Never;
332
333 // (a) Call global from either global or device contexts is allowed as part
334 // of CUDA's dynamic parallelism support.
335 if (CalleeTarget == CUDAFunctionTarget::Global &&
336 (CallerTarget == CUDAFunctionTarget::Global ||
337 CallerTarget == CUDAFunctionTarget::Device))
338 return CFP_Native;
339
340 // (b) Calling HostDevice is OK for everyone.
341 if (CalleeTarget == CUDAFunctionTarget::HostDevice)
342 return CFP_HostDevice;
343
344 // (c) Best case scenarios
345 if (CalleeTarget == CallerTarget ||
346 (CallerTarget == CUDAFunctionTarget::Host &&
347 CalleeTarget == CUDAFunctionTarget::Global) ||
348 (CallerTarget == CUDAFunctionTarget::Global &&
349 CalleeTarget == CUDAFunctionTarget::Device))
350 return CFP_Native;
351
352 // HipStdPar mode is special, in that assessing whether a device side call to
353 // a host target is deferred to a subsequent pass, and cannot unambiguously be
354 // adjudicated in the AST, hence we optimistically allow them to pass here.
355 if (getLangOpts().HIPStdPar &&
356 (CallerTarget == CUDAFunctionTarget::Global ||
357 CallerTarget == CUDAFunctionTarget::Device ||
358 CallerTarget == CUDAFunctionTarget::HostDevice) &&
359 CalleeTarget == CUDAFunctionTarget::Host)
360 return CFP_HostDevice;
361
362 // (d) HostDevice behavior depends on compilation mode.
363 if (CallerTarget == CUDAFunctionTarget::HostDevice) {
364 // It's OK to call a compilation-mode matching function from an HD one.
365 if ((getLangOpts().CUDAIsDevice &&
366 (CalleeTarget == CUDAFunctionTarget::Device ||
367 CalleeTarget == CUDAFunctionTarget::Global)) ||
368 (!getLangOpts().CUDAIsDevice &&
369 (CalleeTarget == CUDAFunctionTarget::Host ||
370 CalleeTarget == CUDAFunctionTarget::Global)))
371 return CFP_SameSide;
372
373 // Calls from HD to non-mode-matching functions (i.e., to host functions
374 // when compiling in device mode or to device functions when compiling in
375 // host mode) are allowed at the sema level, but eventually rejected if
376 // they're ever codegened. TODO: Reject said calls earlier.
377 return CFP_WrongSide;
378 }
379
380 // (e) Calling across device/host boundary is not something you should do.
381 if ((CallerTarget == CUDAFunctionTarget::Host &&
382 CalleeTarget == CUDAFunctionTarget::Device) ||
383 (CallerTarget == CUDAFunctionTarget::Device &&
384 CalleeTarget == CUDAFunctionTarget::Host) ||
385 (CallerTarget == CUDAFunctionTarget::Global &&
386 CalleeTarget == CUDAFunctionTarget::Host))
387 return CFP_Never;
388
389 llvm_unreachable("All cases should've been handled by now.");
390}
391
392template <typename AttrT> static bool hasImplicitAttr(const FunctionDecl *D) {
393 if (!D)
394 return false;
395 if (auto *A = D->getAttr<AttrT>())
396 return A->isImplicit();
397 return D->isImplicit();
398}
399
401 bool IsImplicitDevAttr = hasImplicitAttr<CUDADeviceAttr>(D);
402 bool IsImplicitHostAttr = hasImplicitAttr<CUDAHostAttr>(D);
403 return IsImplicitDevAttr && IsImplicitHostAttr;
404}
405
409
411 const FunctionDecl *Caller,
412 SmallVectorImpl<std::pair<DeclAccessPair, FunctionDecl *>> &Matches) {
413 if (Matches.size() <= 1)
414 return;
415
416 using Pair = std::pair<DeclAccessPair, FunctionDecl *>;
417
418 // Gets the CUDA function preference for a call from Caller to Match.
419 auto GetCFP = [&](const Pair &Match) {
420 return IdentifyPreference(Caller, Match.second);
421 };
422
423 // Find the best call preference among the functions in Matches.
424 CUDAFunctionPreference BestCFP =
425 GetCFP(*llvm::max_element(Matches, [&](const Pair &M1, const Pair &M2) {
426 return GetCFP(M1) < GetCFP(M2);
427 }));
428
429 // Erase all functions with lower priority.
430 llvm::erase_if(Matches,
431 [&](const Pair &Match) { return GetCFP(Match) < BestCFP; });
432}
433
434/// When an implicitly-declared special member has to invoke more than one
435/// base/field special member, conflicts may occur in the targets of these
436/// members. For example, if one base's member __host__ and another's is
437/// __device__, it's a conflict.
438/// This function figures out if the given targets \param Target1 and
439/// \param Target2 conflict, and if they do not it fills in
440/// \param ResolvedTarget with a target that resolves for both calls.
441/// \return true if there's a conflict, false otherwise.
442static bool
444 CUDAFunctionTarget Target2,
445 CUDAFunctionTarget *ResolvedTarget) {
446 // Only free functions and static member functions may be global.
447 assert(Target1 != CUDAFunctionTarget::Global);
448 assert(Target2 != CUDAFunctionTarget::Global);
449
450 if (Target1 == CUDAFunctionTarget::HostDevice) {
451 *ResolvedTarget = Target2;
452 } else if (Target2 == CUDAFunctionTarget::HostDevice) {
453 *ResolvedTarget = Target1;
454 } else if (Target1 != Target2) {
455 return true;
456 } else {
457 *ResolvedTarget = Target1;
458 }
459
460 return false;
461}
462
465 CXXMethodDecl *MemberDecl,
466 bool ConstRHS,
467 bool Diagnose) {
468 // If the defaulted special member is defined lexically outside of its
469 // owning class, or the special member already has explicit device or host
470 // attributes, do not infer.
471 bool InClass = MemberDecl->getLexicalParent() == MemberDecl->getParent();
472 bool HasH = MemberDecl->hasAttr<CUDAHostAttr>();
473 bool HasD = MemberDecl->hasAttr<CUDADeviceAttr>();
474 bool HasExplicitAttr =
475 (HasD && !MemberDecl->getAttr<CUDADeviceAttr>()->isImplicit()) ||
476 (HasH && !MemberDecl->getAttr<CUDAHostAttr>()->isImplicit());
477 if (!InClass || HasExplicitAttr)
478 return false;
479
480 std::optional<CUDAFunctionTarget> InferredTarget;
481
482 // We're going to invoke special member lookup; mark that these special
483 // members are called from this one, and not from its caller.
484 Sema::ContextRAII MethodContext(SemaRef, MemberDecl);
485
486 // Look for special members in base classes that should be invoked from here.
487 // Infer the target of this member base on the ones it should call.
488 // Skip direct and indirect virtual bases for abstract classes, except for
489 // destructors — the complete destructor variant destroys virtual bases
490 // regardless of whether the class is abstract.
492 for (const auto &B : ClassDecl->bases()) {
493 if (!B.isVirtual()) {
494 Bases.push_back(&B);
495 }
496 }
497
498 if (!ClassDecl->isAbstract() || CSM == CXXSpecialMemberKind::Destructor)
499 llvm::append_range(Bases, llvm::make_pointer_range(ClassDecl->vbases()));
500
501 for (const auto *B : Bases) {
502 auto *BaseClassDecl = B->getType()->getAsCXXRecordDecl();
503 if (!BaseClassDecl)
504 continue;
505
507 SemaRef.LookupSpecialMember(BaseClassDecl, CSM,
508 /* ConstArg */ ConstRHS,
509 /* VolatileArg */ false,
510 /* RValueThis */ false,
511 /* ConstThis */ false,
512 /* VolatileThis */ false);
513
514 if (!SMOR.getMethod())
515 continue;
516
517 CUDAFunctionTarget BaseMethodTarget = IdentifyTarget(SMOR.getMethod());
518
519 if (!InferredTarget) {
520 InferredTarget = BaseMethodTarget;
521 } else {
522 bool ResolutionError = resolveCalleeCUDATargetConflict(
523 *InferredTarget, BaseMethodTarget, &*InferredTarget);
524 if (ResolutionError) {
525 if (Diagnose) {
526 Diag(ClassDecl->getLocation(),
527 diag::note_implicit_member_target_infer_collision)
528 << (unsigned)CSM << *InferredTarget << BaseMethodTarget;
529 }
530 MemberDecl->addAttr(
531 CUDAInvalidTargetAttr::CreateImplicit(getASTContext()));
532 return true;
533 }
534 }
535 }
536
537 // Same as for bases, but now for special members of fields.
538 for (const auto *F : ClassDecl->fields()) {
539 if (F->isInvalidDecl()) {
540 continue;
541 }
542
543 auto *FieldRecDecl =
545 if (!FieldRecDecl)
546 continue;
547
549 SemaRef.LookupSpecialMember(FieldRecDecl, CSM,
550 /* ConstArg */ ConstRHS && !F->isMutable(),
551 /* VolatileArg */ false,
552 /* RValueThis */ false,
553 /* ConstThis */ false,
554 /* VolatileThis */ false);
555
556 if (!SMOR.getMethod())
557 continue;
558
559 CUDAFunctionTarget FieldMethodTarget = IdentifyTarget(SMOR.getMethod());
560
561 if (!InferredTarget) {
562 InferredTarget = FieldMethodTarget;
563 } else {
564 bool ResolutionError = resolveCalleeCUDATargetConflict(
565 *InferredTarget, FieldMethodTarget, &*InferredTarget);
566 if (ResolutionError) {
567 if (Diagnose) {
568 Diag(ClassDecl->getLocation(),
569 diag::note_implicit_member_target_infer_collision)
570 << (unsigned)CSM << *InferredTarget << FieldMethodTarget;
571 }
572 MemberDecl->addAttr(
573 CUDAInvalidTargetAttr::CreateImplicit(getASTContext()));
574 return true;
575 }
576 }
577 }
578
579 // If no target was inferred, mark this member as __host__ __device__;
580 // it's the least restrictive option that can be invoked from any target.
581 bool NeedsH = true, NeedsD = true;
582 if (InferredTarget) {
583 if (*InferredTarget == CUDAFunctionTarget::Device)
584 NeedsH = false;
585 else if (*InferredTarget == CUDAFunctionTarget::Host)
586 NeedsD = false;
587 }
588
589 // We either setting attributes first time, or the inferred ones must match
590 // previously set ones.
591 if (NeedsD && !HasD)
592 MemberDecl->addAttr(CUDADeviceAttr::CreateImplicit(getASTContext()));
593 if (NeedsH && !HasH)
594 MemberDecl->addAttr(CUDAHostAttr::CreateImplicit(getASTContext()));
595
596 return false;
597}
598
600 if (!CD->isDefined() && CD->isTemplateInstantiation())
601 SemaRef.InstantiateFunctionDefinition(Loc, CD->getFirstDecl());
602
603 // (E.2.3.1, CUDA 7.5) A constructor for a class type is considered
604 // empty at a point in the translation unit, if it is either a
605 // trivial constructor
606 if (CD->isTrivial())
607 return true;
608
609 // ... or it satisfies all of the following conditions:
610 // The constructor function has been defined.
611 // The constructor function has no parameters,
612 // and the function body is an empty compound statement.
613 if (!(CD->hasTrivialBody() && CD->getNumParams() == 0))
614 return false;
615
616 // Its class has no virtual functions and no virtual base classes.
617 if (CD->getParent()->isDynamicClass())
618 return false;
619
620 // Union ctor does not call ctors of its data members.
621 if (CD->getParent()->isUnion())
622 return true;
623
624 // The only form of initializer allowed is an empty constructor.
625 // This will recursively check all base classes and member initializers
626 if (!llvm::all_of(CD->inits(), [&](const CXXCtorInitializer *CI) {
627 if (const CXXConstructExpr *CE =
628 dyn_cast<CXXConstructExpr>(CI->getInit()))
629 return isEmptyConstructor(Loc, CE->getConstructor());
630 return false;
631 }))
632 return false;
633
634 return true;
635}
636
638 // No destructor -> no problem.
639 if (!DD)
640 return true;
641
642 if (!DD->isDefined() && DD->isTemplateInstantiation())
643 SemaRef.InstantiateFunctionDefinition(Loc, DD->getFirstDecl());
644
645 // (E.2.3.1, CUDA 7.5) A destructor for a class type is considered
646 // empty at a point in the translation unit, if it is either a
647 // trivial constructor
648 if (DD->isTrivial())
649 return true;
650
651 // ... or it satisfies all of the following conditions:
652 // The destructor function has been defined.
653 // and the function body is an empty compound statement.
654 if (!DD->hasTrivialBody())
655 return false;
656
657 const CXXRecordDecl *ClassDecl = DD->getParent();
658
659 // Its class has no virtual functions and no virtual base classes.
660 if (ClassDecl->isDynamicClass())
661 return false;
662
663 // Union does not have base class and union dtor does not call dtors of its
664 // data members.
665 if (DD->getParent()->isUnion())
666 return true;
667
668 // Only empty destructors are allowed. This will recursively check
669 // destructors for all base classes...
670 if (!llvm::all_of(ClassDecl->bases(), [&](const CXXBaseSpecifier &BS) {
671 if (CXXRecordDecl *RD = BS.getType()->getAsCXXRecordDecl())
672 return isEmptyDestructor(Loc, RD->getDestructor());
673 return true;
674 }))
675 return false;
676
677 // ... and member fields.
678 if (!llvm::all_of(ClassDecl->fields(), [&](const FieldDecl *Field) {
679 if (CXXRecordDecl *RD = Field->getType()
680 ->getBaseElementTypeUnsafe()
681 ->getAsCXXRecordDecl())
682 return isEmptyDestructor(Loc, RD->getDestructor());
683 return true;
684 }))
685 return false;
686
687 return true;
688}
689
690namespace {
691enum CUDAInitializerCheckKind {
692 CICK_DeviceOrConstant, // Check initializer for device/constant variable
693 CICK_Shared, // Check initializer for shared variable
694};
695
696bool IsDependentVar(VarDecl *VD) {
697 if (VD->getType()->isDependentType())
698 return true;
699 if (const auto *Init = VD->getInit())
700 return Init->isValueDependent();
701 return false;
702}
703
704// Check whether a variable has an allowed initializer for a CUDA device side
705// variable with global storage. \p VD may be a host variable to be checked for
706// potential promotion to device side variable.
707//
708// CUDA/HIP allows only empty constructors as initializers for global
709// variables (see E.2.3.1, CUDA 7.5). The same restriction also applies to all
710// __shared__ variables whether they are local or not (they all are implicitly
711// static in CUDA). One exception is that CUDA allows constant initializers
712// for __constant__ and __device__ variables.
713bool HasAllowedCUDADeviceStaticInitializer(SemaCUDA &S, VarDecl *VD,
714 CUDAInitializerCheckKind CheckKind) {
715 assert(!VD->isInvalidDecl() && VD->hasGlobalStorage());
716 assert(!IsDependentVar(VD) && "do not check dependent var");
717 const Expr *Init = VD->getInit();
718 auto IsEmptyInit = [&](const Expr *Init) {
719 if (!Init)
720 return true;
721 if (const auto *CE = dyn_cast<CXXConstructExpr>(Init)) {
722 return S.isEmptyConstructor(VD->getLocation(), CE->getConstructor());
723 }
724 return false;
725 };
726 auto IsConstantInit = [&](const Expr *Init) {
727 assert(Init);
728 ASTContext::CUDAConstantEvalContextRAII EvalCtx(S.getASTContext(),
729 /*NoWronSidedVars=*/true);
730 return Init->isConstantInitializer(S.getASTContext(),
731 VD->getType()->isReferenceType());
732 };
733 auto HasEmptyDtor = [&](VarDecl *VD) {
734 if (const auto *RD = VD->getType()->getAsCXXRecordDecl())
735 return S.isEmptyDestructor(VD->getLocation(), RD->getDestructor());
736 return true;
737 };
738 if (CheckKind == CICK_Shared)
739 return IsEmptyInit(Init) && HasEmptyDtor(VD);
740 return S.getLangOpts().GPUAllowDeviceInit ||
741 ((IsEmptyInit(Init) || IsConstantInit(Init)) && HasEmptyDtor(VD));
742}
743} // namespace
744
746 // Return early if VD is inside a non-instantiated template function since
747 // the implicit constructor is not defined yet.
748 if (const FunctionDecl *FD =
749 dyn_cast_or_null<FunctionDecl>(VD->getDeclContext());
750 FD && FD->isDependentContext())
751 return;
752
753 bool IsSharedVar = VD->hasAttr<CUDASharedAttr>();
754 bool IsDeviceOrConstantVar =
755 !IsSharedVar &&
756 (VD->hasAttr<CUDADeviceAttr>() || VD->hasAttr<CUDAConstantAttr>());
757 if ((IsSharedVar || IsDeviceOrConstantVar) &&
759 Diag(VD->getLocation(), diag::err_cuda_address_space_gpuvar);
760 VD->setInvalidDecl();
761 return;
762 }
763 // Do not check dependent variables since the ctor/dtor/initializer are not
764 // determined. Do it after instantiation.
765 if (VD->isInvalidDecl() || !VD->hasInit() || !VD->hasGlobalStorage() ||
766 IsDependentVar(VD))
767 return;
768 const Expr *Init = VD->getInit();
769 if (IsDeviceOrConstantVar || IsSharedVar) {
770 if (HasAllowedCUDADeviceStaticInitializer(
771 *this, VD, IsSharedVar ? CICK_Shared : CICK_DeviceOrConstant))
772 return;
773 Diag(VD->getLocation(),
774 IsSharedVar ? diag::err_shared_var_init : diag::err_dynamic_var_init)
775 << Init->getSourceRange();
776 VD->setInvalidDecl();
777 } else {
778 // This is a host-side global variable. Check that the initializer is
779 // callable from the host side.
780
781 struct GlobVarInitChecker : ConstEvaluatedExprVisitor<GlobVarInitChecker> {
782 private:
784 SemaCUDA &SCRef;
785 VarDecl *VD;
786 void CheckForWrongSidedCall(const FunctionDecl *FD) {
787 CUDAFunctionTarget InitFnTarget = SCRef.IdentifyTarget(FD);
788 if (InitFnTarget != CUDAFunctionTarget::Host &&
789 InitFnTarget != CUDAFunctionTarget::HostDevice &&
790 !VD->isInvalidDecl()) {
791 SCRef.Diag(VD->getLocation(),
792 diag::err_ref_bad_target_global_initializer)
793 << InitFnTarget << FD;
794 SCRef.Diag(FD->getLocation(), diag::note_previous_decl) << FD;
795 VD->setInvalidDecl();
796 }
797 }
798
799 public:
800 GlobVarInitChecker(SemaCUDA &S, VarDecl *VD)
801 : Base(S.getASTContext()), SCRef(S), VD(VD) {}
802 void VisitDeclRefExpr(const DeclRefExpr *DRE) {
803 if (auto *VarD = dyn_cast<VarDecl>(DRE->getDecl());
804 VarD && VarD->hasAttr<HIPManagedAttr>()) {
805 SCRef.Diag(DRE->getLocation(),
806 diag::err_cuda_invalid_use_of_managedvar);
807 SCRef.Diag(VD->getLocation(),
808 diag::note_cuda_managed_var_in_glob_init);
809 }
810 }
811 void VisitCallExpr(const CallExpr *CE) {
812 const FunctionDecl *InitFn = CE->getDirectCallee();
813 if (InitFn)
814 CheckForWrongSidedCall(InitFn);
815 Base::VisitCallExpr(CE);
816 }
817
818 void VisitCXXConstructExpr(const CXXConstructExpr *CE) {
819 const CXXConstructorDecl *Ctor = CE->getConstructor();
820 if (Ctor) {
821 CheckForWrongSidedCall(Ctor);
822 for (auto *I : Ctor->inits())
823 Visit(I->getInit());
824 }
825 Base::VisitCXXConstructExpr(CE);
826 }
827
828 void VisitCXXDefaultArgExpr(const CXXDefaultArgExpr *E) {
829 Visit(E->getExpr());
830 }
831
832 void VisitCXXDefaultInitExpr(const CXXDefaultInitExpr *E) {
833 Visit(E->getExpr());
834 }
835 };
836 GlobVarInitChecker Checker(*this, VD);
837 Checker.Visit(Init);
838 }
839}
840
842 const FunctionDecl *Callee) {
843 FunctionDecl *Caller = SemaRef.getCurFunctionDecl(/*AllowLambda=*/true);
844 if (!Caller)
845 return;
846
847 if (!isImplicitHostDeviceFunction(Callee))
848 return;
849
850 CUDAFunctionTarget CallerTarget = IdentifyTarget(Caller);
851
852 // Record whether an implicit host device function is used on device side.
853 if (CallerTarget != CUDAFunctionTarget::Device &&
854 CallerTarget != CUDAFunctionTarget::Global &&
855 (CallerTarget != CUDAFunctionTarget::HostDevice ||
857 !getASTContext().CUDAImplicitHostDeviceFunUsedByDevice.count(Caller))))
858 return;
859
861}
862
863// With -fcuda-host-device-constexpr, an unattributed constexpr function is
864// treated as implicitly __host__ __device__, unless:
865// * it is a variadic function (device-side variadic functions are not
866// allowed), or
867// * a __device__ function with this signature was already declared, in which
868// case in which case we output an error, unless the __device__ decl is in a
869// system header, in which case we leave the constexpr function unattributed.
870//
871// In addition, all function decls are treated as __host__ __device__ when
872// ForceHostDeviceDepth > 0 (corresponding to code within a
873// #pragma clang force_cuda_host_device_begin/end
874// pair).
876 const LookupResult &Previous) {
877 assert(getLangOpts().CUDA && "Should only be called during CUDA compilation");
878
879 if (ForceHostDeviceDepth > 0) {
880 if (!NewD->hasAttr<CUDAHostAttr>())
881 NewD->addAttr(CUDAHostAttr::CreateImplicit(getASTContext()));
882 if (!NewD->hasAttr<CUDADeviceAttr>())
883 NewD->addAttr(CUDADeviceAttr::CreateImplicit(getASTContext()));
884 return;
885 }
886
887 // If a template function has no host/device/global attributes,
888 // make it implicitly host device function.
889 if (getLangOpts().OffloadImplicitHostDeviceTemplates &&
890 !NewD->hasAttr<CUDAHostAttr>() && !NewD->hasAttr<CUDADeviceAttr>() &&
891 !NewD->hasAttr<CUDAGlobalAttr>() &&
894 NewD->addAttr(CUDAHostAttr::CreateImplicit(getASTContext()));
895 NewD->addAttr(CUDADeviceAttr::CreateImplicit(getASTContext()));
896 return;
897 }
898
899 if (!getLangOpts().CUDAHostDeviceConstexpr || !NewD->isConstexpr() ||
900 NewD->isVariadic() || NewD->hasAttr<CUDAHostAttr>() ||
901 NewD->hasAttr<CUDADeviceAttr>() || NewD->hasAttr<CUDAGlobalAttr>())
902 return;
903
904 // Is D a __device__ function with the same signature as NewD, ignoring CUDA
905 // attributes?
906 auto IsMatchingDeviceFn = [&](NamedDecl *D) {
907 if (UsingShadowDecl *Using = dyn_cast<UsingShadowDecl>(D))
908 D = Using->getTargetDecl();
909 FunctionDecl *OldD = D->getAsFunction();
910 return OldD && OldD->hasAttr<CUDADeviceAttr>() &&
911 !OldD->hasAttr<CUDAHostAttr>() &&
912 !SemaRef.IsOverload(NewD, OldD,
913 /* UseMemberUsingDeclRules = */ false,
914 /* ConsiderCudaAttrs = */ false);
915 };
916 auto It = llvm::find_if(Previous, IsMatchingDeviceFn);
917 if (It != Previous.end()) {
918 // We found a __device__ function with the same name and signature as NewD
919 // (ignoring CUDA attrs). This is an error unless that function is defined
920 // in a system header, in which case we simply return without making NewD
921 // host+device.
922 NamedDecl *Match = *It;
923 if (!SemaRef.getSourceManager().isInSystemHeader(Match->getLocation())) {
924 Diag(NewD->getLocation(),
925 diag::err_cuda_unattributed_constexpr_cannot_overload_device)
926 << NewD;
927 Diag(Match->getLocation(),
928 diag::note_cuda_conflicting_device_function_declared_here);
929 }
930 return;
931 }
932
933 NewD->addAttr(CUDAHostAttr::CreateImplicit(getASTContext()));
934 NewD->addAttr(CUDADeviceAttr::CreateImplicit(getASTContext()));
935}
936
937// TODO: `__constant__` memory may be a limited resource for certain targets.
938// A safeguard may be needed at the end of compilation pipeline if
939// `__constant__` memory usage goes beyond limit.
941 // Do not promote dependent variables since the cotr/dtor/initializer are
942 // not determined. Do it after instantiation.
943 if (getLangOpts().CUDAIsDevice && !VD->hasAttr<CUDAConstantAttr>() &&
944 !VD->hasAttr<CUDASharedAttr>() &&
945 (VD->isFileVarDecl() || VD->isStaticDataMember()) &&
946 !IsDependentVar(VD) &&
947 ((VD->isConstexpr() || VD->getType().isConstQualified()) &&
948 HasAllowedCUDADeviceStaticInitializer(*this, VD,
949 CICK_DeviceOrConstant))) {
950 VD->addAttr(CUDAConstantAttr::CreateImplicit(getASTContext()));
951 }
952}
953
955 unsigned DiagID) {
956 assert(getLangOpts().CUDA && "Should only be called during CUDA compilation");
957 FunctionDecl *CurFunContext =
958 SemaRef.getCurFunctionDecl(/*AllowLambda=*/true);
959 SemaDiagnosticBuilder::Kind DiagKind = [&] {
960 if (!CurFunContext)
961 return SemaDiagnosticBuilder::K_Nop;
962 switch (CurrentTarget()) {
965 return SemaDiagnosticBuilder::K_Immediate;
967 // An HD function counts as host code if we're compiling for host, and
968 // device code if we're compiling for device. Defer any errors in device
969 // mode until the function is known-emitted.
970 if (!getLangOpts().CUDAIsDevice)
971 return SemaDiagnosticBuilder::K_Nop;
972 if (SemaRef.IsLastErrorImmediate &&
973 getDiagnostics().getDiagnosticIDs()->isNote(DiagID))
974 return SemaDiagnosticBuilder::K_Immediate;
975 if (isImplicitHDExplicitInstantiation(CurFunContext))
976 return SemaDiagnosticBuilder::K_Deferred;
977 return (SemaRef.getEmissionStatus(CurFunContext) ==
979 ? SemaDiagnosticBuilder::K_ImmediateWithCallStack
980 : SemaDiagnosticBuilder::K_Deferred;
981 default:
982 return SemaDiagnosticBuilder::K_Nop;
983 }
984 }();
985 return SemaDiagnosticBuilder(DiagKind, Loc, DiagID, CurFunContext, SemaRef);
986}
987
989 unsigned DiagID) {
990 assert(getLangOpts().CUDA && "Should only be called during CUDA compilation");
991 FunctionDecl *CurFunContext =
992 SemaRef.getCurFunctionDecl(/*AllowLambda=*/true);
993 SemaDiagnosticBuilder::Kind DiagKind = [&] {
994 if (!CurFunContext)
995 return SemaDiagnosticBuilder::K_Nop;
996 switch (CurrentTarget()) {
998 return SemaDiagnosticBuilder::K_Immediate;
1000 // An HD function counts as host code if we're compiling for host, and
1001 // device code if we're compiling for device. Defer any errors in device
1002 // mode until the function is known-emitted.
1003 if (getLangOpts().CUDAIsDevice)
1004 return SemaDiagnosticBuilder::K_Nop;
1005 if (SemaRef.IsLastErrorImmediate &&
1006 getDiagnostics().getDiagnosticIDs()->isNote(DiagID))
1007 return SemaDiagnosticBuilder::K_Immediate;
1008 return (SemaRef.getEmissionStatus(CurFunContext) ==
1010 ? SemaDiagnosticBuilder::K_ImmediateWithCallStack
1011 : SemaDiagnosticBuilder::K_Deferred;
1012 default:
1013 return SemaDiagnosticBuilder::K_Nop;
1014 }
1015 }();
1016 return SemaDiagnosticBuilder(DiagKind, Loc, DiagID, CurFunContext, SemaRef);
1017}
1018
1019bool SemaCUDA::isDeviceVarInit() const {
1022}
1023
1025 assert(getLangOpts().CUDA && "Should only be called during CUDA compilation");
1026 // A default argument is checked where it is used.
1027 if (isa_and_present<ParmVarDecl>(
1028 SemaRef.currentEvaluationContext().ManglingContextDecl))
1029 return;
1030
1031 if (SemaRef.getCurFunctionDecl(/*AllowLambda=*/true)) {
1032 DiagIfDeviceCode(Loc, diag::err_cuda_device_rtti) << Op << CurrentTarget();
1033 return;
1034 }
1035
1036 // Outside a function, only the initializer of a device variable is device
1037 // code. A default member initializer is checked where it is used.
1038 if (isDeviceVarInit())
1039 Diag(Loc, diag::err_cuda_device_rtti_var_init) << Op;
1040}
1041
1042namespace {
1043/// Finds a use of RTTI in a default argument or default member initializer.
1044struct RTTIUseFinder : ConstDynamicRecursiveASTVisitor {
1045 const Expr *Use = nullptr;
1046
1047 RTTIUseFinder() {
1048 // Look into nested default arguments and default member initializers.
1049 ShouldVisitImplicitCode = true;
1050 // Lambda bodies are checked as functions of their own.
1051 ShouldVisitLambdaBody = false;
1052 }
1053
1054 bool VisitCXXTypeidExpr(const CXXTypeidExpr *E) override {
1055 Use = E;
1056 return false;
1057 }
1058
1059 bool VisitCXXDynamicCastExpr(const CXXDynamicCastExpr *E) override {
1060 // As with -fno-rtti, upcasts and dynamic_cast to void* don't use RTTI.
1061 QualType DestTy = E->getType();
1062 if (E->getCastKind() != CK_Dynamic ||
1063 (DestTy->isPointerType() && DestTy->getPointeeType()->isVoidType()))
1064 return true;
1065 Use = E;
1066 return false;
1067 }
1068};
1069} // namespace
1070
1072 SourceLocation UseLoc) {
1073 assert(getLangOpts().CUDA && "Should only be called during CUDA compilation");
1074 assert((isa<FieldDecl, ParmVarDecl>(D)) &&
1075 "Expected a default member initializer or default argument");
1076 const FunctionDecl *CurFn = SemaRef.getCurFunctionDecl(/*AllowLambda=*/true);
1077 if (!CurFn && !isDeviceVarInit())
1078 return;
1079 RTTIUseFinder Finder;
1080 Finder.TraverseStmt(Init);
1081 const Expr *Use = Finder.Use;
1082 if (!Use)
1083 return;
1084 // An initializer can be built more than once for the same use.
1085 if (!RTTICheckedDefaultInits.insert({D, CurFn}).second)
1086 return;
1087
1088 StringRef Op = isa<CXXTypeidExpr>(Use) ? "typeid" : "dynamic_cast";
1089 bool IsDefaultArg = isa<ParmVarDecl>(D);
1090 if (!CurFn) {
1091 Diag(Use->getBeginLoc(), diag::err_cuda_device_rtti_var_init) << Op;
1092 Diag(UseLoc, diag::note_cuda_device_rtti_default_used_here) << IsDefaultArg;
1093 return;
1094 }
1095 {
1097 DiagIfDeviceCode(Use->getBeginLoc(), diag::err_cuda_device_rtti);
1098 DB << Op << CurrentTarget();
1099 // Let the note below follow the error.
1100 SemaRef.IsLastErrorImmediate = DB.isImmediate();
1101 }
1102 DiagIfDeviceCode(UseLoc, diag::note_cuda_device_rtti_default_used_here)
1103 << IsDefaultArg;
1104}
1105
1107 assert(getLangOpts().CUDA && "Should only be called during CUDA compilation");
1108 assert(Callee && "Callee may not be null.");
1109
1110 const auto &ExprEvalCtx = SemaRef.currentEvaluationContext();
1111 if (ExprEvalCtx.isUnevaluated() || ExprEvalCtx.isConstantEvaluated() ||
1112 ExprEvalCtx.isDiscardedStatementContext())
1113 return true;
1114
1115 // C++ deduction guides participate in overload resolution but are not
1116 // callable functions and are never codegen'ed. Treat them as always
1117 // allowed for CUDA/HIP compatibility checking.
1118 if (isa<CXXDeductionGuideDecl>(Callee))
1119 return true;
1120
1121 // FIXME: Is bailing out early correct here? Should we instead assume that
1122 // the caller is a global initializer?
1123 FunctionDecl *Caller = SemaRef.getCurFunctionDecl(/*AllowLambda=*/true);
1124 if (!Caller)
1125 return true;
1126
1127 // If the caller is known-emitted, mark the callee as known-emitted.
1128 // Otherwise, mark the call in our call graph so we can traverse it later.
1129 bool CallerKnownEmitted = SemaRef.getEmissionStatus(Caller) ==
1131 bool CallerIsImplicitHDExplicitInst =
1133 SemaDiagnosticBuilder::Kind DiagKind = [this, Caller, Callee,
1134 CallerKnownEmitted,
1135 CallerIsImplicitHDExplicitInst] {
1136 switch (IdentifyPreference(Caller, Callee)) {
1137 case CFP_Never:
1138 case CFP_WrongSide:
1139 assert(Caller && "Never/wrongSide calls require a non-null caller");
1140 // If we know the caller will be emitted, we know this wrong-side call
1141 // will be emitted, so it's an immediate error. Otherwise, defer the
1142 // error until we know the caller is emitted.
1143 return (CallerKnownEmitted && !CallerIsImplicitHDExplicitInst)
1144 ? SemaDiagnosticBuilder::K_ImmediateWithCallStack
1145 : SemaDiagnosticBuilder::K_Deferred;
1146 default:
1147 return SemaDiagnosticBuilder::K_Nop;
1148 }
1149 }();
1150
1151 bool IsDeviceKernelCall = Callee == getASTContext().getcudaLaunchDeviceDecl();
1152 bool CallerHD = Caller && Caller->hasAttr<CUDAHostAttr>() &&
1153 Caller->hasAttr<CUDADeviceAttr>();
1154 bool CallerDiscard = SemaRef.getEmissionStatus(Caller) ==
1156 bool RDC = getLangOpts().GPURelocatableDeviceCode;
1157 if (IsDeviceKernelCall && !(CallerHD && CallerDiscard) && !RDC) {
1158 Diag(Loc, diag::err_cuda_device_kernel_launch_require_rdc);
1159 return false;
1160 }
1161
1162 if (DiagKind == SemaDiagnosticBuilder::K_Nop) {
1163 // For -fgpu-rdc, keep track of external kernels used by host functions.
1164 if (getLangOpts().CUDAIsDevice && RDC &&
1165 Callee->hasAttr<CUDAGlobalAttr>() && !Callee->isDefined() &&
1166 (!Caller || (!Caller->getDescribedFunctionTemplate() &&
1167 getASTContext().GetGVALinkageForFunction(Caller) ==
1170 return true;
1171 }
1172
1173 // Avoid emitting this error twice for the same location. Using a hashtable
1174 // like this is unfortunate, but because we must continue parsing as normal
1175 // after encountering a deferred error, it's otherwise very tricky for us to
1176 // ensure that we only emit this deferred error once.
1177 if (!LocsWithCUDACallDiags.insert({Caller, Loc}).second)
1178 return true;
1179
1180 SemaDiagnosticBuilder(DiagKind, Loc, diag::err_ref_bad_target, Caller,
1181 SemaRef)
1182 << IdentifyTarget(Callee) << /*function*/ 0 << Callee
1183 << IdentifyTarget(Caller);
1184 if (!Callee->getBuiltinID())
1185 SemaDiagnosticBuilder(DiagKind, Callee->getLocation(),
1186 diag::note_previous_decl, Caller, SemaRef)
1187 << Callee;
1188 return DiagKind != SemaDiagnosticBuilder::K_Immediate &&
1189 DiagKind != SemaDiagnosticBuilder::K_ImmediateWithCallStack;
1190}
1191
1192// Check the wrong-sided reference capture of lambda for CUDA/HIP.
1193// A lambda function may capture a stack variable by reference when it is
1194// defined and uses the capture by reference when the lambda is called. When
1195// the capture and use happen on different sides, the capture is invalid and
1196// should be diagnosed.
1198 const sema::Capture &Capture) {
1199 // In host compilation we only need to check lambda functions emitted on host
1200 // side. In such lambda functions, a reference capture is invalid only
1201 // if the lambda structure is populated by a device function or kernel then
1202 // is passed to and called by a host function. However that is impossible,
1203 // since a device function or kernel can only call a device function, also a
1204 // kernel cannot pass a lambda back to a host function since we cannot
1205 // define a kernel argument type which can hold the lambda before the lambda
1206 // itself is defined.
1207 if (!getLangOpts().CUDAIsDevice)
1208 return;
1209
1210 // File-scope lambda can only do init captures for global variables, which
1211 // results in passing by value for these global variables.
1212 FunctionDecl *Caller = SemaRef.getCurFunctionDecl(/*AllowLambda=*/true);
1213 if (!Caller)
1214 return;
1215
1216 // In device compilation, we only need to check lambda functions which are
1217 // emitted on device side. For such lambdas, a reference capture is invalid
1218 // only if the lambda structure is populated by a host function then passed
1219 // to and called in a device function or kernel.
1220 bool CalleeIsDevice = Callee->hasAttr<CUDADeviceAttr>();
1221 bool CallerIsHost =
1222 !Caller->hasAttr<CUDAGlobalAttr>() && !Caller->hasAttr<CUDADeviceAttr>();
1223 bool ShouldCheck = CalleeIsDevice && CallerIsHost;
1224 if (!ShouldCheck || !Capture.isReferenceCapture())
1225 return;
1226 auto DiagKind = SemaDiagnosticBuilder::K_Deferred;
1227 if (Capture.isVariableCapture() && !getLangOpts().HIPStdPar) {
1229 diag::err_capture_bad_target, Callee, SemaRef)
1230 << Capture.getVariable();
1231 } else if (Capture.isThisCapture()) {
1232 // Capture of this pointer is allowed since this pointer may be pointing to
1233 // managed memory which is accessible on both device and host sides. It only
1234 // results in invalid memory access if this pointer points to memory not
1235 // accessible on device side.
1237 diag::warn_maybe_capture_bad_target_this_ptr, Callee,
1238 SemaRef);
1239 }
1240}
1241
1243 assert(getLangOpts().CUDA && "Should only be called during CUDA compilation");
1244 if (Method->hasAttr<CUDAHostAttr>() || Method->hasAttr<CUDADeviceAttr>())
1245 return;
1246 Method->addAttr(CUDADeviceAttr::CreateImplicit(getASTContext()));
1247 Method->addAttr(CUDAHostAttr::CreateImplicit(getASTContext()));
1248}
1249
1251 const LookupResult &Previous) {
1252 assert(getLangOpts().CUDA && "Should only be called during CUDA compilation");
1253 CUDAFunctionTarget NewTarget = IdentifyTarget(NewFD);
1254 for (NamedDecl *OldND : Previous) {
1255 FunctionDecl *OldFD = OldND->getAsFunction();
1256 if (!OldFD)
1257 continue;
1258
1259 CUDAFunctionTarget OldTarget = IdentifyTarget(OldFD);
1260 // Don't allow HD and global functions to overload other functions with the
1261 // same signature. We allow overloading based on CUDA attributes so that
1262 // functions can have different implementations on the host and device, but
1263 // HD/global functions "exist" in some sense on both the host and device, so
1264 // should have the same implementation on both sides.
1265 if (NewTarget != OldTarget &&
1266 !SemaRef.IsOverload(NewFD, OldFD, /* UseMemberUsingDeclRules = */ false,
1267 /* ConsiderCudaAttrs = */ false)) {
1268 if ((NewTarget == CUDAFunctionTarget::HostDevice &&
1269 !(getLangOpts().OffloadImplicitHostDeviceTemplates &&
1271 OldTarget == CUDAFunctionTarget::Device)) ||
1272 (OldTarget == CUDAFunctionTarget::HostDevice &&
1273 !(getLangOpts().OffloadImplicitHostDeviceTemplates &&
1275 NewTarget == CUDAFunctionTarget::Device)) ||
1276 (NewTarget == CUDAFunctionTarget::Global) ||
1277 (OldTarget == CUDAFunctionTarget::Global)) {
1278 Diag(NewFD->getLocation(), diag::err_cuda_ovl_target)
1279 << NewTarget << NewFD->getDeclName() << OldTarget << OldFD;
1280 Diag(OldFD->getLocation(), diag::note_previous_declaration);
1281 NewFD->setInvalidDecl();
1282 break;
1283 }
1284 if ((NewTarget == CUDAFunctionTarget::Host &&
1285 OldTarget == CUDAFunctionTarget::Device) ||
1286 (NewTarget == CUDAFunctionTarget::Device &&
1287 OldTarget == CUDAFunctionTarget::Host)) {
1288 Diag(NewFD->getLocation(), diag::warn_offload_incompatible_redeclare)
1289 << NewTarget << OldTarget;
1290 Diag(OldFD->getLocation(), diag::note_previous_declaration);
1291 }
1292 }
1293 }
1294}
1295
1296template <typename AttrTy>
1298 const FunctionDecl &TemplateFD) {
1299 if (FD->hasAttr<AttrTy>())
1300 return;
1301 if (AttrTy *Attribute = TemplateFD.getAttr<AttrTy>()) {
1302 AttrTy *Clone = Attribute->clone(S.Context);
1303 Clone->setInherited(true);
1304 FD->addAttr(Clone);
1305 }
1306}
1307
1309 const FunctionTemplateDecl &TD) {
1310 const FunctionDecl &TemplateFD = *TD.getTemplatedDecl();
1314}
1315
1317 if (getLangOpts().OffloadViaLLVM)
1318 return "__llvmPushCallConfiguration";
1319
1320 if (getLangOpts().HIP)
1321 return getLangOpts().HIPUseNewLaunchAPI ? "__hipPushCallConfiguration"
1322 : "hipConfigureCall";
1323
1324 // New CUDA kernel launch sequence.
1325 if (CudaFeatureEnabled(getASTContext().getTargetInfo().getSDKVersion(),
1327 return "__cudaPushCallConfiguration";
1328
1329 // Legacy CUDA kernel configuration call
1330 return "cudaConfigureCall";
1331}
1332
1334 return "cudaGetParameterBuffer";
1335}
1336
1338 return "cudaLaunchDevice";
1339}
1340
1341// Record any local constexpr variables that are passed one way on the host
1342// and another on the device.
1344 MultiExprArg Arguments, OverloadCandidateSet &Candidates) {
1345 sema::LambdaScopeInfo *LambdaInfo = SemaRef.getCurLambda();
1346 if (!LambdaInfo)
1347 return;
1348
1349 for (unsigned I = 0; I < Arguments.size(); ++I) {
1350 auto *DeclRef = dyn_cast<DeclRefExpr>(Arguments[I]);
1351 if (!DeclRef)
1352 continue;
1353 auto *Variable = dyn_cast<VarDecl>(DeclRef->getDecl());
1354 if (!Variable || !Variable->isLocalVarDecl() || !Variable->isConstexpr())
1355 continue;
1356
1357 bool HostByValue = false, HostByRef = false;
1358 bool DeviceByValue = false, DeviceByRef = false;
1359
1360 for (OverloadCandidate &Candidate : Candidates) {
1361 FunctionDecl *Callee = Candidate.Function;
1362 if (!Callee || I >= Callee->getNumParams())
1363 continue;
1364
1368 continue;
1369
1370 bool CoversHost = (Target == CUDAFunctionTarget::Host ||
1372 bool CoversDevice = (Target == CUDAFunctionTarget::Device ||
1374
1375 bool IsRef = Callee->getParamDecl(I)->getType()->isReferenceType();
1376 HostByValue |= CoversHost && !IsRef;
1377 HostByRef |= CoversHost && IsRef;
1378 DeviceByValue |= CoversDevice && !IsRef;
1379 DeviceByRef |= CoversDevice && IsRef;
1380 }
1381
1382 if ((HostByValue && DeviceByRef) || (HostByRef && DeviceByValue))
1383 LambdaInfo->CUDAPotentialODRUsedVars.insert(Variable);
1384 }
1385}
static bool hasImplicitAttr(const ValueDecl *D)
Defines the clang::ASTContext interface.
Defines the clang::Expr interface and subclasses for C++ expressions.
FormatToken * Previous
The previous token in the unwrapped line.
Defines the clang::Preprocessor interface.
static bool resolveCalleeCUDATargetConflict(CUDAFunctionTarget Target1, CUDAFunctionTarget Target2, CUDAFunctionTarget *ResolvedTarget)
When an implicitly-declared special member has to invoke more than one base/field special member,...
Definition SemaCUDA.cpp:443
static bool hasAttr(const Decl *D, bool IgnoreImplicitAttr)
Definition SemaCUDA.cpp:187
static void copyAttrIfPresent(Sema &S, FunctionDecl *FD, const FunctionDecl &TemplateFD)
static bool hasExplicitAttr(const VarDecl *D)
Definition SemaCUDA.cpp:33
This file declares semantic analysis for CUDA constructs.
FunctionDecl * getcudaGetParameterBufferDecl()
QualType getBaseElementType(const ArrayType *VAT) const
Return the innermost element type of an array type.
llvm::SetVector< const ValueDecl * > CUDAExternalDeviceDeclODRUsedByHost
Keep track of CUDA/HIP external kernels or device variables ODR-used by host code.
llvm::DenseSet< const FunctionDecl * > CUDAImplicitHostDeviceFunUsedByDevice
Keep track of CUDA/HIP implicit host device functions used on device side in device compilation.
FunctionDecl * getcudaConfigureCallDecl()
FunctionDecl * getcudaLaunchDeviceDecl()
Attr - This represents one attribute.
Definition Attr.h:46
Represents a base class of a C++ class.
Definition DeclCXX.h:146
Represents a call to a C++ constructor.
Definition ExprCXX.h:1553
CXXConstructorDecl * getConstructor() const
Get the constructor that this expression will (ultimately) call.
Definition ExprCXX.h:1616
Represents a C++ constructor within a class.
Definition DeclCXX.h:2642
Represents a C++ base or member initializer.
Definition DeclCXX.h:2407
A default argument (C++ [dcl.fct.default]).
Definition ExprCXX.h:1275
A use of a default initializer in a constructor or in aggregate initialization.
Definition ExprCXX.h:1382
Expr * getExpr()
Get the initialization expression that will be used.
Definition ExprCXX.cpp:1137
Represents a C++ destructor within a class.
Definition DeclCXX.h:2907
Represents a static or instance method of a struct/union/class.
Definition DeclCXX.h:2150
const CXXRecordDecl * getParent() const
Return the parent of this method declaration, which is the class in which this method is defined.
Definition DeclCXX.h:2293
The null pointer literal (C++11 [lex.nullptr])
Definition ExprCXX.h:773
Represents a C++ struct/union/class.
Definition DeclCXX.h:258
base_class_range bases()
Definition DeclCXX.h:609
base_class_range vbases()
Definition DeclCXX.h:626
bool isAbstract() const
Determine whether this class has a pure virtual function.
Definition DeclCXX.h:1231
bool isDynamicClass() const
Definition DeclCXX.h:575
A C++ typeid expression (C++ [expr.typeid]), which gets the type_info that corresponds to the supplie...
Definition ExprCXX.h:853
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
Definition Expr.h:3012
FunctionDecl * getDirectCallee()
If the callee is a FunctionDecl, return it. Otherwise return null.
Definition Expr.h:3195
CastKind getCastKind() const
Definition Expr.h:3789
ConstEvaluatedExprVisitor - This class visits 'const Expr *'s.
bool isDependentContext() const
Determines whether this context is dependent on a template parameter.
DeclContext * getLexicalParent()
getLexicalParent - Returns the containing lexical DeclContext.
Definition DeclBase.h:2138
A reference to a declared variable, function, enum, etc.
Definition Expr.h:1315
ValueDecl * getDecl()
Definition Expr.h:1383
SourceLocation getLocation() const
Definition Expr.h:1391
Decl - This represents one declaration (or definition), e.g.
Definition DeclBase.h:86
T * getAttr() const
Definition DeclBase.h:583
bool hasAttrs() const
Definition DeclBase.h:528
void addAttr(Attr *A)
bool isImplicit() const
isImplicit - Indicates whether the declaration was implicitly generated by the implementation.
Definition DeclBase.h:603
void setInvalidDecl(bool Invalid=true)
setInvalidDecl - Indicates the Decl had a semantic error.
Definition DeclBase.cpp:178
FunctionDecl * getAsFunction() LLVM_READONLY
Returns the function itself, or the templated function if this is a function template.
Definition DeclBase.cpp:273
bool isInvalidDecl() const
Definition DeclBase.h:598
SourceLocation getLocation() const
Definition DeclBase.h:449
DeclContext * getDeclContext()
Definition DeclBase.h:458
AttrVec & getAttrs()
Definition DeclBase.h:534
bool hasAttr() const
Definition DeclBase.h:587
This represents one expression.
Definition Expr.h:114
QualType getType() const
Definition Expr.h:146
Represents a member of a struct/union/class.
Definition Decl.h:3311
Represents a function declaration or definition.
Definition Decl.h:2071
bool hasTrivialBody() const
Returns whether the function has a trivial body that does not require any specific codegen.
Definition Decl.cpp:3210
bool isFunctionTemplateSpecialization() const
Determine whether this function is a function template specialization.
Definition Decl.cpp:4262
FunctionTemplateDecl * getDescribedFunctionTemplate() const
Retrieves the function template that is described by this function declaration.
Definition Decl.cpp:4250
bool isTrivial() const
Whether this function is "trivial" in some specialized C++ senses.
Definition Decl.h:2516
bool isVariadic() const
Whether this function is variadic.
Definition Decl.cpp:3132
bool isTemplateInstantiation() const
Determines if the given function was instantiated from a function template.
Definition Decl.cpp:4314
bool isConstexpr() const
Whether this is a (C++11) constexpr function or constexpr constructor.
Definition Decl.h:2609
bool isConsteval() const
Definition Decl.h:2621
bool isUserProvided() const
True if this method is user-declared and was not deleted or defaulted on its first declaration.
Definition Decl.h:2549
bool isImplicitHDExplicitInstantiation() const
True if both host and device are implicit attributes and this is (or is a member of) an explicit temp...
Definition Decl.cpp:4571
unsigned getNumParams() const
Return the number of parameters this function must have based on its FunctionType.
Definition Decl.cpp:3881
bool isDefined(const FunctionDecl *&Definition, bool CheckForPendingFriendDefinition=false) const
Returns true if the function has a definition that does not need to be instantiated.
Definition Decl.cpp:3246
Declaration of a template function.
FunctionDecl * getTemplatedDecl() const
Get the underlying function declaration of the template.
static IntegerLiteral * Create(const ASTContext &C, const llvm::APInt &V, QualType type, SourceLocation l)
Returns a new integer literal with value 'V' and type 'type'.
Definition Expr.cpp:985
Represents the results of name lookup.
Definition Lookup.h:147
This represents a decl that may have a name.
Definition Decl.h:276
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
Definition Decl.h:342
OverloadCandidateSet - A set of overload candidates, used in C++ overload resolution (C++ 13....
Definition Overload.h:1164
ParsedAttr - Represents a syntactic attribute.
Definition ParsedAttr.h:119
A (possibly-)qualified type.
Definition TypeBase.h:938
Qualifiers getQualifiers() const
Retrieve the set of qualifiers applied to this type.
Definition TypeBase.h:8486
bool isConstQualified() const
Determine whether this type is const-qualified.
Definition TypeBase.h:8519
LangAS getAddressSpace() const
Definition TypeBase.h:572
field_range fields() const
Definition Decl.h:4679
decl_type * getFirstDecl()
Return the first declaration of this declaration or itself if this is the only declaration.
Scope - A scope is a transient data structure that is used while parsing the program.
Definition Scope.h:41
A generic diagnostic builder for errors which may or may not be deferred.
Definition SemaBase.h:111
SemaBase(Sema &S)
Definition SemaBase.cpp:7
ASTContext & getASTContext() const
Definition SemaBase.cpp:9
Sema & SemaRef
Definition SemaBase.h:40
const LangOptions & getLangOpts() const
Definition SemaBase.cpp:11
DiagnosticsEngine & getDiagnostics() const
Definition SemaBase.cpp:10
SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID)
Emit a diagnostic.
Definition SemaBase.cpp:61
std::string getLaunchDeviceFuncName() const
Return the name of the device kernel launch function.
void PushForceHostDevice()
Increments our count of the number of times we've seen a pragma forcing functions to be host device.
Definition SemaCUDA.cpp:41
void checkAllowedInitializer(VarDecl *VD)
Definition SemaCUDA.cpp:745
void RecordImplicitHostDeviceFuncUsedByDevice(const FunctionDecl *FD)
Record FD if it is a CUDA/HIP implicit host device function used on device side in device compilation...
Definition SemaCUDA.cpp:841
std::string getConfigureFuncName() const
Returns the name of the launch configuration function.
bool PopForceHostDevice()
Decrements our count of the number of times we've seen a pragma forcing functions to be host device.
Definition SemaCUDA.cpp:46
CUDAFunctionTarget IdentifyTarget(const FunctionDecl *D, bool IgnoreImplicitHDAttr=false)
Determines whether the given function is a CUDA device/host/kernel/etc.
Definition SemaCUDA.cpp:212
static bool isImplicitHDExplicitInstantiation(const FunctionDecl *FD)
Null-tolerant wrapper for FunctionDecl::isImplicitHDExplicitInstantiation.
Definition SemaCUDA.cpp:406
void maybeAddHostDeviceAttrs(FunctionDecl *FD, const LookupResult &Previous)
May add implicit CUDAHostAttr and CUDADeviceAttr attributes to FD, depending on FD and the current co...
Definition SemaCUDA.cpp:875
ExprResult ActOnExecConfigExpr(Scope *S, SourceLocation LLLLoc, MultiExprArg ExecConfig, SourceLocation GGGLoc)
Definition SemaCUDA.cpp:54
bool isEmptyConstructor(SourceLocation Loc, CXXConstructorDecl *CD)
Definition SemaCUDA.cpp:599
std::string getGetParameterBufferFuncName() const
Return the name of the parameter buffer allocation function for the device kernel launch.
bool isEmptyDestructor(SourceLocation Loc, CXXDestructorDecl *CD)
Definition SemaCUDA.cpp:637
void checkTargetOverload(FunctionDecl *NewFD, const LookupResult &Previous)
Check whether NewFD is a valid overload for CUDA.
CUDAFunctionTarget CurrentTarget()
Gets the CUDA target for the current context.
Definition SemaCUDA.h:162
SemaDiagnosticBuilder DiagIfHostCode(SourceLocation Loc, unsigned DiagID)
Creates a SemaDiagnosticBuilder that emits the diagnostic if the current context is "used as host cod...
Definition SemaCUDA.cpp:988
bool inferTargetForImplicitSpecialMember(CXXRecordDecl *ClassDecl, CXXSpecialMemberKind CSM, CXXMethodDecl *MemberDecl, bool ConstRHS, bool Diagnose)
Given a implicit special member, infer its CUDA target from the calls it needs to make to underlying ...
Definition SemaCUDA.cpp:463
struct clang::SemaCUDA::CUDATargetContext CurCUDATargetCtx
CUDATargetContextKind
Defines kinds of CUDA global host/device context where a function may be called.
Definition SemaCUDA.h:139
@ CTCK_InitGlobalVar
Unknown context.
Definition SemaCUDA.h:141
SemaDiagnosticBuilder DiagIfDeviceCode(SourceLocation Loc, unsigned DiagID)
Creates a SemaDiagnosticBuilder that emits the diagnostic if the current context is "used as device c...
Definition SemaCUDA.cpp:954
llvm::DenseSet< FunctionDeclAndLoc > LocsWithCUDACallDiags
FunctionDecls and SourceLocations for which CheckCall has emitted a (maybe deferred) "bad call" diagn...
Definition SemaCUDA.h:73
bool CheckCall(SourceLocation Loc, FunctionDecl *Callee)
Check whether we're allowed to call Callee from the current context.
void inheritTargetAttrs(FunctionDecl *FD, const FunctionTemplateDecl &TD)
Copies target attributes from the template TD to the function FD.
static bool isImplicitHostDeviceFunction(const FunctionDecl *D)
Definition SemaCUDA.cpp:400
void CheckLambdaCapture(CXXMethodDecl *D, const sema::Capture &Capture)
void MaybeAddConstantAttr(VarDecl *VD)
May add implicit CUDAConstantAttr attribute to VD, depending on VD and current compilation settings.
Definition SemaCUDA.cpp:940
void EraseUnwantedMatches(const FunctionDecl *Caller, llvm::SmallVectorImpl< std::pair< DeclAccessPair, FunctionDecl * > > &Matches)
Finds a function in Matches with highest calling priority from Caller context and erases all function...
Definition SemaCUDA.cpp:410
SemaCUDA(Sema &S)
Definition SemaCUDA.cpp:31
void checkRTTIInDefaultInit(const ValueDecl *D, const Expr *Init, SourceLocation UseLoc)
Diagnoses a use of RTTI in Init, the default argument or default member initializer of D if it is use...
void SetLambdaAttrs(CXXMethodDecl *Method)
Set device or host device attributes on the given lambda operator() method.
void checkRTTIUse(SourceLocation Loc, StringRef Op)
Diagnoses a use of RTTI at Loc if it is in device function or the initializer of a device variable,...
CUDAFunctionPreference IdentifyPreference(const FunctionDecl *Caller, const FunctionDecl *Callee)
Identifies relative preference of a given Caller/Callee combination, based on their host/device attri...
Definition SemaCUDA.cpp:312
void recordPotentialODRUsedVariable(MultiExprArg Args, OverloadCandidateSet &CandidateSet)
Record variables that are potentially ODR-used in CUDA/HIP.
@ CVT_Host
Emitted on device side with a shadow variable on host side.
Definition SemaCUDA.h:130
@ CVT_Both
Emitted on host side only.
Definition SemaCUDA.h:131
@ CVT_Unified
Emitted on both sides with different addresses.
Definition SemaCUDA.h:132
A RAII object to temporarily push a declaration context.
Definition Sema.h:3634
SpecialMemberOverloadResult - The overloading result for a special member function.
Definition Sema.h:9468
CXXMethodDecl * getMethod() const
Definition Sema.h:9480
Sema - This implements semantic analysis and AST building for C.
Definition Sema.h:863
ASTContext & Context
Definition Sema.h:1332
Encodes a location in the source.
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Stmt.cpp:355
bool isUnion() const
Definition Decl.h:4079
bool isVoidType() const
Definition TypeBase.h:9068
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
Definition Type.h:26
bool isPointerType() const
Definition TypeBase.h:8683
bool isReferenceType() const
Definition TypeBase.h:8707
bool isCUDADeviceBuiltinSurfaceType() const
Check if the type is the CUDA device builtin surface type.
Definition Type.cpp:5654
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
Definition Type.cpp:885
bool isDependentType() const
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
Definition TypeBase.h:2863
bool isCUDADeviceBuiltinTextureType() const
Check if the type is the CUDA device builtin texture type.
Definition Type.cpp:5663
Represents a shadow declaration implicitly introduced into a scope by a (resolved) using-declaration ...
Definition DeclCXX.h:3429
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition Decl.h:714
QualType getType() const
Definition Decl.h:725
Represents a variable declaration or definition.
Definition Decl.h:934
bool isConstexpr() const
Whether this variable is (C++11) constexpr.
Definition Decl.h:1606
bool hasInit() const
Definition Decl.cpp:2384
bool isStaticDataMember() const
Determines whether this is a static data member.
Definition Decl.h:1308
bool hasGlobalStorage() const
Returns true for all variables that do not have local storage.
Definition Decl.h:1249
bool isFileVarDecl() const
Returns true for file scoped variable declaration.
Definition Decl.h:1367
const Expr * getInit() const
Definition Decl.h:1393
ValueDecl * getVariable() const
Definition ScopeInfo.h:676
bool isVariableCapture() const
Definition ScopeInfo.h:651
SourceLocation getLocation() const
Retrieve the location at which this variable was captured.
Definition ScopeInfo.h:687
bool isThisCapture() const
Definition ScopeInfo.h:650
bool isReferenceCapture() const
Definition ScopeInfo.h:656
llvm::SmallPtrSet< VarDecl *, 4 > CUDAPotentialODRUsedVars
Variables that are potentially ODR-used in CUDA/HIP.
Definition ScopeInfo.h:956
Defines the clang::TargetInfo interface.
Top level wrappers for InstallAPI frontend operations.
@ Match
This is not an overload because the signature exactly matches an existing declaration.
Definition Sema.h:824
bool isa(CodeGen::Address addr)
Definition Address.h:330
@ GVA_StrongExternal
Definition Linkage.h:76
CUDAFunctionTarget
Definition Cuda.h:65
DynamicRecursiveASTVisitorBase< true > ConstDynamicRecursiveASTVisitor
MutableArrayRef< Expr * > MultiExprArg
Definition Ownership.h:259
bool CudaFeatureEnabled(llvm::VersionTuple, CudaFeature)
Definition Cuda.cpp:119
ExprResult ExprError()
Definition Ownership.h:265
@ CUDA_USES_NEW_LAUNCH
Definition Cuda.h:82
CXXSpecialMemberKind
Kinds of C++ special members.
Definition Decl.h:2031
@ VK_LValue
An l-value expression is a reference to an object with independent storage.
Definition Specifiers.h:143
ActionResult< Expr * > ExprResult
Definition Ownership.h:249
OverloadCandidate - A single candidate in an overload set (C++ 13.3).
Definition Overload.h:937
SemaCUDA::CUDATargetContext SavedCtx
Definition SemaCUDA.h:155
CUDATargetContextRAII(SemaCUDA &S_, SemaCUDA::CUDATargetContextKind K, Decl *D)
Definition SemaCUDA.cpp:194
CUDATargetContextKind Kind
Definition SemaCUDA.h:149