Skip to content

Commit

Permalink
[NFC] Fix potential dereferencing of nullptr.
Browse files Browse the repository at this point in the history
Replace getAs with castAs and add assert if needed.
Differential revision: https://reviews.llvm.org/D153236
  • Loading branch information
schittir committed Jun 22, 2023
1 parent 116953b commit d2fafa7
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
3 changes: 3 additions & 0 deletions clang/lib/Sema/SemaExprObjC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 3 additions & 4 deletions clang/lib/Sema/SemaObjCProperty.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions clang/lib/Sema/SemaType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit d2fafa7

Please sign in to comment.