Skip to content

Commit

Permalink
Add new keyword spellings with cilk_ instead of _Cilk_
Browse files Browse the repository at this point in the history
  • Loading branch information
VoxSciurorum committed Jan 14, 2025
1 parent ef3cdc8 commit 1a7a684
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 48 deletions.
5 changes: 5 additions & 0 deletions clang/include/clang/Basic/TokenKinds.def
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ KEYWORD(_Bool , KEYNOCXX)
KEYWORD(_Complex , KEYALL)
KEYWORD(_Generic , KEYALL)
KEYWORD(_Hyperobject , KEYALL)
KEYWORD(cilk_reducer , KEYOPENCILK)
KEYWORD(_Imaginary , KEYALL)
KEYWORD(_Noreturn , KEYALL)
KEYWORD(_Static_assert , KEYALL)
Expand Down Expand Up @@ -479,6 +480,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 @@ -520,7 +524,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
3 changes: 2 additions & 1 deletion clang/lib/Parse/ParseExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1773,7 +1773,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
8 changes: 6 additions & 2 deletions clang/lib/Parse/ParseStmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,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 @@ -482,16 +483,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 @@ -500,6 +503,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
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
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}}
36 changes: 18 additions & 18 deletions clang/test/Cilk/looptest.cpp
Original file line number Diff line number Diff line change
@@ -1,57 +1,57 @@
// RUN: %clang_cc1 -std=c++1z -verify %s
// RUN: %clang_cc1 -std=c++1z -fopencilk -verify %s

int foo(int n);

int Cilk_for_tests(int n) {
/* int n = 10; */
/* _Cilk_for(int i = 0; i < n; i += 2); */
/* _Cilk_for(int j = 0, __begin = 0, __end = n/2; __begin < __end; j += 2, __begin++); */
_Cilk_for (int i = 0; i < n; ++i); // expected-warning {{'cilk_for' loop has empty body}}
_Cilk_for (int i = 0, __end = n; i < __end; ++i); // expected-warning {{'cilk_for' loop has empty body}}
/* cilk_for(int i = 0; i < n; i += 2); */
/* cilk_for(int j = 0, __begin = 0, __end = n/2; __begin < __end; j += 2, __begin++); */
cilk_for (int i = 0; i < n; ++i); // expected-warning {{'cilk_for' loop has empty body}}
cilk_for (int i = 0, __end = n; i < __end; ++i); // expected-warning {{'cilk_for' loop has empty body}}
unsigned long long m = 10;
_Cilk_for (int i = 0; i < m; ++i); // expected-warning {{'cilk_for' loop has empty body}}
_Cilk_for (int i = 0, __end = m; i < __end; ++i); // expected-warning {{'cilk_for' loop has empty body}}
cilk_for (int i = 0; i < m; ++i); // expected-warning {{'cilk_for' loop has empty body}}
cilk_for (int i = 0, __end = m; i < __end; ++i); // expected-warning {{'cilk_for' loop has empty body}}

// Check for return statements, which cannot appear anywhere in the body of a
// _Cilk_for loop.
_Cilk_for (int i = 0; i < n; ++i) return 7; // expected-error{{cannot return}}
_Cilk_for (int i = 0; i < n; ++i)
// cilk_for loop.
cilk_for (int i = 0; i < n; ++i) return 7; // expected-error{{cannot return}}
cilk_for (int i = 0; i < n; ++i)
for (int j = 1; j < i; ++j)
return 7; // expected-error{{cannot return}}

// Check for illegal break statements, which cannot bind to the scope of a
// _Cilk_for loop, but can bind to loops nested within.
_Cilk_for (int i = 0; i < n; ++i) break; // expected-error{{cannot break}}
_Cilk_for (int i = 0; i < n; ++i)
// cilk_for loop, but can bind to loops nested within.
cilk_for (int i = 0; i < n; ++i) break; // expected-error{{cannot break}}
cilk_for (int i = 0; i < n; ++i)
for (int j = 1; j < i; ++j)
break;
return 0;
}

int pragma_tests(int n) {
#pragma clang loop unroll_count(4)
_Cilk_for (int i = 0; i < n; ++i)
cilk_for (int i = 0; i < n; ++i)
foo(i);

#pragma cilk grainsize(4)
_Cilk_for (int i = 0; i < n; ++i)
cilk_for (int i = 0; i < n; ++i)
foo(i);

#pragma cilk grainsize 4
_Cilk_for (int i = 0; i < n; ++i)
cilk_for (int i = 0; i < n; ++i)
foo(i);

#pragma cilk grainsize = 4 \
// expected-warning{{'#pragma cilk grainsize' no longer requires '='}}
_Cilk_for (int i = 0; i < n; ++i)
cilk_for (int i = 0; i < n; ++i)
foo(i);

return 0;
}

int scope_tests(int n) {
int A[5];
_Cilk_for(int i = 0; i < n; ++i) {
cilk_for(int i = 0; i < n; ++i) {
int A[5];
A[i%5] = i;
}
Expand Down

0 comments on commit 1a7a684

Please sign in to comment.