[clang] e75989e - [NFC][Clang] Fix potential dereferencing of nullptr (#85944)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Mar 26 09:48:41 PDT 2024
Author: smanna12
Date: 2024-03-26T11:48:37-05:00
New Revision: e75989e93063d1ac2626c3478c28ca364e04ef28
URL: https://github.com/llvm/llvm-project/commit/e75989e93063d1ac2626c3478c28ca364e04ef28
DIFF: https://github.com/llvm/llvm-project/commit/e75989e93063d1ac2626c3478c28ca364e04ef28.diff
LOG: [NFC][Clang] Fix potential dereferencing of nullptr (#85944)
This patch replaces getAs<> with castAs<> to resolve potential static
analyzer bugs for
1. Dereferencing a pointer issue with nullptr FPT when calling
ResolveExceptionSpec() in
checkEscapingByref(clang::VarDecl *, clang::Sema &).
3. Dereferencing a pointer issue with nullptr ElementTy->getAs() when
calling getElementType() in
clang::Sema::SemaBuiltinFPClassification(clang::CallExpr *, unsigned
int).
4. Dereferencing a pointer issue with nullptr ConvType->getAs() when
calling getKeyword() in
clang::Sema::ActOnConversionDeclarator(clang::CXXConversionDecl *).
Added:
Modified:
clang/lib/Sema/Sema.cpp
clang/lib/Sema/SemaChecking.cpp
clang/lib/Sema/SemaDeclCXX.cpp
Removed:
################################################################################
diff --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp
index b4a47898cd17fc..b55f433a8be76f 100644
--- a/clang/lib/Sema/Sema.cpp
+++ b/clang/lib/Sema/Sema.cpp
@@ -2207,7 +2207,7 @@ static void checkEscapingByref(VarDecl *VD, Sema &S) {
// block copy/destroy functions. Resolve it here.
if (const CXXRecordDecl *RD = T->getAsCXXRecordDecl())
if (CXXDestructorDecl *DD = RD->getDestructor()) {
- auto *FPT = DD->getType()->getAs<FunctionProtoType>();
+ auto *FPT = DD->getType()->castAs<FunctionProtoType>();
S.ResolveExceptionSpec(Loc, FPT);
}
}
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index c725ec0ef055bf..b4e87b61803234 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -9709,7 +9709,7 @@ bool Sema::SemaBuiltinFPClassification(CallExpr *TheCall, unsigned NumArgs,
// vector argument can be supported in all of them.
if (ElementTy->isVectorType() && IsFPClass) {
VectorResultTy = GetSignedVectorType(ElementTy);
- ElementTy = ElementTy->getAs<VectorType>()->getElementType();
+ ElementTy = ElementTy->castAs<VectorType>()->getElementType();
}
// This operation requires a non-_Complex floating-point number.
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 7070ea00cff275..c63f2bdc5f8340 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -11353,7 +11353,7 @@ Decl *Sema::ActOnConversionDeclarator(CXXConversionDecl *Conversion) {
if (ConvType->isUndeducedAutoType()) {
Diag(Conversion->getTypeSpecStartLoc(), diag::err_auto_not_allowed)
<< getReturnTypeLoc(Conversion).getSourceRange()
- << llvm::to_underlying(ConvType->getAs<AutoType>()->getKeyword())
+ << llvm::to_underlying(ConvType->castAs<AutoType>()->getKeyword())
<< /* in declaration of conversion function template= */ 24;
}
More information about the cfe-commits
mailing list