Skip to content

Commit

Permalink
[NFC] Fix potential dereferencing of nullptr
Browse files Browse the repository at this point in the history
Differential Revision: https://reviews.llvm.org/D139148
  • Loading branch information
schittir committed Jul 12, 2023
1 parent 6e6d2b7 commit 472232a
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion clang/lib/Sema/SemaInit.cpp
Expand Up @@ -6336,6 +6336,7 @@ void InitializationSequence::InitializeFrom(Sema &S,
// We're at the end of the line for C: it's either a write-back conversion
// or it's a C assignment. There's no need to check anything else.
if (!S.getLangOpts().CPlusPlus) {
assert(Initializer && "Initializer must be non-null");
// If allowed, check whether this is an Objective-C writeback conversion.
if (allowObjCWritebackConversion &&
tryObjCWritebackConversion(S, *this, Entity, Initializer)) {
Expand All @@ -6362,7 +6363,8 @@ void InitializationSequence::InitializeFrom(Sema &S,
if (Kind.getKind() == InitializationKind::IK_Direct ||
(Kind.getKind() == InitializationKind::IK_Copy &&
(Context.hasSameUnqualifiedType(SourceType, DestType) ||
S.IsDerivedFrom(Initializer->getBeginLoc(), SourceType, DestType)))) {
(Initializer && S.IsDerivedFrom(Initializer->getBeginLoc(),
SourceType, DestType))))) {
TryConstructorInitialization(S, Entity, Kind, Args, DestType, DestType,
*this);

Expand Down Expand Up @@ -6406,6 +6408,7 @@ void InitializationSequence::InitializeFrom(Sema &S,
// function is used) to a derived class thereof are enumerated as
// described in 13.3.1.4, and the best one is chosen through
// overload resolution (13.3).
assert(Initializer && "Initializer must be non-null");
TryUserDefinedConversion(S, DestType, Kind, Initializer, *this,
TopLevelOfInitList);
}
Expand Down Expand Up @@ -6457,6 +6460,7 @@ void InitializationSequence::InitializeFrom(Sema &S,
// - Otherwise, if the source type is a (possibly cv-qualified) class
// type, conversion functions are considered.
if (!SourceType.isNull() && SourceType->isRecordType()) {
assert(Initializer && "Initializer must be non-null");
// For a conversion to _Atomic(T) from either T or a class type derived
// from T, initialize the T object then convert to _Atomic type.
bool NeedAtomicConversion = false;
Expand Down

0 comments on commit 472232a

Please sign in to comment.