[PATCH] D13280: Adding reserved operator logical xor for OpenCL
Neil Hickey via cfe-commits
cfe-commits at lists.llvm.org
Wed Sep 30 01:36:59 PDT 2015
neil.hickey created this revision.
neil.hickey added a reviewer: cfe-commits.
This patch adds the reserved operator ^^ when compiling for OpenCL, which results in a more meaningful error message.
http://reviews.llvm.org/D13280
Files:
include/clang/Basic/DiagnosticParseKinds.td
include/clang/Basic/TokenKinds.def
lib/Basic/OperatorPrecedence.cpp
lib/Lex/Lexer.cpp
lib/Parse/ParseExpr.cpp
test/SemaOpenCL/unsupported.cl
Index: test/SemaOpenCL/unsupported.cl
===================================================================
--- test/SemaOpenCL/unsupported.cl
+++ test/SemaOpenCL/unsupported.cl
@@ -7,3 +7,7 @@
void no_vla(int n) {
int a[n]; // expected-error {{variable length arrays are not supported in OpenCL}}
}
+
+void no_logxor(int n) {
+ int logxor = n ^^ n; // expected-error {{^^ is a reserved operator in OpenCL}}
+}
Index: lib/Parse/ParseExpr.cpp
===================================================================
--- lib/Parse/ParseExpr.cpp
+++ lib/Parse/ParseExpr.cpp
@@ -261,6 +261,9 @@
Token OpToken = Tok;
ConsumeToken();
+ if (OpToken.is(tok::caretcaret)) {
+ return ExprError(Diag(Tok, diag::err_opencl_logical_exclusive_or));
+ }
// Bail out when encountering a comma followed by a token which can't
// possibly be the start of an expression. For instance:
// int f() { return 1, }
Index: lib/Lex/Lexer.cpp
===================================================================
--- lib/Lex/Lexer.cpp
+++ lib/Lex/Lexer.cpp
@@ -3473,6 +3473,9 @@
if (Char == '=') {
CurPtr = ConsumeChar(CurPtr, SizeTmp, Result);
Kind = tok::caretequal;
+ } else if (LangOpts.OpenCL && Char == '^') {
+ CurPtr = ConsumeChar(CurPtr, SizeTmp, Result);
+ Kind = tok::caretcaret;
} else {
Kind = tok::caret;
}
Index: lib/Basic/OperatorPrecedence.cpp
===================================================================
--- lib/Basic/OperatorPrecedence.cpp
+++ lib/Basic/OperatorPrecedence.cpp
@@ -53,6 +53,7 @@
case tok::pipeequal: return prec::Assignment;
case tok::question: return prec::Conditional;
case tok::pipepipe: return prec::LogicalOr;
+ case tok::caretcaret:
case tok::ampamp: return prec::LogicalAnd;
case tok::pipe: return prec::InclusiveOr;
case tok::caret: return prec::ExclusiveOr;
Index: include/clang/Basic/TokenKinds.def
===================================================================
--- include/clang/Basic/TokenKinds.def
+++ include/clang/Basic/TokenKinds.def
@@ -219,6 +219,9 @@
PUNCTUATOR(lesslessless, "<<<")
PUNCTUATOR(greatergreatergreater, ">>>")
+// CL support
+PUNCTUATOR(caretcaret, "^^")
+
// C99 6.4.1: Keywords. These turn into kw_* tokens.
// Flags allowed:
// KEYALL - This is a keyword in all variants of C and C++, or it
Index: include/clang/Basic/DiagnosticParseKinds.td
===================================================================
--- include/clang/Basic/DiagnosticParseKinds.td
+++ include/clang/Basic/DiagnosticParseKinds.td
@@ -964,6 +964,8 @@
// OpenCL Section 6.8.g
def err_opencl_unknown_type_specifier : Error<
"OpenCL does not support the '%0' %select{type qualifier|storage class specifier}1">;
+def err_opencl_logical_exclusive_or : Error<
+ "^^ is a reserved operator in OpenCL">;
// OpenCL EXTENSION pragma (OpenCL 1.1 [9.1])
def warn_pragma_expected_colon : Warning<
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D13280.36074.patch
Type: text/x-patch
Size: 3042 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150930/f5587b54/attachment.bin>
More information about the cfe-commits
mailing list