Skip to content

[SYCL][NFC] Fix static code analysis concerns #2531

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 25, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions clang/lib/Sema/SemaDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3215,8 +3215,12 @@ static void adjustDeclContextForDeclaratorDecl(DeclaratorDecl *NewD,
template <typename AttributeType>
static void checkDimensionsAndSetDiagnostics(Sema &S, FunctionDecl *New,
FunctionDecl *Old) {
AttributeType *NewDeclAttr = New->getAttr<AttributeType>();
AttributeType *OldDeclAttr = Old->getAttr<AttributeType>();
const auto *NewDeclAttr = New->getAttr<AttributeType>();
const auto *OldDeclAttr = Old->getAttr<AttributeType>();

if (!NewDeclAttr || !OldDeclAttr)
return;

if ((NewDeclAttr->getXDim() != OldDeclAttr->getXDim()) ||
(NewDeclAttr->getYDim() != OldDeclAttr->getYDim()) ||
(NewDeclAttr->getZDim() != OldDeclAttr->getZDim())) {
Expand Down Expand Up @@ -3302,12 +3306,8 @@ bool Sema::MergeFunctionDecl(FunctionDecl *New, NamedDecl *&OldD,
}
}

if (New->hasAttr<ReqdWorkGroupSizeAttr>() &&
Old->hasAttr<ReqdWorkGroupSizeAttr>())
checkDimensionsAndSetDiagnostics<ReqdWorkGroupSizeAttr>(*this, New, Old);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand this is what @erichkeane suggested earlier, but I am not sure I like this. Would we do this for every attribute we want to merge? Seems like a lot of wasted calls.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it ends up being basically the same runtime-cost here after optimization. It seems like an easy function to inline, and hasAttr and getAttr have identical runtime cost.

My fear here is that this ends up being REALLY error-prone as time goes on, we're going to be adding these for a handful of attributes and it becomes easy to copy/paste error the THREE uses of the attribute type.


if (New->hasAttr<SYCLIntelMaxWorkGroupSizeAttr>() &&
Old->hasAttr<SYCLIntelMaxWorkGroupSizeAttr>())
checkDimensionsAndSetDiagnostics<SYCLIntelMaxWorkGroupSizeAttr>(*this, New,
Old);

Expand Down