Skip to content

Commit ab2e70c

Browse files
committed
Skip task outline pragmas if we're in C mode and class context. Fix a buggy diagnostic too.
Fixes llvm#152
1 parent c46c2c1 commit ab2e70c

File tree

4 files changed

+22
-6
lines changed

4 files changed

+22
-6
lines changed

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11426,7 +11426,7 @@ def warn_oss_section_is_char : Warning<"array section %select{lower bound|length
1142611426
def err_oss_single_decl_in_task : Error<
1142711427
"single declaration is expected after 'task' directive">;
1142811428
def err_oss_function_expected : Error<
11429-
"'#pragma oss task' can only be applied to %select{functions|non-volatile or static methods}0">;
11429+
"'#pragma oss task' can only be applied to functions">;
1143011430
def err_oss_non_void_task : Error<
1143111431
"non-void tasks are not supported">;
1143211432
def err_oss_rvalue_param_task : Error<

clang/lib/Parse/ParseOmpSs.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,9 @@ Parser::DeclGroupPtrTy Parser::ParseOmpSsDeclarativeDirectiveWithExtDecl(
461461

462462
switch (DKind) {
463463
case OSSD_task: {
464+
// Only allowed in C++ mode
465+
if (!getLangOpts().CPlusPlus && getCurScope()->isClassScope())
466+
break;
464467
// The syntax is:
465468
// { #pragma oss task }
466469
// <function-declaration-or-definition>

clang/test/OmpSs/Sema/task_function.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,17 @@ void foo7(int *p) {}
2020
#pragma oss task reduction(+: *p) weakreduction(+: *p) // expected-error {{unexpected OmpSs-2 clause 'reduction' in directive '#pragma oss task'}} expected-error {{unexpected OmpSs-2 clause 'weakreduction' in directive '#pragma oss task'}}
2121
void foo8(int *p) {}
2222

23+
struct S0 {
24+
// expected-error@+2 {{field 'foo' declared as a function}}
25+
#pragma oss task
26+
void foo();
27+
};
28+
29+
struct S1 {
30+
// expected-error@+3 {{field 'bar' declared as a function}}
31+
// expected-error@+2 {{expected ';' at end of declaration list}}
32+
#pragma oss task
33+
void bar() {}
34+
};
35+
2336
#pragma oss task // expected-error {{function declaration is expected after 'task' function directive}}

clang/test/OmpSs/Sema/task_function1.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
// RUN: %clang_cc1 -verify -x c++ -fompss-2 -ferror-limit 100 -o - %s
22

33
struct S {
4-
// expected-error@+2 {{'#pragma oss task' can only be applied to non-volatile or static methods}}
4+
// expected-error@+2 {{'#pragma oss task' can only be applied to functions}}
55
#pragma oss task in(*p)
66
virtual void foo(int *p) {}
77
};
88

99
struct P : S {
1010
P() {};
11-
// expected-error@+2 {{'#pragma oss task' can only be applied to non-volatile or static methods}}
11+
// expected-error@+2 {{'#pragma oss task' can only be applied to functions}}
1212
#pragma oss task in(*p)
1313
P(int *p) {}
14-
// expected-error@+2 {{'#pragma oss task' can only be applied to non-volatile or static methods}}
14+
// expected-error@+2 {{'#pragma oss task' can only be applied to functions}}
1515
#pragma oss task
1616
~P() {}
17-
// expected-error@+2 {{'#pragma oss task' can only be applied to non-volatile or static methods}}
17+
// expected-error@+2 {{'#pragma oss task' can only be applied to functions}}
1818
#pragma oss task
1919
P& operator=(const P &) {}
20-
// expected-error@+2 {{'#pragma oss task' can only be applied to non-volatile or static methods}}
20+
// expected-error@+2 {{'#pragma oss task' can only be applied to functions}}
2121
#pragma oss task in(*p)
2222
void foo(int *p) {}
2323
#pragma oss task

0 commit comments

Comments
 (0)