Author: Ambrose Leeb Date: 2026-11-18T19:58:14+01:00 New Revision: ed262c3672b697eb629c9db9fb6e0f11d418507c
URL: https://github.com/llvm/llvm-project/commit/ed262c3672b697eb629c9db9fb6e0f11d418507c DIFF: https://github.com/llvm/llvm-project/commit/ed262c3672b697eb629c9db9fb6e0f11d418507c.diff LOG: [Clang] [CUDA] Support ADL kernel launches (#240947) There are a few places where the parser checks if an identifier is the callee of a function call by looking at the next token and checking if it is a '('. This meant that kernel launches (where the next token is '<<<' instead) were incorrectly not being treated as calls sometimes; in particular, this led to ADL not functioning correctly with kernels (https://godbolt.org/z/zbr9fPn8G). This patch fixes that by checking for '<<<' alongside '(' where relevant. Fixes #45327. Assisted-by: Codex Added: clang/test/CodeGenCUDA/kernel-call-adl.cu clang/test/SemaCUDA/kernel-call-adl.cu Modified: clang/docs/ReleaseNotes.md clang/include/clang/AST/ExprCXX.h clang/include/clang/Parse/Parser.h clang/include/clang/Sema/Sema.h clang/lib/AST/ExprCXX.cpp clang/lib/Parse/ParseExpr.cpp clang/lib/Parse/ParseExprCXX.cpp clang/lib/Parse/ParseOpenACC.cpp clang/lib/Sema/SemaCodeComplete.cpp clang/lib/Sema/SemaDecl.cpp clang/lib/Sema/SemaExpr.cpp clang/lib/Sema/SemaExprObjC.cpp clang/lib/Sema/SemaStmtAsm.cpp Removed: ################################################################################ diff --git a/clang/docs/ReleaseNotes.md b/clang/docs/ReleaseNotes.md index baa1b96357aaf5..aab88904167abc 100644 --- a/clang/docs/ReleaseNotes.md +++ b/clang/docs/ReleaseNotes.md @@ -1501,6 +1501,9 @@ documentation](CIR/index.md) for more information regarding ClangIR's status and #### CUDA Support +- Fixed argument-dependent lookup for CUDA and HIP kernel launches, including + calls to kernels declared as hidden friends. (#GH45327) + - Fixed missing diagnostics for wrong-side functions reached through constructor and member initializers, as well as inherited constructors. (#GH118415) diff --git a/clang/include/clang/AST/ExprCXX.h b/clang/include/clang/AST/ExprCXX.h index af1d3be39004e6..e648bdaef5d98a 100644 --- a/clang/include/clang/AST/ExprCXX.h +++ b/clang/include/clang/AST/ExprCXX.h @@ -246,17 +246,17 @@ class CUDAKernelCallExpr final : public CallExpr { CUDAKernelCallExpr(Expr *Fn, CallExpr *Config, ArrayRef<Expr *> Args, QualType Ty, ExprValueKind VK, SourceLocation RP, - FPOptionsOverride FPFeatures, unsigned MinNumArgs); + FPOptionsOverride FPFeatures, unsigned MinNumArgs, + ADLCallKind UsesADL); CUDAKernelCallExpr(unsigned NumArgs, bool HasFPFeatures, EmptyShell Empty); public: - static CUDAKernelCallExpr *Create(const ASTContext &Ctx, Expr *Fn, - CallExpr *Config, ArrayRef<Expr *> Args, - QualType Ty, ExprValueKind VK, - SourceLocation RP, - FPOptionsOverride FPFeatures, - unsigned MinNumArgs = 0); + static CUDAKernelCallExpr * + Create(const ASTContext &Ctx, Expr *Fn, CallExpr *Config, + ArrayRef<Expr *> Args, QualType Ty, ExprValueKind VK, + SourceLocation RP, FPOptionsOverride FPFeatures, + unsigned MinNumArgs = 0, ADLCallKind UsesADL = NotADL); static CUDAKernelCallExpr *CreateEmpty(const ASTContext &Ctx, unsigned NumArgs, bool HasFPFeatures, diff --git a/clang/include/clang/Parse/Parser.h b/clang/include/clang/Parse/Parser.h index 5c1cf9b687291e..946f63765ca388 100644 --- a/clang/include/clang/Parse/Parser.h +++ b/clang/include/clang/Parse/Parser.h @@ -4124,8 +4124,9 @@ class Parser : public CodeCompletionHandler { /// suffix. bool isPostfixExpressionSuffixStart() { tok::TokenKind K = Tok.getKind(); - return (K == tok::l_square || K == tok::l_paren || K == tok::period || - K == tok::arrow || K == tok::plusplus || K == tok::minusminus); + return (K == tok::l_square || K == tok::l_paren || K == tok::lesslessless || + K == tok::period || K == tok::arrow || K == tok::plusplus || + K == tok::minusminus); } /// Once the leading part of a postfix-expression is parsed, this diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h index bc8793c4b7a533..8e9e7e7dd1242d 100644 --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -7366,7 +7366,7 @@ class Sema final : public SemaBase { ExprResult ActOnIdExpression(Scope *S, CXXScopeSpec &SS, SourceLocation TemplateKWLoc, UnqualifiedId &Id, - bool HasTrailingLParen, bool IsAddressOfOperand, + bool IsCall, bool IsAddressOfOperand, CorrectionCandidateCallback *CCC = nullptr, bool IsInlineAsmIdentifier = false); @@ -7429,7 +7429,7 @@ class Sema final : public SemaBase { const TemplateArgumentListInfo *TemplateArgs = nullptr); bool UseArgumentDependentLookup(const CXXScopeSpec &SS, const LookupResult &R, - bool HasTrailingLParen); + bool IsCall); /// BuildQualifiedDeclarationNameExpr - Build a C++ qualified /// declaration name, generally during template instantiation. diff --git a/clang/lib/AST/ExprCXX.cpp b/clang/lib/AST/ExprCXX.cpp index 497957a374f0d5..1db85437db2a50 100644 --- a/clang/lib/AST/ExprCXX.cpp +++ b/clang/lib/AST/ExprCXX.cpp @@ -1994,9 +1994,9 @@ CUDAKernelCallExpr::CUDAKernelCallExpr(Expr *Fn, CallExpr *Config, ArrayRef<Expr *> Args, QualType Ty, ExprValueKind VK, SourceLocation RP, FPOptionsOverride FPFeatures, - unsigned MinNumArgs) + unsigned MinNumArgs, ADLCallKind UsesADL) : CallExpr(CUDAKernelCallExprClass, Fn, /*PreArgs=*/Config, Args, Ty, VK, - RP, FPFeatures, MinNumArgs, NotADL) {} + RP, FPFeatures, MinNumArgs, UsesADL) {} CUDAKernelCallExpr::CUDAKernelCallExpr(unsigned NumArgs, bool HasFPFeatures, EmptyShell Empty) @@ -2007,7 +2007,7 @@ CUDAKernelCallExpr * CUDAKernelCallExpr::Create(const ASTContext &Ctx, Expr *Fn, CallExpr *Config, ArrayRef<Expr *> Args, QualType Ty, ExprValueKind VK, SourceLocation RP, FPOptionsOverride FPFeatures, - unsigned MinNumArgs) { + unsigned MinNumArgs, ADLCallKind UsesADL) { // Allocate storage for the trailing objects of CallExpr. unsigned NumArgs = std::max<unsigned>(Args.size(), MinNumArgs); unsigned SizeOfTrailingObjects = CallExpr::sizeOfTrailingObjects( @@ -2016,8 +2016,8 @@ CUDAKernelCallExpr::Create(const ASTContext &Ctx, Expr *Fn, CallExpr *Config, Ctx.Allocate(sizeToAllocateForCallExprSubclass<CUDAKernelCallExpr>( SizeOfTrailingObjects), alignof(CUDAKernelCallExpr)); - return new (Mem) - CUDAKernelCallExpr(Fn, Config, Args, Ty, VK, RP, FPFeatures, MinNumArgs); + return new (Mem) CUDAKernelCallExpr(Fn, Config, Args, Ty, VK, RP, FPFeatures, + MinNumArgs, UsesADL); } CUDAKernelCallExpr *CUDAKernelCallExpr::CreateEmpty(const ASTContext &Ctx, diff --git a/clang/lib/Parse/ParseExpr.cpp b/clang/lib/Parse/ParseExpr.cpp index 36fc61f8a50bcf..be3d029c09b08c 100644 --- a/clang/lib/Parse/ParseExpr.cpp +++ b/clang/lib/Parse/ParseExpr.cpp @@ -1034,10 +1034,11 @@ Parser::ParseCastExpression(CastParseKind ParseKind, bool isAddressOfOperand, Validator.WantRemainingKeywords = Tok.isNot(tok::r_paren); } Name.setIdentifier(&II, ILoc); - Res = Actions.ActOnIdExpression(getCurScope(), ScopeSpec, TemplateKWLoc, - Name, Tok.is(tok::l_paren), - isAddressOfOperand, &Validator, - /*IsInlineAsmIdentifier=*/false); + Res = + Actions.ActOnIdExpression(getCurScope(), ScopeSpec, TemplateKWLoc, Name, + Tok.isOneOf(tok::l_paren, tok::lesslessless), + isAddressOfOperand, &Validator, + /*IsInlineAsmIdentifier=*/false); Res = tryParseCXXPackIndexingExpression(Res); if (!Res.isInvalid() && Tok.is(tok::less)) checkPotentialAngleBracket(Res); diff --git a/clang/lib/Parse/ParseExprCXX.cpp b/clang/lib/Parse/ParseExprCXX.cpp index f867fc8932bd44..22f309661bdc80 100644 --- a/clang/lib/Parse/ParseExprCXX.cpp +++ b/clang/lib/Parse/ParseExprCXX.cpp @@ -650,9 +650,10 @@ ExprResult Parser::tryParseCXXIdExpression(CXXScopeSpec &SS, if (isAddressOfOperand && isPostfixExpressionSuffixStart()) isAddressOfOperand = false; - E = Actions.ActOnIdExpression( - getCurScope(), SS, TemplateKWLoc, Name, Tok.is(tok::l_paren), - isAddressOfOperand, /*CCC=*/nullptr, /*IsInlineAsmIdentifier=*/false); + E = Actions.ActOnIdExpression(getCurScope(), SS, TemplateKWLoc, Name, + Tok.isOneOf(tok::l_paren, tok::lesslessless), + isAddressOfOperand, /*CCC=*/nullptr, + /*IsInlineAsmIdentifier=*/false); break; } diff --git a/clang/lib/Parse/ParseOpenACC.cpp b/clang/lib/Parse/ParseOpenACC.cpp index eb9106b6730458..692d00d60e91c0 100644 --- a/clang/lib/Parse/ParseOpenACC.cpp +++ b/clang/lib/Parse/ParseOpenACC.cpp @@ -1377,10 +1377,10 @@ ExprResult Parser::ParseOpenACCIDExpression() { Name.setIdentifier(FuncName.getIdentifierInfo(), ConsumeToken()); // Ensure this is a valid identifier. We don't accept causing implicit - // function declarations per the spec, so always claim to not have trailing - // L Paren. + // function declarations per the spec, so always claim that this isn't + // a call. Res = Actions.ActOnIdExpression(getCurScope(), ScopeSpec, TemplateKWLoc, - Name, /*HasTrailingLParen=*/false, + Name, /*IsCall=*/false, /*isAddressOfOperand=*/false); } diff --git a/clang/lib/Sema/SemaCodeComplete.cpp b/clang/lib/Sema/SemaCodeComplete.cpp index 727933f7d7195f..791f567b406c87 100644 --- a/clang/lib/Sema/SemaCodeComplete.cpp +++ b/clang/lib/Sema/SemaCodeComplete.cpp @@ -8543,7 +8543,7 @@ void SemaCodeCompletion::CodeCompleteObjCSuperMessage( id.setIdentifier(Super, SuperLoc); ExprResult SuperExpr = SemaRef.ActOnIdExpression(S, SS, TemplateKWLoc, id, - /*HasTrailingLParen=*/false, + /*IsCall=*/false, /*IsAddressOfOperand=*/false); return CodeCompleteObjCInstanceMessage(S, (Expr *)SuperExpr.get(), SelIdents, AtArgumentExpression); diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 5a70ab0162f14c..e0fb824c1e14dc 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -967,9 +967,9 @@ Sema::NameClassification Sema::ClassifyName(Scope *S, CXXScopeSpec &SS, Corrected: switch (Result.getResultKind()) { case LookupResultKind::NotFound: - // If an unqualified-id is followed by a '(', then we have a function - // call. - if (SS.isEmpty() && NextToken.is(tok::l_paren)) { + // If an unqualified-id is followed by '(' or '<<<', then we have a + // function call or kernel launch. + if (SS.isEmpty() && NextToken.isOneOf(tok::l_paren, tok::lesslessless)) { // In C++, this is an ADL-only call. // FIXME: Reference? if (getLangOpts().CPlusPlus) @@ -1289,7 +1289,8 @@ Sema::NameClassification Sema::ClassifyName(Scope *S, CXXScopeSpec &SS, // that declaration directly. Defer resolving even non-overloaded class // member accesses, as we need to defer certain access checks until we know // the context. - bool ADL = UseArgumentDependentLookup(SS, Result, NextToken.is(tok::l_paren)); + bool ADL = UseArgumentDependentLookup( + SS, Result, NextToken.isOneOf(tok::l_paren, tok::lesslessless)); if (Result.isSingleResult() && !ADL && (!FirstDecl->isCXXClassMember() || isa<EnumConstantDecl>(FirstDecl))) return NameClassification::NonType(Result.getRepresentativeDecl()); @@ -1335,7 +1336,8 @@ ExprResult Sema::ActOnNameClassifiedAsNonType(Scope *S, const CXXScopeSpec &SS, Result.addDecl(Found); Result.resolveKind(); - bool ADL = UseArgumentDependentLookup(SS, Result, NextToken.is(tok::l_paren)); + bool ADL = UseArgumentDependentLookup( + SS, Result, NextToken.isOneOf(tok::l_paren, tok::lesslessless)); return BuildDeclarationNameExpr(SS, Result, ADL, /*AcceptInvalidDecl=*/true); } diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index d3deecb3ee74c6..45cc932c3eb938 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -1110,7 +1110,7 @@ ExprResult Sema::DefaultVariadicArgumentPromotion(Expr *E, VariadicCallType CT, Name.setIdentifier(PP.getIdentifierInfo("__builtin_trap"), E->getBeginLoc()); ExprResult TrapFn = ActOnIdExpression(TUScope, SS, TemplateKWLoc, Name, - /*HasTrailingLParen=*/true, + /*IsCall=*/true, /*IsAddressOfOperand=*/false); if (TrapFn.isInvalid()) return ExprError(); @@ -2888,12 +2888,12 @@ recoverFromMSUnqualifiedLookup(Sema &S, ASTContext &Context, ExprResult Sema::ActOnIdExpression(Scope *S, CXXScopeSpec &SS, SourceLocation TemplateKWLoc, - UnqualifiedId &Id, bool HasTrailingLParen, + UnqualifiedId &Id, bool IsCall, bool IsAddressOfOperand, CorrectionCandidateCallback *CCC, bool IsInlineAsmIdentifier) { - assert(!(IsAddressOfOperand && HasTrailingLParen) && - "cannot be direct & operand and have a trailing lparen"); + assert(!(IsAddressOfOperand && IsCall) && + "cannot be direct & operand and a function call"); if (SS.isInvalid()) return ExprError(); @@ -2992,15 +2992,14 @@ ExprResult Sema::ActOnIdExpression(Scope *S, CXXScopeSpec &SS, // This could be an implicitly declared function reference if the language // mode allows it as a feature. - if (R.empty() && HasTrailingLParen && II && - getLangOpts().implicitFunctionsAllowed()) { + if (R.empty() && IsCall && II && getLangOpts().implicitFunctionsAllowed()) { NamedDecl *D = ImplicitlyDefineFunction(NameLoc, *II, S); if (D) R.addDecl(D); } // Determine whether this name might be a candidate for // argument-dependent lookup. - bool ADL = UseArgumentDependentLookup(SS, R, HasTrailingLParen); + bool ADL = UseArgumentDependentLookup(SS, R, IsCall); if (R.empty() && !ADL) { if (SS.isEmpty() && getLangOpts().MSVCCompat) { @@ -3323,10 +3322,9 @@ ExprResult Sema::PerformObjectMemberConversion(Expr *From, } bool Sema::UseArgumentDependentLookup(const CXXScopeSpec &SS, - const LookupResult &R, - bool HasTrailingLParen) { + const LookupResult &R, bool IsCall) { // Only when used directly as the postfix-expression of a call. - if (!HasTrailingLParen) + if (!IsCall) return false; // Never if a scope specifier was provided. @@ -3373,7 +3371,6 @@ bool Sema::UseArgumentDependentLookup(const CXXScopeSpec &SS, return true; } - /// Diagnoses obvious problems with the use of the given declaration /// as an expression. This is only actually called for lookups that /// were not overloaded, and it doesn't promise that the declaration @@ -7433,11 +7430,9 @@ ExprResult Sema::BuildResolvedCallExpr(Expr *Fn, NamedDecl *NDecl, CallExpr *TheCall; if (Config) { - assert(UsesADL == ADLCallKind::NotADL && - "CUDAKernelCallExpr should not use ADL"); - TheCall = CUDAKernelCallExpr::Create(Context, Fn, cast<CallExpr>(Config), - Args, ResultTy, VK_PRValue, RParenLoc, - CurFPFeatureOverrides(), NumParams); + TheCall = CUDAKernelCallExpr::Create( + Context, Fn, cast<CallExpr>(Config), Args, ResultTy, VK_PRValue, + RParenLoc, CurFPFeatureOverrides(), NumParams, UsesADL); } else { TheCall = CallExpr::Create(Context, Fn, Args, ResultTy, VK_PRValue, RParenLoc, diff --git a/clang/lib/Sema/SemaExprObjC.cpp b/clang/lib/Sema/SemaExprObjC.cpp index 7a3be956196835..611ad1ba453515 100644 --- a/clang/lib/Sema/SemaExprObjC.cpp +++ b/clang/lib/Sema/SemaExprObjC.cpp @@ -5065,7 +5065,7 @@ ExprResult SemaObjC::BuildIvarRefExpr(Scope *S, SourceLocation Loc, SourceLocation TemplateKWLoc; ExprResult SelfExpr = SemaRef.ActOnIdExpression(S, SelfScopeSpec, TemplateKWLoc, SelfName, - /*HasTrailingLParen=*/false, + /*IsCall=*/false, /*IsAddressOfOperand=*/false); if (SelfExpr.isInvalid()) return ExprError(); diff --git a/clang/lib/Sema/SemaStmtAsm.cpp b/clang/lib/Sema/SemaStmtAsm.cpp index 7a575819fe6a45..cfb537eba8034f 100644 --- a/clang/lib/Sema/SemaStmtAsm.cpp +++ b/clang/lib/Sema/SemaStmtAsm.cpp @@ -885,10 +885,10 @@ ExprResult Sema::LookupInlineAsmIdentifier(CXXScopeSpec &SS, ReuseLambdaContextDecl); ExprResult Result = ActOnIdExpression(getCurScope(), SS, TemplateKWLoc, Id, - /*trailing lparen*/ false, + /*IsCall=*/false, /*is & operand*/ false, /*CorrectionCandidateCallback=*/nullptr, - /*IsInlineAsmIdentifier=*/ true); + /*IsInlineAsmIdentifier=*/true); if (IsUnevaluatedContext) PopExpressionEvaluationContext(); diff --git a/clang/test/CodeGenCUDA/kernel-call-adl.cu b/clang/test/CodeGenCUDA/kernel-call-adl.cu new file mode 100644 index 00000000000000..a34a9e54f6000d --- /dev/null +++ b/clang/test/CodeGenCUDA/kernel-call-adl.cu @@ -0,0 +1,55 @@ +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -aux-triple nvptx64-nvidia-cuda -std=c++20 -emit-llvm -o - %s | FileCheck %s --check-prefix=HOST +// RUN: %clang_cc1 -triple nvptx64-nvidia-cuda -aux-triple x86_64-unknown-linux-gnu -fcuda-is-device -std=c++20 -emit-llvm -o - %s | FileCheck %s --check-prefix=DEVICE +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -aux-triple amdgpu9.00-amd-amdhsa -x hip -std=c++20 -emit-llvm -o - %s | FileCheck %s --check-prefix=HOST +// RUN: %clang_cc1 -triple amdgpu9.00-amd-amdhsa -aux-triple x86_64-unknown-linux-gnu -fcuda-is-device -x hip -std=c++20 -emit-llvm -o - %s | FileCheck %s --check-prefix=DEVICE +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -std=c++20 -ast-dump -ast-dump-filter=gh45327 %s | FileCheck %s --check-prefix=AST +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -std=c++20 -emit-pch -o %t.cuda %s +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -std=c++20 -include-pch %t.cuda -x cuda -ast-dump-all -ast-dump-filter=gh45327 /dev/null | FileCheck %s --check-prefix=AST +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -std=c++20 -x hip -emit-pch -o %t.hip %s +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -std=c++20 -include-pch %t.hip -x hip -ast-dump-all -ast-dump-filter=gh45327 /dev/null | FileCheck %s --check-prefix=AST + +#include "Inputs/cuda.h" + +namespace gh45327 { +// The launch translation unit in the issue sees only this friend declaration; +// init is defined in another translation unit. +class MyClass { +public: + friend __global__ void init(MyClass *simulation_map); +}; + +// HOST-LABEL: define{{.*}} @_ZN7gh453274testEv( +// HOST: call void @_ZN7gh45327{{.*}}initEPNS_7MyClassE( +// AST-LABEL: FunctionDecl {{.*}} test 'void ()' +// AST: CUDAKernelCallExpr {{.*}} 'void' adl +void test() { + MyClass obj; + init<<<1, 1>>>(&obj); +} +} // namespace gh45327 + +namespace associated { +struct Arg {}; + +// DEVICE-LABEL: define{{.*}} @_ZN10associated6kernelENS_3ArgE( +__global__ void kernel(Arg) {} + +// DEVICE-LABEL: define{{.*}} @_ZN10associated15template_kernelIiEEvNS_3ArgET_( +template <class T> __global__ void template_kernel(Arg, T) {} +} // namespace associated + +// HOST-LABEL: define{{.*}} @_Z6launchv( +// HOST: call void @_ZN10associated{{.*}}kernelENS_3ArgE( +// HOST: call void @_ZN10associated{{.*}}template_kernelIiEEvNS_3ArgET_( +void launch() { + associated::Arg arg; + kernel<<<1, 1>>>(arg); + // An explicit template argument list takes the C++ id-expression path. + template_kernel<int><<<1, 1>>>(arg, 0); +} + +// Lookup of the kernel is deferred until this function is instantiated. +template <class T> void dependent_launch(T arg) { + kernel<<<1, 1>>>(arg); +} +template void dependent_launch(associated::Arg); diff --git a/clang/test/SemaCUDA/kernel-call-adl.cu b/clang/test/SemaCUDA/kernel-call-adl.cu new file mode 100644 index 00000000000000..134089dee2ce27 --- /dev/null +++ b/clang/test/SemaCUDA/kernel-call-adl.cu @@ -0,0 +1,60 @@ +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -aux-triple nvptx64-nvidia-cuda -std=c++20 -fsyntax-only -fno-spell-checking -verify %s +// RUN: %clang_cc1 -triple nvptx64-nvidia-cuda -aux-triple x86_64-unknown-linux-gnu -fcuda-is-device -std=c++20 -fsyntax-only -fno-spell-checking -verify %s +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -aux-triple amdgpu9.00-amd-amdhsa -x hip -std=c++20 -fsyntax-only -fno-spell-checking -verify %s +// RUN: %clang_cc1 -triple amdgpu9.00-amd-amdhsa -aux-triple x86_64-unknown-linux-gnu -fcuda-is-device -x hip -std=c++20 -fsyntax-only -fno-spell-checking -verify %s + +#include "Inputs/cuda.h" + +namespace associated { +struct Arg {}; +__global__ void kernel(Arg); +template <class T> __global__ void template_kernel(T); +void host_function(Arg); +} // namespace associated + +void test(associated::Arg arg) { + // Parentheses and qualification still suppress ADL. + (kernel)<<<1, 1>>>(arg); // expected-error {{use of undeclared identifier 'kernel'}} + ::kernel<<<1, 1>>>(arg); // expected-error {{no member named 'kernel' in the global namespace}} + // The address-of operand is the whole call, not the kernel name. + &kernel<<<1, 1>>>(arg); // expected-error {{cannot take the address of an rvalue of type 'void'}} + &template_kernel<associated::Arg><<<1, 1>>>(arg); // expected-error {{cannot take the address of an rvalue of type 'void'}} + // Finding a function by ADL does not make it a kernel. + host_function<<<1, 1>>>(arg); // expected-error {{kernel call to non-global function 'host_function'}} +} + +void block_scope(associated::Arg arg) { + __global__ void kernel(int); // expected-note {{passing argument to parameter here}} + kernel<<<1, 1>>>(arg); // expected-error {{no viable conversion from 'associated::Arg' to 'int'}} +} + +struct Member { + static __global__ void kernel(int); // expected-note {{passing argument to parameter here}} + void test(associated::Arg arg) { + kernel<<<1, 1>>>(arg); // expected-error {{no viable conversion from 'associated::Arg' to 'int'}} + } +}; + +namespace config { +struct Grid { + operator dim3() const; +}; +__global__ void only_in_config(); +} // namespace config + +void configuration() { + // Only the kernel arguments, not the execution configuration, supply + // associated namespaces for lookup of the kernel. + only_in_config<<<config::Grid{}, 1>>>(); // expected-error {{use of undeclared identifier 'only_in_config'}} +} + +namespace associated { +__global__ void ambiguous(Arg); // expected-note {{candidate function}} +} // namespace associated + +__global__ void ambiguous(associated::Arg); // expected-note {{candidate function}} + +void overloads(associated::Arg arg) { + // ADL augments ordinary lookup rather than replacing its candidates. + ambiguous<<<1, 1>>>(arg); // expected-error {{call to 'ambiguous' is ambiguous}} +} _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
