Skip to content

Commit ea8ede4

Browse files
author
iclsrc
committed
Merge from 'sycl' to 'sycl-web' (#5)
2 parents bdc5794 + b3a9426 commit ea8ede4

File tree

31 files changed

+805
-150
lines changed

31 files changed

+805
-150
lines changed

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10629,7 +10629,7 @@ def err_sycl_kernel_name_class_not_top_level : Error<
1062910629
"nest in a namespace: %0">;
1063010630
def err_sycl_restrict : Error<
1063110631
"SYCL kernel cannot "
10632-
"%select{use a global variable"
10632+
"%select{use a non-const global variable"
1063310633
"|use rtti"
1063410634
"|use a non-const static data variable"
1063510635
"|call a virtual function"

clang/include/clang/Sema/Sema.h

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
#include "clang/AST/DeclTemplate.h"
2323
#include "clang/AST/DeclarationName.h"
2424
#include "clang/AST/Expr.h"
25-
#include "clang/AST/ExprConcepts.h"
2625
#include "clang/AST/ExprCXX.h"
26+
#include "clang/AST/ExprConcepts.h"
2727
#include "clang/AST/ExprObjC.h"
2828
#include "clang/AST/ExternalASTSource.h"
2929
#include "clang/AST/LocInfoType.h"
@@ -34,6 +34,7 @@
3434
#include "clang/AST/TypeLoc.h"
3535
#include "clang/AST/TypeOrdering.h"
3636
#include "clang/Basic/BitmaskEnum.h"
37+
#include "clang/Basic/DiagnosticSema.h"
3738
#include "clang/Basic/ExpressionTraits.h"
3839
#include "clang/Basic/Module.h"
3940
#include "clang/Basic/OpenMPKinds.h"
@@ -12328,6 +12329,71 @@ class Sema final {
1232812329
void checkSYCLDeviceFunction(SourceLocation Loc, FunctionDecl *Callee);
1232912330
};
1233012331

12332+
template <typename AttrType>
12333+
void Sema::AddOneConstantValueAttr(Decl *D, const AttributeCommonInfo &CI,
12334+
Expr *E) {
12335+
AttrType TmpAttr(Context, CI, E);
12336+
12337+
if (!E->isValueDependent()) {
12338+
ExprResult ICE;
12339+
if (checkRangedIntegralArgument<AttrType>(E, &TmpAttr, ICE))
12340+
return;
12341+
E = ICE.get();
12342+
}
12343+
12344+
if (IntelFPGAPrivateCopiesAttr::classof(&TmpAttr)) {
12345+
if (!D->hasAttr<IntelFPGAMemoryAttr>())
12346+
D->addAttr(IntelFPGAMemoryAttr::CreateImplicit(
12347+
Context, IntelFPGAMemoryAttr::Default));
12348+
}
12349+
12350+
D->addAttr(::new (Context) AttrType(Context, CI, E));
12351+
}
12352+
12353+
template <typename AttrType>
12354+
void Sema::AddOneConstantPowerTwoValueAttr(Decl *D,
12355+
const AttributeCommonInfo &CI,
12356+
Expr *E) {
12357+
AttrType TmpAttr(Context, CI, E);
12358+
12359+
if (!E->isValueDependent()) {
12360+
ExprResult ICE;
12361+
if (checkRangedIntegralArgument<AttrType>(E, &TmpAttr, ICE))
12362+
return;
12363+
Expr::EvalResult Result;
12364+
E->EvaluateAsInt(Result, Context);
12365+
llvm::APSInt Value = Result.Val.getInt();
12366+
if (!Value.isPowerOf2()) {
12367+
Diag(CI.getLoc(), diag::err_attribute_argument_not_power_of_two)
12368+
<< &TmpAttr;
12369+
return;
12370+
}
12371+
if (IntelFPGANumBanksAttr::classof(&TmpAttr)) {
12372+
if (auto *BBA = D->getAttr<IntelFPGABankBitsAttr>()) {
12373+
unsigned NumBankBits = BBA->args_size();
12374+
if (NumBankBits != Value.ceilLogBase2()) {
12375+
Diag(TmpAttr.getLocation(), diag::err_bankbits_numbanks_conflicting);
12376+
return;
12377+
}
12378+
}
12379+
}
12380+
E = ICE.get();
12381+
}
12382+
12383+
if (!D->hasAttr<IntelFPGAMemoryAttr>())
12384+
D->addAttr(IntelFPGAMemoryAttr::CreateImplicit(
12385+
Context, IntelFPGAMemoryAttr::Default));
12386+
12387+
// We are adding a user NumBanks, drop any implicit default.
12388+
if (IntelFPGANumBanksAttr::classof(&TmpAttr)) {
12389+
if (auto *NBA = D->getAttr<IntelFPGANumBanksAttr>())
12390+
if (NBA->isImplicit())
12391+
D->dropAttr<IntelFPGANumBanksAttr>();
12392+
}
12393+
12394+
D->addAttr(::new (Context) AttrType(Context, CI, E));
12395+
}
12396+
1233112397
/// RAII object that enters a new expression evaluation context.
1233212398
class EnterExpressionEvaluationContext {
1233312399
Sema &Actions;

clang/lib/Sema/SemaDeclAttr.cpp

Lines changed: 0 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -3869,71 +3869,6 @@ bool Sema::checkRangedIntegralArgument(Expr *E, const AttrType *TmpAttr,
38693869
return false;
38703870
}
38713871

3872-
template <typename AttrType>
3873-
void Sema::AddOneConstantValueAttr(Decl *D, const AttributeCommonInfo &CI,
3874-
Expr *E) {
3875-
AttrType TmpAttr(Context, CI, E);
3876-
3877-
if (!E->isValueDependent()) {
3878-
ExprResult ICE;
3879-
if (checkRangedIntegralArgument<AttrType>(E, &TmpAttr, ICE))
3880-
return;
3881-
E = ICE.get();
3882-
}
3883-
3884-
if (IntelFPGAPrivateCopiesAttr::classof(&TmpAttr)) {
3885-
if (!D->hasAttr<IntelFPGAMemoryAttr>())
3886-
D->addAttr(IntelFPGAMemoryAttr::CreateImplicit(
3887-
Context, IntelFPGAMemoryAttr::Default));
3888-
}
3889-
3890-
D->addAttr(::new (Context) AttrType(Context, CI, E));
3891-
}
3892-
3893-
template <typename AttrType>
3894-
void Sema::AddOneConstantPowerTwoValueAttr(Decl *D,
3895-
const AttributeCommonInfo &CI,
3896-
Expr *E) {
3897-
AttrType TmpAttr(Context, CI, E);
3898-
3899-
if (!E->isValueDependent()) {
3900-
ExprResult ICE;
3901-
if (checkRangedIntegralArgument<AttrType>(E, &TmpAttr, ICE))
3902-
return;
3903-
Expr::EvalResult Result;
3904-
E->EvaluateAsInt(Result, Context);
3905-
llvm::APSInt Value = Result.Val.getInt();
3906-
if (!Value.isPowerOf2()) {
3907-
Diag(CI.getLoc(), diag::err_attribute_argument_not_power_of_two)
3908-
<< &TmpAttr;
3909-
return;
3910-
}
3911-
if (IntelFPGANumBanksAttr::classof(&TmpAttr)) {
3912-
if (auto *BBA = D->getAttr<IntelFPGABankBitsAttr>()) {
3913-
unsigned NumBankBits = BBA->args_size();
3914-
if (NumBankBits != Value.ceilLogBase2()) {
3915-
Diag(TmpAttr.getLocation(), diag::err_bankbits_numbanks_conflicting);
3916-
return;
3917-
}
3918-
}
3919-
}
3920-
E = ICE.get();
3921-
}
3922-
3923-
if (!D->hasAttr<IntelFPGAMemoryAttr>())
3924-
D->addAttr(IntelFPGAMemoryAttr::CreateImplicit(
3925-
Context, IntelFPGAMemoryAttr::Default));
3926-
3927-
// We are adding a user NumBanks, drop any implicit default.
3928-
if (IntelFPGANumBanksAttr::classof(&TmpAttr)) {
3929-
if (auto *NBA = D->getAttr<IntelFPGANumBanksAttr>())
3930-
if (NBA->isImplicit())
3931-
D->dropAttr<IntelFPGANumBanksAttr>();
3932-
}
3933-
3934-
D->addAttr(::new (Context) AttrType(Context, CI, E));
3935-
}
3936-
39373872
void Sema::AddAlignedAttr(Decl *D, const AttributeCommonInfo &CI, Expr *E,
39383873
bool IsPackExpansion) {
39393874
AlignedAttr TmpAttr(Context, CI, true, E);

clang/lib/Sema/SemaExpr.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,15 @@ bool Sema::DiagnoseUseOfDecl(NamedDecl *D, ArrayRef<SourceLocation> Locs,
210210
bool ObjCPropertyAccess,
211211
bool AvoidPartialAvailabilityChecks,
212212
ObjCInterfaceDecl *ClassReceiver) {
213+
if (getLangOpts().SYCLIsDevice) {
214+
if (auto VD = dyn_cast<VarDecl>(D)) {
215+
if (VD->getStorageClass() == SC_Static &&
216+
!VD->getType().isConstant(Context))
217+
SYCLDiagIfDeviceCode(*Locs.begin(), diag::err_sycl_restrict)
218+
<< Sema::KernelNonConstStaticDataVariable;
219+
}
220+
}
221+
213222
SourceLocation Loc = Locs.front();
214223
if (getLangOpts().CPlusPlus && isa<FunctionDecl>(D)) {
215224
// If there were any diagnostics suppressed by template argument deduction,

clang/lib/Sema/SemaSYCL.cpp

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -321,29 +321,16 @@ class MarkDeviceFunction : public RecursiveASTVisitor<MarkDeviceFunction> {
321321
return true;
322322
}
323323

324-
bool VisitMemberExpr(MemberExpr *E) {
325-
if (VarDecl *VD = dyn_cast<VarDecl>(E->getMemberDecl())) {
326-
bool IsConst = VD->getType().getNonReferenceType().isConstQualified();
327-
if (!IsConst && VD->isStaticDataMember())
328-
SemaRef.Diag(E->getExprLoc(), diag::err_sycl_restrict)
329-
<< Sema::KernelNonConstStaticDataVariable;
330-
}
331-
return true;
332-
}
333-
334324
bool VisitDeclRefExpr(DeclRefExpr *E) {
335-
Decl* D = E->getDecl();
325+
Decl *D = E->getDecl();
336326
if (SemaRef.isKnownGoodSYCLDecl(D))
337327
return true;
338328

339329
CheckSYCLType(E->getType(), E->getSourceRange());
340330
if (VarDecl *VD = dyn_cast<VarDecl>(D)) {
341331
bool IsConst = VD->getType().getNonReferenceType().isConstQualified();
342-
if (!IsConst && VD->isStaticDataMember())
343-
SemaRef.Diag(E->getExprLoc(), diag::err_sycl_restrict)
344-
<< Sema::KernelNonConstStaticDataVariable;
345-
else if (!IsConst && VD->hasGlobalStorage() && !VD->isStaticLocal() &&
346-
!VD->isStaticDataMember() && !isa<ParmVarDecl>(VD)) {
332+
if (!IsConst && VD->hasGlobalStorage() && !VD->isStaticLocal() &&
333+
!VD->isStaticDataMember() && !isa<ParmVarDecl>(VD)) {
347334
if (VD->getTLSKind() != VarDecl::TLS_None)
348335
SemaRef.Diag(E->getLocation(), diag::err_thread_unsupported);
349336
SemaRef.Diag(E->getLocation(), diag::err_sycl_restrict)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// RUN: %clang_cc1 -verify -fsyntax-only -fsycl-is-device %s
2+
const int glob1 = 1;
3+
int glob2 = 2;
4+
template <typename name, typename Func>
5+
__attribute__((sycl_kernel)) void kernel_single_task(Func kernelFunc) {
6+
// expected-note-re@+1{{called by 'kernel_single_task<fake_kernel, (lambda at {{.*}})>}}
7+
kernelFunc();
8+
}
9+
10+
int main() {
11+
static int n = 0;
12+
const static int l = 0;
13+
kernel_single_task<class fake_kernel>([]() {
14+
int m = l;
15+
m = glob1;
16+
// expected-error@+1{{SYCL kernel cannot use a non-const static data variable}}
17+
m = n;
18+
// expected-error@+1{{SYCL kernel cannot use a non-const global variable}}
19+
m = glob2;
20+
});
21+
return 0;
22+
}

0 commit comments

Comments
 (0)