[clang] d2fafa7 - [NFC] Fix potential dereferencing of nullptr.
Sindhu Chittireddy via cfe-commits
cfe-commits at lists.llvm.org
Thu Jun 22 09:53:35 PDT 2023
Author: Sindhu Chittireddy
Date: 2023-06-22T09:53:28-07:00
New Revision: d2fafa79ef08f9ef9cd0108a6caa7fc61a31bdeb
URL: https://github.com/llvm/llvm-project/commit/d2fafa79ef08f9ef9cd0108a6caa7fc61a31bdeb
DIFF: https://github.com/llvm/llvm-project/commit/d2fafa79ef08f9ef9cd0108a6caa7fc61a31bdeb.diff
LOG: [NFC] Fix potential dereferencing of nullptr.
Replace getAs with castAs and add assert if needed.
Differential revision: https://reviews.llvm.org/D153236
Added:
Modified:
clang/lib/Sema/SemaExprObjC.cpp
clang/lib/Sema/SemaObjCProperty.cpp
clang/lib/Sema/SemaType.cpp
Removed:
################################################################################
diff --git a/clang/lib/Sema/SemaExprObjC.cpp b/clang/lib/Sema/SemaExprObjC.cpp
index e8984d298a29c..5df830e5bee6d 100644
--- a/clang/lib/Sema/SemaExprObjC.cpp
+++ b/clang/lib/Sema/SemaExprObjC.cpp
@@ -2438,6 +2438,9 @@ ExprResult Sema::BuildClassMessageImplicit(QualType ReceiverType,
if (!ReceiverType.isNull())
receiverTypeInfo = Context.getTrivialTypeSourceInfo(ReceiverType);
+ assert(((isSuperReceiver && Loc.isValid()) || receiverTypeInfo) &&
+ "Either the super receiver location needs to be valid or the receiver "
+ "needs valid type source information");
return BuildClassMessage(receiverTypeInfo, ReceiverType,
/*SuperLoc=*/isSuperReceiver ? Loc : SourceLocation(),
Sel, Method, Loc, Loc, Loc, Args,
diff --git a/clang/lib/Sema/SemaObjCProperty.cpp b/clang/lib/Sema/SemaObjCProperty.cpp
index 3317bfce41192..7e5dc3a71cbba 100644
--- a/clang/lib/Sema/SemaObjCProperty.cpp
+++ b/clang/lib/Sema/SemaObjCProperty.cpp
@@ -1363,10 +1363,9 @@ Decl *Sema::ActOnPropertyImplDecl(Scope *S,
if (!Context.hasSameType(PropertyIvarType, IvarType)) {
if (isa<ObjCObjectPointerType>(PropertyIvarType)
&& isa<ObjCObjectPointerType>(IvarType))
- compat =
- Context.canAssignObjCInterfaces(
- PropertyIvarType->getAs<ObjCObjectPointerType>(),
- IvarType->getAs<ObjCObjectPointerType>());
+ compat = Context.canAssignObjCInterfaces(
+ PropertyIvarType->castAs<ObjCObjectPointerType>(),
+ IvarType->castAs<ObjCObjectPointerType>());
else {
compat = (CheckAssignmentConstraints(PropertyIvarLoc, PropertyIvarType,
IvarType)
diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index 77a1ce866d5c7..838ec19fcb3be 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -2708,8 +2708,8 @@ QualType Sema::BuildVectorType(QualType CurType, Expr *SizeExpr,
return QualType();
}
// Only support _BitInt elements with byte-sized power of 2 NumBits.
- if (CurType->isBitIntType()) {
- unsigned NumBits = CurType->getAs<BitIntType>()->getNumBits();
+ if (const auto *BIT = CurType->getAs<BitIntType>()) {
+ unsigned NumBits = BIT->getNumBits();
if (!llvm::isPowerOf2_32(NumBits) || NumBits < 8) {
Diag(AttrLoc, diag::err_attribute_invalid_bitint_vector_type)
<< (NumBits < 8);
More information about the cfe-commits
mailing list