[clang] 98339f1 - Avoid nullptr dereferencing of 'Constraint'; NFC
Aaron Ballman via cfe-commits
cfe-commits at lists.llvm.org
Tue Aug 24 04:09:27 PDT 2021
Author: Sindhu Chittireddy
Date: 2021-08-24T07:08:18-04:00
New Revision: 98339f14a0420cdfbe4215d8d1bc0a01165e0495
URL: https://github.com/llvm/llvm-project/commit/98339f14a0420cdfbe4215d8d1bc0a01165e0495
DIFF: https://github.com/llvm/llvm-project/commit/98339f14a0420cdfbe4215d8d1bc0a01165e0495.diff
LOG: Avoid nullptr dereferencing of 'Constraint'; NFC
Klocwork static code analysis exposed this bug:
Pointer 'Constraint' returned from call to function
'cast_or_null<clang::ConceptSpecializationExpr,clang::Expr>' may
be NULL and will be dereferenced in the statement following it
Replace 'cast_or_null' with 'cast' so that the latter can assert
when it encounters a NULL.
This also removes an 'assert' that is covered by the previous
call to 'cast<>'.
Added:
Modified:
clang/lib/Sema/SemaConcept.cpp
Removed:
################################################################################
diff --git a/clang/lib/Sema/SemaConcept.cpp b/clang/lib/Sema/SemaConcept.cpp
index 188c92841096f..c582446426892 100644
--- a/clang/lib/Sema/SemaConcept.cpp
+++ b/clang/lib/Sema/SemaConcept.cpp
@@ -1062,11 +1062,8 @@ ReturnTypeRequirement(TemplateParameterList *TPL) :
assert(TPL->size() == 1);
const TypeConstraint *TC =
cast<TemplateTypeParmDecl>(TPL->getParam(0))->getTypeConstraint();
- assert(TC &&
- "TPL must have a template type parameter with a type constraint");
auto *Constraint =
- cast_or_null<ConceptSpecializationExpr>(
- TC->getImmediatelyDeclaredConstraint());
+ cast<ConceptSpecializationExpr>(TC->getImmediatelyDeclaredConstraint());
bool Dependent =
Constraint->getTemplateArgsAsWritten() &&
TemplateSpecializationType::anyInstantiationDependentTemplateArguments(
More information about the cfe-commits
mailing list