Skip to content

Commit f95d4a6

Browse files
committed
Sema: Determine if there're branches from OmpSs-2 region to outside of it
Fixes llvm#20
1 parent 52a5167 commit f95d4a6

File tree

4 files changed

+50
-0
lines changed

4 files changed

+50
-0
lines changed

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9751,6 +9751,8 @@ def err_oss_shape_incomplete_type : Error<
97519751
"shape of pointer to incomplete type %0">;
97529752
def err_oss_variadic_templates_not_clause_allowed : Error<
97539753
"variadic templates are not allowed in OmpSs-2 clauses">;
9754+
def err_oss_invalid_branch : Error<
9755+
"invalid branch from OmpSs-2 structured block">;
97549756
def warn_oss_section_is_char : Warning<"array section %select{lower bound|length}0 is of type 'char'">,
97559757
InGroup<CharSubscript>, DefaultIgnore;
97569758
} // end of OmpSs component.

clang/include/clang/Sema/Scope.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,11 @@ class Scope {
407407
return false;
408408
}
409409

410+
/// Determines whether this scope is the OmpSs directive scope
411+
bool isOmpSsDirectiveScope() const {
412+
return (getFlags() & Scope::OmpSsDirectiveScope);
413+
}
414+
410415
/// Determines whether this scope is the OpenMP directive scope
411416
bool isOpenMPDirectiveScope() const {
412417
return (getFlags() & Scope::OpenMPDirectiveScope);

clang/lib/Sema/SemaStmt.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3568,6 +3568,17 @@ StmtResult Sema::BuildReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp) {
35683568
if (RetValExp && DiagnoseUnexpandedParameterPack(RetValExp))
35693569
return StmtError();
35703570

3571+
// OmpSs directives introduce a new Scope that is both
3572+
// a FnScope and OmpSsDirectiveScope.
3573+
// Lambdas are FnScopes too, so we can determine if
3574+
// the stmt belongs to the lambda or the OmpSs-2 region.
3575+
if (getLangOpts().OmpSs
3576+
&& getCurScope()->getFnParent()->isOmpSsDirectiveScope()) {
3577+
3578+
Diag(ReturnLoc, diag::err_oss_invalid_branch);
3579+
return StmtError();
3580+
}
3581+
35713582
if (isa<CapturingScopeInfo>(getCurFunction()))
35723583
return ActOnCapScopeReturnStmt(ReturnLoc, RetValExp);
35733584

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// RUN: %clang_cc1 -verify -x c++ -std=c++11 -fompss-2 -ferror-limit 100 -o - %s
2+
3+
void bar() {
4+
#pragma oss task
5+
{
6+
auto l = []() {
7+
return 1;
8+
break; // expected-error {{'break' statement not in loop or switch statement}}
9+
goto label; // expected-error {{use of undeclared label 'label'}}
10+
};
11+
label:
12+
return; // expected-error {{invalid branch from OmpSs-2 structured block}}
13+
break; // expected-error {{'break' statement not in loop or switch statement}}
14+
goto label;
15+
}
16+
auto l = []() {
17+
#pragma oss task
18+
{
19+
for (int i = 0; i < 10; ++i)
20+
#pragma oss task
21+
{
22+
continue; // expected-error {{'continue' statement not in loop statement}}
23+
return 2; // expected-error {{invalid branch from OmpSs-2 structured block}}
24+
}
25+
return 3; // expected-error {{invalid branch from OmpSs-2 structured block}}
26+
break; // expected-error {{'break' statement not in loop or switch statement}}
27+
goto label; // expected-error {{use of undeclared label 'label'}}
28+
}
29+
label:
30+
return 4;
31+
};
32+
}

0 commit comments

Comments
 (0)