Skip to content

Commit 735c6cd

Browse files
author
Anastasia Stulova
committed
[OpenCL] Adding reserved operator logical xor for OpenCL
This patch adds the reserved operator ^^ when compiling for OpenCL (spec v1.1 s6.3.g), which results in a more meaningful error message. Patch by Neil Hickey! Review: http://reviews.llvm.org/D13280 M test/SemaOpenCL/unsupported.cl M include/clang/Basic/TokenKinds.def M include/clang/Basic/DiagnosticParseKinds.td M lib/Basic/OperatorPrecedence.cpp M lib/Lex/Lexer.cpp M lib/Parse/ParseExpr.cpp llvm-svn: 259651
1 parent b4ee0af commit 735c6cd

File tree

6 files changed

+17
-1
lines changed

6 files changed

+17
-1
lines changed

clang/include/clang/Basic/DiagnosticParseKinds.td

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -910,9 +910,11 @@ def warn_pragma_expected_enable_disable : Warning<
910910
def warn_pragma_unknown_extension : Warning<
911911
"unknown OpenCL extension %0 - ignoring">, InGroup<IgnoredPragmas>;
912912

913-
// OpenCL error
913+
// OpenCL errors.
914914
def err_opencl_taking_function_address_parser : Error<
915915
"taking address of function is not allowed">;
916+
def err_opencl_logical_exclusive_or : Error<
917+
"^^ is a reserved operator in OpenCL">;
916918

917919
// OpenMP support.
918920
def warn_pragma_omp_ignored : Warning<

clang/include/clang/Basic/TokenKinds.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,9 @@ PUNCTUATOR(at, "@")
219219
PUNCTUATOR(lesslessless, "<<<")
220220
PUNCTUATOR(greatergreatergreater, ">>>")
221221

222+
// CL support
223+
PUNCTUATOR(caretcaret, "^^")
224+
222225
// C99 6.4.1: Keywords. These turn into kw_* tokens.
223226
// Flags allowed:
224227
// KEYALL - This is a keyword in all variants of C and C++, or it

clang/lib/Basic/OperatorPrecedence.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ prec::Level getBinOpPrecedence(tok::TokenKind Kind, bool GreaterThanIsOperator,
5353
case tok::pipeequal: return prec::Assignment;
5454
case tok::question: return prec::Conditional;
5555
case tok::pipepipe: return prec::LogicalOr;
56+
case tok::caretcaret:
5657
case tok::ampamp: return prec::LogicalAnd;
5758
case tok::pipe: return prec::InclusiveOr;
5859
case tok::caret: return prec::ExclusiveOr;

clang/lib/Lex/Lexer.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3505,6 +3505,9 @@ bool Lexer::LexTokenInternal(Token &Result, bool TokAtPhysicalStartOfLine) {
35053505
if (Char == '=') {
35063506
CurPtr = ConsumeChar(CurPtr, SizeTmp, Result);
35073507
Kind = tok::caretequal;
3508+
} else if (LangOpts.OpenCL && Char == '^') {
3509+
CurPtr = ConsumeChar(CurPtr, SizeTmp, Result);
3510+
Kind = tok::caretcaret;
35083511
} else {
35093512
Kind = tok::caret;
35103513
}

clang/lib/Parse/ParseExpr.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,9 @@ Parser::ParseRHSOfBinaryExpression(ExprResult LHS, prec::Level MinPrec) {
263263
Token OpToken = Tok;
264264
ConsumeToken();
265265

266+
if (OpToken.is(tok::caretcaret)) {
267+
return ExprError(Diag(Tok, diag::err_opencl_logical_exclusive_or));
268+
}
266269
// Bail out when encountering a comma followed by a token which can't
267270
// possibly be the start of an expression. For instance:
268271
// int f() { return 1, }

clang/test/SemaOpenCL/unsupported.cl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,7 @@ struct {
77
void no_vla(int n) {
88
int a[n]; // expected-error {{variable length arrays are not supported in OpenCL}}
99
}
10+
11+
void no_logxor(int n) {
12+
int logxor = n ^^ n; // expected-error {{^^ is a reserved operator in OpenCL}}
13+
}

0 commit comments

Comments
 (0)