Skip to content

[Clang][OpenMP] Emit unroll directive w/o captured stmt #65862

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 9, 2023

Conversation

shiltian
Copy link
Contributor

@shiltian shiltian commented Sep 9, 2023

The front end doesn't create captured stmt for unroll directive. This leads to
a crash when -fopenmp-simd is used, as reported in #63570.

Fix #63570.

The front end doesn't create captured region for unroll directive. This leads to
a crash when `-fopenmp-simd` is used, as reported in llvm#63570.

Fix llvm#63570.
@shiltian shiltian requested a review from a team as a code owner September 9, 2023 21:32
@shiltian shiltian requested review from alexey-bataev and a team September 9, 2023 21:33
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:codegen IR generation bugs: mangling, exceptions, etc. labels Sep 9, 2023
@llvmbot
Copy link
Member

llvmbot commented Sep 9, 2023

@llvm/pr-subscribers-clang

Changes

The front end doesn't create captured region for unroll directive. This leads to
a crash when -fopenmp-simd is used, as reported in #63570.

Fix #63570.

--
Full diff: https://github.com/llvm/llvm-project/pull/65862.diff

2 Files Affected:

  • (modified) clang/lib/CodeGen/CGStmtOpenMP.cpp (+2-1)
  • (added) clang/test/OpenMP/bug63570.c (+10)
diff --git a/clang/lib/CodeGen/CGStmtOpenMP.cpp b/clang/lib/CodeGen/CGStmtOpenMP.cpp
index 6eca0a5ccab41d7..a4e80a4a9e1fd75 100644
--- a/clang/lib/CodeGen/CGStmtOpenMP.cpp
+++ b/clang/lib/CodeGen/CGStmtOpenMP.cpp
@@ -8064,7 +8064,8 @@ void CodeGenFunction::EmitSimpleOMPExecutableDirective(
       D.getDirectiveKind() == OMPD_critical ||
       D.getDirectiveKind() == OMPD_section ||
       D.getDirectiveKind() == OMPD_master ||
-      D.getDirectiveKind() == OMPD_masked) {
+      D.getDirectiveKind() == OMPD_masked ||
+      D.getDirectiveKind() == OMPD_unroll) {
     EmitStmt(D.getAssociatedStmt());
   } else {
     auto LPCRegion =
diff --git a/clang/test/OpenMP/bug63570.c b/clang/test/OpenMP/bug63570.c
new file mode 100644
index 000000000000000..f61a2ee49b388d0
--- /dev/null
+++ b/clang/test/OpenMP/bug63570.c
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -verify -fopenmp -x c -triple x86_64-apple-darwin10 %s
+// RUN: %clang_cc1 -verify -fopenmp-simd -x c -triple x86_64-apple-darwin10 %s
+// expected-no-diagnostics
+
+void f(float *a, float *b) {
+#pragma omp unroll
+  for (int i = 0; i < 128; i++) {
+    a[i] = b[i];
+  }
+}

@shiltian shiltian changed the title [Clang][OpenMP] Emit unroll directive w/o captured region [Clang][OpenMP] Emit unroll directive w/o captured stmt Sep 9, 2023
Copy link
Member

@alexey-bataev alexey-bataev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LG

@shiltian shiltian merged commit 52b4bec into llvm:main Sep 9, 2023
@shiltian shiltian deleted the 63570 branch September 9, 2023 22:52
ZijunZhaoCCK pushed a commit to ZijunZhaoCCK/llvm-project that referenced this pull request Sep 19, 2023
The front end doesn't create captured stmt for unroll directive. This
leads to
a crash when `-fopenmp-simd` is used, as reported in llvm#63570.

Fix llvm#63570.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:codegen IR generation bugs: mangling, exceptions, etc. clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

clangtk crashes when processing a simple assignment loop wrapped by #pragma omp unroll
3 participants