Fix InitListExpr::getSourceRange() to work in the case of no locations for '(' and ')'.  This can happen
in the case of transparent unions.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@118472 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/AST/Expr.cpp b/lib/AST/Expr.cpp
index 078bd7c..7d05bdb 100644
--- a/lib/AST/Expr.cpp
+++ b/lib/AST/Expr.cpp
@@ -1028,6 +1028,35 @@
   return Result;
 }
 
+SourceRange InitListExpr::getSourceRange() const {
+  if (SyntacticForm)
+    return SyntacticForm->getSourceRange();
+  SourceLocation Beg = LBraceLoc, End = RBraceLoc;
+  if (Beg.isInvalid()) {
+    // Find the first non-null initializer.
+    for (InitExprsTy::const_iterator I = InitExprs.begin(),
+                                     E = InitExprs.end(); 
+      I != E; ++I) {
+      if (Stmt *S = *I) {
+        Beg = S->getLocStart();
+        break;
+      }  
+    }
+  }
+  if (End.isInvalid()) {
+    // Find the first non-null initializer from the end.
+    for (InitExprsTy::const_reverse_iterator I = InitExprs.rbegin(),
+                                             E = InitExprs.rend();
+      I != E; ++I) {
+      if (Stmt *S = *I) {
+        End = S->getSourceRange().getEnd();
+        break;
+      }  
+    }
+  }
+  return SourceRange(Beg, End);
+}
+
 /// getFunctionType - Return the underlying function type for this block.
 ///
 const FunctionType *BlockExpr::getFunctionType() const {