Skip to content

Commit b7bdcbe

Browse files
author
Erich Keane
authored
[SYCL] [NFC] Replace redecl walk with getMostRecentDecl. (#1915)
Clang ensures that the latest declaration of a function has all of the attributes, so doing a search through the declarations isn't necessary. This patch replaces our expensive search through the redeclaration list with a getMostRecentDecl.
1 parent cce700d commit b7bdcbe

File tree

1 file changed

+4
-11
lines changed

1 file changed

+4
-11
lines changed

clang/lib/Sema/SemaSYCL.cpp

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1820,19 +1820,12 @@ void Sema::finalizeSYCLDelayedAnalysis(const FunctionDecl *Caller,
18201820
if (Callee->getTemplatedKind() == FunctionDecl::TK_FunctionTemplate)
18211821
return;
18221822

1823-
bool RedeclHasAttr = false;
1824-
1825-
for (const Decl *Redecl : Callee->redecls()) {
1826-
if (const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(Redecl)) {
1827-
if (FD->hasAttr<SYCLDeviceAttr>() || FD->hasAttr<SYCLKernelAttr>()) {
1828-
RedeclHasAttr = true;
1829-
break;
1830-
}
1831-
}
1832-
}
1823+
Callee = Callee->getMostRecentDecl();
1824+
bool HasAttr =
1825+
Callee->hasAttr<SYCLDeviceAttr>() || Callee->hasAttr<SYCLKernelAttr>();
18331826

18341827
// Disallow functions with neither definition nor SYCL_EXTERNAL mark
1835-
bool NotDefinedNoAttr = !Callee->isDefined() && !RedeclHasAttr;
1828+
bool NotDefinedNoAttr = !Callee->isDefined() && !HasAttr;
18361829

18371830
if (NotDefinedNoAttr && !Callee->getBuiltinID()) {
18381831
Diag(Loc, diag::err_sycl_restrict)

0 commit comments

Comments
 (0)