Skip to content

[OpenMP] return empty stmt for nothing #74042

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 3, 2023
Merged
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
3 changes: 2 additions & 1 deletion clang/lib/Parse/ParseOpenMP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2528,7 +2528,8 @@ StmtResult Parser::ParseOpenMPDeclarativeOrExecutableDirective(
skipUntilPragmaOpenMPEnd(DKind);
if (Tok.is(tok::annot_pragma_openmp_end))
ConsumeAnnotationToken();
break;
// return an empty statement
return StmtEmpty();
case OMPD_metadirective: {
ConsumeToken();
SmallVector<VariantMatchInfo, 4> VMIs;
Expand Down
20 changes: 20 additions & 0 deletions clang/test/OpenMP/nothing_ast_print.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// RUN: %clang_cc1 -fopenmp -ast-print %s | FileCheck %s --check-prefix=PRINT
// RUN: %clang_cc1 -ast-print %s | FileCheck %s --check-prefix=PRINT

// Checks whether the `if` body looks same with and without OpenMP enabled

void foo() {
return;
}

int main() {
int x = 3;
if (x % 2 == 0)
#pragma omp nothing
foo();

return 0;
// PRINT: if (x % 2 == 0)
// PRINT: foo();
// PRINT: return 0;
}
27 changes: 27 additions & 0 deletions openmp/runtime/test/misc_bugs/omp_nothing.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// RUN: %libomp-compile
// RUN: %libomp-run | FileCheck %s --check-prefix OMP-CHECK

#include <stdio.h>

void foo(int x) {
printf("foo");
return;
}

int main() {
int x = 4;
// should call foo()
if (x % 2 == 0)
#pragma omp nothing
foo(x);

// should not call foo()
x = 3;
if (x % 2 == 0)
#pragma omp nothing
foo(x);

// OMP-CHECK: foo
// OMP-CHECK-NOT: foo
return 0;
}