[clang] [NFC][Clang] Fix potential dereferencing of nullptr (PR #85944)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Mar 20 08:14:12 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: None (smanna12)
<details>
<summary>Changes</summary>
This patch replaces getAs<> with castAs<> to resolve
1. Dereferencing a pointer issue with nullptr FPT when calling ResolveExceptionSpec() in checkEscapingByref(clang::VarDecl *, clang::Sema &).
2. Dereferencing a pointer issue with nullptr ElementTy->getAs() when calling getElementType() in clang::Sema::SemaBuiltinFPClassification(clang::CallExpr *, unsigned int).
3. Dereferencing a pointer issue with nullptr ConvType->getAs() when calling getKeyword() in clang::Sema::ActOnConversionDeclarator(clang::CXXConversionDecl *).
---
Full diff: https://github.com/llvm/llvm-project/pull/85944.diff
3 Files Affected:
- (modified) clang/lib/Sema/Sema.cpp (+1-1)
- (modified) clang/lib/Sema/SemaChecking.cpp (+1-1)
- (modified) clang/lib/Sema/SemaDeclCXX.cpp (+1-1)
``````````diff
diff --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp
index cd0c42d5ffbacd..ba03b4f50a195a 100644
--- a/clang/lib/Sema/Sema.cpp
+++ b/clang/lib/Sema/Sema.cpp
@@ -2206,7 +2206,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 ef3ab16ba29b41..40b92a03afcaae 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -9647,7 +9647,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 e258a4f7c89415..e2cefcb9099755 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -11352,7 +11352,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;
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/85944
More information about the cfe-commits
mailing list