From dca1761c9b91d0a730ac6368425dc978e8481392 Mon Sep 17 00:00:00 2001 From: Peter Collingbourne Date: Thu, 1 Mar 2012 16:34:31 +0000 Subject: [PATCH] StmtProfiler: Add a null check for child statements. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@151812 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/AST/StmtProfile.cpp | 8 ++++++-- test/SemaCXX/warn-memset-bad-sizeof.cpp | 8 ++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/AST/StmtProfile.cpp b/lib/AST/StmtProfile.cpp index 643bca817c..d996925906 100644 --- a/lib/AST/StmtProfile.cpp +++ b/lib/AST/StmtProfile.cpp @@ -69,8 +69,12 @@ namespace { void StmtProfiler::VisitStmt(const Stmt *S) { ID.AddInteger(S->getStmtClass()); - for (Stmt::const_child_range C = S->children(); C; ++C) - Visit(*C); + for (Stmt::const_child_range C = S->children(); C; ++C) { + if (*C) + Visit(*C); + else + ID.AddInteger(0); + } } void StmtProfiler::VisitDeclStmt(const DeclStmt *S) { diff --git a/test/SemaCXX/warn-memset-bad-sizeof.cpp b/test/SemaCXX/warn-memset-bad-sizeof.cpp index 388e362768..e0d28da3d5 100644 --- a/test/SemaCXX/warn-memset-bad-sizeof.cpp +++ b/test/SemaCXX/warn-memset-bad-sizeof.cpp @@ -104,6 +104,14 @@ void f(Mat m, const Foo& const_foo, char *buffer) { // Copy to raw buffer shouldn't warn either memcpy(&foo, &arr, sizeof(Foo)); memcpy(&arr, &foo, sizeof(Foo)); + + // Shouldn't warn, and shouldn't crash either. + memset(({ + if (0) {} + while (0) {} + for (;;) {} + &s; + }), 0, sizeof(s)); } namespace ns { -- 2.50.1