Skip to content

[Clang] [OMPIRBuilder] Prevent Null Pointer Dereference in OpenMP IR Builder #115506

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 2 commits into from
Nov 21, 2024

Conversation

smanna12
Copy link
Contributor

@smanna12 smanna12 commented Nov 8, 2024

This commit addresses Static Analyzer issues related to potential null dereference by replacing dyn_cast<> with cast<> in OMPIRBuilder.cpp to ensure that ArgStructType is not null before it is used, improving the stability and reliability of the code.

@llvmbot llvmbot added flang:openmp clang:openmp OpenMP related changes to Clang labels Nov 8, 2024
@llvmbot
Copy link
Member

llvmbot commented Nov 8, 2024

@llvm/pr-subscribers-flang-openmp

Author: None (smanna12)

Changes

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 --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);

@smanna12 smanna12 requested a review from Fznamznon November 12, 2024 13:59
@smanna12 smanna12 requested a review from Fznamznon November 21, 2024 14:29
@smanna12 smanna12 changed the title [Clang] [OMPIRBuilder] Add Assertion to Prevent Null Pointer Dereference in OpenMP IR Builder [Clang] [OMPIRBuilder] Prevent Null Pointer Dereference in OpenMP IR Builder Nov 21, 2024
@smanna12
Copy link
Contributor Author

Thank you @Fznamznon for reviews!

@smanna12 smanna12 merged commit d936c0c into llvm:main Nov 21, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:openmp OpenMP related changes to Clang flang:openmp
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants