1 //===--- CGExprConstant.cpp - Emit LLVM Code from Constant Expressions ----===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 // 10 // This contains code to emit Constant Expr nodes as LLVM code. 11 // 12 //===----------------------------------------------------------------------===// 13 14 #include "CodeGenFunction.h" 15 #include "CodeGenModule.h" 16 #include "CGObjCRuntime.h" 17 #include "clang/AST/APValue.h" 18 #include "clang/AST/ASTContext.h" 19 #include "clang/AST/StmtVisitor.h" 20 #include "clang/Basic/Builtins.h" 21 #include "llvm/Constants.h" 22 #include "llvm/Function.h" 23 #include "llvm/GlobalVariable.h" 24 #include "llvm/Support/Compiler.h" 25 #include "llvm/Target/TargetData.h" 26 using namespace clang; 27 using namespace CodeGen; 28 29 namespace { 30 class VISIBILITY_HIDDEN ConstExprEmitter : 31 public StmtVisitor<ConstExprEmitter, llvm::Constant*> { 32 CodeGenModule &CGM; 33 CodeGenFunction *CGF; 34 llvm::LLVMContext &VMContext; 35 public: 36 ConstExprEmitter(CodeGenModule &cgm, CodeGenFunction *cgf) 37 : CGM(cgm), CGF(cgf), VMContext(cgm.getLLVMContext()) { 38 } 39 40 //===--------------------------------------------------------------------===// 41 // Visitor Methods 42 //===--------------------------------------------------------------------===// 43 44 llvm::Constant *VisitStmt(Stmt *S) { 45 return 0; 46 } 47 48 llvm::Constant *VisitParenExpr(ParenExpr *PE) { 49 return Visit(PE->getSubExpr()); 50 } 51 52 llvm::Constant *VisitCompoundLiteralExpr(CompoundLiteralExpr *E) { 53 return Visit(E->getInitializer()); 54 } 55 56 llvm::Constant *VisitCastExpr(CastExpr* E) { 57 // GCC cast to union extension 58 if (E->getType()->isUnionType()) { 59 const llvm::Type *Ty = ConvertType(E->getType()); 60 Expr *SubExpr = E->getSubExpr(); 61 return EmitUnion(CGM.EmitConstantExpr(SubExpr, SubExpr->getType(), CGF), 62 Ty); 63 } 64 // Explicit and implicit no-op casts 65 QualType Ty = E->getType(), SubTy = E->getSubExpr()->getType(); 66 if (CGM.getContext().hasSameUnqualifiedType(Ty, SubTy)) { 67 return Visit(E->getSubExpr()); 68 } 69 return 0; 70 } 71 72 llvm::Constant *VisitCXXDefaultArgExpr(CXXDefaultArgExpr *DAE) { 73 return Visit(DAE->getExpr()); 74 } 75 76 llvm::Constant *EmitArrayInitialization(InitListExpr *ILE) { 77 std::vector<llvm::Constant*> Elts; 78 const llvm::ArrayType *AType = 79 cast<llvm::ArrayType>(ConvertType(ILE->getType())); 80 unsigned NumInitElements = ILE->getNumInits(); 81 // FIXME: Check for wide strings 82 // FIXME: Check for NumInitElements exactly equal to 1?? 83 if (NumInitElements > 0 && 84 (isa<StringLiteral>(ILE->getInit(0)) || 85 isa<ObjCEncodeExpr>(ILE->getInit(0))) && 86 ILE->getType()->getArrayElementTypeNoTypeQual()->isCharType()) 87 return Visit(ILE->getInit(0)); 88 const llvm::Type *ElemTy = AType->getElementType(); 89 unsigned NumElements = AType->getNumElements(); 90 91 // Initialising an array requires us to automatically 92 // initialise any elements that have not been initialised explicitly 93 unsigned NumInitableElts = std::min(NumInitElements, NumElements); 94 95 // Copy initializer elements. 96 unsigned i = 0; 97 bool RewriteType = false; 98 for (; i < NumInitableElts; ++i) { 99 Expr *Init = ILE->getInit(i); 100 llvm::Constant *C = CGM.EmitConstantExpr(Init, Init->getType(), CGF); 101 if (!C) 102 return 0; 103 RewriteType |= (C->getType() != ElemTy); 104 Elts.push_back(C); 105 } 106 107 // Initialize remaining array elements. 108 // FIXME: This doesn't handle member pointers correctly! 109 for (; i < NumElements; ++i) 110 Elts.push_back(VMContext.getNullValue(ElemTy)); 111 112 if (RewriteType) { 113 // FIXME: Try to avoid packing the array 114 std::vector<const llvm::Type*> Types; 115 for (unsigned i = 0; i < Elts.size(); ++i) 116 Types.push_back(Elts[i]->getType()); 117 const llvm::StructType *SType = VMContext.getStructType(Types, true); 118 return VMContext.getConstantStruct(SType, Elts); 119 } 120 121 return VMContext.getConstantArray(AType, Elts); 122 } 123 124 void InsertBitfieldIntoStruct(std::vector<llvm::Constant*>& Elts, 125 FieldDecl* Field, Expr* E) { 126 // Calculate the value to insert 127 llvm::Constant *C = CGM.EmitConstantExpr(E, Field->getType(), CGF); 128 if (!C) 129 return; 130 131 llvm::ConstantInt *CI = dyn_cast<llvm::ConstantInt>(C); 132 if (!CI) { 133 CGM.ErrorUnsupported(E, "bitfield initialization"); 134 return; 135 } 136 llvm::APInt V = CI->getValue(); 137 138 // Calculate information about the relevant field 139 const llvm::Type* Ty = CI->getType(); 140 const llvm::TargetData &TD = CGM.getTypes().getTargetData(); 141 unsigned size = TD.getTypeAllocSizeInBits(Ty); 142 CodeGenTypes::BitFieldInfo Info = CGM.getTypes().getBitFieldInfo(Field); 143 unsigned FieldOffset = Info.FieldNo * size; 144 145 FieldOffset += Info.Start; 146 147 // Find where to start the insertion 148 // FIXME: This is O(n^2) in the number of bit-fields! 149 // FIXME: This won't work if the struct isn't completely packed! 150 unsigned offset = 0, i = 0; 151 while (offset < (FieldOffset & -8)) 152 offset += TD.getTypeAllocSizeInBits(Elts[i++]->getType()); 153 154 // Advance over 0 sized elements (must terminate in bounds since 155 // the bitfield must have a size). 156 while (TD.getTypeAllocSizeInBits(Elts[i]->getType()) == 0) 157 ++i; 158 159 // Promote the size of V if necessary 160 // FIXME: This should never occur, but currently it can because initializer 161 // constants are cast to bool, and because clang is not enforcing bitfield 162 // width limits. 163 if (Info.Size > V.getBitWidth()) 164 V.zext(Info.Size); 165 166 // Insert the bits into the struct 167 // FIXME: This algorthm is only correct on X86! 168 // FIXME: THis algorthm assumes bit-fields only have byte-size elements! 169 unsigned bitsToInsert = Info.Size; 170 unsigned curBits = std::min(8 - (FieldOffset & 7), bitsToInsert); 171 unsigned byte = V.getLoBits(curBits).getZExtValue() << (FieldOffset & 7); 172 do { 173 llvm::Constant* byteC = 174 VMContext.getConstantInt(llvm::Type::Int8Ty, byte); 175 Elts[i] = VMContext.getConstantExprOr(Elts[i], byteC); 176 ++i; 177 V = V.lshr(curBits); 178 bitsToInsert -= curBits; 179 180 if (!bitsToInsert) 181 break; 182 183 curBits = bitsToInsert > 8 ? 8 : bitsToInsert; 184 byte = V.getLoBits(curBits).getZExtValue(); 185 } while (true); 186 } 187 188 llvm::Constant *EmitStructInitialization(InitListExpr *ILE) { 189 const llvm::StructType *SType = 190 cast<llvm::StructType>(ConvertType(ILE->getType())); 191 RecordDecl *RD = ILE->getType()->getAsRecordType()->getDecl(); 192 std::vector<llvm::Constant*> Elts; 193 194 // Initialize the whole structure to zero. 195 // FIXME: This doesn't handle member pointers correctly! 196 for (unsigned i = 0; i < SType->getNumElements(); ++i) { 197 const llvm::Type *FieldTy = SType->getElementType(i); 198 Elts.push_back(VMContext.getNullValue(FieldTy)); 199 } 200 201 // Copy initializer elements. Skip padding fields. 202 unsigned EltNo = 0; // Element no in ILE 203 bool RewriteType = false; 204 for (RecordDecl::field_iterator Field = RD->field_begin(), 205 FieldEnd = RD->field_end(); 206 EltNo < ILE->getNumInits() && Field != FieldEnd; ++Field) { 207 if (Field->isBitField()) { 208 if (!Field->getIdentifier()) 209 continue; 210 InsertBitfieldIntoStruct(Elts, *Field, ILE->getInit(EltNo)); 211 } else { 212 unsigned FieldNo = CGM.getTypes().getLLVMFieldNo(*Field); 213 llvm::Constant *C = CGM.EmitConstantExpr(ILE->getInit(EltNo), 214 Field->getType(), CGF); 215 if (!C) return 0; 216 RewriteType |= (C->getType() != Elts[FieldNo]->getType()); 217 Elts[FieldNo] = C; 218 } 219 EltNo++; 220 } 221 222 if (RewriteType) { 223 // FIXME: Make this work for non-packed structs 224 assert(SType->isPacked() && "Cannot recreate unpacked structs"); 225 std::vector<const llvm::Type*> Types; 226 for (unsigned i = 0; i < Elts.size(); ++i) 227 Types.push_back(Elts[i]->getType()); 228 SType = VMContext.getStructType(Types, true); 229 } 230 231 return VMContext.getConstantStruct(SType, Elts); 232 } 233 234 llvm::Constant *EmitUnion(llvm::Constant *C, const llvm::Type *Ty) { 235 if (!C) 236 return 0; 237 238 // Build a struct with the union sub-element as the first member, 239 // and padded to the appropriate size 240 std::vector<llvm::Constant*> Elts; 241 std::vector<const llvm::Type*> Types; 242 Elts.push_back(C); 243 Types.push_back(C->getType()); 244 unsigned CurSize = CGM.getTargetData().getTypeAllocSize(C->getType()); 245 unsigned TotalSize = CGM.getTargetData().getTypeAllocSize(Ty); 246 247 assert(CurSize <= TotalSize && "Union size mismatch!"); 248 if (unsigned NumPadBytes = TotalSize - CurSize) { 249 const llvm::Type *Ty = llvm::Type::Int8Ty; 250 if (NumPadBytes > 1) 251 Ty = VMContext.getArrayType(Ty, NumPadBytes); 252 253 Elts.push_back(VMContext.getNullValue(Ty)); 254 Types.push_back(Ty); 255 } 256 257 llvm::StructType* STy = VMContext.getStructType(Types, false); 258 return VMContext.getConstantStruct(STy, Elts); 259 } 260 261 llvm::Constant *EmitUnionInitialization(InitListExpr *ILE) { 262 const llvm::Type *Ty = ConvertType(ILE->getType()); 263 264 FieldDecl* curField = ILE->getInitializedFieldInUnion(); 265 if (!curField) { 266 // There's no field to initialize, so value-initialize the union. 267 #ifndef NDEBUG 268 // Make sure that it's really an empty and not a failure of 269 // semantic analysis. 270 RecordDecl *RD = ILE->getType()->getAsRecordType()->getDecl(); 271 for (RecordDecl::field_iterator Field = RD->field_begin(), 272 FieldEnd = RD->field_end(); 273 Field != FieldEnd; ++Field) 274 assert(Field->isUnnamedBitfield() && "Only unnamed bitfields allowed"); 275 #endif 276 return VMContext.getNullValue(Ty); 277 } 278 279 if (curField->isBitField()) { 280 // Create a dummy struct for bit-field insertion 281 unsigned NumElts = CGM.getTargetData().getTypeAllocSize(Ty); 282 llvm::Constant* NV = 283 VMContext.getNullValue(llvm::Type::Int8Ty); 284 std::vector<llvm::Constant*> Elts(NumElts, NV); 285 286 InsertBitfieldIntoStruct(Elts, curField, ILE->getInit(0)); 287 const llvm::ArrayType *RetTy = 288 VMContext.getArrayType(NV->getType(), NumElts); 289 return VMContext.getConstantArray(RetTy, Elts); 290 } 291 292 llvm::Constant *InitElem; 293 if (ILE->getNumInits() > 0) { 294 Expr *Init = ILE->getInit(0); 295 InitElem = CGM.EmitConstantExpr(Init, Init->getType(), CGF); 296 } else { 297 InitElem = CGM.EmitNullConstant(curField->getType()); 298 } 299 return EmitUnion(InitElem, Ty); 300 } 301 302 llvm::Constant *EmitVectorInitialization(InitListExpr *ILE) { 303 const llvm::VectorType *VType = 304 cast<llvm::VectorType>(ConvertType(ILE->getType())); 305 const llvm::Type *ElemTy = VType->getElementType(); 306 std::vector<llvm::Constant*> Elts; 307 unsigned NumElements = VType->getNumElements(); 308 unsigned NumInitElements = ILE->getNumInits(); 309 310 unsigned NumInitableElts = std::min(NumInitElements, NumElements); 311 312 // Copy initializer elements. 313 unsigned i = 0; 314 for (; i < NumInitableElts; ++i) { 315 Expr *Init = ILE->getInit(i); 316 llvm::Constant *C = CGM.EmitConstantExpr(Init, Init->getType(), CGF); 317 if (!C) 318 return 0; 319 Elts.push_back(C); 320 } 321 322 for (; i < NumElements; ++i) 323 Elts.push_back(VMContext.getNullValue(ElemTy)); 324 325 return VMContext.getConstantVector(VType, Elts); 326 } 327 328 llvm::Constant *VisitImplicitValueInitExpr(ImplicitValueInitExpr* E) { 329 return CGM.EmitNullConstant(E->getType()); 330 } 331 332 llvm::Constant *VisitInitListExpr(InitListExpr *ILE) { 333 if (ILE->getType()->isScalarType()) { 334 // We have a scalar in braces. Just use the first element. 335 if (ILE->getNumInits() > 0) { 336 Expr *Init = ILE->getInit(0); 337 return CGM.EmitConstantExpr(Init, Init->getType(), CGF); 338 } 339 return CGM.EmitNullConstant(ILE->getType()); 340 } 341 342 if (ILE->getType()->isArrayType()) 343 return EmitArrayInitialization(ILE); 344 345 if (ILE->getType()->isStructureType()) 346 return EmitStructInitialization(ILE); 347 348 if (ILE->getType()->isUnionType()) 349 return EmitUnionInitialization(ILE); 350 351 if (ILE->getType()->isVectorType()) 352 return EmitVectorInitialization(ILE); 353 354 assert(0 && "Unable to handle InitListExpr"); 355 // Get rid of control reaches end of void function warning. 356 // Not reached. 357 return 0; 358 } 359 360 llvm::Constant *VisitStringLiteral(StringLiteral *E) { 361 assert(!E->getType()->isPointerType() && "Strings are always arrays"); 362 363 // This must be a string initializing an array in a static initializer. 364 // Don't emit it as the address of the string, emit the string data itself 365 // as an inline array. 366 return VMContext.getConstantArray(CGM.GetStringForStringLiteral(E), false); 367 } 368 369 llvm::Constant *VisitObjCEncodeExpr(ObjCEncodeExpr *E) { 370 // This must be an @encode initializing an array in a static initializer. 371 // Don't emit it as the address of the string, emit the string data itself 372 // as an inline array. 373 std::string Str; 374 CGM.getContext().getObjCEncodingForType(E->getEncodedType(), Str); 375 const ConstantArrayType *CAT = cast<ConstantArrayType>(E->getType()); 376 377 // Resize the string to the right size, adding zeros at the end, or 378 // truncating as needed. 379 Str.resize(CAT->getSize().getZExtValue(), '\0'); 380 return VMContext.getConstantArray(Str, false); 381 } 382 383 llvm::Constant *VisitUnaryExtension(const UnaryOperator *E) { 384 return Visit(E->getSubExpr()); 385 } 386 387 // Utility methods 388 const llvm::Type *ConvertType(QualType T) { 389 return CGM.getTypes().ConvertType(T); 390 } 391 392 public: 393 llvm::Constant *EmitLValue(Expr *E) { 394 switch (E->getStmtClass()) { 395 default: break; 396 case Expr::CompoundLiteralExprClass: { 397 // Note that due to the nature of compound literals, this is guaranteed 398 // to be the only use of the variable, so we just generate it here. 399 CompoundLiteralExpr *CLE = cast<CompoundLiteralExpr>(E); 400 llvm::Constant* C = Visit(CLE->getInitializer()); 401 // FIXME: "Leaked" on failure. 402 if (C) 403 C = new llvm::GlobalVariable(CGM.getModule(), C->getType(), 404 E->getType().isConstQualified(), 405 llvm::GlobalValue::InternalLinkage, 406 C, ".compoundliteral"); 407 return C; 408 } 409 case Expr::DeclRefExprClass: 410 case Expr::QualifiedDeclRefExprClass: { 411 NamedDecl *Decl = cast<DeclRefExpr>(E)->getDecl(); 412 if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(Decl)) 413 return CGM.GetAddrOfFunction(GlobalDecl(FD)); 414 if (const VarDecl* VD = dyn_cast<VarDecl>(Decl)) { 415 // We can never refer to a variable with local storage. 416 if (!VD->hasLocalStorage()) { 417 if (VD->isFileVarDecl() || VD->hasExternalStorage()) 418 return CGM.GetAddrOfGlobalVar(VD); 419 else if (VD->isBlockVarDecl()) { 420 assert(CGF && "Can't access static local vars without CGF"); 421 return CGF->GetAddrOfStaticLocalVar(VD); 422 } 423 } 424 } 425 break; 426 } 427 case Expr::StringLiteralClass: 428 return CGM.GetAddrOfConstantStringFromLiteral(cast<StringLiteral>(E)); 429 case Expr::ObjCEncodeExprClass: 430 return CGM.GetAddrOfConstantStringFromObjCEncode(cast<ObjCEncodeExpr>(E)); 431 case Expr::ObjCStringLiteralClass: { 432 ObjCStringLiteral* SL = cast<ObjCStringLiteral>(E); 433 llvm::Constant *C = CGM.getObjCRuntime().GenerateConstantString(SL); 434 return VMContext.getConstantExprBitCast(C, ConvertType(E->getType())); 435 } 436 case Expr::PredefinedExprClass: { 437 // __func__/__FUNCTION__ -> "". __PRETTY_FUNCTION__ -> "top level". 438 std::string Str; 439 if (cast<PredefinedExpr>(E)->getIdentType() == 440 PredefinedExpr::PrettyFunction) 441 Str = "top level"; 442 443 return CGM.GetAddrOfConstantCString(Str, ".tmp"); 444 } 445 case Expr::AddrLabelExprClass: { 446 assert(CGF && "Invalid address of label expression outside function."); 447 unsigned id = CGF->GetIDForAddrOfLabel(cast<AddrLabelExpr>(E)->getLabel()); 448 llvm::Constant *C = VMContext.getConstantInt(llvm::Type::Int32Ty, id); 449 return VMContext.getConstantExprIntToPtr(C, ConvertType(E->getType())); 450 } 451 case Expr::CallExprClass: { 452 CallExpr* CE = cast<CallExpr>(E); 453 if (CE->isBuiltinCall(CGM.getContext()) != 454 Builtin::BI__builtin___CFStringMakeConstantString) 455 break; 456 const Expr *Arg = CE->getArg(0)->IgnoreParenCasts(); 457 const StringLiteral *Literal = cast<StringLiteral>(Arg); 458 // FIXME: need to deal with UCN conversion issues. 459 return CGM.GetAddrOfConstantCFString(Literal); 460 } 461 case Expr::BlockExprClass: { 462 std::string FunctionName; 463 if (CGF) 464 FunctionName = CGF->CurFn->getName(); 465 else 466 FunctionName = "global"; 467 468 return CGM.GetAddrOfGlobalBlock(cast<BlockExpr>(E), FunctionName.c_str()); 469 } 470 } 471 472 return 0; 473 } 474 }; 475 476 } // end anonymous namespace. 477 478 llvm::Constant *CodeGenModule::EmitConstantExpr(const Expr *E, 479 QualType DestType, 480 CodeGenFunction *CGF) { 481 Expr::EvalResult Result; 482 483 bool Success = false; 484 485 if (DestType->isReferenceType()) 486 Success = E->EvaluateAsLValue(Result, Context); 487 else 488 Success = E->Evaluate(Result, Context); 489 490 if (Success) { 491 assert(!Result.HasSideEffects && 492 "Constant expr should not have any side effects!"); 493 switch (Result.Val.getKind()) { 494 case APValue::Uninitialized: 495 assert(0 && "Constant expressions should be initialized."); 496 return 0; 497 case APValue::LValue: { 498 const llvm::Type *DestTy = getTypes().ConvertTypeForMem(DestType); 499 llvm::Constant *Offset = 500 VMContext.getConstantInt(llvm::Type::Int64Ty, 501 Result.Val.getLValueOffset()); 502 503 llvm::Constant *C; 504 if (const Expr *LVBase = Result.Val.getLValueBase()) { 505 C = ConstExprEmitter(*this, CGF).EmitLValue(const_cast<Expr*>(LVBase)); 506 507 // Apply offset if necessary. 508 if (!Offset->isNullValue()) { 509 const llvm::Type *Type = 510 VMContext.getPointerTypeUnqual(llvm::Type::Int8Ty); 511 llvm::Constant *Casted = VMContext.getConstantExprBitCast(C, Type); 512 Casted = VMContext.getConstantExprGetElementPtr(Casted, &Offset, 1); 513 C = VMContext.getConstantExprBitCast(Casted, C->getType()); 514 } 515 516 // Convert to the appropriate type; this could be an lvalue for 517 // an integer. 518 if (isa<llvm::PointerType>(DestTy)) 519 return VMContext.getConstantExprBitCast(C, DestTy); 520 521 return VMContext.getConstantExprPtrToInt(C, DestTy); 522 } else { 523 C = Offset; 524 525 // Convert to the appropriate type; this could be an lvalue for 526 // an integer. 527 if (isa<llvm::PointerType>(DestTy)) 528 return VMContext.getConstantExprIntToPtr(C, DestTy); 529 530 // If the types don't match this should only be a truncate. 531 if (C->getType() != DestTy) 532 return VMContext.getConstantExprTrunc(C, DestTy); 533 534 return C; 535 } 536 } 537 case APValue::Int: { 538 llvm::Constant *C = VMContext.getConstantInt(Result.Val.getInt()); 539 540 if (C->getType() == llvm::Type::Int1Ty) { 541 const llvm::Type *BoolTy = getTypes().ConvertTypeForMem(E->getType()); 542 C = VMContext.getConstantExprZExt(C, BoolTy); 543 } 544 return C; 545 } 546 case APValue::ComplexInt: { 547 llvm::Constant *Complex[2]; 548 549 Complex[0] = VMContext.getConstantInt(Result.Val.getComplexIntReal()); 550 Complex[1] = VMContext.getConstantInt(Result.Val.getComplexIntImag()); 551 552 return VMContext.getConstantStruct(Complex, 2); 553 } 554 case APValue::Float: 555 return VMContext.getConstantFP(Result.Val.getFloat()); 556 case APValue::ComplexFloat: { 557 llvm::Constant *Complex[2]; 558 559 Complex[0] = VMContext.getConstantFP(Result.Val.getComplexFloatReal()); 560 Complex[1] = VMContext.getConstantFP(Result.Val.getComplexFloatImag()); 561 562 return VMContext.getConstantStruct(Complex, 2); 563 } 564 case APValue::Vector: { 565 llvm::SmallVector<llvm::Constant *, 4> Inits; 566 unsigned NumElts = Result.Val.getVectorLength(); 567 568 for (unsigned i = 0; i != NumElts; ++i) { 569 APValue &Elt = Result.Val.getVectorElt(i); 570 if (Elt.isInt()) 571 Inits.push_back(VMContext.getConstantInt(Elt.getInt())); 572 else 573 Inits.push_back(VMContext.getConstantFP(Elt.getFloat())); 574 } 575 return VMContext.getConstantVector(&Inits[0], Inits.size()); 576 } 577 } 578 } 579 580 llvm::Constant* C = ConstExprEmitter(*this, CGF).Visit(const_cast<Expr*>(E)); 581 if (C && C->getType() == llvm::Type::Int1Ty) { 582 const llvm::Type *BoolTy = getTypes().ConvertTypeForMem(E->getType()); 583 C = VMContext.getConstantExprZExt(C, BoolTy); 584 } 585 return C; 586 } 587 588 llvm::Constant *CodeGenModule::EmitNullConstant(QualType T) { 589 // Always return an LLVM null constant for now; this will change when we 590 // get support for IRGen of member pointers. 591 return getLLVMContext().getNullValue(getTypes().ConvertType(T)); 592 } 593