[PATCH] D108481: Avoid nullptr dereferencing of 'Constraint'

Sindhu Chittireddy via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Aug 20 12:49:40 PDT 2021


schittir created this revision.
schittir added reviewers: erichkeane, saar.raz.
schittir added a project: clang.
schittir requested review of this revision.
Herald added a subscriber: cfe-commits.

  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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D108481

Files:
  clang/lib/Sema/SemaConcept.cpp


Index: clang/lib/Sema/SemaConcept.cpp
===================================================================
--- clang/lib/Sema/SemaConcept.cpp
+++ clang/lib/Sema/SemaConcept.cpp
@@ -1065,8 +1065,7 @@
   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(


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D108481.367871.patch
Type: text/x-patch
Size: 641 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210820/4fdb47b5/attachment.bin>


More information about the cfe-commits mailing list