Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new keyword spellings with cilk_ instead of _Cilk_ #308

Merged
merged 1 commit into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions clang/include/clang/Basic/TokenKinds.def
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ KEYWORD(_Bool , KEYNOCXX)
KEYWORD(_Complex , KEYALL)
KEYWORD(_Generic , KEYALL)
KEYWORD(_Hyperobject , KEYALL)
KEYWORD(cilk_reducer , KEYOPENCILK)
// Note, C2y removed support for _Imaginary; we retain it as a keyword because
// 1) it's a reserved identifier, so we're allowed to steal it, 2) there's no
// good way to specify a keyword in earlier but not later language modes within
Expand Down Expand Up @@ -494,6 +495,10 @@ KEYWORD(_Cilk_spawn , KEYALL)
KEYWORD(_Cilk_sync , KEYALL)
KEYWORD(_Cilk_for , KEYALL)
KEYWORD(_Cilk_scope , KEYALL)
KEYWORD(cilk_spawn , KEYOPENCILK)
KEYWORD(cilk_sync , KEYOPENCILK)
KEYWORD(cilk_for , KEYOPENCILK)
KEYWORD(cilk_scope , KEYOPENCILK)

// MSVC12.0 / VS2013 Type Traits
TYPE_TRAIT_1(__is_destructible, IsDestructible, KEYALL)
Expand Down
6 changes: 5 additions & 1 deletion clang/lib/Basic/IdentifierTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ namespace {
KEYCUDA = 0x1000000,
KEYHLSL = 0x2000000,
KEYFIXEDPOINT = 0x4000000,
KEYMAX = KEYFIXEDPOINT, // The maximum key
KEYOPENCILK = 0x8000000,
KEYMAX = KEYOPENCILK, // The maximum key
KEYALLCXX = KEYCXX | KEYCXX11 | KEYCXX20,
KEYALL = (KEYMAX | (KEYMAX-1)) & ~KEYNOMS18 &
~KEYNOOPENCL // KEYNOMS18 and KEYNOOPENCL are used to exclude.
Expand Down Expand Up @@ -213,6 +214,9 @@ static KeywordStatus getKeywordStatusHelper(const LangOptions &LangOpts,
return KS_Unknown;
case KEYFIXEDPOINT:
return LangOpts.FixedPoint ? KS_Enabled : KS_Disabled;
case KEYOPENCILK:
return LangOpts.getCilk() == LangOptions::Cilk_opencilk ?
KS_Enabled : KS_Disabled;
default:
llvm_unreachable("Unknown KeywordStatus flag");
}
Expand Down
23 changes: 14 additions & 9 deletions clang/lib/Parse/ParseCilk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,17 @@ using namespace clang;
/// cilk_sync-statement:
/// '_Cilk_sync' ';'
StmtResult Parser::ParseCilkSyncStatement() {
assert(Tok.is(tok::kw__Cilk_sync) && "Not a _Cilk_sync stmt!");
assert(Tok.isOneOf(tok::kw__Cilk_sync, tok::kw_cilk_sync) &&
"Not a cilk_sync stmt!");
return Actions.ActOnCilkSyncStmt(ConsumeToken());
}

/// ParseCilkSpawnStatement
/// cilk_spawn-statement:
/// '_Cilk_spawn' statement
StmtResult Parser::ParseCilkSpawnStatement() {
assert(Tok.is(tok::kw__Cilk_spawn) && "Not a _Cilk_spawn stmt!");
assert(Tok.isOneOf(tok::kw__Cilk_spawn, tok::kw_cilk_spawn) &&
"Not a cilk_spawn stmt!");
SourceLocation SpawnLoc = ConsumeToken(); // eat the '_Cilk_spawn'.

unsigned ScopeFlags = Scope::BlockScope | Scope::FnScope | Scope::DeclScope;
Expand Down Expand Up @@ -149,9 +151,9 @@ struct MisleadingIndentationChecker {

/// ParseCilkForStatement
/// cilk_for-statement:
/// '_Cilk_for' '(' expr ';' expr ';' expr ')' statement
/// '_Cilk_for' '(' declaration expr ';' expr ';' expr ')' statement
/// [C++0x] '_Cilk_for'
/// 'cilk_for' '(' expr ';' expr ';' expr ')' statement
/// 'cilk_for' '(' declaration expr ';' expr ';' expr ')' statement
/// [C++0x] 'cilk_for'
/// '(' for-range-declaration ':' for-range-initializer ')'
/// statement
///
Expand All @@ -161,15 +163,17 @@ struct MisleadingIndentationChecker {
/// [C++0x] expression
/// [C++0x] braced-init-list
StmtResult Parser::ParseCilkForStatement(SourceLocation *TrailingElseLoc) {
assert(Tok.is(tok::kw__Cilk_for) && "Not a _Cilk_for stmt!");
SourceLocation ForLoc = ConsumeToken(); // eat the '_Cilk_for'.
StringRef Spelling = Tok.getName();
assert(Tok.isOneOf(tok::kw__Cilk_for, tok::kw_cilk_for) &&
"Not a cilk_for stmt!");
SourceLocation ForLoc = ConsumeToken(); // eat the 'cilk_for'.

// SourceLocation CoawaitLoc;
// if (Tok.is(tok::kw_co_await))
// CoawaitLoc = ConsumeToken();

if (Tok.isNot(tok::l_paren)) {
Diag(Tok, diag::err_expected_lparen_after) << "_Cilk_for";
Diag(Tok, diag::err_expected_lparen_after) << Spelling;
SkipUntil(tok::semi);
return StmtError();
}
Expand Down Expand Up @@ -523,7 +527,8 @@ StmtResult Parser::ParseCilkForStatement(SourceLocation *TrailingElseLoc) {
/// cilk_scope-statement:
/// '_Cilk_scope' statement
StmtResult Parser::ParseCilkScopeStatement() {
assert(Tok.is(tok::kw__Cilk_scope) && "Not a _Cilk_scope stmt!");
assert(Tok.isOneOf(tok::kw__Cilk_scope, tok::kw_cilk_scope) &&
"Not a cilk_scope stmt!");
SourceLocation ScopeLoc = ConsumeToken(); // eat the '_Cilk_scope'.

// TODO: Decide whether to allow break statements in _Cilk_scopes.
Expand Down
7 changes: 5 additions & 2 deletions clang/lib/Parse/ParseDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5776,6 +5776,7 @@ bool Parser::isKnownToBeTypeSpecifier(const Token &Tok) const {
case tok::kw_signed:
case tok::kw_unsigned:
case tok::kw__Hyperobject:
case tok::kw_cilk_reducer:
case tok::kw__Complex:
case tok::kw__Imaginary:
case tok::kw_void:
Expand Down Expand Up @@ -5861,6 +5862,7 @@ bool Parser::isTypeSpecifierQualifier() {
case tok::kw_signed:
case tok::kw_unsigned:
case tok::kw__Hyperobject:
case tok::kw_cilk_reducer:
case tok::kw__Complex:
case tok::kw__Imaginary:
case tok::kw_void:
Expand Down Expand Up @@ -6083,6 +6085,7 @@ bool Parser::isDeclarationSpecifier(
case tok::kw_signed:
case tok::kw_unsigned:
case tok::kw__Hyperobject:
case tok::kw_cilk_reducer:
case tok::kw__Complex:
case tok::kw__Imaginary:
case tok::kw_void:
Expand Down Expand Up @@ -6586,7 +6589,7 @@ static bool isPtrOperatorToken(tok::TokenKind Kind, const LangOptions &Lang,
Lang.getOpenCLCompatibleVersion() >= 200)
return true;

if (Kind == tok::kw__Hyperobject)
if (Kind == tok::kw__Hyperobject || Kind == tok::kw_cilk_reducer)
return true;

if (!Lang.CPlusPlus)
Expand Down Expand Up @@ -6725,7 +6728,7 @@ void Parser::ParseDeclaratorInternal(Declarator &D,
SourceLocation Loc = ConsumeToken(); // Eat the *, ^, & or &&.
D.SetRangeEnd(Loc);

if (Kind == tok::kw__Hyperobject) {
if (Kind == tok::kw__Hyperobject || Kind == tok::kw_cilk_reducer) {
// Is a hyperobject.
DeclSpec DS(AttrFactory);

Expand Down
3 changes: 2 additions & 1 deletion clang/lib/Parse/ParseExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1840,7 +1840,8 @@ ExprResult Parser::ParseCastExpression(CastParseKind ParseKind,

// postfix-expression: [CP]
// _Cilk_spawn[opt] postfix-expression '(' argument-expression-list[opt] ')'
case tok::kw__Cilk_spawn: {
case tok::kw__Cilk_spawn:
case tok::kw_cilk_spawn: {
SourceLocation SpawnLoc = ConsumeToken();
// if (!getLangOpts().Cilk) {
// Diag(SpawnLoc, diag::err_cilkplus_disable);
Expand Down
1 change: 1 addition & 0 deletions clang/lib/Parse/ParseObjc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1162,6 +1162,7 @@ IdentifierInfo *Parser::ParseObjCSelectorPiece(SourceLocation &SelectorLoc) {
case tok::kw___alignof:
case tok::kw___auto_type:
case tok::kw__Hyperobject:
case tok::kw_cilk_reducer:
IdentifierInfo *II = Tok.getIdentifierInfo();
SelectorLoc = ConsumeToken();
return II;
Expand Down
8 changes: 6 additions & 2 deletions clang/lib/Parse/ParseStmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,8 @@ StmtResult Parser::ParseStatementOrDeclarationAfterAttributes(
ProhibitAttributes(GNUAttrs);
return HandlePragmaCaptured();

case tok::kw__Cilk_spawn: // [CP] _Cilk_spawn statement
case tok::kw__Cilk_spawn: // [CP] cilk_spawn statement
case tok::kw_cilk_spawn:
// if (!getLangOpts().Cilk) {
// Diag(Tok, diag::err_cilkplus_disable);
// SkipUntil(tok::semi);
Expand All @@ -497,16 +498,18 @@ StmtResult Parser::ParseStatementOrDeclarationAfterAttributes(
return ParseCilkSpawnStatement();

case tok::kw__Cilk_sync: // [CP] _Cilk_sync statement
case tok::kw_cilk_sync:
// if (!getLangOpts().Cilk) {
// Diag(Tok, diag::err_cilkplus_disable);
// SkipUntil(tok::semi);
// return StmtError();
// }
Res = ParseCilkSyncStatement();
SemiError = "_Cilk_sync";
SemiError = "cilk_sync";
break;

case tok::kw__Cilk_for:
case tok::kw_cilk_for:
// if (!getLangOpts().Cilk) {
// Diag(Tok, diag::err_cilkplus_disable);
// SkipUntil(tok::semi);
Expand All @@ -515,6 +518,7 @@ StmtResult Parser::ParseStatementOrDeclarationAfterAttributes(
return ParseCilkForStatement(TrailingElseLoc);

case tok::kw__Cilk_scope: // [CP] _Cilk_scope statement
case tok::kw_cilk_scope:
// if (!getLangOpts().Cilk) {
// Diag(Tok, diag::err_cilkplus_disable);
// SkipUntil(tok::semi);
Expand Down
1 change: 1 addition & 0 deletions clang/lib/Parse/ParseTentative.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1557,6 +1557,7 @@ Parser::isCXXDeclarationSpecifier(ImplicitTypenameContext AllowImplicitTypename,

// Cilk
case tok::kw__Hyperobject:
case tok::kw_cilk_reducer:

// GNU
case tok::kw_restrict:
Expand Down
34 changes: 17 additions & 17 deletions clang/test/Cilk/cilk-exceptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,15 @@ void serial_tryblock(int n) {
}

////////////////////////////////////////////////////////////////////////////////
/// _Cilk_for code snippets
/// cilk_for code snippets
////////////////////////////////////////////////////////////////////////////////

// CHECK-LABEL: @_Z20parallelfor_noexcepti(
// CHECK-NOT: detach within %{{.+}}, label %{{.+}}, label %{{.+}} unwind
// CHECK-NOT: landingpad
// CHECK-NOT: resume
void parallelfor_noexcept(int n) {
_Cilk_for (int i = 0; i < n; ++i)
cilk_for (int i = 0; i < n; ++i)
quuz(i);
}

Expand All @@ -99,7 +99,7 @@ void parallelfor_noexcept(int n) {
// CHECK: [[DRUNREACH]]:
// CHECK-NEXT: unreachable
void parallelfor_except(int n) {
_Cilk_for (int i = 0; i < n; ++i)
cilk_for (int i = 0; i < n; ++i)
bar(new Foo());
}

Expand All @@ -110,7 +110,7 @@ void parallelfor_tryblock(int n) {
try
{
// CHECK-NOT: detach within %[[SYNCREG1]], label %{{.+}}, label %{{.+}} unwind
_Cilk_for (int i = 0; i < n; ++i)
cilk_for (int i = 0; i < n; ++i)
quuz(i);
// CHECK: invoke void @llvm.sync.unwind(token %[[SYNCREG1]])
// CHECK-NEXT: to label %{{.+}} unwind label %[[CATCH:.+]]
Expand Down Expand Up @@ -145,7 +145,7 @@ void parallelfor_tryblock(int n) {
// CHECK: invoke void @llvm.detached.rethrow
// CHECK: (token %[[SYNCREG2]], [[LPADTYPE]] {{.+}})
// CHECK-NEXT: to label {{.+}} unwind label %[[CATCH]]
_Cilk_for (int i = 0; i < n; ++i)
cilk_for (int i = 0; i < n; ++i)
bar(new Foo());
}
catch (int e)
Expand Down Expand Up @@ -182,7 +182,7 @@ void parallelfor_tryblock_inline(int n) {
// CHECK: landingpad [[LPADTYPE]]
// CHECK-NEXT: catch ptr @_ZTIi
// CHECK-NEXT: catch ptr null
_Cilk_for (int i = 0; i < n; ++i)
cilk_for (int i = 0; i < n; ++i)
foo(new Foo());
}
catch (int e)
Expand All @@ -196,14 +196,14 @@ void parallelfor_tryblock_inline(int n) {
}

////////////////////////////////////////////////////////////////////////////////
/// _Cilk_spawn code snippets
/// cilk_spawn code snippets
////////////////////////////////////////////////////////////////////////////////

// CHECK-LABEL: @_Z14spawn_noexcepti(
// CHECK-NOT: landingpad
// CHECK-NOT: detached.rethrow
void spawn_noexcept(int n) {
_Cilk_spawn quuz(n);
cilk_spawn quuz(n);
quuz(n);
}

Expand Down Expand Up @@ -237,7 +237,7 @@ void spawn_tf_except(int n) {
// CHECK-NOT: load ptr, ptr %[[EXN]],
// CHECK-NOT: load i32, ptr %[[EHSELECTOR]],
// CHECK: resume [[LPADTYPE]]
_Cilk_spawn bar(new Foo());
cilk_spawn bar(new Foo());
quuz(n);
}

Expand Down Expand Up @@ -292,7 +292,7 @@ void spawn_stmt_destructor(int n) {
// CHECK-NOT: load ptr, ptr %[[EXNTF]],
// CHECK-NOT: load i32, ptr %[[EHSELECTORTF]],
// CHECK: resume [[LPADTYPE]]
_Cilk_spawn baz(Foo());
cilk_spawn baz(Foo());
quuz(n);
}

Expand Down Expand Up @@ -348,7 +348,7 @@ void spawn_decl_destructor(int n) {
// CHECK-NOT: load ptr, ptr %[[EXNTF]],
// CHECK-NOT: load i32, ptr %[[EHSELECTORTF]],
// CHECK: resume [[LPADTYPE]]
int result = _Cilk_spawn baz(Foo());
int result = cilk_spawn baz(Foo());
quuz(n);
}

Expand Down Expand Up @@ -414,7 +414,7 @@ void spawn_block_destructor(int n) {
// CHECK: resume [[LPADTYPE]]
{
auto f = Foo();
int result = _Cilk_spawn baz(f);
int result = cilk_spawn baz(f);
quuz(n);
}
}
Expand Down Expand Up @@ -444,7 +444,7 @@ void spawn_throw_inline(int n) {
// CHECK: invoke void @llvm.taskframe.resume
// CHECK: (token %[[TASKFRAME]], [[LPADTYPE]] {{.+}})
// CHECK-NEXT: to label {{.+}} unwind label {{.+}}
_Cilk_spawn foo(new Foo());
cilk_spawn foo(new Foo());
quuz(n);
}

Expand All @@ -460,7 +460,7 @@ void spawn_tryblock(int n) {
// CHECK-NEXT: call void @llvm.taskframe.use(token %[[TASKFRAME]])
// CHECK-NEXT: call {{.*}}i32 @_Z4quuzi(
// CHECK-NEXT: reattach within %[[SYNCREG]], label %[[CONTINUE1]]
_Cilk_spawn quuz(n);
cilk_spawn quuz(n);
// CHECK: %[[TASKFRAME2:.+]] = call token @llvm.taskframe.create()
// CHECK: detach within %[[SYNCREG]], label %[[DETACHED2:.+]], label %[[CONTINUE2:.+]] unwind label %[[DUNWIND:.+]]
// CHECK: [[DETACHED2]]:
Expand All @@ -469,21 +469,21 @@ void spawn_tryblock(int n) {
// CHECK-NEXT: to label %[[INVOKECONT1:.+]] unwind label %[[TASKLPAD:.+]]
// CHECK: [[INVOKECONT1]]:
// CHECK-NEXT: reattach within %[[SYNCREG]], label %[[CONTINUE2]]
_Cilk_spawn bar(new Foo());
cilk_spawn bar(new Foo());
// CHECK: %[[TASKFRAME3:.+]] = call token @llvm.taskframe.create()
// CHECK: detach within %[[SYNCREG]], label %[[DETACHED3:.+]], label %[[CONTINUE3:.+]]
// CHECK: [[DETACHED3]]:
// CHECK-NEXT: call void @llvm.taskframe.use(token %[[TASKFRAME3]])
// CHECK-NEXT: call {{.*}}i32 @_Z4quuzi(
// CHECK-NEXT: reattach within %[[SYNCREG]], label %[[CONTINUE3]]
_Cilk_spawn quuz(n);
cilk_spawn quuz(n);
// CHECK: [[CONTINUE3]]:
// CHECK: invoke {{.*}}i32 @_Z3barP3Foo(
// CHECK-NEXT: to label %[[INVOKECONT2:.+]] unwind label %[[CONT3UNWIND:.+]]
bar(new Foo());
// CHECK: [[INVOKECONT2]]:
// CHECK-NEXT: sync within %[[SYNCREG]]
_Cilk_sync;
cilk_sync;
}
// CHECK: [[DUNWIND]]:
// CHECK: landingpad [[LPADTYPE]]
Expand Down
4 changes: 2 additions & 2 deletions clang/test/Cilk/hyper-address.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
void identity(void * value);
void reduce(void* left, void* right);
extern void consume_view(long *);
extern void consume_hyper(long _Hyperobject *);
extern void consume_hyper(long cilk_reducer *);
// CHECK-LABEL: assorted_addresses
void assorted_addresses()
{
// CHECK: call void @llvm.reducer.register
long _Hyperobject(identity, reduce) sum = 0;
long cilk_reducer(identity, reduce) sum = 0;
// CHECK-NOT: llvm.hyper.lookup
// CHECK: call void @[[FN1:.*consume_hyper]]
consume_hyper(__builtin_addressof(sum));
Expand Down
2 changes: 1 addition & 1 deletion clang/test/Cilk/hyper-assign.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// RUN: %clang_cc1 %s -x c++ -fopencilk -verify -emit-llvm -disable-llvm-passes -o - | FileCheck %s
// expected-no-diagnostics

extern long _Hyperobject x, _Hyperobject y;
extern long _Hyperobject x, cilk_reducer y; // use both spellings of keyword

long chain_assign()
{
Expand Down
16 changes: 16 additions & 0 deletions clang/test/Cilk/keywords.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// RUN: %clang_cc1 %s -fopencilk -fsyntax-only -verify
// RUN: %clang_cc1 %s -fsyntax-only -verify=nokeyword
// nokeyword-no-diagnostics
int cilk_spawn;
// expected-error@-1{{expected identifier}}
int cilk_sync = 1;
// expected-error@-1{{expected identifier}}
int cilk_scope = 2;
// expected-error@-1{{expected identifier}}
int cilk_for(int x)
// expected-error@-1{{expected identifier}}
{
return cilk_spawn + cilk_sync + cilk_scope;
}
int cilk_reducer = 3;
// expected-error@-1{{expected identifier}}
Loading
Loading