[cfe-commits] r59405 - /cfe/trunk/lib/CodeGen/CGExprConstant.cpp

Anders Carlsson andersca at mac.com
Sat Nov 15 22:23:45 PST 2008


Author: andersca
Date: Sun Nov 16 00:23:45 2008
New Revision: 59405

URL: http://llvm.org/viewvc/llvm-project?rev=59405&view=rev
Log:
More constant expr work.

Modified:
    cfe/trunk/lib/CodeGen/CGExprConstant.cpp

Modified: cfe/trunk/lib/CodeGen/CGExprConstant.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprConstant.cpp?rev=59405&r1=59404&r2=59405&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprConstant.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprConstant.cpp Sun Nov 16 00:23:45 2008
@@ -743,6 +743,7 @@
     return llvm::ConstantInt::get(llvm::APInt(ResultWidth, Val));
   }
 
+public:
   llvm::Constant *EmitLValue(Expr *E) {
     switch (E->getStmtClass()) {
     default: break;
@@ -798,6 +799,13 @@
     }
     case Expr::StringLiteralClass:
       return CGM.GetAddrOfConstantStringFromLiteral(cast<StringLiteral>(E));
+    case Expr::ObjCStringLiteralClass: {
+      ObjCStringLiteral* SL = cast<ObjCStringLiteral>(E);
+      std::string S(SL->getString()->getStrData(), 
+                    SL->getString()->getByteLength());
+      llvm::Constant *C = CGM.getObjCRuntime().GenerateConstantString(S);
+      return llvm::ConstantExpr::getBitCast(C, ConvertType(E->getType()));
+    }
     case Expr::UnaryOperatorClass: {
       UnaryOperator *Exp = cast<UnaryOperator>(E);
       switch (Exp->getOpcode()) {
@@ -831,7 +839,6 @@
   
 }  // end anonymous namespace.
 
-
 llvm::Constant *CodeGenModule::EmitConstantExpr(const Expr *E,
                                                 CodeGenFunction *CGF) {
   QualType type = Context.getCanonicalType(E->getType());
@@ -843,13 +850,18 @@
     switch (V.getKind()) {
     default: assert(0 && "unhandled value kind!");
     case APValue::LValue: {
-      if (V.getLValueBase())
-        break;
+      llvm::Constant *Offset = llvm::ConstantInt::get(llvm::Type::Int64Ty,
+                                                      V.getLValueOffset());
       
-      llvm::Constant *C = llvm::ConstantInt::get(llvm::Type::Int64Ty,
-                                                 V.getLValueOffset());
+      if (const Expr *LVBase = V.getLValueBase()) {
+        llvm::Constant *Base = 
+          ConstExprEmitter(*this, CGF).EmitLValue(const_cast<Expr*>(LVBase));
+
+        return llvm::ConstantExpr::getGetElementPtr(Base, &Offset, 1);
+      }
       
-      return llvm::ConstantExpr::getIntToPtr(C, getTypes().ConvertType(type));
+      return llvm::ConstantExpr::getIntToPtr(Offset, 
+                                             getTypes().ConvertType(type));
     }
     case APValue::Int:
       llvm::Constant *C = llvm::ConstantInt::get(V.getInt());





More information about the cfe-commits mailing list