]> granicus.if.org Git - clang/commitdiff
Make the constant folder aware of
authorEli Friedman <eli.friedman@gmail.com>
Sun, 25 Jan 2009 01:54:01 +0000 (01:54 +0000)
committerEli Friedman <eli.friedman@gmail.com>
Sun, 25 Jan 2009 01:54:01 +0000 (01:54 +0000)
__builtin___CFStringMakeConstantString.  (We get into trouble in
GenerateStaticBlockVarDecl if the constant folder isn't accurate.)

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@62949 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/ExprConstant.cpp
lib/CodeGen/CGBuiltin.cpp
lib/CodeGen/CGExprConstant.cpp
test/CodeGen/cfstring.c

index 76bdaa2c8f8389cb2551818c07fdb91a9e5af882..43b45612b940d7d39028a2a6e66232a9aedd3edd 100644 (file)
@@ -217,6 +217,7 @@ public:
       { return APValue(E, 0); }
   APValue VisitAddrLabelExpr(AddrLabelExpr *E)
       { return APValue(E, 0); }
+  APValue VisitCallExpr(CallExpr *E);
   APValue VisitConditionalOperator(ConditionalOperator *E);
 };
 } // end anonymous namespace
@@ -306,6 +307,12 @@ APValue PointerExprEvaluator::VisitCastExpr(const CastExpr* E) {
   return APValue();
 }  
 
+APValue PointerExprEvaluator::VisitCallExpr(CallExpr *E) {
+  if (E->isBuiltinCall() == Builtin::BI__builtin___CFStringMakeConstantString)
+    return APValue(E, 0);
+  return APValue();
+}
+
 APValue PointerExprEvaluator::VisitConditionalOperator(ConditionalOperator *E) {
   bool BoolResult;
   if (!HandleConversionToBool(E->getCond(), BoolResult, Info))
index 30f8c34c5876ced2de3f9f312409fe17b70023f0..9260b11ed34ac9642086ea4bfe794e4d564e7a2e 100644 (file)
@@ -42,8 +42,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(unsigned BuiltinID, const CallExpr *E) {
   if (E->Evaluate(Result, CGM.getContext())) {
     if (Result.Val.isInt())
       return RValue::get(llvm::ConstantInt::get(Result.Val.getInt()));
-    assert(Result.Val.isFloat() && "Unsupported constant type");
-    return RValue::get(llvm::ConstantFP::get(Result.Val.getFloat()));
+    else if (Result.Val.isFloat())
+      return RValue::get(llvm::ConstantFP::get(Result.Val.getFloat()));
   }
       
   switch (BuiltinID) {
index 0e31cacd1b038c52dba088c4987d314f77825a9f..716e295f3e0c1d43ebc779a5cf5a5c91b932b844 100644 (file)
@@ -625,6 +625,15 @@ public:
       llvm::Constant *C = llvm::ConstantInt::get(llvm::Type::Int32Ty, id);
       return llvm::ConstantExpr::getIntToPtr(C, ConvertType(E->getType()));
     }
+    case Expr::CallExprClass: {
+      CallExpr* CE = cast<CallExpr>(E);
+      if (CE->isBuiltinCall() != Builtin::BI__builtin___CFStringMakeConstantString)
+        break;
+      const Expr *Arg = CE->getArg(0)->IgnoreParenCasts();
+      const StringLiteral *Literal = cast<StringLiteral>(Arg);
+      std::string S(Literal->getStrData(), Literal->getByteLength());
+      return CGM.GetAddrOfConstantCFString(S);
+    }
     }
     CGM.ErrorUnsupported(E, "constant l-value expression");
     llvm::Type *Ty = llvm::PointerType::getUnqual(ConvertType(E->getType()));
index 7d7edeca3cb3a2f17ce10e0c0570914bef0cd341..3bd1a2d1834455290597a4ea0911b9ccaf796f08 100644 (file)
@@ -8,4 +8,6 @@ void f() {
 // rdar://6248329
 void *G = CFSTR("yo joe");
 
-
+void h() {
+  static void* h = CFSTR("Goodbye, World!");
+}