Skip to content

Commit

Permalink
[OpenCL] Adding reserved operator logical xor for OpenCL
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Anastasia Stulova committed Feb 3, 2016

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent b4ee0af commit 735c6cd
Showing 6 changed files with 17 additions and 1 deletion.
4 changes: 3 additions & 1 deletion clang/include/clang/Basic/DiagnosticParseKinds.td
Original file line number Diff line number Diff line change
@@ -910,9 +910,11 @@ def warn_pragma_expected_enable_disable : Warning<
def warn_pragma_unknown_extension : Warning<
"unknown OpenCL extension %0 - ignoring">, InGroup<IgnoredPragmas>;

// OpenCL error
// OpenCL errors.
def err_opencl_taking_function_address_parser : Error<
"taking address of function is not allowed">;
def err_opencl_logical_exclusive_or : Error<
"^^ is a reserved operator in OpenCL">;

// OpenMP support.
def warn_pragma_omp_ignored : Warning<
3 changes: 3 additions & 0 deletions clang/include/clang/Basic/TokenKinds.def
Original file line number Diff line number Diff line change
@@ -219,6 +219,9 @@ PUNCTUATOR(at, "@")
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
1 change: 1 addition & 0 deletions clang/lib/Basic/OperatorPrecedence.cpp
Original file line number Diff line number Diff line change
@@ -53,6 +53,7 @@ prec::Level getBinOpPrecedence(tok::TokenKind Kind, bool GreaterThanIsOperator,
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;
3 changes: 3 additions & 0 deletions clang/lib/Lex/Lexer.cpp
Original file line number Diff line number Diff line change
@@ -3505,6 +3505,9 @@ bool Lexer::LexTokenInternal(Token &Result, bool TokAtPhysicalStartOfLine) {
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;
}
3 changes: 3 additions & 0 deletions clang/lib/Parse/ParseExpr.cpp
Original file line number Diff line number Diff line change
@@ -263,6 +263,9 @@ Parser::ParseRHSOfBinaryExpression(ExprResult LHS, prec::Level MinPrec) {
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, }
4 changes: 4 additions & 0 deletions clang/test/SemaOpenCL/unsupported.cl
Original file line number Diff line number Diff line change
@@ -7,3 +7,7 @@ struct {
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}}
}

0 comments on commit 735c6cd

Please sign in to comment.