[PATCH] D157554: [NFC][Clang] Fix static analyzer concern about null pointer dereference
Elizabeth Andrews via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Aug 9 15:38:45 PDT 2023
eandrews created this revision.
eandrews added reviewers: tahonermann, aaron.ballman.
Herald added subscribers: manas, ASDenysPetrov, dkrupp, donat.nagy, Szelethus, a.sidorin, baloghadamsoftware.
Herald added a project: All.
eandrews requested review of this revision.
Herald added a subscriber: wangpc.
Param->getTypeConstraint() can return nullptr, and was dereferenced without a check.
I followed the logic for invalid constraints and set Status as concepts::ExprRequirement::SS_ExprSubstitutionFailure if getTypeConstraint() returns null unexpectedly. I am not a 100% certain about this change since I am unfamiliar with concepts.
https://reviews.llvm.org/D157554
Files:
clang/lib/Sema/SemaExprCXX.cpp
Index: clang/lib/Sema/SemaExprCXX.cpp
===================================================================
--- clang/lib/Sema/SemaExprCXX.cpp
+++ clang/lib/Sema/SemaExprCXX.cpp
@@ -9072,15 +9072,20 @@
MultiLevelTemplateArgumentList MLTAL(Param, TAL.asArray(),
/*Final=*/false);
MLTAL.addOuterRetainedLevels(TPL->getDepth());
- Expr *IDC = Param->getTypeConstraint()->getImmediatelyDeclaredConstraint();
- ExprResult Constraint = SubstExpr(IDC, MLTAL);
- if (Constraint.isInvalid()) {
+ const TypeConstraint *TC = Param->getTypeConstraint();
+ if (!TC) {
Status = concepts::ExprRequirement::SS_ExprSubstitutionFailure;
} else {
- SubstitutedConstraintExpr =
- cast<ConceptSpecializationExpr>(Constraint.get());
- if (!SubstitutedConstraintExpr->isSatisfied())
- Status = concepts::ExprRequirement::SS_ConstraintsNotSatisfied;
+ ExprResult Constraint =
+ SubstExpr(TC->getImmediatelyDeclaredConstraint(), MLTAL);
+ if (Constraint.isInvalid()) {
+ Status = concepts::ExprRequirement::SS_ExprSubstitutionFailure;
+ } else {
+ SubstitutedConstraintExpr =
+ cast<ConceptSpecializationExpr>(Constraint.get());
+ if (!SubstitutedConstraintExpr->isSatisfied())
+ Status = concepts::ExprRequirement::SS_ConstraintsNotSatisfied;
+ }
}
}
return new (Context) concepts::ExprRequirement(E, IsSimple, NoexceptLoc,
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D157554.548791.patch
Type: text/x-patch
Size: 1484 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230809/8b1f526d/attachment.bin>
More information about the cfe-commits
mailing list