Skip to content
Draft
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
2 changes: 2 additions & 0 deletions clang/include/clang/Basic/DiagnosticSemaKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -11564,6 +11564,8 @@ def err_cilk_spawn_invalid_func_context : Error<
"|a varargs function}0">;
def err_pragma_cilk_precedes_noncilk : Error<
"expected a Cilk keyword to follow '%0'">;
def err_cilk_in_statement_expression : Error<
"'%0' cannot be used inside a statement expression">;

// cilk_scope
def note_protected_by_cilk_scope: Note<
Expand Down
10 changes: 10 additions & 0 deletions clang/lib/Sema/SemaCilk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "clang/AST/ExprCilk.h"
#include "clang/AST/StmtCilk.h"
#include "clang/Sema/SemaInternal.h"
#include "clang/Sema/ScopeInfo.h"
using namespace clang;
using namespace sema;

Expand Down Expand Up @@ -51,6 +52,15 @@ static FunctionScopeInfo *checkCilkContext(Sema &S, SourceLocation Loc,
FunctionScopeInfo *ScopeInfo = S.getCurFunction();
assert(ScopeInfo && "missing function scope for function");

// Cilk keywords inside statement expressions cause problems
// generating IR.
for (CompoundScopeInfo &Scope : ScopeInfo->CompoundScopes) {
if (Scope.IsStmtExpr) {
S.Diag(Loc, diag::err_cilk_in_statement_expression) << Keyword;
return nullptr;
}
}

return ScopeInfo;
}

Expand Down
13 changes: 13 additions & 0 deletions clang/test/Cilk/stmt-expr.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// RUN: %clang_cc1 %s -triple x86_64-unknown-linux-gnu -fopencilk -fsyntax-only -verify

extern int f(int);

// CHECK_LABEL: stmt_expr_fn
void stmt_expr_fn(int arg)
{
int x = cilk_spawn(f( ({cilk_sync; 1;}) ));
// expected-error@-1{{'cilk_sync' cannot be used inside a statement expression}}
int y = ({cilk_spawn f(2); -1;});
// expected-error@-1{{'cilk_spawn' cannot be used inside a statement expression}}
int z = cilk_spawn f(3);
}
Loading