From 62b088a21701107ad4318ce58be293ba77c82854 Mon Sep 17 00:00:00 2001 From: Chris Perkins Date: Mon, 13 Apr 2020 14:08:56 -0700 Subject: [PATCH 1/5] moved VLA test, updated lit tests Signed-off-by: Chris Perkins --- clang/lib/Sema/SemaSYCL.cpp | 11 ++++++++++- clang/test/SemaSYCL/sycl-restrict.cpp | 14 +++++++------- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/clang/lib/Sema/SemaSYCL.cpp b/clang/lib/Sema/SemaSYCL.cpp index e795947add373..ec7c2446efb9f 100644 --- a/clang/lib/Sema/SemaSYCL.cpp +++ b/clang/lib/Sema/SemaSYCL.cpp @@ -236,6 +236,10 @@ static void checkSYCLVarType(Sema &S, QualType Ty, SourceRange Loc, emitDeferredDiagnosticAndNote(S, Loc, diag::err_typecheck_zero_array_size, UsedAtLoc); + // variable length arrays + if (Ty->isVariableArrayType()) + emitDeferredDiagnosticAndNote(S, Loc, diag::err_vla_unsupported, UsedAtLoc); + // Sub-reference array or pointer, then proceed with that type. while (Ty->isAnyPointerType() || Ty->isArrayType()) Ty = QualType{Ty->getPointeeOrArrayElementType(), 0}; @@ -508,11 +512,16 @@ class MarkDeviceFunction : public RecursiveASTVisitor { private: bool CheckSYCLType(QualType Ty, SourceRange Loc) { llvm::DenseSet visited; - return CheckSYCLType(Ty, Loc, visited); + return true; + //return CheckSYCLType(Ty, Loc, visited); } bool CheckSYCLType(QualType Ty, SourceRange Loc, llvm::DenseSet &Visited) { + + return true; + + if (Ty->isVariableArrayType()) { SemaRef.Diag(Loc.getBegin(), diag::err_vla_unsupported); return false; diff --git a/clang/test/SemaSYCL/sycl-restrict.cpp b/clang/test/SemaSYCL/sycl-restrict.cpp index 097baf742403f..482e64327618f 100644 --- a/clang/test/SemaSYCL/sycl-restrict.cpp +++ b/clang/test/SemaSYCL/sycl-restrict.cpp @@ -36,7 +36,7 @@ void no_restriction(int p) { int index[p + 2]; } void restriction(int p) { - int index[p + 2]; // expected-error {{variable length arrays are not supported for the current target}} + int index[p + 2]; // expected-error 2{{variable length arrays are not supported for the current target}} } } // namespace Check_VLA_Restriction @@ -67,7 +67,7 @@ bool isa_B(A *a) { if (f1 == f2) // expected-note 2{{called by 'isa_B'}} return false; - Check_VLA_Restriction::restriction(7); + Check_VLA_Restriction::restriction(7); // expected-note 2{{called by 'isa_B'}} int *ip = new int; // expected-error 2{{SYCL kernel cannot allocate storage}} int i; int *p3 = new (&i) int; // no error on placement new @@ -79,7 +79,7 @@ bool isa_B(A *a) { template __attribute__((sycl_kernel)) void kernel1(L l) { - l(); // expected-note 6{{called by 'kernel1([]() { // expected-note 3{{called by 'usage'}} + Check_RTTI_Restriction::kernel1([]() { // expected-note 4{{called by 'usage'}} Check_RTTI_Restriction::A *a; - Check_RTTI_Restriction::isa_B(a); // expected-note 6{{called by 'operator()'}} + Check_RTTI_Restriction::isa_B(a); // expected-note 8{{called by 'operator()'}} }); // ======= Float128 Not Allowed in Kernel ========== @@ -323,7 +323,7 @@ int use2(a_type ab, a_type *abp) { template __attribute__((sycl_kernel)) void kernel_single_task(Func kernelFunc) { - kernelFunc(); // expected-note 7{{called by 'kernel_single_task([=]() { - usage(&addInt); // expected-note 5{{called by 'operator()'}} + usage(&addInt); // expected-note 6{{called by 'operator()'}} a_type *p; use2(ab, p); // expected-note 2{{called by 'operator()'}} }); From 0a78215089ef175350a4a37a3fdbd734d8096b19 Mon Sep 17 00:00:00 2001 From: Chris Perkins Date: Mon, 13 Apr 2020 14:26:56 -0700 Subject: [PATCH 2/5] removing CheckSYCLType and calls to it. Several AST Visitor methods retired as well Signed-off-by: Chris Perkins --- clang/lib/Sema/SemaSYCL.cpp | 103 ------------------------------------ 1 file changed, 103 deletions(-) diff --git a/clang/lib/Sema/SemaSYCL.cpp b/clang/lib/Sema/SemaSYCL.cpp index ec7c2446efb9f..99400370646b0 100644 --- a/clang/lib/Sema/SemaSYCL.cpp +++ b/clang/lib/Sema/SemaSYCL.cpp @@ -288,9 +288,6 @@ class MarkDeviceFunction : public RecursiveASTVisitor { : RecursiveASTVisitor(), SemaRef(S) {} bool VisitCallExpr(CallExpr *e) { - for (const auto &Arg : e->arguments()) - CheckSYCLType(Arg->getType(), Arg->getSourceRange()); - if (FunctionDecl *Callee = e->getDirectCallee()) { Callee = Callee->getCanonicalDecl(); assert(Callee && "Device function canonical decl must be available"); @@ -312,8 +309,6 @@ class MarkDeviceFunction : public RecursiveASTVisitor { SemaRef.Diag(e->getExprLoc(), diag::err_sycl_restrict) << Sema::KernelCallVirtualFunction; - CheckSYCLType(Callee->getReturnType(), Callee->getSourceRange()); - if (auto const *FD = dyn_cast(Callee)) { // FIXME: We need check all target specified attributes for error if // that function with attribute can not be called from sycl kernel. The @@ -342,12 +337,6 @@ class MarkDeviceFunction : public RecursiveASTVisitor { return true; } - bool VisitCXXConstructExpr(CXXConstructExpr *E) { - for (const auto &Arg : E->arguments()) - CheckSYCLType(Arg->getType(), Arg->getSourceRange()); - return true; - } - bool VisitCXXTypeidExpr(CXXTypeidExpr *E) { SemaRef.Diag(E->getExprLoc(), diag::err_sycl_restrict) << Sema::KernelRTTI; return true; @@ -358,35 +347,6 @@ class MarkDeviceFunction : public RecursiveASTVisitor { return true; } - bool VisitTypedefNameDecl(TypedefNameDecl *TD) { - CheckSYCLType(TD->getUnderlyingType(), TD->getLocation()); - return true; - } - - bool VisitRecordDecl(RecordDecl *RD) { - CheckSYCLType(QualType{RD->getTypeForDecl(), 0}, RD->getLocation()); - return true; - } - - bool VisitParmVarDecl(VarDecl *VD) { - CheckSYCLType(VD->getType(), VD->getLocation()); - return true; - } - - bool VisitVarDecl(VarDecl *VD) { - CheckSYCLType(VD->getType(), VD->getLocation()); - return true; - } - - bool VisitDeclRefExpr(DeclRefExpr *E) { - Decl *D = E->getDecl(); - if (SemaRef.isKnownGoodSYCLDecl(D)) - return true; - - CheckSYCLType(E->getType(), E->getSourceRange()); - return true; - } - // The call graph for this translation unit. CallGraph SYCLCG; // The set of functions called by a kernel function. @@ -510,69 +470,6 @@ class MarkDeviceFunction : public RecursiveASTVisitor { } private: - bool CheckSYCLType(QualType Ty, SourceRange Loc) { - llvm::DenseSet visited; - return true; - //return CheckSYCLType(Ty, Loc, visited); - } - - bool CheckSYCLType(QualType Ty, SourceRange Loc, - llvm::DenseSet &Visited) { - - return true; - - - if (Ty->isVariableArrayType()) { - SemaRef.Diag(Loc.getBegin(), diag::err_vla_unsupported); - return false; - } - - while (Ty->isAnyPointerType() || Ty->isArrayType()) - Ty = QualType{Ty->getPointeeOrArrayElementType(), 0}; - - // Pointers complicate recursion. Add this type to Visited. - // If already there, bail out. - if (!Visited.insert(Ty).second) - return true; - - if (const auto *ATy = dyn_cast(Ty)) - return CheckSYCLType(ATy->getModifiedType(), Loc, Visited); - - if (const auto *CRD = Ty->getAsCXXRecordDecl()) { - // If the class is a forward declaration - skip it, because otherwise we - // would query property of class with no definition, which results in - // clang crash. - if (!CRD->hasDefinition()) - return true; - - for (const auto &Field : CRD->fields()) { - if (!CheckSYCLType(Field->getType(), Field->getSourceRange(), - Visited)) { - if (SemaRef.getLangOpts().SYCLIsDevice) - SemaRef.Diag(Loc.getBegin(), diag::note_sycl_used_here); - return false; - } - } - } else if (const auto *RD = Ty->getAsRecordDecl()) { - for (const auto &Field : RD->fields()) { - if (!CheckSYCLType(Field->getType(), Field->getSourceRange(), - Visited)) { - if (SemaRef.getLangOpts().SYCLIsDevice) - SemaRef.Diag(Loc.getBegin(), diag::note_sycl_used_here); - return false; - } - } - } else if (const auto *FPTy = dyn_cast(Ty)) { - for (const auto &ParamTy : FPTy->param_types()) - if (!CheckSYCLType(ParamTy, Loc, Visited)) - return false; - return CheckSYCLType(FPTy->getReturnType(), Loc, Visited); - } else if (const auto *FTy = dyn_cast(Ty)) { - return CheckSYCLType(FTy->getReturnType(), Loc, Visited); - } - return true; - } - Sema &SemaRef; }; From 5681620bfd2e7edece6e6fed45f8c156b13d46a2 Mon Sep 17 00:00:00 2001 From: Chris Perkins Date: Mon, 13 Apr 2020 14:42:44 -0700 Subject: [PATCH 3/5] clang-formattery Signed-off-by: Chris Perkins --- clang/lib/Sema/SemaSYCL.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/lib/Sema/SemaSYCL.cpp b/clang/lib/Sema/SemaSYCL.cpp index 99400370646b0..1c07c91e7dbb7 100644 --- a/clang/lib/Sema/SemaSYCL.cpp +++ b/clang/lib/Sema/SemaSYCL.cpp @@ -238,7 +238,7 @@ static void checkSYCLVarType(Sema &S, QualType Ty, SourceRange Loc, // variable length arrays if (Ty->isVariableArrayType()) - emitDeferredDiagnosticAndNote(S, Loc, diag::err_vla_unsupported, UsedAtLoc); + emitDeferredDiagnosticAndNote(S, Loc, diag::err_vla_unsupported, UsedAtLoc); // Sub-reference array or pointer, then proceed with that type. while (Ty->isAnyPointerType() || Ty->isArrayType()) From cba85e50b9770a22c94c2df1e4fd717d6ba4b0e2 Mon Sep 17 00:00:00 2001 From: Chris Perkins Date: Tue, 14 Apr 2020 14:34:50 -0700 Subject: [PATCH 4/5] added some markers so the crazy nested notes get tidied up, at least for the vla error Signed-off-by: Chris Perkins --- clang/test/SemaSYCL/sycl-restrict.cpp | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/clang/test/SemaSYCL/sycl-restrict.cpp b/clang/test/SemaSYCL/sycl-restrict.cpp index 482e64327618f..4bfd6e8bf0d9f 100644 --- a/clang/test/SemaSYCL/sycl-restrict.cpp +++ b/clang/test/SemaSYCL/sycl-restrict.cpp @@ -36,6 +36,15 @@ void no_restriction(int p) { int index[p + 2]; } void restriction(int p) { + // This particular violation is nested under two kernels with intermediate function calls. + // e.g. main -> 1stkernel -> usage -> 2ndkernel -> isa_B -> restriction -> !! + // Because the error is in two different kernels, we are given helpful notes for the origination of the error, twice. + // expected-note@#call_usage {{called by 'operator()'}} + // expected-note@#call_kernelFunc {{called by 'kernel_single_task __attribute__((sycl_kernel)) void kernel1(L l) { - l(); // expected-note 8{{called by 'kernel1([]() { // expected-note 4{{called by 'usage'}} + Check_RTTI_Restriction::kernel1([]() { //#call_rtti_kernel // expected-note 3{{called by 'usage'}} Check_RTTI_Restriction::A *a; - Check_RTTI_Restriction::isa_B(a); // expected-note 8{{called by 'operator()'}} + Check_RTTI_Restriction::isa_B(a); //#call_isa_B // expected-note 6{{called by 'operator()'}} }); // ======= Float128 Not Allowed in Kernel ========== @@ -323,7 +332,7 @@ int use2(a_type ab, a_type *abp) { template __attribute__((sycl_kernel)) void kernel_single_task(Func kernelFunc) { - kernelFunc(); // expected-note 8{{called by 'kernel_single_task([=]() { - usage(&addInt); // expected-note 6{{called by 'operator()'}} + usage(&addInt); //#call_usage // expected-note 5{{called by 'operator()'}} a_type *p; use2(ab, p); // expected-note 2{{called by 'operator()'}} }); From 75c6efd497f89f022be31d8e55f31af96ec0519e Mon Sep 17 00:00:00 2001 From: Chris Perkins Date: Tue, 14 Apr 2020 14:36:17 -0700 Subject: [PATCH 5/5] clang formatation Signed-off-by: Chris Perkins --- clang/test/SemaSYCL/sycl-restrict.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clang/test/SemaSYCL/sycl-restrict.cpp b/clang/test/SemaSYCL/sycl-restrict.cpp index 4bfd6e8bf0d9f..ba946097be9da 100644 --- a/clang/test/SemaSYCL/sycl-restrict.cpp +++ b/clang/test/SemaSYCL/sycl-restrict.cpp @@ -38,7 +38,7 @@ void no_restriction(int p) { void restriction(int p) { // This particular violation is nested under two kernels with intermediate function calls. // e.g. main -> 1stkernel -> usage -> 2ndkernel -> isa_B -> restriction -> !! - // Because the error is in two different kernels, we are given helpful notes for the origination of the error, twice. + // Because the error is in two different kernels, we are given helpful notes for the origination of the error, twice. // expected-note@#call_usage {{called by 'operator()'}} // expected-note@#call_kernelFunc {{called by 'kernel_single_task