aboutsummaryrefslogtreecommitdiff
path: root/clang
diff options
context:
space:
mode:
authorElizabeth Andrews <elizabeth.andrews@intel.com>2023-08-04 09:30:51 -0700
committerElizabeth Andrews <elizabeth.andrews@intel.com>2023-08-29 12:23:26 -0700
commit39191c45771564b8a0930d71b4c229147cf839db (patch)
treed8db7cc2758e18da95bd95aacf55b83415454315 /clang
parent66ff408c724a5c349d43393aea8bb10e52cc3d48 (diff)
downloadllvm-39191c45771564b8a0930d71b4c229147cf839db.zip
llvm-39191c45771564b8a0930d71b4c229147cf839db.tar.gz
llvm-39191c45771564b8a0930d71b4c229147cf839db.tar.bz2
[NFC][Clang] Fix static analyzer concerns
Fix static analyzer concerns about dereferencing null values. Differential Revision: https://reviews.llvm.org/D157118
Diffstat (limited to 'clang')
-rw-r--r--clang/lib/AST/StmtPrinter.cpp9
-rw-r--r--clang/lib/Analysis/PathDiagnostic.cpp1
2 files changed, 7 insertions, 3 deletions
diff --git a/clang/lib/AST/StmtPrinter.cpp b/clang/lib/AST/StmtPrinter.cpp
index 20e0e5d..a31aa0c 100644
--- a/clang/lib/AST/StmtPrinter.cpp
+++ b/clang/lib/AST/StmtPrinter.cpp
@@ -175,6 +175,7 @@ namespace {
/// 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 @@ void StmtPrinter::VisitObjCAtTryStmt(ObjCAtTryStmt *Node) {
if (auto *FS = static_cast<ObjCAtFinallyStmt *>(Node->getFinallyStmt())) {
Indent() << "@finally";
- PrintRawCompoundStmt(dyn_cast<CompoundStmt>(FS->getFinallyBody()));
- OS << NL;
+ if (auto *CS = dyn_cast<CompoundStmt>(FS->getFinallyBody())) {
+ PrintRawCompoundStmt(CS);
+ OS << NL;
+ }
}
}
@@ -635,7 +638,7 @@ void StmtPrinter::VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *Node) {
void StmtPrinter::VisitObjCAutoreleasePoolStmt(ObjCAutoreleasePoolStmt *Node) {
Indent() << "@autoreleasepool";
- PrintRawCompoundStmt(dyn_cast<CompoundStmt>(Node->getSubStmt()));
+ PrintRawCompoundStmt(cast<CompoundStmt>(Node->getSubStmt()));
OS << NL;
}
diff --git a/clang/lib/Analysis/PathDiagnostic.cpp b/clang/lib/Analysis/PathDiagnostic.cpp
index ac1306f..93e6d98 100644
--- a/clang/lib/Analysis/PathDiagnostic.cpp
+++ b/clang/lib/Analysis/PathDiagnostic.cpp
@@ -584,6 +584,7 @@ PathDiagnosticLocation
PathDiagnosticLocation::createBegin(const Stmt *S,
const SourceManager &SM,
LocationOrAnalysisDeclContext LAC) {
+ assert(S && "Statement cannot be null");
return PathDiagnosticLocation(getValidSourceLocation(S, LAC),
SM, SingleLocK);
}