Skip to content

Commit 7e0f02a

Browse files
authored
Merge pull request #62724 from valeriyvan/Formatting
Add check against NULL before dereferencing pointer
2 parents 641e5ef + c5493d8 commit 7e0f02a

File tree

4 files changed

+2
-18
lines changed

4 files changed

+2
-18
lines changed

include/swift/AST/Expr.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3863,9 +3863,6 @@ class AbstractClosureExpr : public DeclContext, public Expr {
38633863
/// Only valid when \c hasSingleExpressionBody() is true.
38643864
Expr *getSingleExpressionBody() const;
38653865

3866-
/// Whether this closure has a body
3867-
bool hasBody() const;
3868-
38693866
/// Returns the body of closures that have a body
38703867
/// returns nullptr if the closure doesn't have a body
38713868
BraceStmt *getBody() const;
@@ -4273,6 +4270,7 @@ class CaptureListExpr final : public Expr,
42734270
AbstractClosureExpr *closureBody)
42744271
: Expr(ExprKind::CaptureList, /*Implicit=*/false, Type()),
42754272
closureBody(closureBody) {
4273+
assert(closureBody);
42764274
Bits.CaptureListExpr.NumCaptures = captureList.size();
42774275
std::uninitialized_copy(captureList.begin(), captureList.end(),
42784276
getTrailingObjects<CaptureListEntry>());

lib/AST/Expr.cpp

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1918,19 +1918,7 @@ void AbstractClosureExpr::setParameterList(ParameterList *P) {
19181918
P->setDeclContextOfParamDecls(this);
19191919
}
19201920

1921-
bool AbstractClosureExpr::hasBody() const {
1922-
switch (getKind()) {
1923-
case ExprKind::Closure:
1924-
case ExprKind::AutoClosure:
1925-
return true;
1926-
default:
1927-
return false;
1928-
}
1929-
}
1930-
19311921
BraceStmt * AbstractClosureExpr::getBody() const {
1932-
if (!hasBody())
1933-
return nullptr;
19341922
if (const AutoClosureExpr *autocls = dyn_cast<AutoClosureExpr>(this))
19351923
return autocls->getBody();
19361924
if (const ClosureExpr *cls = dyn_cast<ClosureExpr>(this))

lib/IDE/Formatting.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2486,7 +2486,7 @@ class FormatWalker : public ASTWalker {
24862486
SourceLoc ContextLoc = SourceLoc()) {
24872487
AbstractClosureExpr *CE = CL->getClosureBody();
24882488
BraceStmt *BS = CE->getBody();
2489-
if (!CE || !BS)
2489+
if (!BS)
24902490
return None;
24912491

24922492
if (ContextLoc.isValid()) {

lib/SIL/IR/SILProfiler.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,6 @@ shouldWalkIntoExpr(Expr *E, ASTWalker::ParentTy Parent, SILDeclRef Constant) {
213213
// initializer instead.
214214
if (!Parent.isNull() || !Constant || !Constant.getAbstractClosureExpr())
215215
return Action::SkipChildren(E);
216-
217-
assert(CE->hasBody());
218216
}
219217
return Action::Continue(E);
220218
}

0 commit comments

Comments
 (0)