diff --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp index fb7e7a979e49f..da5f6605c6ffa 100644 --- a/clang/lib/Parse/ParseOpenMP.cpp +++ b/clang/lib/Parse/ParseOpenMP.cpp @@ -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 VMIs; diff --git a/clang/test/OpenMP/nothing_ast_print.cpp b/clang/test/OpenMP/nothing_ast_print.cpp new file mode 100644 index 0000000000000..a16f95044b60d --- /dev/null +++ b/clang/test/OpenMP/nothing_ast_print.cpp @@ -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; +} \ No newline at end of file diff --git a/openmp/runtime/test/misc_bugs/omp_nothing.c b/openmp/runtime/test/misc_bugs/omp_nothing.c new file mode 100644 index 0000000000000..e50d32d147ec9 --- /dev/null +++ b/openmp/runtime/test/misc_bugs/omp_nothing.c @@ -0,0 +1,27 @@ +// RUN: %libomp-compile +// RUN: %libomp-run | FileCheck %s --check-prefix OMP-CHECK + +#include + +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; +} \ No newline at end of file