Skip to content

Conversation

sandeepkosuri
Copy link
Contributor

  • 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.

@sandeepkosuri sandeepkosuri self-assigned this Dec 1, 2023
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" clang:openmp OpenMP related changes to Clang openmp:libomp OpenMP host runtime labels Dec 1, 2023
@llvmbot
Copy link
Member

llvmbot commented Dec 1, 2023

@llvm/pr-subscribers-clang

Author: Sandeep Kosuri (sandeepkosuri)

Changes
  • 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 --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

@sandeepkosuri sandeepkosuri merged commit ecc080c into llvm:main Dec 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" clang:openmp OpenMP related changes to Clang clang Clang issues not falling into any other category openmp:libomp OpenMP host runtime
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants