From 3598dbc007bab6fa3f866c405fbd7e1d55ca25f3 Mon Sep 17 00:00:00 2001 From: Aleksander Fadeev Date: Fri, 28 Feb 2020 13:49:46 +0300 Subject: [PATCH] [SYCL] Forbid non-const static variable uses in device code (fix #7) Signed-off-by: Aleksander Fadeev --- clang/lib/Sema/SemaExpr.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index a79e347d26b09..bbebd926d9b24 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -211,12 +211,14 @@ bool Sema::DiagnoseUseOfDecl(NamedDecl *D, ArrayRef Locs, bool AvoidPartialAvailabilityChecks, ObjCInterfaceDecl *ClassReceiver) { if (getLangOpts().SYCLIsDevice) { - if (auto VD = dyn_cast(D)) + if (auto VD = dyn_cast(D)) { if (VD->getStorageClass() == SC_Static && !VD->getType().isConstant(Context)) SYCLDiagIfDeviceCode(*Locs.begin(), diag::err_sycl_restrict) << Sema::KernelNonConstStaticDataVariable; + } } + SourceLocation Loc = Locs.front(); if (getLangOpts().CPlusPlus && isa(D)) { // If there were any diagnostics suppressed by template argument deduction,