]> granicus.if.org Git - clang/commitdiff
Add a reverse iterator to DeclStmt, and use it when building a CFG.
authorJordan Rose <jordan_rose@apple.com>
Fri, 20 Jul 2012 18:50:48 +0000 (18:50 +0000)
committerJordan Rose <jordan_rose@apple.com>
Fri, 20 Jul 2012 18:50:48 +0000 (18:50 +0000)
The CFG creates dummy DeclStmts with one Decl per statement, and it has
to do so from last to first in order to build the graph correctly.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@160560 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/Stmt.h
lib/Analysis/CFG.cpp

index 14b28f8e3d894ea010d0e211d36c7cbfac16d105..2ac503aa61469228cc5de1720bfa4785aeec1a31 100644 (file)
@@ -500,6 +500,14 @@ public:
   decl_iterator decl_end() { return DG.end(); }
   const_decl_iterator decl_begin() const { return DG.begin(); }
   const_decl_iterator decl_end() const { return DG.end(); }
+
+  typedef std::reverse_iterator<decl_iterator> reverse_decl_iterator;
+  reverse_decl_iterator decl_rbegin() {
+    return reverse_decl_iterator(decl_end());
+  }
+  reverse_decl_iterator decl_rend() {
+    return reverse_decl_iterator(decl_begin());
+  }
 };
 
 /// NullStmt - This is the null statement ";": C99 6.8.3p3.
index e141ed9a447e98ee0ff2a09e6b1bcd28c80296f1..1e3fa90c37237f0f68f2a0d7b690b390952818c5 100644 (file)
@@ -1527,11 +1527,10 @@ CFGBlock *CFGBuilder::VisitDeclStmt(DeclStmt *DS) {
 
   CFGBlock *B = 0;
 
-  // FIXME: Add a reverse iterator for DeclStmt to avoid this extra copy.
-  typedef SmallVector<Decl*,10> BufTy;
-  BufTy Buf(DS->decl_begin(), DS->decl_end());
-
-  for (BufTy::reverse_iterator I = Buf.rbegin(), E = Buf.rend(); I != E; ++I) {
+  // Build an individual DeclStmt for each decl.
+  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 = llvm::AlignOf<DeclStmt>::Alignment < 8
                ? 8 : llvm::AlignOf<DeclStmt>::Alignment;