[PATCH] D158671: [NFC][Clang] Fix static analyzer concerns

Elizabeth Andrews via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Aug 23 13:57:56 PDT 2023


eandrews created this revision.
eandrews added reviewers: aaron.ballman, tahonermann.
Herald added subscribers: manas, ASDenysPetrov, dkrupp, donat.nagy, Szelethus, a.sidorin, baloghadamsoftware.
Herald added a reviewer: ributzka.
Herald added a project: All.
eandrews requested review of this revision.
Herald added a reviewer: dang.

Fix static analyzer concerns about null value reference


https://reviews.llvm.org/D158671

Files:
  clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
  clang/lib/ExtractAPI/DeclarationFragments.cpp
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp


Index: clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
===================================================================
--- clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -5062,6 +5062,7 @@
     } IR{*this, PatternRec, NewRec};
 
     TypeSourceInfo *NewSI = IR.TransformType(Function->getTypeSourceInfo());
+    assert(NewSI && "Type Transform failed?");
     Function->setType(NewSI->getType());
     Function->setTypeSourceInfo(NewSI);
 
Index: clang/lib/ExtractAPI/DeclarationFragments.cpp
===================================================================
--- clang/lib/ExtractAPI/DeclarationFragments.cpp
+++ clang/lib/ExtractAPI/DeclarationFragments.cpp
@@ -609,7 +609,7 @@
   std::string Name;
   if (isa<CXXConstructorDecl>(Method)) {
     Name = Method->getNameAsString();
-    if (dyn_cast<CXXConstructorDecl>(Method)->isExplicit())
+    if (cast<CXXConstructorDecl>(Method)->isExplicit())
       Fragments.append("explicit", DeclarationFragments::FragmentKind::Keyword)
           .appendSpace();
   } else if (isa<CXXDestructorDecl>(Method))
Index: clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
===================================================================
--- clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
+++ clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
@@ -192,7 +192,7 @@
 
   if (Decl->isStaticDataMember()) {
     SymbolReference Context;
-    auto Record = dyn_cast<RecordDecl>(Decl->getDeclContext());
+    auto Record = cast<RecordDecl>(Decl->getDeclContext());
     Context.Name = Record->getName();
     Context.USR = API.recordUSR(Record);
     auto Access = DeclarationFragmentsBuilder::getAccessControl(Decl);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D158671.552881.patch
Type: text/x-patch
Size: 1716 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230823/ba817305/attachment-0001.bin>


More information about the cfe-commits mailing list