[cfe-commits] r172765 - /cfe/trunk/lib/Sema/SemaChecking.cpp

Richard Smith richard-llvm at metafoo.co.uk
Thu Jan 17 15:18:09 PST 2013


Author: rsmith
Date: Thu Jan 17 17:18:09 2013
New Revision: 172765

URL: http://llvm.org/viewvc/llvm-project?rev=172765&view=rev
Log:
Defer checking for unsequenced operations on the RHS of && and || in order to
reduce stack usage and hopefully bring back the linux x86_64 buildbot.

Modified:
    cfe/trunk/lib/Sema/SemaChecking.cpp

Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=172765&r1=172764&r2=172765&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Thu Jan 17 17:18:09 2013
@@ -5281,6 +5281,9 @@
   /// Filled in with declarations which were modified as a side-effect
   /// (that is, post-increment operations).
   llvm::SmallVectorImpl<std::pair<Object, Usage> > *ModAsSideEffect;
+  /// Expressions to check later. We defer checking these to reduce
+  /// stack usage.
+  llvm::SmallVectorImpl<Expr*> &WorkList;
 
   /// RAII object wrapping the visitation of a sequenced subexpression of an
   /// expression. At the end of this process, the side-effects of the evaluation
@@ -5385,9 +5388,10 @@
   }
 
 public:
-  SequenceChecker(Sema &S, Expr *E)
+  SequenceChecker(Sema &S, Expr *E,
+                  llvm::SmallVectorImpl<Expr*> &WorkList)
     : EvaluatedExprVisitor<SequenceChecker>(S.Context), SemaRef(S),
-      Region(Tree.root()), ModAsSideEffect(0) {
+      Region(Tree.root()), ModAsSideEffect(0), WorkList(WorkList) {
     Visit(E);
   }
 
@@ -5517,7 +5521,7 @@
       // FIXME: If there are operations in the RHS which are unsequenced
       // with respect to operations outside the RHS, and those operations
       // are unconditionally evaluated, diagnose them.
-      SequenceChecker(SemaRef, BO->getRHS());
+      WorkList.push_back(BO->getRHS());
     }
   }
   void VisitBinLAnd(BinaryOperator *BO) {
@@ -5532,7 +5536,7 @@
       if (Result)
         Visit(BO->getRHS());
     } else {
-      SequenceChecker(SemaRef, BO->getRHS());
+      WorkList.push_back(BO->getRHS());
     }
   }
 
@@ -5547,8 +5551,8 @@
         CO->getCond()->EvaluateAsBooleanCondition(Result, SemaRef.Context))
       Visit(Result ? CO->getTrueExpr() : CO->getFalseExpr());
     else {
-      SequenceChecker(SemaRef, CO->getTrueExpr());
-      SequenceChecker(SemaRef, CO->getFalseExpr());
+      WorkList.push_back(CO->getTrueExpr());
+      WorkList.push_back(CO->getFalseExpr());
     }
   }
 
@@ -5597,7 +5601,13 @@
 }
 
 void Sema::CheckUnsequencedOperations(Expr *E) {
-  SequenceChecker(*this, E);
+  llvm::SmallVector<Expr*, 8> WorkList;
+  WorkList.push_back(E);
+  while (!WorkList.empty()) {
+    Expr *Item = WorkList.back();
+    WorkList.pop_back();
+    SequenceChecker(*this, Item, WorkList);
+  }
 }
 
 void Sema::CheckCompletedExpr(Expr *E, SourceLocation CheckLoc) {





More information about the cfe-commits mailing list