Skip to content

Commit ecc080c

Browse files
[OpenMP] return empty stmt for nothing (#74042)
- `nothing` directive was effecting the `if` block structure which it should not. So return an empty statement instead of an error statement while parsing to avoid this.
1 parent 0fc69b1 commit ecc080c

File tree

3 files changed

+49
-1
lines changed

3 files changed

+49
-1
lines changed

clang/lib/Parse/ParseOpenMP.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2528,7 +2528,8 @@ StmtResult Parser::ParseOpenMPDeclarativeOrExecutableDirective(
25282528
skipUntilPragmaOpenMPEnd(DKind);
25292529
if (Tok.is(tok::annot_pragma_openmp_end))
25302530
ConsumeAnnotationToken();
2531-
break;
2531+
// return an empty statement
2532+
return StmtEmpty();
25322533
case OMPD_metadirective: {
25332534
ConsumeToken();
25342535
SmallVector<VariantMatchInfo, 4> VMIs;
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// RUN: %clang_cc1 -fopenmp -ast-print %s | FileCheck %s --check-prefix=PRINT
2+
// RUN: %clang_cc1 -ast-print %s | FileCheck %s --check-prefix=PRINT
3+
4+
// Checks whether the `if` body looks same with and without OpenMP enabled
5+
6+
void foo() {
7+
return;
8+
}
9+
10+
int main() {
11+
int x = 3;
12+
if (x % 2 == 0)
13+
#pragma omp nothing
14+
foo();
15+
16+
return 0;
17+
// PRINT: if (x % 2 == 0)
18+
// PRINT: foo();
19+
// PRINT: return 0;
20+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// RUN: %libomp-compile
2+
// RUN: %libomp-run | FileCheck %s --check-prefix OMP-CHECK
3+
4+
#include <stdio.h>
5+
6+
void foo(int x) {
7+
printf("foo");
8+
return;
9+
}
10+
11+
int main() {
12+
int x = 4;
13+
// should call foo()
14+
if (x % 2 == 0)
15+
#pragma omp nothing
16+
foo(x);
17+
18+
// should not call foo()
19+
x = 3;
20+
if (x % 2 == 0)
21+
#pragma omp nothing
22+
foo(x);
23+
24+
// OMP-CHECK: foo
25+
// OMP-CHECK-NOT: foo
26+
return 0;
27+
}

0 commit comments

Comments
 (0)