Make sema and codegen allow __builtin___CFStringMakeConstantString as a valid
constant lvalue.  Implement this in codegen by moving the code out of CGBuiltin
into EmitConstantExpr.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@57163 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/CGExprConstant.cpp b/lib/CodeGen/CGExprConstant.cpp
index 50f0d12..69abbcc 100644
--- a/lib/CodeGen/CGExprConstant.cpp
+++ b/lib/CodeGen/CGExprConstant.cpp
@@ -617,6 +617,24 @@
         return llvm::ConstantFP::get(Result.getFloat());
     }
 
+    // Handle __builtin___CFStringMakeConstantString.
+    if (E->isBuiltinCall() ==Builtin::BI__builtin___CFStringMakeConstantString){
+      const Expr *Arg = E->getArg(0);
+      
+      while (1) {
+        if (const ParenExpr *PE = dyn_cast<ParenExpr>(Arg))
+          Arg = PE->getSubExpr();
+        else if (const ImplicitCastExpr *CE = dyn_cast<ImplicitCastExpr>(Arg))
+          Arg = CE->getSubExpr();
+        else
+          break;
+      }
+      
+      const StringLiteral *Literal = cast<StringLiteral>(Arg);
+      std::string S(Literal->getStrData(), Literal->getByteLength());
+      return CGM.GetAddrOfConstantCFString(S);
+    }
+    
     CGM.ErrorUnsupported(E, "constant call expression");
     return llvm::Constant::getNullValue(ConvertType(E->getType()));
   }