Skip to content

Commit 75b3dc2

Browse files
[SYCL] Fix check for reqd_sub_group_size attribute mismatches (#1905)
Fixed an issue with comparing pointers to Attr objects rather than values passed to the attribute in source code. The bug were uncovered after #1778 landed, but it had been introduced in #1807
1 parent 24726df commit 75b3dc2

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

clang/lib/Sema/SemaSYCL.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -308,11 +308,12 @@ static void reportConflictingAttrs(Sema &S, FunctionDecl *F, const Attr *A1,
308308
F->setInvalidDecl();
309309
}
310310

311-
// Returns the signed constant integer value represented by given expression.
312-
static int64_t getIntExprValue(Sema &S, const Expr *E) {
311+
/// Returns the signed constant integer value represented by given expression
312+
static int64_t getIntExprValue(const Expr *E, ASTContext &Ctx) {
313313
llvm::APSInt Val(32);
314-
bool IsValid = E->isIntegerConstantExpr(Val, S.getASTContext());
314+
bool IsValid = E->isIntegerConstantExpr(Val, Ctx);
315315
assert(IsValid && "expression must be constant integer");
316+
(void)IsValid;
316317
return Val.getSExtValue();
317318
}
318319

@@ -1696,15 +1697,16 @@ void Sema::MarkDevice(void) {
16961697
KernelBody ? KernelBody->getAttr<SYCLSimdAttr>() : nullptr;
16971698
if (auto *Existing =
16981699
SYCLKernel->getAttr<IntelReqdSubGroupSizeAttr>()) {
1699-
if (Existing->getSubGroupSize() != Attr->getSubGroupSize()) {
1700+
if (getIntExprValue(Existing->getSubGroupSize(), getASTContext()) !=
1701+
getIntExprValue(Attr->getSubGroupSize(), getASTContext())) {
17001702
Diag(SYCLKernel->getLocation(),
17011703
diag::err_conflicting_sycl_kernel_attributes);
17021704
Diag(Existing->getLocation(), diag::note_conflicting_attribute);
17031705
Diag(Attr->getLocation(), diag::note_conflicting_attribute);
17041706
SYCLKernel->setInvalidDecl();
17051707
}
1706-
} else if (KBSimdAttr &&
1707-
(getIntExprValue(*this, Attr->getSubGroupSize()) != 1)) {
1708+
} else if (KBSimdAttr && (getIntExprValue(Attr->getSubGroupSize(),
1709+
getASTContext()) != 1)) {
17081710
reportConflictingAttrs(*this, KernelBody, KBSimdAttr, Attr);
17091711
} else {
17101712
SYCLKernel->addAttr(A);

clang/test/SemaSYCL/reqd-sub-group-size-device.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,16 @@ void bar() {
4545
baz();
4646
});
4747
#endif
48+
4849
kernel<class kernel_name5>([]() [[cl::intel_reqd_sub_group_size(2)]] { });
50+
kernel<class kernel_name6>([]() [[cl::intel_reqd_sub_group_size(4)]] { foo(); });
51+
}
52+
53+
[[cl::intel_reqd_sub_group_size(16)]] SYCL_EXTERNAL void B();
54+
[[cl::intel_reqd_sub_group_size(16)]] void A() {
55+
}
56+
[[cl::intel_reqd_sub_group_size(16)]] SYCL_EXTERNAL void B() {
57+
A();
4958
}
5059

5160
#ifdef TRIGGER_ERROR

0 commit comments

Comments
 (0)