-
Notifications
You must be signed in to change notification settings - Fork 15.1k
[Clang] [NFC] Prevent null pointer dereference in Sema::InstantiateFunctionDefinition #89801
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
Conversation
…nctionDefinition In the lambda function within clang::Sema::InstantiateFunctionDefinition, the return value of a function that may return null is now checked before dereferencing to avoid potential null pointer dereference issues.
|
@llvm/pr-subscribers-clang Author: None (smanna12) Changes…nctionDefinition In the lambda function within clang::Sema::InstantiateFunctionDefinition, the return value of a function that may return null is now checked before dereferencing to avoid potential null pointer dereference issues. Full diff: https://github.com/llvm/llvm-project/pull/89801.diff 1 Files Affected:
diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
index 787a485e0b2f8c..2490ec4ca614a8 100644
--- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -5183,7 +5183,9 @@ void Sema::InstantiateFunctionDefinition(SourceLocation PointOfInstantiation,
Function->setTypeSourceInfo(NewSI);
ParmVarDecl *Parm = Function->getParamDecl(0);
+ assert(Parm && "First parameter not found in function declaration.");
TypeSourceInfo *NewParmSI = IR.TransformType(Parm->getTypeSourceInfo());
+ assert(NewParmSI && "Type transformation failed.");
Parm->setType(NewParmSI->getType());
Parm->setTypeSourceInfo(NewParmSI);
};
|
Sirraide
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A pr that just adds assertions and nothing else seems like a very weird thing to do. Moreover, a few lines above in the same function, we return if this isn’t a copy/move ctor/assignment operator, which always has at least one parameter; I don’t think it is possible for Parm to be nullptr here. Do you have any code examples that would trigger this asertion here?
Thanks @Sirraide for reviews and the pointer. Yes, it is not possible for Param to be nullptr. I have removed that assert |
tahonermann
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, thanks @smanna12!
|
Thank you @tahonermann for reviews! |
In the lambda function within clang::Sema::InstantiateFunctionDefinition, the return value of a function that may return null is now checked before dereferencing to avoid potential null pointer dereference issues which can lead to crashes or undefined behavior in the program.