[clang] [Clang] Prevent potential null pointer dereferences (PR #117176)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Nov 21 07:38:50 PST 2024
https://github.com/smanna12 updated https://github.com/llvm/llvm-project/pull/117176
>From 1b6b411291b4d7cfd830d43609eaddc65b0f2c56 Mon Sep 17 00:00:00 2001
From: "Manna, Soumi" <soumi.manna at intel.com>
Date: Thu, 21 Nov 2024 07:25:11 -0800
Subject: [PATCH 1/2] [Clang] Prevent potential null pointer dereferences
---
clang/lib/AST/ASTContext.cpp | 2 +-
clang/lib/Sema/SemaFunctionEffects.cpp | 2 +-
clang/lib/Sema/SemaHLSL.cpp | 4 ++--
3 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 14fbadbc35ae5d..23df7878a3bf29 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -3558,7 +3558,7 @@ ASTContext::adjustType(QualType Orig,
llvm::function_ref<QualType(QualType)> Adjust) const {
switch (Orig->getTypeClass()) {
case Type::Attributed: {
- const auto *AT = dyn_cast<AttributedType>(Orig);
+ const auto *AT = cast<AttributedType>(Orig);
return getAttributedType(AT->getAttrKind(),
adjustType(AT->getModifiedType(), Adjust),
adjustType(AT->getEquivalentType(), Adjust),
diff --git a/clang/lib/Sema/SemaFunctionEffects.cpp b/clang/lib/Sema/SemaFunctionEffects.cpp
index 6fe4d2353a2282..c5c1e3fb41a2ff 100644
--- a/clang/lib/Sema/SemaFunctionEffects.cpp
+++ b/clang/lib/Sema/SemaFunctionEffects.cpp
@@ -627,7 +627,7 @@ class Analyzer {
IsNoexcept = isNoexcept(FD);
} else if (auto *BD = dyn_cast<BlockDecl>(D)) {
if (auto *TSI = BD->getSignatureAsWritten()) {
- auto *FPT = TSI->getType()->getAs<FunctionProtoType>();
+ auto *FPT = TSI->getType()->castAs<FunctionProtoType>();
IsNoexcept = FPT->isNothrow() || BD->hasAttr<NoThrowAttr>();
}
}
diff --git a/clang/lib/Sema/SemaHLSL.cpp b/clang/lib/Sema/SemaHLSL.cpp
index f4fc0f2ddc27a6..a1adc66ddb9ce9 100644
--- a/clang/lib/Sema/SemaHLSL.cpp
+++ b/clang/lib/Sema/SemaHLSL.cpp
@@ -1908,9 +1908,9 @@ bool SemaHLSL::CheckBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall) {
return true;
// ensure both args have 3 elements
int NumElementsArg1 =
- TheCall->getArg(0)->getType()->getAs<VectorType>()->getNumElements();
+ TheCall->getArg(0)->getType()->casAs<VectorType>()->getNumElements();
int NumElementsArg2 =
- TheCall->getArg(1)->getType()->getAs<VectorType>()->getNumElements();
+ TheCall->getArg(1)->getType()->castAs<VectorType>()->getNumElements();
if (NumElementsArg1 != 3) {
int LessOrMore = NumElementsArg1 > 3 ? 1 : 0;
>From dd7c34b8309e744e329b10ec5270444bb455a00c Mon Sep 17 00:00:00 2001
From: "Manna, Soumi" <soumi.manna at intel.com>
Date: Thu, 21 Nov 2024 07:38:00 -0800
Subject: [PATCH 2/2] Address review comments
---
clang/lib/Sema/SemaHLSL.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/clang/lib/Sema/SemaHLSL.cpp b/clang/lib/Sema/SemaHLSL.cpp
index a1adc66ddb9ce9..0c70d4e5cff25c 100644
--- a/clang/lib/Sema/SemaHLSL.cpp
+++ b/clang/lib/Sema/SemaHLSL.cpp
@@ -1908,7 +1908,7 @@ bool SemaHLSL::CheckBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall) {
return true;
// ensure both args have 3 elements
int NumElementsArg1 =
- TheCall->getArg(0)->getType()->casAs<VectorType>()->getNumElements();
+ TheCall->getArg(0)->getType()->castAs<VectorType>()->getNumElements();
int NumElementsArg2 =
TheCall->getArg(1)->getType()->castAs<VectorType>()->getNumElements();
More information about the cfe-commits
mailing list