https://github.com/sandeepkosuri created https://github.com/llvm/llvm-project/pull/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. >From e60bc748d9c856d6f7be9cea42df834c94332359 Mon Sep 17 00:00:00 2001 From: Sandeep Kosuri <sandeepkosur...@gmail.com> Date: Fri, 1 Dec 2023 11:26:59 +0530 Subject: [PATCH] [OpenMP] return empty stmt for `nothing` --- clang/lib/Parse/ParseOpenMP.cpp | 3 ++- clang/test/OpenMP/nothing_ast_print.cpp | 20 +++++++++++++++ openmp/runtime/test/misc_bugs/omp_nothing.c | 27 +++++++++++++++++++++ 3 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 clang/test/OpenMP/nothing_ast_print.cpp create mode 100644 openmp/runtime/test/misc_bugs/omp_nothing.c diff --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp index fb7e7a979e49f7e..da5f6605c6ffac9 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<VariantMatchInfo, 4> VMIs; diff --git a/clang/test/OpenMP/nothing_ast_print.cpp b/clang/test/OpenMP/nothing_ast_print.cpp new file mode 100644 index 000000000000000..a16f95044b60d69 --- /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 000000000000000..e50d32d147ec9bc --- /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 <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; +} \ No newline at end of file _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits