]> granicus.if.org Git - clang/commitdiff
[analyzer] Fix crash in exploded graph dumping
authorGeorge Karpenkov <ekarpenkov@apple.com>
Tue, 2 Oct 2018 21:19:01 +0000 (21:19 +0000)
committerGeorge Karpenkov <ekarpenkov@apple.com>
Tue, 2 Oct 2018 21:19:01 +0000 (21:19 +0000)
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
test/Analysis/dump_egraph.c

index 6bb181c2253cf66621aa90d1873f9b4948f5053d..b998c3f84ed5c2f4640cb64dc5d86cf191b32dcf 100644 (file)
@@ -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.
index 70b7e1f08895daae58e36afd6446b3bd35c75bb6..a4bc547a485a740b0736ae150fa8ca421fdaff8e 100644 (file)
@@ -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" {