diff --git a/clang/lib/AST/StmtPrinter.cpp b/clang/lib/AST/StmtPrinter.cpp --- a/clang/lib/AST/StmtPrinter.cpp +++ b/clang/lib/AST/StmtPrinter.cpp @@ -175,6 +175,7 @@ /// PrintRawCompoundStmt - Print a compound stmt without indenting the {, and /// with no newline after the }. void StmtPrinter::PrintRawCompoundStmt(CompoundStmt *Node) { + assert(Node && "Compound statement cannot be null"); OS << "{" << NL; PrintFPPragmas(Node); for (auto *I : Node->body()) @@ -599,8 +600,10 @@ if (auto *FS = static_cast(Node->getFinallyStmt())) { Indent() << "@finally"; - PrintRawCompoundStmt(dyn_cast(FS->getFinallyBody())); - OS << NL; + if (auto *CS = dyn_cast(FS->getFinallyBody())) { + PrintRawCompoundStmt(CS); + OS << NL; + } } } @@ -635,7 +638,7 @@ void StmtPrinter::VisitObjCAutoreleasePoolStmt(ObjCAutoreleasePoolStmt *Node) { Indent() << "@autoreleasepool"; - PrintRawCompoundStmt(dyn_cast(Node->getSubStmt())); + PrintRawCompoundStmt(cast(Node->getSubStmt())); OS << NL; } diff --git a/clang/lib/Analysis/PathDiagnostic.cpp b/clang/lib/Analysis/PathDiagnostic.cpp --- a/clang/lib/Analysis/PathDiagnostic.cpp +++ b/clang/lib/Analysis/PathDiagnostic.cpp @@ -584,6 +584,7 @@ PathDiagnosticLocation::createBegin(const Stmt *S, const SourceManager &SM, LocationOrAnalysisDeclContext LAC) { + assert(S && "Statement cannot be null"); return PathDiagnosticLocation(getValidSourceLocation(S, LAC), SM, SingleLocK); }