[PATCH] D34031: [OpenCL] Diagnose some reserved types
Sven van Haastregt via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Jun 8 05:46:40 PDT 2017
svenvh created this revision.
Catch uses of the 'long long', 'unsigned long long', and 'long double'
reserved types.
Remove use of 'long long' in test/Misc/languageOptsOpenCL.cl; it
shouldn't have been added there in the first place as the OpenCL
specification explicitly forbids it in s6.1.4.
Initial patch by Simon Perretta.
https://reviews.llvm.org/D34031
Files:
include/clang/Basic/DiagnosticSemaKinds.td
lib/Sema/SemaType.cpp
test/Misc/languageOptsOpenCL.cl
test/SemaOpenCL/unsupported.cl
Index: test/SemaOpenCL/unsupported.cl
===================================================================
--- test/SemaOpenCL/unsupported.cl
+++ test/SemaOpenCL/unsupported.cl
@@ -11,3 +11,10 @@
void no_logxor(int n) {
int logxor = n ^^ n; // expected-error {{^^ is a reserved operator in OpenCL}}
}
+
+#pragma OPENCL EXTENSION cl_khr_fp64 : enable
+
+kernel void no_long_double(global long double *n) {} // expected-error {{'long double' is a reserved type in OpenCL}}
+
+kernel void no_long_long(global long long *n) {} // expected-error {{'long long' is a reserved type in OpenCL}}
+kernel void no_unsigned_long_long(global unsigned long long *n) {} // expected-error {{'unsigned long long' is a reserved type in OpenCL}}
Index: test/Misc/languageOptsOpenCL.cl
===================================================================
--- test/Misc/languageOptsOpenCL.cl
+++ test/Misc/languageOptsOpenCL.cl
@@ -8,14 +8,12 @@
int v1[(__alignof(int)== 4) - 1];
int v2[(sizeof(long) == 8) - 1];
int v3[(__alignof(long)== 8) - 1];
- int v4[(sizeof(long long) == 16) - 1];
- int v5[(__alignof(long long)== 16) - 1];
- int v6[(sizeof(float) == 4) - 1];
- int v7[(__alignof(float)== 4) - 1];
+ int v4[(sizeof(float) == 4) - 1];
+ int v5[(__alignof(float)== 4) - 1];
#pragma OPENCL EXTENSION cl_khr_fp64 : enable
- int v8[(sizeof(double) == 8) - 1];
- int v9[(__alignof(double)== 8) - 1];
+ int v6[(sizeof(double) == 8) - 1];
+ int v7[(__alignof(double)== 8) - 1];
#pragma OPENCL EXTENSION cl_khr_fp16 : enable
- int v10[(sizeof(half) == 2) - 1];
- int v11[(__alignof(half) == 2) - 1];
+ int v8[(sizeof(half) == 2) - 1];
+ int v9[(__alignof(half) == 2) - 1];
}
Index: lib/Sema/SemaType.cpp
===================================================================
--- lib/Sema/SemaType.cpp
+++ lib/Sema/SemaType.cpp
@@ -1363,6 +1363,11 @@
else
S.Diag(DS.getTypeSpecWidthLoc(), diag::ext_c99_longlong);
}
+ else if (S.getLangOpts().OpenCL) {
+ // OpenCL v2.0 s6.1.4: 'long long' is a reserved data type.
+ S.Diag(DS.getTypeSpecWidthLoc(), diag::err_ocl_type_reserved)
+ << "long long";
+ }
break;
}
} else {
@@ -1382,6 +1387,11 @@
else
S.Diag(DS.getTypeSpecWidthLoc(), diag::ext_c99_longlong);
}
+ else if (S.getLangOpts().OpenCL) {
+ // OpenCL v2.0 s6.1.4: 'unsigned long long' is a reserved data type.
+ S.Diag(DS.getTypeSpecWidthLoc(), diag::err_ocl_type_reserved)
+ << "unsigned long long";
+ }
break;
}
}
@@ -1399,9 +1409,14 @@
case DeclSpec::TST_half: Result = Context.HalfTy; break;
case DeclSpec::TST_float: Result = Context.FloatTy; break;
case DeclSpec::TST_double:
- if (DS.getTypeSpecWidth() == DeclSpec::TSW_long)
+ if (DS.getTypeSpecWidth() == DeclSpec::TSW_long) {
Result = Context.LongDoubleTy;
- else
+ if (S.getLangOpts().OpenCL) {
+ // OpenCL v2.0 s6.1.4: 'long double' is a reserved data type.
+ S.Diag(DS.getTypeSpecWidthLoc(), diag::err_ocl_type_reserved)
+ << "long double";
+ }
+ } else
Result = Context.DoubleTy;
break;
case DeclSpec::TST_float128:
Index: include/clang/Basic/DiagnosticSemaKinds.td
===================================================================
--- include/clang/Basic/DiagnosticSemaKinds.td
+++ include/clang/Basic/DiagnosticSemaKinds.td
@@ -8156,6 +8156,8 @@
"feature, not permitted in C++">;
def err_type_unsupported : Error<
"%0 is not supported on this target">;
+def err_ocl_type_reserved : Error<
+ "'%0' is a reserved type in OpenCL">;
def err_nsconsumed_attribute_mismatch : Error<
"overriding method has mismatched ns_consumed attribute on its"
" parameter">;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D34031.101897.patch
Type: text/x-patch
Size: 3815 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170608/6631022b/attachment.bin>
More information about the cfe-commits
mailing list