https://github.com/Sirraide updated https://github.com/llvm/llvm-project/pull/240947
>From f2fbe4167d31b34d663cc0ab97a6e29ed1cf0baf Mon Sep 17 00:00:00 2001 From: Ambrose Leeb <[email protected]> Date: Tue, 10 Nov 2026 18:12:45 +0000 Subject: [PATCH 1/2] [Clang] [CUDA] Support ADL kernel launches 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. This patch fixes that by checking for '<<<' alongside '(' where relevant. Fixes #45327. Assisted-by: Codex --- clang/docs/ReleaseNotes.md | 3 ++ clang/include/clang/Parse/Parser.h | 5 +- clang/include/clang/Sema/Sema.h | 4 +- clang/lib/Parse/ParseExpr.cpp | 9 ++-- clang/lib/Parse/ParseExprCXX.cpp | 7 +-- clang/lib/Parse/ParseOpenACC.cpp | 6 +-- clang/lib/Sema/SemaCodeComplete.cpp | 2 +- clang/lib/Sema/SemaDecl.cpp | 12 +++-- clang/lib/Sema/SemaExpr.cpp | 22 ++++----- clang/lib/Sema/SemaExprObjC.cpp | 2 +- clang/lib/Sema/SemaStmtAsm.cpp | 4 +- clang/test/CodeGenCUDA/kernel-call-adl.cu | 55 +++++++++++++++++++++ clang/test/SemaCUDA/kernel-call-adl.cu | 60 +++++++++++++++++++++++ 13 files changed, 155 insertions(+), 36 deletions(-) create mode 100644 clang/test/CodeGenCUDA/kernel-call-adl.cu create mode 100644 clang/test/SemaCUDA/kernel-call-adl.cu diff --git a/clang/docs/ReleaseNotes.md b/clang/docs/ReleaseNotes.md index 7a0169be43980e..14e0257655c68b 100644 --- a/clang/docs/ReleaseNotes.md +++ b/clang/docs/ReleaseNotes.md @@ -1353,6 +1353,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/Parse/Parser.h b/clang/include/clang/Parse/Parser.h index b19f0ed880ddfe..05c492c704810c 100644 --- a/clang/include/clang/Parse/Parser.h +++ b/clang/include/clang/Parse/Parser.h @@ -4118,8 +4118,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 ba215e7e18d7ba..2bfa5c047879d0 100644 --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -7325,7 +7325,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); @@ -7388,7 +7388,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/Parse/ParseExpr.cpp b/clang/lib/Parse/ParseExpr.cpp index d42ffc2ccf0a65..f3169cf0f2f77d 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 2e852281395280..67424c580ddaf8 100644 --- a/clang/lib/Sema/SemaCodeComplete.cpp +++ b/clang/lib/Sema/SemaCodeComplete.cpp @@ -8542,7 +8542,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 f3d38a555a524a..d7484491abbbcc 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -965,9 +965,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) @@ -1287,7 +1287,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()); @@ -1333,7 +1334,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 a14c3d50d12851..b4e3a7a40f5f1b 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -1108,7 +1108,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(); @@ -2886,12 +2886,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(); @@ -2990,15 +2990,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) { @@ -3321,10 +3320,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. @@ -3371,7 +3369,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 @@ -7425,11 +7422,10 @@ 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->setADLCallKind(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 bf460ebe75ef10..3eee0580961428 100644 --- a/clang/lib/Sema/SemaStmtAsm.cpp +++ b/clang/lib/Sema/SemaStmtAsm.cpp @@ -842,10 +842,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..e58035cfe6b778 --- /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 amdgcn-amd-amdhsa -x hip -std=c++20 -emit-llvm -o - %s | FileCheck %s --check-prefix=HOST +// RUN: %clang_cc1 -triple amdgcn-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..fee11166df002e --- /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 amdgcn-amd-amdhsa -x hip -std=c++20 -fsyntax-only -fno-spell-checking -verify %s +// RUN: %clang_cc1 -triple amdgcn-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}} +} >From 06e1338d92cb81012bb2aeaaacc4e023ff3030c6 Mon Sep 17 00:00:00 2001 From: Ambrose Leeb <[email protected]> Date: Wed, 11 Nov 2026 22:55:17 +0000 Subject: [PATCH 2/2] address review comments --- clang/include/clang/AST/ExprCXX.h | 14 +++++++------- clang/lib/AST/ExprCXX.cpp | 10 +++++----- clang/lib/Sema/SemaExpr.cpp | 7 +++---- clang/test/CodeGenCUDA/kernel-call-adl.cu | 4 ++-- clang/test/SemaCUDA/kernel-call-adl.cu | 4 ++-- 5 files changed, 19 insertions(+), 20 deletions(-) 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/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/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index b4e3a7a40f5f1b..3329544523fa2f 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -7422,10 +7422,9 @@ ExprResult Sema::BuildResolvedCallExpr(Expr *Fn, NamedDecl *NDecl, CallExpr *TheCall; if (Config) { - TheCall = CUDAKernelCallExpr::Create(Context, Fn, cast<CallExpr>(Config), - Args, ResultTy, VK_PRValue, RParenLoc, - CurFPFeatureOverrides(), NumParams); - TheCall->setADLCallKind(UsesADL); + 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/test/CodeGenCUDA/kernel-call-adl.cu b/clang/test/CodeGenCUDA/kernel-call-adl.cu index e58035cfe6b778..a34a9e54f6000d 100644 --- a/clang/test/CodeGenCUDA/kernel-call-adl.cu +++ b/clang/test/CodeGenCUDA/kernel-call-adl.cu @@ -1,7 +1,7 @@ // 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 amdgcn-amd-amdhsa -x hip -std=c++20 -emit-llvm -o - %s | FileCheck %s --check-prefix=HOST -// RUN: %clang_cc1 -triple amdgcn-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 -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 diff --git a/clang/test/SemaCUDA/kernel-call-adl.cu b/clang/test/SemaCUDA/kernel-call-adl.cu index fee11166df002e..134089dee2ce27 100644 --- a/clang/test/SemaCUDA/kernel-call-adl.cu +++ b/clang/test/SemaCUDA/kernel-call-adl.cu @@ -1,7 +1,7 @@ // 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 amdgcn-amd-amdhsa -x hip -std=c++20 -fsyntax-only -fno-spell-checking -verify %s -// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -aux-triple x86_64-unknown-linux-gnu -fcuda-is-device -x hip -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" _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
