Skip to content

Commit adf91fa

Browse files
committed
[SYCL] Avoid nullptr dereferencing of YDimExpr and ZDimExpr
Fix the Klocworks exposed bug for non sycl:: or intel:: usage by refactoring and adding checks to avoid nullptr dereferencing
1 parent 46c9f3e commit adf91fa

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

clang/lib/Sema/SemaDeclAttr.cpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3177,25 +3177,32 @@ static void handleWorkGroupSize(Sema &S, Decl *D, const ParsedAttr &AL) {
31773177

31783178
ASTContext &Ctx = S.getASTContext();
31793179

3180-
if (!XDimExpr->isValueDependent() && !YDimExpr->isValueDependent() &&
3181-
!ZDimExpr->isValueDependent()) {
3182-
llvm::APSInt XDimVal, YDimVal, ZDimVal;
3183-
ExprResult XDim = S.VerifyIntegerConstantExpression(XDimExpr, &XDimVal);
3184-
ExprResult YDim = S.VerifyIntegerConstantExpression(YDimExpr, &YDimVal);
3185-
ExprResult ZDim = S.VerifyIntegerConstantExpression(ZDimExpr, &ZDimVal);
3180+
bool YDimExprIsDereferencable = YDimExpr && (!YDimExpr->isValueDependent());
3181+
bool ZDimExprIsDereferencable = ZDimExpr && (!ZDimExpr->isValueDependent());
31863182

3183+
llvm::APSInt XDimVal, YDimVal, ZDimVal;
3184+
if (!XDimExpr->isValueDependent()) {
3185+
ExprResult XDim = S.VerifyIntegerConstantExpression(XDimExpr, &XDimVal);
31873186
if (XDim.isInvalid())
31883187
return;
31893188
XDimExpr = XDim.get();
3189+
}
31903190

3191+
if (YDimExprIsDereferencable) {
3192+
ExprResult YDim = S.VerifyIntegerConstantExpression(YDimExpr, &YDimVal);
31913193
if (YDim.isInvalid())
31923194
return;
31933195
YDimExpr = YDim.get();
3196+
}
31943197

3198+
if (ZDimExprIsDereferencable) {
3199+
ExprResult ZDim = S.VerifyIntegerConstantExpression(ZDimExpr, &ZDimVal);
31953200
if (ZDim.isInvalid())
31963201
return;
31973202
ZDimExpr = ZDim.get();
3203+
}
31983204

3205+
if ((XDimVal >= 1) && (YDimVal >= 1) && (ZDimVal >= 1)) {
31993206
// If the num_simd_work_items attribute is specified on a declaration it
32003207
// must evenly divide the index that increments fastest in the
32013208
// reqd_work_group_size attribute. In OpenCL, the first argument increments

0 commit comments

Comments
 (0)