[Openmp-commits] [openmp] ecc080c - [OpenMP] return empty stmt for `nothing` (#74042)
via Openmp-commits
openmp-commits at lists.llvm.org
Sun Dec 3 00:03:42 PST 2023
Author: Sandeep Kosuri
Date: 2023-12-03T13:33:38+05:30
New Revision: ecc080c07d97f7879ce64e644cac828922a7b0d9
URL: https://github.com/llvm/llvm-project/commit/ecc080c07d97f7879ce64e644cac828922a7b0d9
DIFF: https://github.com/llvm/llvm-project/commit/ecc080c07d97f7879ce64e644cac828922a7b0d9.diff
LOG: [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.
Added:
clang/test/OpenMP/nothing_ast_print.cpp
openmp/runtime/test/misc_bugs/omp_nothing.c
Modified:
clang/lib/Parse/ParseOpenMP.cpp
Removed:
################################################################################
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<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 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 <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
More information about the Openmp-commits
mailing list