Skip to content

Commit 1095f71

Browse files
authored
[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).
1 parent f75eeba commit 1095f71

File tree

3 files changed

+3
-3
lines changed

3 files changed

+3
-3
lines changed

clang/lib/CodeGen/CGExprComplex.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ class ComplexExprEmitter
289289
const BinOpInfo &Op);
290290

291291
QualType GetHigherPrecisionFPType(QualType ElementType) {
292-
const auto *CurrentBT = dyn_cast<BuiltinType>(ElementType);
292+
const auto *CurrentBT = cast<BuiltinType>(ElementType);
293293
switch (CurrentBT->getKind()) {
294294
case BuiltinType::Kind::Float16:
295295
return CGF.getContext().FloatTy;

clang/lib/CodeGen/Targets/PPC.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ void AIXTargetCodeGenInfo::setTargetAttributes(
274274
if (!isa<llvm::GlobalVariable>(GV))
275275
return;
276276

277-
auto *GVar = dyn_cast<llvm::GlobalVariable>(GV);
277+
auto *GVar = cast<llvm::GlobalVariable>(GV);
278278
auto GVId = GV->getName();
279279

280280
// Is this a global variable specified by the user as toc-data?

clang/lib/Sema/SemaTemplate.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2974,7 +2974,7 @@ void DeclareImplicitDeductionGuidesForTypeAlias(
29742974
if (auto *FPrime = SemaRef.InstantiateFunctionDeclaration(
29752975
F, TemplateArgListForBuildingFPrime, AliasTemplate->getLocation(),
29762976
Sema::CodeSynthesisContext::BuildingDeductionGuides)) {
2977-
auto *GG = dyn_cast<CXXDeductionGuideDecl>(FPrime);
2977+
auto *GG = cast<CXXDeductionGuideDecl>(FPrime);
29782978
buildDeductionGuide(SemaRef, AliasTemplate, FPrimeTemplateParamList,
29792979
GG->getCorrespondingConstructor(),
29802980
GG->getExplicitSpecifier(), GG->getTypeSourceInfo(),

0 commit comments

Comments
 (0)