Skip to content

Commit a36ebb2

Browse files
committed
[SYCL] Enable more OpenCL diagnostics for SYCL
Signed-off-by: Alexey Bader <alexey.bader@intel.com>
1 parent 877dc6c commit a36ebb2

File tree

4 files changed

+30
-28
lines changed

4 files changed

+30
-28
lines changed

clang/lib/Sema/SemaDecl.cpp

+20-20
Original file line numberDiff line numberDiff line change
@@ -6327,6 +6327,26 @@ NamedDecl *Sema::ActOnVariableDeclarator(
63276327
return nullptr;
63286328
}
63296329

6330+
if (R->isSamplerT()) {
6331+
// OpenCL v1.2 s6.9.b p4:
6332+
// The sampler type cannot be used with the __local and __global address
6333+
// space qualifiers.
6334+
if (R.getAddressSpace() == LangAS::opencl_local ||
6335+
R.getAddressSpace() == LangAS::opencl_global) {
6336+
Diag(D.getIdentifierLoc(), diag::err_wrong_sampler_addressspace);
6337+
}
6338+
6339+
// OpenCL v1.2 s6.12.14.1:
6340+
// A global sampler must be declared with either the constant address
6341+
// space qualifier or with the const qualifier.
6342+
if (DC->isTranslationUnit() &&
6343+
!(R.getAddressSpace() == LangAS::opencl_constant ||
6344+
R.isConstQualified())) {
6345+
Diag(D.getIdentifierLoc(), diag::err_opencl_nonconst_global_sampler);
6346+
D.setInvalidType();
6347+
}
6348+
}
6349+
63306350
if (getLangOpts().OpenCL) {
63316351
// OpenCL v2.0 s6.9.b - Image type can only be used as a function argument.
63326352
// OpenCL v2.0 s6.13.16.1 - Pipe type can only be used as a function
@@ -6372,26 +6392,6 @@ NamedDecl *Sema::ActOnVariableDeclarator(
63726392
}
63736393
}
63746394

6375-
if (R->isSamplerT()) {
6376-
// OpenCL v1.2 s6.9.b p4:
6377-
// The sampler type cannot be used with the __local and __global address
6378-
// space qualifiers.
6379-
if (R.getAddressSpace() == LangAS::opencl_local ||
6380-
R.getAddressSpace() == LangAS::opencl_global) {
6381-
Diag(D.getIdentifierLoc(), diag::err_wrong_sampler_addressspace);
6382-
}
6383-
6384-
// OpenCL v1.2 s6.12.14.1:
6385-
// A global sampler must be declared with either the constant address
6386-
// space qualifier or with the const qualifier.
6387-
if (DC->isTranslationUnit() &&
6388-
!(R.getAddressSpace() == LangAS::opencl_constant ||
6389-
R.isConstQualified())) {
6390-
Diag(D.getIdentifierLoc(), diag::err_opencl_nonconst_global_sampler);
6391-
D.setInvalidType();
6392-
}
6393-
}
6394-
63956395
// OpenCL v1.2 s6.9.r:
63966396
// The event type cannot be used with the __local, __constant and __global
63976397
// address space qualifiers.

clang/lib/Sema/SemaExpr.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -12404,7 +12404,7 @@ ExprResult Sema::CreateBuiltinBinOp(SourceLocation OpLoc,
1240412404
if (!LHS.isUsable() || !RHS.isUsable())
1240512405
return ExprError();
1240612406

12407-
if (getLangOpts().OpenCL || getLangOpts().SYCLIsDevice) {
12407+
if (getLangOpts().OpenCL) {
1240812408
QualType LHSTy = LHSExpr->getType();
1240912409
QualType RHSTy = RHSExpr->getType();
1241012410
// OpenCLC v2.0 s6.13.11.1 allows atomic variables to be initialized by
@@ -13019,7 +13019,7 @@ ExprResult Sema::CreateBuiltinUnaryOp(SourceLocation OpLoc,
1301913019
bool CanOverflow = false;
1302013020

1302113021
bool ConvertHalfVec = false;
13022-
if (getLangOpts().OpenCL) {
13022+
if (getLangOpts().OpenCL || getLangOpts().SYCLIsDevice) {
1302313023
QualType Ty = InputExpr->getType();
1302413024
// The only legal unary operation for atomics is '&'.
1302513025
if ((Opc != UO_AddrOf && Ty->isAtomicType()) ||

clang/lib/Sema/SemaInit.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -5620,6 +5620,9 @@ void InitializationSequence::InitializeFrom(Sema &S,
56205620
bool allowObjCWritebackConversion = S.getLangOpts().ObjCAutoRefCount &&
56215621
Entity.isParameterKind();
56225622

5623+
if (TryOCLSamplerInitialization(S, *this, DestType, Initializer))
5624+
return;
5625+
56235626
// We're at the end of the line for C: it's either a write-back conversion
56245627
// or it's a C assignment. There's no need to check anything else.
56255628
if (!S.getLangOpts().CPlusPlus) {
@@ -5629,9 +5632,6 @@ void InitializationSequence::InitializeFrom(Sema &S,
56295632
return;
56305633
}
56315634

5632-
if (TryOCLSamplerInitialization(S, *this, DestType, Initializer))
5633-
return;
5634-
56355635
if (TryOCLZeroOpaqueTypeInitialization(S, *this, DestType, Initializer))
56365636
return;
56375637

clang/lib/Sema/SemaType.cpp

+5-3
Original file line numberDiff line numberDiff line change
@@ -2303,7 +2303,7 @@ QualType Sema::BuildArrayType(QualType T, ArrayType::ArraySizeModifier ASM,
23032303
// OpenCL v2.0 s6.12.5 - Arrays of blocks are not supported.
23042304
// OpenCL v2.0 s6.16.13.1 - Arrays of pipe type are not supported.
23052305
// OpenCL v2.0 s6.9.b - Arrays of image/sampler type are not supported.
2306-
if (getLangOpts().OpenCL) {
2306+
if (getLangOpts().OpenCL || getLangOpts().SYCLIsDevice) {
23072307
const QualType ArrType = Context.getBaseElementType(T);
23082308
if (ArrType->isBlockPointerType() || ArrType->isPipeType() ||
23092309
ArrType->isSamplerT() || ArrType->isImageType()) {
@@ -4389,7 +4389,7 @@ static TypeSourceInfo *GetFullTypeForDeclarator(TypeProcessingState &state,
43894389
// OpenCL v2.0 s6.9b - Pointer to image/sampler cannot be used.
43904390
// OpenCL v2.0 s6.13.16.1 - Pointer to pipe cannot be used.
43914391
// OpenCL v2.0 s6.12.5 - Pointers to Blocks are not allowed.
4392-
if (LangOpts.OpenCL) {
4392+
if (LangOpts.OpenCL || LangOpts.SYCLIsDevice) {
43934393
if (T->isImageType() || T->isSamplerT() || T->isPipeType() ||
43944394
T->isBlockPointerType()) {
43954395
S.Diag(D.getIdentifierLoc(), diag::err_opencl_pointer_to_type) << T;
@@ -4587,7 +4587,7 @@ static TypeSourceInfo *GetFullTypeForDeclarator(TypeProcessingState &state,
45874587
}
45884588
}
45894589

4590-
if (LangOpts.OpenCL) {
4590+
if (LangOpts.OpenCL || LangOpts.SYCLIsDevice) {
45914591
// OpenCL v2.0 s6.12.5 - A block cannot be the return value of a
45924592
// function.
45934593
if (T->isBlockPointerType() || T->isImageType() || T->isSamplerT() ||
@@ -4599,7 +4599,9 @@ static TypeSourceInfo *GetFullTypeForDeclarator(TypeProcessingState &state,
45994599
// OpenCL doesn't support variadic functions and blocks
46004600
// (s6.9.e and s6.12.5 OpenCL v2.0) except for printf.
46014601
// We also allow here any toolchain reserved identifiers.
4602+
// FIXME: Use deferred diagnostics engine to skip host side issues.
46024603
if (FTI.isVariadic &&
4604+
!LangOpts.SYCLIsDevice &&
46034605
!(D.getIdentifier() &&
46044606
((D.getIdentifier()->getName() == "printf" &&
46054607
(LangOpts.OpenCLCPlusPlus || LangOpts.OpenCLVersion >= 120)) ||

0 commit comments

Comments
 (0)