[clang] 847186e - [NFC][Clang] Fix static analyzer concern
Elizabeth Andrews via cfe-commits
cfe-commits at lists.llvm.org
Fri Aug 25 13:03:29 PDT 2023
Author: Elizabeth Andrews
Date: 2023-08-25T13:03:06-07:00
New Revision: 847186eb94bd8c3535f0384456eeffe85f1d9696
URL: https://github.com/llvm/llvm-project/commit/847186eb94bd8c3535f0384456eeffe85f1d9696
DIFF: https://github.com/llvm/llvm-project/commit/847186eb94bd8c3535f0384456eeffe85f1d9696.diff
LOG: [NFC][Clang] Fix static analyzer concern
Fix a few static analyzer concerns about dereferencing
null value.
Differential Revision: https://reviews.llvm.org/D158671
Added:
Modified:
clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
clang/lib/ExtractAPI/DeclarationFragments.cpp
clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/ExtractAPI/ExtractAPIVisitor.h b/clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
index 17c2ab6fd20501..84ea8e2f7ce385 100644
--- a/clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
+++ b/clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
@@ -266,7 +266,9 @@ bool ExtractAPIVisitorBase<Derived>::VisitVarDecl(const VarDecl *Decl) {
if (Decl->isStaticDataMember()) {
SymbolReference Context;
- auto Record = dyn_cast<RecordDecl>(Decl->getDeclContext());
+ // getDeclContext() should return a RecordDecl since we
+ // are currently handling a static data member.
+ auto *Record = cast<RecordDecl>(Decl->getDeclContext());
Context.Name = Record->getName();
Context.USR = API.recordUSR(Record);
auto Access = DeclarationFragmentsBuilder::getAccessControl(Decl);
diff --git a/clang/lib/ExtractAPI/DeclarationFragments.cpp b/clang/lib/ExtractAPI/DeclarationFragments.cpp
index 3c15d5073b01eb..5c5a9df6505271 100644
--- a/clang/lib/ExtractAPI/DeclarationFragments.cpp
+++ b/clang/lib/ExtractAPI/DeclarationFragments.cpp
@@ -688,9 +688,9 @@ DeclarationFragmentsBuilder::getFragmentsForSpecialCXXMethod(
const CXXMethodDecl *Method) {
DeclarationFragments Fragments;
std::string Name;
- if (isa<CXXConstructorDecl>(Method)) {
+ if (const auto *Constructor = dyn_cast<CXXConstructorDecl>(Method)) {
Name = Method->getNameAsString();
- if (dyn_cast<CXXConstructorDecl>(Method)->isExplicit())
+ if (Constructor->isExplicit())
Fragments.append("explicit", DeclarationFragments::FragmentKind::Keyword)
.appendSpace();
} else if (isa<CXXDestructorDecl>(Method))
diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
index f78d46f5950360..63f022d5c2ff09 100644
--- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -5062,6 +5062,7 @@ void Sema::InstantiateFunctionDefinition(SourceLocation PointOfInstantiation,
} IR{*this, PatternRec, NewRec};
TypeSourceInfo *NewSI = IR.TransformType(Function->getTypeSourceInfo());
+ assert(NewSI && "Type Transform failed?");
Function->setType(NewSI->getType());
Function->setTypeSourceInfo(NewSI);
More information about the cfe-commits
mailing list