From 8ea4dea1b6fd9db71e45497fec694af77a1bf28f Mon Sep 17 00:00:00 2001 From: George Karpenkov Date: Tue, 2 Oct 2018 21:19:01 +0000 Subject: [PATCH] [analyzer] Fix crash in exploded graph dumping By allocating new DeclStmt to ASTContext Differential Revision: https://reviews.llvm.org/D52756 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@343635 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Analysis/CFG.cpp | 5 +---- test/Analysis/dump_egraph.c | 4 ++-- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/lib/Analysis/CFG.cpp b/lib/Analysis/CFG.cpp index 6bb181c225..b998c3f84e 100644 --- a/lib/Analysis/CFG.cpp +++ b/lib/Analysis/CFG.cpp @@ -2632,15 +2632,12 @@ CFGBlock *CFGBuilder::VisitDeclStmt(DeclStmt *DS) { for (DeclStmt::reverse_decl_iterator I = DS->decl_rbegin(), E = DS->decl_rend(); I != E; ++I) { - // Get the alignment of the new DeclStmt, padding out to >=8 bytes. - unsigned A = alignof(DeclStmt) < 8 ? 8 : alignof(DeclStmt); // Allocate the DeclStmt using the BumpPtrAllocator. It will get // automatically freed with the CFG. DeclGroupRef DG(*I); Decl *D = *I; - void *Mem = cfg->getAllocator().Allocate(sizeof(DeclStmt), A); - DeclStmt *DSNew = new (Mem) DeclStmt(DG, D->getLocation(), GetEndLoc(D)); + DeclStmt *DSNew = new (Context) DeclStmt(DG, D->getLocation(), GetEndLoc(D)); cfg->addSyntheticDeclStmt(DSNew, DS); // Append the fake DeclStmt to block. diff --git a/test/Analysis/dump_egraph.c b/test/Analysis/dump_egraph.c index 70b7e1f088..a4bc547a48 100644 --- a/test/Analysis/dump_egraph.c +++ b/test/Analysis/dump_egraph.c @@ -5,8 +5,8 @@ int getJ(); int foo() { - int *x = 0; - return *x; + int *x = 0, *y = 0; + return *x + *y; } // CHECK: digraph "Exploded Graph" { -- 2.50.1