[clang] 1095f71 - [NFC][Clang] Fix potential dereferencing of nullptr (#86759)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Mar 27 18:20:26 PDT 2024
Author: smanna12
Date: 2024-03-27T20:20:22-05:00
New Revision: 1095f71bdfe25778c169954f249819bc5b553c91
URL: https://github.com/llvm/llvm-project/commit/1095f71bdfe25778c169954f249819bc5b553c91
DIFF: https://github.com/llvm/llvm-project/commit/1095f71bdfe25778c169954f249819bc5b553c91.diff
LOG: [NFC][Clang] Fix potential dereferencing of nullptr (#86759)
This patch replaces dyn_cast<> with cast<> to resolve potential static
analyzer bugs for
1. Dereferencing a pointer issue with nullptr GVar when calling
addAttribute() in AIXTargetCodeGenInfo::setTargetAttributes(clang::Decl
const *, llvm::GlobalValue *, clang::CodeGen::CodeGenModule &).
2. Dereferencing a pointer issue with nullptr GG when calling
getCorrespondingConstructor() in
DeclareImplicitDeductionGuidesForTypeAlias(clang::Sema &,
clang::TypeAliasTemplateDecl *, clang::SourceLocation).
3. Dereferencing a pointer issue with nullptr CurrentBT when calling
getKind() in
ComplexExprEmitter::GetHigherPrecisionFPType(clang::QualType).
Added:
Modified:
clang/lib/CodeGen/CGExprComplex.cpp
clang/lib/CodeGen/Targets/PPC.cpp
clang/lib/Sema/SemaTemplate.cpp
Removed:
################################################################################
diff --git a/clang/lib/CodeGen/CGExprComplex.cpp b/clang/lib/CodeGen/CGExprComplex.cpp
index b873bc6737bb0a..c3774d0cb75edc 100644
--- a/clang/lib/CodeGen/CGExprComplex.cpp
+++ b/clang/lib/CodeGen/CGExprComplex.cpp
@@ -289,7 +289,7 @@ class ComplexExprEmitter
const BinOpInfo &Op);
QualType GetHigherPrecisionFPType(QualType ElementType) {
- const auto *CurrentBT = dyn_cast<BuiltinType>(ElementType);
+ const auto *CurrentBT = cast<BuiltinType>(ElementType);
switch (CurrentBT->getKind()) {
case BuiltinType::Kind::Float16:
return CGF.getContext().FloatTy;
diff --git a/clang/lib/CodeGen/Targets/PPC.cpp b/clang/lib/CodeGen/Targets/PPC.cpp
index 00b04723f17dd2..3eadb19bd2058f 100644
--- a/clang/lib/CodeGen/Targets/PPC.cpp
+++ b/clang/lib/CodeGen/Targets/PPC.cpp
@@ -274,7 +274,7 @@ void AIXTargetCodeGenInfo::setTargetAttributes(
if (!isa<llvm::GlobalVariable>(GV))
return;
- auto *GVar = dyn_cast<llvm::GlobalVariable>(GV);
+ auto *GVar = cast<llvm::GlobalVariable>(GV);
auto GVId = GV->getName();
// Is this a global variable specified by the user as toc-data?
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index 005529a53270c3..aab72dbaf48c46 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -2974,7 +2974,7 @@ void DeclareImplicitDeductionGuidesForTypeAlias(
if (auto *FPrime = SemaRef.InstantiateFunctionDeclaration(
F, TemplateArgListForBuildingFPrime, AliasTemplate->getLocation(),
Sema::CodeSynthesisContext::BuildingDeductionGuides)) {
- auto *GG = dyn_cast<CXXDeductionGuideDecl>(FPrime);
+ auto *GG = cast<CXXDeductionGuideDecl>(FPrime);
buildDeductionGuide(SemaRef, AliasTemplate, FPrimeTemplateParamList,
GG->getCorrespondingConstructor(),
GG->getExplicitSpecifier(), GG->getTypeSourceInfo(),
More information about the cfe-commits
mailing list