Compute the proper sourcerange for an CompoundLiteralExpr.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@45504 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/AST/StmtSerialization.cpp b/AST/StmtSerialization.cpp
index 5320a39..d6f9dca 100644
--- a/AST/StmtSerialization.cpp
+++ b/AST/StmtSerialization.cpp
@@ -387,13 +387,15 @@
 
 void CompoundLiteralExpr::EmitImpl(Serializer& S) const {
   S.Emit(getType());
+  S.Emit(getLParenLoc());
   S.EmitOwnedPtr(Init);
 }
 
 CompoundLiteralExpr* CompoundLiteralExpr::CreateImpl(Deserializer& D) {
   QualType Q = QualType::ReadVal(D);
+  SourceLocation L = SourceLocation::ReadVal(D);
   Expr* Init = D.ReadOwnedPtr<Expr>();
-  return new CompoundLiteralExpr(Q,Init);
+  return new CompoundLiteralExpr(L, Q, Init);
 }
 
 void CompoundStmt::EmitImpl(Serializer& S) const {
diff --git a/Driver/RewriteTest.cpp b/Driver/RewriteTest.cpp
index c29241b..bec1332 100644
--- a/Driver/RewriteTest.cpp
+++ b/Driver/RewriteTest.cpp
@@ -1454,7 +1454,8 @@
       InitListExpr *ILE = new InitListExpr(SourceLocation(), 
                                            &InitExprs[0], InitExprs.size(), 
                                            SourceLocation());
-      CompoundLiteralExpr *SuperRep = new CompoundLiteralExpr(superType, ILE);
+      CompoundLiteralExpr *SuperRep = new CompoundLiteralExpr(SourceLocation(),
+                                                              superType, ILE);
       // struct objc_super *
       Expr *Unop = new UnaryOperator(SuperRep, UnaryOperator::AddrOf,
                                Context->getPointerType(SuperRep->getType()), 
@@ -1506,7 +1507,8 @@
       InitListExpr *ILE = new InitListExpr(SourceLocation(), 
                                            &InitExprs[0], InitExprs.size(), 
                                            SourceLocation());
-      CompoundLiteralExpr *SuperRep = new CompoundLiteralExpr(superType, ILE);
+      CompoundLiteralExpr *SuperRep = new CompoundLiteralExpr(SourceLocation(),
+                                                              superType, ILE);
       // struct objc_super *
       Expr *Unop = new UnaryOperator(SuperRep, UnaryOperator::AddrOf,
                                Context->getPointerType(SuperRep->getType()), 
diff --git a/Sema/SemaExpr.cpp b/Sema/SemaExpr.cpp
index 20118c2..0778bbd 100644
--- a/Sema/SemaExpr.cpp
+++ b/Sema/SemaExpr.cpp
@@ -704,7 +704,7 @@
   if (CheckInitializer(literalExpr, literalType, false))
     return 0;
 
-  return new CompoundLiteralExpr(literalType, literalExpr);
+  return new CompoundLiteralExpr(LParenLoc, literalType, literalExpr);
 }
 
 Action::ExprResult Sema::
@@ -1982,7 +1982,7 @@
   
   // Otherwise, create a compound literal expression as the base, and
   // iteratively process the offsetof designators.
-  Expr *Res = new CompoundLiteralExpr(ArgTy, 0);
+  Expr *Res = new CompoundLiteralExpr(SourceLocation(), ArgTy, 0);
   
   // offsetof with non-identifier designators (e.g. "offsetof(x, a.b[c])") are a
   // GCC extension, diagnose them.
diff --git a/clang.xcodeproj/project.pbxproj b/clang.xcodeproj/project.pbxproj
index 6a4013b..85781e5 100644
--- a/clang.xcodeproj/project.pbxproj
+++ b/clang.xcodeproj/project.pbxproj
@@ -796,7 +796,6 @@
 		08FB7793FE84155DC02AAC07 /* Project object */ = {
 			isa = PBXProject;
 			buildConfigurationList = 1DEB923508733DC60010E9CD /* Build configuration list for PBXProject "clang" */;
-			compatibilityVersion = "Xcode 2.4";
 			hasScannedForEncodings = 1;
 			mainGroup = 08FB7794FE84155DC02AAC07 /* clang */;
 			projectDirPath = "";
diff --git a/include/clang/AST/Expr.h b/include/clang/AST/Expr.h
index a0dbdb7..151fc06 100644
--- a/include/clang/AST/Expr.h
+++ b/include/clang/AST/Expr.h
@@ -723,18 +723,27 @@
 /// CompoundLiteralExpr - [C99 6.5.2.5] 
 ///
 class CompoundLiteralExpr : public Expr {
+  /// LParenLoc - If non-null, this is the location of the left paren in a
+  /// compound literal like "(int){4}".  This can be null if this is a
+  /// synthesized compound expression.
+  SourceLocation LParenLoc;
   Expr *Init;
 public:
-  CompoundLiteralExpr(QualType ty, Expr *init) : 
-    Expr(CompoundLiteralExprClass, ty), Init(init) {}
+  CompoundLiteralExpr(SourceLocation lparenloc, QualType ty, Expr *init) : 
+    Expr(CompoundLiteralExprClass, ty), LParenLoc(lparenloc), Init(init) {}
   
   const Expr *getInitializer() const { return Init; }
   Expr *getInitializer() { return Init; }
   
+  SourceLocation getLParenLoc() const { return LParenLoc; }
+  
   virtual SourceRange getSourceRange() const {
-    if (Init)
+    // FIXME: Init should never be null.
+    if (!Init)
+      return SourceRange();
+    if (LParenLoc.isInvalid())
       return Init->getSourceRange();
-    return SourceRange();
+    return SourceRange(LParenLoc, Init->getLocEnd());
   }
 
   static bool classof(const Stmt *T) {