Skip to content

Commit f1fe46d

Browse files
authored
[SYCL][NFC] Update mutual diagnostic for different work_group_size attributes (#3128)
This patch 1. fixes typo 2. removes redundant comments (we have disabled swapping dimension values of WorkGroupAttr arguments for semantic checks on #2962) 3. Hoist the logic from the second if into the above if (AttrValue == 0) Signed-off-by: Soumi Manna <[email protected]>
1 parent dc1423a commit f1fe46d

File tree

1 file changed

+24
-28
lines changed

1 file changed

+24
-28
lines changed

clang/lib/Sema/SemaDeclAttr.cpp

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3006,12 +3006,14 @@ static bool checkWorkGroupSizeValues(Sema &S, Decl *D, const ParsedAttr &AL) {
30063006
return true;
30073007
};
30083008

3009-
/// Returns the usigned constant integer value represented by
3010-
/// given expression.
3009+
// Returns the unsigned constant integer value represented by
3010+
// given expression.
30113011
auto getExprValue = [](const Expr *E, ASTContext &Ctx) {
30123012
return E->getIntegerConstantExpr(Ctx)->getZExtValue();
30133013
};
30143014

3015+
ASTContext &Ctx = S.getASTContext();
3016+
30153017
if (AL.getKind() == ParsedAttr::AT_SYCLIntelMaxGlobalWorkDim) {
30163018
ArrayRef<const Expr *> Dims;
30173019
Attr *B = nullptr;
@@ -3020,51 +3022,45 @@ static bool checkWorkGroupSizeValues(Sema &S, Decl *D, const ParsedAttr &AL) {
30203022
else if (const auto *B = D->getAttr<ReqdWorkGroupSizeAttr>())
30213023
Dims = B->dimensions();
30223024
if (B) {
3023-
Result &= checkZeroDim(B, getExprValue(Dims[0], S.getASTContext()),
3024-
getExprValue(Dims[1], S.getASTContext()),
3025-
getExprValue(Dims[2], S.getASTContext()));
3025+
Result &=
3026+
checkZeroDim(B, getExprValue(Dims[0], Ctx),
3027+
getExprValue(Dims[1], Ctx), getExprValue(Dims[2], Ctx));
30263028
}
30273029
return Result;
30283030
}
30293031

30303032
if (AL.getKind() == ParsedAttr::AT_SYCLIntelMaxWorkGroupSize)
30313033
S.CheckDeprecatedSYCLAttributeSpelling(AL);
30323034

3033-
// For a SYCLDevice, WorkGroupAttr arguments are reversed.
3034-
// "XDim" gets the third argument to the attribute and
3035-
// "ZDim" gets the first argument of the attribute.
30363035
if (const auto *A = D->getAttr<SYCLIntelMaxGlobalWorkDimAttr>()) {
3037-
int64_t AttrValue =
3038-
A->getValue()->getIntegerConstantExpr(S.Context)->getSExtValue();
3039-
if (AttrValue == 0) {
3040-
Result &=
3041-
checkZeroDim(A, getExprValue(AL.getArgAsExpr(0), S.getASTContext()),
3042-
getExprValue(AL.getArgAsExpr(1), S.getASTContext()),
3043-
getExprValue(AL.getArgAsExpr(2), S.getASTContext()),
3044-
/*ReverseAttrs=*/true);
3036+
if ((A->getValue()->getIntegerConstantExpr(Ctx)->getSExtValue()) == 0) {
3037+
Result &= checkZeroDim(A, getExprValue(AL.getArgAsExpr(0), Ctx),
3038+
getExprValue(AL.getArgAsExpr(1), Ctx),
3039+
getExprValue(AL.getArgAsExpr(2), Ctx),
3040+
/*ReverseAttrs=*/true);
30453041
}
30463042
}
30473043

30483044
if (const auto *A = D->getAttr<SYCLIntelMaxWorkGroupSizeAttr>()) {
3049-
if (!((getExprValue(AL.getArgAsExpr(0), S.getASTContext()) <=
3050-
getExprValue(A->getXDim(), S.getASTContext())) &&
3051-
(getExprValue(AL.getArgAsExpr(1), S.getASTContext()) <=
3052-
getExprValue(A->getYDim(), S.getASTContext())) &&
3053-
(getExprValue(AL.getArgAsExpr(2), S.getASTContext()) <=
3054-
getExprValue(A->getZDim(), S.getASTContext())))) {
3045+
if (!((getExprValue(AL.getArgAsExpr(0), Ctx) <=
3046+
getExprValue(A->getXDim(), Ctx)) &&
3047+
(getExprValue(AL.getArgAsExpr(1), Ctx) <=
3048+
getExprValue(A->getYDim(), Ctx)) &&
3049+
(getExprValue(AL.getArgAsExpr(2), Ctx) <=
3050+
getExprValue(A->getZDim(), Ctx)))) {
30553051
S.Diag(AL.getLoc(), diag::err_conflicting_sycl_function_attributes)
30563052
<< AL << A->getSpelling();
30573053
Result &= false;
30583054
}
30593055
}
30603056

30613057
if (const auto *A = D->getAttr<ReqdWorkGroupSizeAttr>()) {
3062-
if (!((getExprValue(AL.getArgAsExpr(0), S.getASTContext()) >=
3063-
getExprValue(A->getXDim(), S.getASTContext())) &&
3064-
(getExprValue(AL.getArgAsExpr(1), S.getASTContext()) >=
3065-
getExprValue(A->getYDim(), S.getASTContext())) &&
3066-
(getExprValue(AL.getArgAsExpr(2), S.getASTContext()) >=
3067-
getExprValue(A->getZDim(), S.getASTContext())))) {
3058+
if (!((getExprValue(AL.getArgAsExpr(0), Ctx) >=
3059+
getExprValue(A->getXDim(), Ctx)) &&
3060+
(getExprValue(AL.getArgAsExpr(1), Ctx) >=
3061+
getExprValue(A->getYDim(), Ctx)) &&
3062+
(getExprValue(AL.getArgAsExpr(2), Ctx) >=
3063+
getExprValue(A->getZDim(), Ctx)))) {
30683064
S.Diag(AL.getLoc(), diag::err_conflicting_sycl_function_attributes)
30693065
<< AL << A->getSpelling();
30703066
Result &= false;

0 commit comments

Comments
 (0)