aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsmanna12 <soumi.manna@intel.com>2024-07-31 15:36:21 -0700
committerGitHub <noreply@github.com>2024-07-31 17:36:21 -0500
commitcf79aba99db4909437b8977a59c51bc8899ddb9c (patch)
tree5d9604fd6b29f7d852d66eb7a48c06a35d0c1d4a
parent74f95794433f315a14bd6878d97877566863bc34 (diff)
downloadllvm-upstream/main.zip
llvm-upstream/main.tar.gz
llvm-upstream/main.tar.bz2
[Clang] [NFC] Fix potential dereferencing of nullptr (#101405)upstream/main
This patch replaces getAs with castAs and dyn_cast with cast to ensure type safety and prevents potential null pointer dereferences. These changes enforce compile-time checks for correct type casting in ASTContext and CodeGenModule.
-rw-r--r--clang/lib/AST/ASTContext.cpp4
-rw-r--r--clang/lib/CodeGen/CodeGenModule.cpp2
2 files changed, 3 insertions, 3 deletions
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index a465cdf..b0cc7cb 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -3283,7 +3283,7 @@ static void encodeTypeForFunctionPointerAuth(const ASTContext &Ctx,
return;
case Type::Builtin: {
- const auto *BTy = T->getAs<BuiltinType>();
+ const auto *BTy = T->castAs<BuiltinType>();
switch (BTy->getKind()) {
#define SIGNED_TYPE(Id, SingletonId) \
case BuiltinType::Id: \
@@ -3366,7 +3366,7 @@ static void encodeTypeForFunctionPointerAuth(const ASTContext &Ctx,
llvm_unreachable("should never get here");
}
case Type::Record: {
- const RecordDecl *RD = T->getAs<RecordType>()->getDecl();
+ const RecordDecl *RD = T->castAs<RecordType>()->getDecl();
const IdentifierInfo *II = RD->getIdentifier();
// In C++, an immediate typedef of an anonymous struct or union
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp
index 344a0e5..760185d 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -5659,7 +5659,7 @@ void CodeGenModule::EmitExternalFunctionDeclaration(const FunctionDecl *FD) {
if (getCodeGenOpts().hasReducedDebugInfo()) {
auto *Ty = getTypes().ConvertType(FD->getType());
StringRef MangledName = getMangledName(FD);
- auto *Fn = dyn_cast<llvm::Function>(
+ auto *Fn = cast<llvm::Function>(
GetOrCreateLLVMFunction(MangledName, Ty, FD, /* ForVTable */ false));
if (!Fn->getSubprogram())
DI->EmitFunctionDecl(FD, FD->getLocation(), FD->getType(), Fn);