aboutsummaryrefslogtreecommitdiff
path: root/lib/CodeGen/CGExprConstant.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2008-10-06 07:26:43 +0000
committerChris Lattner <sabre@nondot.org>2008-10-06 07:26:43 +0000
commit506ff88f44562df267b6a06608ab841b76df2a2b (patch)
tree46b584fbf5003c15facceaa7aa3adb4a9c5393a6 /lib/CodeGen/CGExprConstant.cpp
parent7cecee8da98e86cf7118d15a0f198b98956089a7 (diff)
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
Diffstat (limited to 'lib/CodeGen/CGExprConstant.cpp')
-rw-r--r--lib/CodeGen/CGExprConstant.cpp18
1 files changed, 18 insertions, 0 deletions
diff --git a/lib/CodeGen/CGExprConstant.cpp b/lib/CodeGen/CGExprConstant.cpp
index 50f0d12240..69abbcc984 100644
--- a/lib/CodeGen/CGExprConstant.cpp
+++ b/lib/CodeGen/CGExprConstant.cpp
@@ -617,6 +617,24 @@ public:
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()));
}