Implement codegen for __builtin_choose_expr.  For example:

struct X { int A; };

void foo() {
  struct X s;
  int i;
  i = __builtin_choose_expr(0, s, i);
}

compiles to:

        %tmp = load i32* %i             ; <i32> [#uses=1]
        store i32 %tmp, i32* %i

wow :)



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@40801 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/AST/StmtPrinter.cpp b/AST/StmtPrinter.cpp
index bdbbc12..41aa646 100644
--- a/AST/StmtPrinter.cpp
+++ b/AST/StmtPrinter.cpp
@@ -490,9 +490,9 @@
 void StmtPrinter::VisitChooseExpr(ChooseExpr *Node) {
   OS << "__builtin_choose_expr(";
   PrintExpr(Node->getCond());
-  OS << ",";
+  OS << ", ";
   PrintExpr(Node->getLHS());
-  OS << ",";
+  OS << ", ";
   PrintExpr(Node->getRHS());
   OS << ")";
 }
diff --git a/CodeGen/CGExpr.cpp b/CodeGen/CGExpr.cpp
index 9697686..534376e 100644
--- a/CodeGen/CGExpr.cpp
+++ b/CodeGen/CGExpr.cpp
@@ -637,6 +637,8 @@
   
   case Expr::ConditionalOperatorClass:
     return EmitConditionalOperator(cast<ConditionalOperator>(E));
+  case Expr::ChooseExprClass:
+    return EmitChooseExpr(cast<ChooseExpr>(E));
   }
   
 }
@@ -658,6 +660,16 @@
                                             E->typesAreCompatible()));
 }
 
+/// EmitChooseExpr - Implement __builtin_choose_expr.
+RValue CodeGenFunction::EmitChooseExpr(const ChooseExpr *E) {
+  llvm::APSInt CondVal(32);
+  bool IsConst = E->getCond()->isIntegerConstantExpr(CondVal, getContext());
+  assert(IsConst && "Condition of choose expr must be i-c-e"); IsConst=IsConst;
+  
+  // Emit the LHS or RHS as appropriate.
+  return EmitExpr(CondVal != 0 ? E->getLHS() : E->getRHS());
+}
+
 
 RValue CodeGenFunction::EmitArraySubscriptExprRV(const ArraySubscriptExpr *E) {
   // Emit subscript expressions in rvalue context's.  For most cases, this just
diff --git a/CodeGen/CodeGenFunction.h b/CodeGen/CodeGenFunction.h
index 4c79498..0cc5f0d 100644
--- a/CodeGen/CodeGenFunction.h
+++ b/CodeGen/CodeGenFunction.h
@@ -58,6 +58,7 @@
   class ArraySubscriptExpr;
   class OCUVectorElementExpr;
   class ConditionalOperator;
+  class ChooseExpr;
   class PreDefinedExpr;
   
   class BlockVarDecl;
@@ -399,6 +400,7 @@
   
   // Conditional Operator.
   RValue EmitConditionalOperator(const ConditionalOperator *E);
+  RValue EmitChooseExpr(const ChooseExpr *E);
 };
 }  // end namespace CodeGen
 }  // end namespace clang
diff --git a/clang.xcodeproj/project.pbxproj b/clang.xcodeproj/project.pbxproj
index 06fbbc5..352b750 100644
--- a/clang.xcodeproj/project.pbxproj
+++ b/clang.xcodeproj/project.pbxproj
@@ -196,7 +196,7 @@
 		1A869AA70BA21ABA008DA07A /* LiteralSupport.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = LiteralSupport.cpp; sourceTree = "<group>"; };
 		84D9A8870C1A57E100AC7ABC /* AttributeList.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = AttributeList.cpp; path = Parse/AttributeList.cpp; sourceTree = "<group>"; };
 		84D9A88B0C1A581300AC7ABC /* AttributeList.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = AttributeList.h; path = clang/Parse/AttributeList.h; sourceTree = "<group>"; };
-		8DD76F6C0486A84900D96B5E /* clang */ = {isa = PBXFileReference; includeInIndex = 0; lastKnownFileType = "compiled.mach-o.executable"; path = clang; sourceTree = BUILT_PRODUCTS_DIR; };
+		8DD76F6C0486A84900D96B5E /* clang */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = clang; sourceTree = BUILT_PRODUCTS_DIR; };
 		DE01DA480B12ADA300AC22CE /* PPCallbacks.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = PPCallbacks.h; sourceTree = "<group>"; };
 		DE06756B0C051CFE00EBBFD8 /* ParseExprCXX.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = ParseExprCXX.cpp; path = Parse/ParseExprCXX.cpp; sourceTree = "<group>"; };
 		DE06B73D0A8307640050E87E /* LangOptions.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = LangOptions.h; sourceTree = "<group>"; };