]> granicus.if.org Git - clang/commitdiff
[OpenCL] Adding reserved operator logical xor for OpenCL
authorAnastasia Stulova <anastasia.stulova@arm.com>
Wed, 3 Feb 2016 15:17:14 +0000 (15:17 +0000)
committerAnastasia Stulova <anastasia.stulova@arm.com>
Wed, 3 Feb 2016 15:17:14 +0000 (15:17 +0000)
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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@259651 91177308-0d34-0410-b5e6-96231b3b80d8

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 f8dee2f98cca48674086336b0e57b4a95d46f70b..f00f03df76dcd99c271665ed72377c9fa56fc31b 100644 (file)
@@ -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<
index 026945141d24efb93c4def552612df65693f9c49..1a0b141a612749a53214ad2622bc9beb89decc44 100644 (file)
@@ -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
index ade8d6d841df02403f74cbff14e4bf6979b8b55f..384d23c38af5c53d947f007dd4460b494ade996b 100644 (file)
@@ -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;
index 88e7b247806c70d9f3b76aadbb3d1554306271b1..43bd12f24352c20bcab35671fdc92545a0420954 100644 (file)
@@ -3505,6 +3505,9 @@ LexNextToken:
     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 13b77223acc6f3ab0301fb07cb54f8b9f4f0256d..f76e2297337d4d72faf1ad09e8b8830817dc7b7b 100644 (file)
@@ -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, }
index bb9da4b272d72e9bc47a4bb028d0833cd41e78f9..a39a61b9542a07c5baaca1d8b61f63be703f6941 100644 (file)
@@ -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}}
+}