[cfe-commits] r57163 - in /cfe/trunk: lib/CodeGen/CGBuiltin.cpp lib/CodeGen/CGExprConstant.cpp lib/Sema/SemaDecl.cpp test/CodeGen/cfstring.c
Chris Lattner
sabre at nondot.org
Mon Oct 6 00:26:43 PDT 2008
Author: lattner
Date: Mon Oct 6 02:26:43 2008
New Revision: 57163
URL: http://llvm.org/viewvc/llvm-project?rev=57163&view=rev
Log:
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.
Modified:
cfe/trunk/lib/CodeGen/CGBuiltin.cpp
cfe/trunk/lib/CodeGen/CGExprConstant.cpp
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/test/CodeGen/cfstring.c
Modified: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuiltin.cpp?rev=57163&r1=57162&r2=57163&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp Mon Oct 6 02:26:43 2008
@@ -48,23 +48,8 @@
switch (BuiltinID) {
default: break; // Handle intrinsics and libm functions below.
- case 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 RValue::get(CGM.GetAddrOfConstantCFString(S));
- }
+ case Builtin::BI__builtin___CFStringMakeConstantString:
+ return RValue::get(CGM.EmitConstantExpr(E, 0));
case Builtin::BI__builtin_stdarg_start:
case Builtin::BI__builtin_va_start:
case Builtin::BI__builtin_va_end: {
Modified: cfe/trunk/lib/CodeGen/CGExprConstant.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprConstant.cpp?rev=57163&r1=57162&r2=57163&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprConstant.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprConstant.cpp Mon Oct 6 02:26:43 2008
@@ -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()));
}
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=57163&r1=57162&r2=57163&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Mon Oct 6 02:26:43 2008
@@ -872,13 +872,21 @@
Diag(Init->getExprLoc(),
diag::err_init_element_not_constant, Init->getSourceRange());
return true;
- case Expr::ParenExprClass: {
- const ParenExpr* PE = cast<ParenExpr>(Init);
- return CheckAddressConstantExpression(PE->getSubExpr());
- }
+ case Expr::ParenExprClass:
+ return CheckAddressConstantExpression(cast<ParenExpr>(Init)->getSubExpr());
case Expr::StringLiteralClass:
case Expr::ObjCStringLiteralClass:
return false;
+ case Expr::CallExprClass:
+ // __builtin___CFStringMakeConstantString is a valid constant l-value.
+ if (cast<CallExpr>(Init)->isBuiltinCall() ==
+ Builtin::BI__builtin___CFStringMakeConstantString)
+ return false;
+
+ Diag(Init->getExprLoc(),
+ diag::err_init_element_not_constant, Init->getSourceRange());
+ return true;
+
case Expr::UnaryOperatorClass: {
const UnaryOperator *Exp = cast<UnaryOperator>(Init);
Modified: cfe/trunk/test/CodeGen/cfstring.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/cfstring.c?rev=57163&r1=57162&r2=57163&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/cfstring.c (original)
+++ cfe/trunk/test/CodeGen/cfstring.c Mon Oct 6 02:26:43 2008
@@ -4,3 +4,8 @@
void f() {
CFSTR("Hello, World!");
}
+
+// rdar://6248329
+void *G = CFSTR("yo joe");
+
+
More information about the cfe-commits
mailing list