Skip to content

Commit 1881f64

Browse files
authored
Remove ^^ as a token in OpenCL (#108224)
OpenCL has a reserved operator (^^), the use of which was diagnosed as an error (735c6cd). However, OpenCL also encourages working with the blocks language extension. This token has a parsing ambiguity as a result. Consider: unsigned x=0; unsigned y=x^^{return 0;}(); This should result in y holding the value zero (0^0) through an immediately invoked block call as the right-hand side of the xor operator. However, it causes errors instead because of this reserved token: https://godbolt.org/z/navf7jTv1 This token is still reserved in OpenCL 3.0, so we still wish to issue a diagnostic for its use. However, we do not need to create a token for an extension point that's been unused for about a decade. So this patch moves the diagnostic from a parsing diagnostic to a lexing diagnostic and no longer forms a single token. The diagnostic behavior is slightly worse as a result, but still seems acceptable. Part of the reason this is coming up is because WG21 is considering using ^^ as a token for reflection, so this token may come back in the future.
1 parent 5aaf384 commit 1881f64

File tree

10 files changed

+9
-17
lines changed

10 files changed

+9
-17
lines changed

clang-tools-extra/clang-tidy/readability/AvoidUnconditionalPreprocessorIfCheck.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ struct AvoidUnconditionalPreprocessorIfPPCallbacks : public PPCallbacks {
8484
return (Tok.getRawIdentifier() == "true" ||
8585
Tok.getRawIdentifier() == "false");
8686
default:
87-
return Tok.getKind() >= tok::l_square && Tok.getKind() <= tok::caretcaret;
87+
return Tok.getKind() >= tok::l_square &&
88+
Tok.getKind() <= tok::greatergreatergreater;
8889
}
8990
}
9091

clang-tools-extra/pseudo/lib/cxx/cxx.bnf

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,6 @@ operator-name := >
639639
operator-name := <=
640640
operator-name := >=
641641
operator-name := <=>
642-
operator-name := ^^
643642
operator-name := ||
644643
operator-name := <<
645644
operator-name := greatergreater

clang/include/clang/Basic/DiagnosticLexKinds.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,8 @@ def note_macro_expansion_here : Note<"expansion of macro %0 requested here">;
508508

509509
def ext_pp_opencl_variadic_macros : Extension<
510510
"variadic macros are a Clang extension in OpenCL">;
511+
def err_opencl_logical_exclusive_or : Error<
512+
"^^ is a reserved operator in OpenCL">;
511513

512514
def ext_pp_gnu_line_directive : Extension<
513515
"this style of line directive is a GNU extension">,

clang/include/clang/Basic/DiagnosticParseKinds.td

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1397,8 +1397,6 @@ def err_modifier_expected_colon : Error<"missing ':' after %0 modifier">;
13971397
// OpenCL errors.
13981398
def err_opencl_taking_function_address_parser : Error<
13991399
"taking address of function is not allowed">;
1400-
def err_opencl_logical_exclusive_or : Error<
1401-
"^^ is a reserved operator in OpenCL">;
14021400

14031401
// C++ for OpenCL.
14041402
def err_openclcxx_virtual_function : Error<

clang/include/clang/Basic/TokenKinds.def

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -255,9 +255,6 @@ PUNCTUATOR(at, "@")
255255
PUNCTUATOR(lesslessless, "<<<")
256256
PUNCTUATOR(greatergreatergreater, ">>>")
257257

258-
// CL support
259-
PUNCTUATOR(caretcaret, "^^")
260-
261258
// C99 6.4.1: Keywords. These turn into kw_* tokens.
262259
// Flags allowed:
263260
// KEYALL - This is a keyword in all variants of C and C++, or it

clang/lib/Basic/OperatorPrecedence.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ prec::Level getBinOpPrecedence(tok::TokenKind Kind, bool GreaterThanIsOperator,
5252
case tok::pipeequal: return prec::Assignment;
5353
case tok::question: return prec::Conditional;
5454
case tok::pipepipe: return prec::LogicalOr;
55-
case tok::caretcaret:
5655
case tok::ampamp: return prec::LogicalAnd;
5756
case tok::pipe: return prec::InclusiveOr;
5857
case tok::caret: return prec::ExclusiveOr;

clang/lib/Lex/Lexer.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4325,10 +4325,9 @@ bool Lexer::LexTokenInternal(Token &Result, bool TokAtPhysicalStartOfLine) {
43254325
if (Char == '=') {
43264326
CurPtr = ConsumeChar(CurPtr, SizeTmp, Result);
43274327
Kind = tok::caretequal;
4328-
} else if (LangOpts.OpenCL && Char == '^') {
4329-
CurPtr = ConsumeChar(CurPtr, SizeTmp, Result);
4330-
Kind = tok::caretcaret;
43314328
} else {
4329+
if (LangOpts.OpenCL && Char == '^')
4330+
Diag(CurPtr, diag::err_opencl_logical_exclusive_or);
43324331
Kind = tok::caret;
43334332
}
43344333
break;

clang/lib/Parse/ParseExpr.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -446,10 +446,6 @@ Parser::ParseRHSOfBinaryExpression(ExprResult LHS, prec::Level MinPrec) {
446446
Token OpToken = Tok;
447447
ConsumeToken();
448448

449-
if (OpToken.is(tok::caretcaret)) {
450-
return ExprError(Diag(Tok, diag::err_opencl_logical_exclusive_or));
451-
}
452-
453449
// If we're potentially in a template-id, we may now be able to determine
454450
// whether we're actually in one or not.
455451
if (OpToken.isOneOf(tok::comma, tok::greater, tok::greatergreater,

clang/lib/Sema/SemaCodeComplete.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,6 @@ static QualType getPreferredTypeOfBinaryRHS(Sema &S, Expr *LHS,
520520
// Logical operators, assume we want bool.
521521
case tok::ampamp:
522522
case tok::pipepipe:
523-
case tok::caretcaret:
524523
return S.getASTContext().BoolTy;
525524
// Operators often used for bit manipulation are typically used with the type
526525
// of the left argument.

clang/test/SemaOpenCL/unsupported.cl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,7 @@ void no_vla(int n) {
1717
}
1818

1919
void no_logxor(int n) {
20-
int logxor = n ^^ n; // expected-error {{^^ is a reserved operator in OpenCL}}
20+
int logxor = n ^^ n; // expected-error {{^^ is a reserved operator in OpenCL}} \
21+
expected-error {{type name requires a specifier or qualifier}} \
22+
expected-error {{expected expression}}
2123
}

0 commit comments

Comments
 (0)