[Openmp-commits] [openmp] 2a57657 - [OpenMP] [Flang] Resolved Issue llvm#76121: Implemented Check for Unhandled Arguments in __kmpc_fork_call_if (#82221)
via Openmp-commits
openmp-commits at lists.llvm.org
Wed May 8 22:41:08 PDT 2024
Author: chandan singh
Date: 2024-05-09T11:11:04+05:30
New Revision: 2a57657d5571b097eb0070e6f26ad4954c0fd990
URL: https://github.com/llvm/llvm-project/commit/2a57657d5571b097eb0070e6f26ad4954c0fd990
DIFF: https://github.com/llvm/llvm-project/commit/2a57657d5571b097eb0070e6f26ad4954c0fd990.diff
LOG: [OpenMP] [Flang] Resolved Issue llvm#76121: Implemented Check for Unhandled Arguments in __kmpc_fork_call_if (#82221)
Root cause: Segmentation fault is caused by null pointer dereference
inside the __kmpc_fork_call_if function at
https://github.com/llvm/llvm-project/blob/main/openmp/runtime/src/z_Linux_asm.S#L1186
. __kmpc_fork_call_if is missing case to handle argc=0 .
Fix: Added a check inside the __kmp_invoke_microtask function to handle
the case when argc is 0.
---------
Co-authored-by: Singh <chasingh at amd.com>
Added:
openmp/runtime/test/misc_bugs/omp__kmpc_fork_call_if.c
Modified:
openmp/runtime/src/z_Linux_asm.S
Removed:
################################################################################
diff --git a/openmp/runtime/src/z_Linux_asm.S b/openmp/runtime/src/z_Linux_asm.S
index 201949003c014..5b614e26a8337 100644
--- a/openmp/runtime/src/z_Linux_asm.S
+++ b/openmp/runtime/src/z_Linux_asm.S
@@ -1150,6 +1150,9 @@ KMP_LABEL(kmp_invoke_pass_parms): // put 1st - 6th parms to pkfn in registers.
movq %rdi, %rbx // pkfn -> %rbx
leaq __gtid(%rbp), %rdi // >id -> %rdi (store 1st parm to pkfn)
leaq __tid(%rbp), %rsi // &tid -> %rsi (store 2nd parm to pkfn)
+ // Check if argc is 0
+ cmpq $0, %rax
+ je KMP_LABEL(kmp_no_args) // Jump ahead
movq %r8, %r11 // p_argv -> %r11
@@ -1195,6 +1198,7 @@ KMP_LABEL(kmp_1_exit):
cmovnsq (%r11), %rdx // p_argv[0] -> %rdx (store 3rd parm to pkfn)
#endif // KMP_MIC
+KMP_LABEL(kmp_no_args):
call *%rbx // call (*pkfn)();
movq $1, %rax // move 1 into return register;
diff --git a/openmp/runtime/test/misc_bugs/omp__kmpc_fork_call_if.c b/openmp/runtime/test/misc_bugs/omp__kmpc_fork_call_if.c
new file mode 100644
index 0000000000000..60d4bff967874
--- /dev/null
+++ b/openmp/runtime/test/misc_bugs/omp__kmpc_fork_call_if.c
@@ -0,0 +1,36 @@
+// RUN: %libomp-compile && %t | FileCheck %s
+
+#include <stdio.h>
+#include <omp.h>
+
+typedef int32_t kmp_int32;
+typedef void *ident_t;
+typedef void *kmpc_micro;
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+extern void __kmpc_fork_call_if(ident_t *loc, kmp_int32 argc,
+ kmpc_micro microtask, kmp_int32 cond,
+ void *args);
+#ifdef __cplusplus
+}
+#endif
+
+// Microtask function for parallel region
+void microtask(int *global_tid, int *bound_tid) {
+ // CHECK: PASS
+ if (omp_in_parallel()) {
+ printf("FAIL\n");
+ } else {
+ printf("PASS\n");
+ }
+}
+
+int main() {
+ // Condition for parallelization (false in this case)
+ int cond = 0;
+ // Call __kmpc_fork_call_if
+ __kmpc_fork_call_if(NULL, 0, microtask, cond, NULL);
+ return 0;
+}
More information about the Openmp-commits
mailing list