llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang Author: Sandeep Kosuri (sandeepkosuri) <details> <summary>Changes</summary> - `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. --- Full diff: https://github.com/llvm/llvm-project/pull/74042.diff 3 Files Affected: - (modified) clang/lib/Parse/ParseOpenMP.cpp (+2-1) - (added) clang/test/OpenMP/nothing_ast_print.cpp (+20) - (added) openmp/runtime/test/misc_bugs/omp_nothing.c (+27) ``````````diff 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 `````````` </details> https://github.com/llvm/llvm-project/pull/74042 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits