Fix SCEVCommutativeExpr::print to be robust in the case of improper
authorDan Gohman <gohman@apple.com>
Fri, 16 Apr 2010 15:03:25 +0000 (15:03 +0000)
committerDan Gohman <gohman@apple.com>
Fri, 16 Apr 2010 15:03:25 +0000 (15:03 +0000)
expression canonicalization. Its job is to print what's there, not to
make judgements about it.

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

lib/Analysis/ScalarEvolution.cpp

index 9e101370d404ac91f250dfbd39602871f7e5ceda..14e6bcb1815b6f48d22585eabc2fdc6073e64faa 100644 (file)
@@ -247,11 +247,13 @@ void SCEVSignExtendExpr::print(raw_ostream &OS) const {
 }
 
 void SCEVCommutativeExpr::print(raw_ostream &OS) const {
-  assert(NumOperands > 1 && "This plus expr shouldn't exist!");
   const char *OpStr = getOperationStr();
-  OS << "(" << *Operands[0];
-  for (unsigned i = 1, e = NumOperands; i != e; ++i)
-    OS << OpStr << *Operands[i];
+  OS << "(";
+  for (op_iterator I = op_begin(), E = op_end(); I != E; ++I) {
+    OS << **I;
+    if (next(I) != E)
+      OS << OpStr;
+  }
   OS << ")";
 }