Skip to content

Commit cf79aba

Browse files
authored
[Clang] [NFC] Fix potential dereferencing of nullptr (llvm#101405)
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.
1 parent 74f9579 commit cf79aba

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

clang/lib/AST/ASTContext.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3283,7 +3283,7 @@ static void encodeTypeForFunctionPointerAuth(const ASTContext &Ctx,
32833283
return;
32843284

32853285
case Type::Builtin: {
3286-
const auto *BTy = T->getAs<BuiltinType>();
3286+
const auto *BTy = T->castAs<BuiltinType>();
32873287
switch (BTy->getKind()) {
32883288
#define SIGNED_TYPE(Id, SingletonId) \
32893289
case BuiltinType::Id: \
@@ -3366,7 +3366,7 @@ static void encodeTypeForFunctionPointerAuth(const ASTContext &Ctx,
33663366
llvm_unreachable("should never get here");
33673367
}
33683368
case Type::Record: {
3369-
const RecordDecl *RD = T->getAs<RecordType>()->getDecl();
3369+
const RecordDecl *RD = T->castAs<RecordType>()->getDecl();
33703370
const IdentifierInfo *II = RD->getIdentifier();
33713371

33723372
// In C++, an immediate typedef of an anonymous struct or union

clang/lib/CodeGen/CodeGenModule.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5659,7 +5659,7 @@ void CodeGenModule::EmitExternalFunctionDeclaration(const FunctionDecl *FD) {
56595659
if (getCodeGenOpts().hasReducedDebugInfo()) {
56605660
auto *Ty = getTypes().ConvertType(FD->getType());
56615661
StringRef MangledName = getMangledName(FD);
5662-
auto *Fn = dyn_cast<llvm::Function>(
5662+
auto *Fn = cast<llvm::Function>(
56635663
GetOrCreateLLVMFunction(MangledName, Ty, FD, /* ForVTable */ false));
56645664
if (!Fn->getSubprogram())
56655665
DI->EmitFunctionDecl(FD, FD->getLocation(), FD->getType(), Fn);

0 commit comments

Comments
 (0)