From 9b1ea42bd38b4ede10460bef569e80f30a73d115 Mon Sep 17 00:00:00 2001 From: chandan singh Date: Mon, 19 Feb 2024 12:21:37 +0530 Subject: [PATCH] [OpenMP] [Flang] Fix Issue llvm#76121 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. --- openmp/runtime/src/z_Linux_asm.S | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/openmp/runtime/src/z_Linux_asm.S b/openmp/runtime/src/z_Linux_asm.S index 14987c298fa5f96..b44d9fb316a05cb 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;