AST work to support [C++] [IRgen] for ?: with missing LHS
This is also pr7726 and wip. No change in functionality
at this time.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@112612 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/AST/StmtDumper.cpp b/lib/AST/StmtDumper.cpp
index 850bba4..5c236a4 100644
--- a/lib/AST/StmtDumper.cpp
+++ b/lib/AST/StmtDumper.cpp
@@ -65,6 +65,13 @@
               OS << '\n';
               DumpSubTree(*CI++);
             }
+            if (const ConditionalOperator *CO = 
+                  dyn_cast<ConditionalOperator>(S)) {
+              if (CO->getSAVE()) {
+                OS << '\n';
+                DumpSubTree(CO->getSAVE());
+              }
+            }
           }
         }
         OS << ')';
diff --git a/lib/Rewrite/RewriteObjC.cpp b/lib/Rewrite/RewriteObjC.cpp
index 4a7de4b..578a063 100644
--- a/lib/Rewrite/RewriteObjC.cpp
+++ b/lib/Rewrite/RewriteObjC.cpp
@@ -3041,8 +3041,10 @@
     ConditionalOperator *CondExpr =
       new (Context) ConditionalOperator(lessThanExpr,
                                         SourceLocation(), CE,
-                                        SourceLocation(), STCE, returnType);
-    ReplacingStmt = new (Context) ParenExpr(SourceLocation(), SourceLocation(), CondExpr);
+                                        SourceLocation(), STCE, (Expr*)0,
+                                        returnType);
+    ReplacingStmt = new (Context) ParenExpr(SourceLocation(), SourceLocation(), 
+                                            CondExpr);
   }
   // delete Exp; leak for now, see RewritePropertySetter() usage for more info.
   return ReplacingStmt;
@@ -4566,7 +4568,8 @@
     ConditionalOperator *CondExpr =
       new (Context) ConditionalOperator(CONDExp,
                                       SourceLocation(), cast<Expr>(LHSStmt),
-                                      SourceLocation(), cast<Expr>(RHSStmt), 
+                                      SourceLocation(), cast<Expr>(RHSStmt),
+                                      (Expr*)0,
                                       Exp->getType());
     return CondExpr;
   } else if (const ObjCIvarRefExpr *IRE = dyn_cast<ObjCIvarRefExpr>(BlockExp)) {
diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp
index 455730c..ca9c5dc 100644
--- a/lib/Sema/SemaExpr.cpp
+++ b/lib/Sema/SemaExpr.cpp
@@ -4521,8 +4521,10 @@
   // If this is the gnu "x ?: y" extension, analyze the types as though the LHS
   // was the condition.
   bool isLHSNull = LHSExpr == 0;
-  if (isLHSNull)
-    LHSExpr = CondExpr;
+  Expr *SAVEExpr = 0;
+  if (isLHSNull) {
+    LHSExpr = SAVEExpr = CondExpr;
+  }
 
   QualType result = CheckConditionalOperands(CondExpr, LHSExpr,
                                              RHSExpr, QuestionLoc);
@@ -4530,8 +4532,9 @@
     return ExprError();
 
   return Owned(new (Context) ConditionalOperator(CondExpr, QuestionLoc,
-                                                 isLHSNull ? 0 : LHSExpr,
-                                                 ColonLoc, RHSExpr, result));
+                                                 LHSExpr, ColonLoc, 
+                                                 RHSExpr, SAVEExpr,
+                                                 result));
 }
 
 // CheckPointerTypesForAssignment - This is a very tricky routine (despite
diff --git a/lib/Serialization/ASTReaderStmt.cpp b/lib/Serialization/ASTReaderStmt.cpp
index ec227e2..da07f8c 100644
--- a/lib/Serialization/ASTReaderStmt.cpp
+++ b/lib/Serialization/ASTReaderStmt.cpp
@@ -592,6 +592,7 @@
   E->setCond(Reader.ReadSubExpr());
   E->setLHS(Reader.ReadSubExpr());
   E->setRHS(Reader.ReadSubExpr());
+  E->setSAVE(Reader.ReadSubExpr());
   E->setQuestionLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
   E->setColonLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
 }
diff --git a/lib/Serialization/ASTWriterStmt.cpp b/lib/Serialization/ASTWriterStmt.cpp
index 4bde550..922a1cd 100644
--- a/lib/Serialization/ASTWriterStmt.cpp
+++ b/lib/Serialization/ASTWriterStmt.cpp
@@ -598,6 +598,7 @@
   Writer.AddStmt(E->getCond());
   Writer.AddStmt(E->getLHS());
   Writer.AddStmt(E->getRHS());
+  Writer.AddStmt(E->getSAVE());
   Writer.AddSourceLocation(E->getQuestionLoc(), Record);
   Writer.AddSourceLocation(E->getColonLoc(), Record);
   Code = serialization::EXPR_CONDITIONAL_OPERATOR;