[llvm] [Clang] [OMPIRBuilder] Add Assertion to Prevent Null Pointer Dereference in OpenMP IR Builder (PR #115506)

via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 8 08:13:29 PST 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-flang-openmp

Author: None (smanna12)

<details>
<summary>Changes</summary>

The fix in OMPIRBuilder.cpp adds an assertion to ensure that ArgStructType is not null before it is used. 
This prevents potential null pointer dereference issues, improving the stability and reliability of the code.

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


1 Files Affected:

- (modified) llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp (+4) 


``````````diff
diff --git a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
index d2e4dc1c85dfd2..869f237ff992cc 100644
--- a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -6966,6 +6966,10 @@ static Function *emitTargetTaskProxyFunction(OpenMPIRBuilder &OMPBuilder,
     auto *ArgStructType =
         dyn_cast<StructType>(ArgStructAlloca->getAllocatedType());
 
+    assert(ArgStructType &&
+           "Unable to find the struct type corresponding to the alloca "
+           "instruction");
+
     AllocaInst *NewArgStructAlloca =
         Builder.CreateAlloca(ArgStructType, nullptr, "structArg");
     Value *TaskT = ProxyFn->getArg(1);

``````````

</details>


https://github.com/llvm/llvm-project/pull/115506


More information about the llvm-commits mailing list