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     unsigned fieldOffset = CGM.getTypes().getLLVMFieldNo(Field) * size;
143     CodeGenTypes::BitFieldInfo bitFieldInfo =
144         CGM.getTypes().getBitFieldInfo(Field);
145     fieldOffset += bitFieldInfo.Begin;
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 (bitFieldInfo.Size > V.getBitWidth())
164       V.zext(bitFieldInfo.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 = bitFieldInfo.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     while (CurSize < TotalSize) {
247       Elts.push_back(VMContext.getNullValue(llvm::Type::Int8Ty));
248       Types.push_back(llvm::Type::Int8Ty);
249       CurSize++;
250     }
251 
252     // This always generates a packed struct
253     // FIXME: Try to generate an unpacked struct when we can
254     llvm::StructType* STy = VMContext.getStructType(Types, true);
255     return VMContext.getConstantStruct(STy, Elts);
256   }
257 
258   llvm::Constant *EmitUnionInitialization(InitListExpr *ILE) {
259     const llvm::Type *Ty = ConvertType(ILE->getType());
260 
261     FieldDecl* curField = ILE->getInitializedFieldInUnion();
262     if (!curField) {
263       // There's no field to initialize, so value-initialize the union.
264 #ifndef NDEBUG
265       // Make sure that it's really an empty and not a failure of
266       // semantic analysis.
267       RecordDecl *RD = ILE->getType()->getAsRecordType()->getDecl();
268       for (RecordDecl::field_iterator Field = RD->field_begin(),
269                                    FieldEnd = RD->field_end();
270            Field != FieldEnd; ++Field)
271         assert(Field->isUnnamedBitfield() && "Only unnamed bitfields allowed");
272 #endif
273       return VMContext.getNullValue(Ty);
274     }
275 
276     if (curField->isBitField()) {
277       // Create a dummy struct for bit-field insertion
278       unsigned NumElts = CGM.getTargetData().getTypeAllocSize(Ty);
279       llvm::Constant* NV =
280         VMContext.getNullValue(llvm::Type::Int8Ty);
281       std::vector<llvm::Constant*> Elts(NumElts, NV);
282 
283       InsertBitfieldIntoStruct(Elts, curField, ILE->getInit(0));
284       const llvm::ArrayType *RetTy =
285           VMContext.getArrayType(NV->getType(), NumElts);
286       return VMContext.getConstantArray(RetTy, Elts);
287     }
288 
289     llvm::Constant *InitElem;
290     if (ILE->getNumInits() > 0) {
291       Expr *Init = ILE->getInit(0);
292       InitElem = CGM.EmitConstantExpr(Init, Init->getType(), CGF);
293     } else {
294       InitElem = CGM.EmitNullConstant(curField->getType());
295     }
296     return EmitUnion(InitElem, Ty);
297   }
298 
299   llvm::Constant *EmitVectorInitialization(InitListExpr *ILE) {
300     const llvm::VectorType *VType =
301         cast<llvm::VectorType>(ConvertType(ILE->getType()));
302     const llvm::Type *ElemTy = VType->getElementType();
303     std::vector<llvm::Constant*> Elts;
304     unsigned NumElements = VType->getNumElements();
305     unsigned NumInitElements = ILE->getNumInits();
306 
307     unsigned NumInitableElts = std::min(NumInitElements, NumElements);
308 
309     // Copy initializer elements.
310     unsigned i = 0;
311     for (; i < NumInitableElts; ++i) {
312       Expr *Init = ILE->getInit(i);
313       llvm::Constant *C = CGM.EmitConstantExpr(Init, Init->getType(), CGF);
314       if (!C)
315         return 0;
316       Elts.push_back(C);
317     }
318 
319     for (; i < NumElements; ++i)
320       Elts.push_back(VMContext.getNullValue(ElemTy));
321 
322     return VMContext.getConstantVector(VType, Elts);
323   }
324 
325   llvm::Constant *VisitImplicitValueInitExpr(ImplicitValueInitExpr* E) {
326     return CGM.EmitNullConstant(E->getType());
327   }
328 
329   llvm::Constant *VisitInitListExpr(InitListExpr *ILE) {
330     if (ILE->getType()->isScalarType()) {
331       // We have a scalar in braces. Just use the first element.
332       if (ILE->getNumInits() > 0) {
333         Expr *Init = ILE->getInit(0);
334         return CGM.EmitConstantExpr(Init, Init->getType(), CGF);
335       }
336       return CGM.EmitNullConstant(ILE->getType());
337     }
338 
339     if (ILE->getType()->isArrayType())
340       return EmitArrayInitialization(ILE);
341 
342     if (ILE->getType()->isStructureType())
343       return EmitStructInitialization(ILE);
344 
345     if (ILE->getType()->isUnionType())
346       return EmitUnionInitialization(ILE);
347 
348     if (ILE->getType()->isVectorType())
349       return EmitVectorInitialization(ILE);
350 
351     assert(0 && "Unable to handle InitListExpr");
352     // Get rid of control reaches end of void function warning.
353     // Not reached.
354     return 0;
355   }
356 
357   llvm::Constant *VisitStringLiteral(StringLiteral *E) {
358     assert(!E->getType()->isPointerType() && "Strings are always arrays");
359 
360     // This must be a string initializing an array in a static initializer.
361     // Don't emit it as the address of the string, emit the string data itself
362     // as an inline array.
363     return VMContext.getConstantArray(CGM.GetStringForStringLiteral(E), false);
364   }
365 
366   llvm::Constant *VisitObjCEncodeExpr(ObjCEncodeExpr *E) {
367     // This must be an @encode initializing an array in a static initializer.
368     // Don't emit it as the address of the string, emit the string data itself
369     // as an inline array.
370     std::string Str;
371     CGM.getContext().getObjCEncodingForType(E->getEncodedType(), Str);
372     const ConstantArrayType *CAT = cast<ConstantArrayType>(E->getType());
373 
374     // Resize the string to the right size, adding zeros at the end, or
375     // truncating as needed.
376     Str.resize(CAT->getSize().getZExtValue(), '\0');
377     return VMContext.getConstantArray(Str, false);
378   }
379 
380   llvm::Constant *VisitUnaryExtension(const UnaryOperator *E) {
381     return Visit(E->getSubExpr());
382   }
383 
384   // Utility methods
385   const llvm::Type *ConvertType(QualType T) {
386     return CGM.getTypes().ConvertType(T);
387   }
388 
389 public:
390   llvm::Constant *EmitLValue(Expr *E) {
391     switch (E->getStmtClass()) {
392     default: break;
393     case Expr::CompoundLiteralExprClass: {
394       // Note that due to the nature of compound literals, this is guaranteed
395       // to be the only use of the variable, so we just generate it here.
396       CompoundLiteralExpr *CLE = cast<CompoundLiteralExpr>(E);
397       llvm::Constant* C = Visit(CLE->getInitializer());
398       // FIXME: "Leaked" on failure.
399       if (C)
400         C = new llvm::GlobalVariable(CGM.getModule(), C->getType(),
401                                      E->getType().isConstQualified(),
402                                      llvm::GlobalValue::InternalLinkage,
403                                      C, ".compoundliteral");
404       return C;
405     }
406     case Expr::DeclRefExprClass:
407     case Expr::QualifiedDeclRefExprClass: {
408       NamedDecl *Decl = cast<DeclRefExpr>(E)->getDecl();
409       if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(Decl))
410         return CGM.GetAddrOfFunction(GlobalDecl(FD));
411       if (const VarDecl* VD = dyn_cast<VarDecl>(Decl)) {
412         // We can never refer to a variable with local storage.
413         if (!VD->hasLocalStorage()) {
414           if (VD->isFileVarDecl() || VD->hasExternalStorage())
415             return CGM.GetAddrOfGlobalVar(VD);
416           else if (VD->isBlockVarDecl()) {
417             assert(CGF && "Can't access static local vars without CGF");
418             return CGF->GetAddrOfStaticLocalVar(VD);
419           }
420         }
421       }
422       break;
423     }
424     case Expr::StringLiteralClass:
425       return CGM.GetAddrOfConstantStringFromLiteral(cast<StringLiteral>(E));
426     case Expr::ObjCEncodeExprClass:
427       return CGM.GetAddrOfConstantStringFromObjCEncode(cast<ObjCEncodeExpr>(E));
428     case Expr::ObjCStringLiteralClass: {
429       ObjCStringLiteral* SL = cast<ObjCStringLiteral>(E);
430       llvm::Constant *C = CGM.getObjCRuntime().GenerateConstantString(SL);
431       return VMContext.getConstantExprBitCast(C, ConvertType(E->getType()));
432     }
433     case Expr::PredefinedExprClass: {
434       // __func__/__FUNCTION__ -> "".  __PRETTY_FUNCTION__ -> "top level".
435       std::string Str;
436       if (cast<PredefinedExpr>(E)->getIdentType() ==
437           PredefinedExpr::PrettyFunction)
438         Str = "top level";
439 
440       return CGM.GetAddrOfConstantCString(Str, ".tmp");
441     }
442     case Expr::AddrLabelExprClass: {
443       assert(CGF && "Invalid address of label expression outside function.");
444       unsigned id = CGF->GetIDForAddrOfLabel(cast<AddrLabelExpr>(E)->getLabel());
445       llvm::Constant *C = VMContext.getConstantInt(llvm::Type::Int32Ty, id);
446       return VMContext.getConstantExprIntToPtr(C, ConvertType(E->getType()));
447     }
448     case Expr::CallExprClass: {
449       CallExpr* CE = cast<CallExpr>(E);
450       if (CE->isBuiltinCall(CGM.getContext()) !=
451             Builtin::BI__builtin___CFStringMakeConstantString)
452         break;
453       const Expr *Arg = CE->getArg(0)->IgnoreParenCasts();
454       const StringLiteral *Literal = cast<StringLiteral>(Arg);
455       // FIXME: need to deal with UCN conversion issues.
456       return CGM.GetAddrOfConstantCFString(Literal);
457     }
458     case Expr::BlockExprClass: {
459       std::string FunctionName;
460       if (CGF)
461         FunctionName = CGF->CurFn->getName();
462       else
463         FunctionName = "global";
464 
465       return CGM.GetAddrOfGlobalBlock(cast<BlockExpr>(E), FunctionName.c_str());
466     }
467     }
468 
469     return 0;
470   }
471 };
472 
473 }  // end anonymous namespace.
474 
475 llvm::Constant *CodeGenModule::EmitConstantExpr(const Expr *E,
476                                                 QualType DestType,
477                                                 CodeGenFunction *CGF) {
478   Expr::EvalResult Result;
479 
480   bool Success = false;
481 
482   if (DestType->isReferenceType())
483     Success = E->EvaluateAsLValue(Result, Context);
484   else
485     Success = E->Evaluate(Result, Context);
486 
487   if (Success) {
488     assert(!Result.HasSideEffects &&
489            "Constant expr should not have any side effects!");
490     switch (Result.Val.getKind()) {
491     case APValue::Uninitialized:
492       assert(0 && "Constant expressions should be initialized.");
493       return 0;
494     case APValue::LValue: {
495       const llvm::Type *DestTy = getTypes().ConvertTypeForMem(DestType);
496       llvm::Constant *Offset =
497         VMContext.getConstantInt(llvm::Type::Int64Ty,
498                                Result.Val.getLValueOffset());
499 
500       llvm::Constant *C;
501       if (const Expr *LVBase = Result.Val.getLValueBase()) {
502         C = ConstExprEmitter(*this, CGF).EmitLValue(const_cast<Expr*>(LVBase));
503 
504         // Apply offset if necessary.
505         if (!Offset->isNullValue()) {
506           const llvm::Type *Type =
507             VMContext.getPointerTypeUnqual(llvm::Type::Int8Ty);
508           llvm::Constant *Casted = VMContext.getConstantExprBitCast(C, Type);
509           Casted = VMContext.getConstantExprGetElementPtr(Casted, &Offset, 1);
510           C = VMContext.getConstantExprBitCast(Casted, C->getType());
511         }
512 
513         // Convert to the appropriate type; this could be an lvalue for
514         // an integer.
515         if (isa<llvm::PointerType>(DestTy))
516           return VMContext.getConstantExprBitCast(C, DestTy);
517 
518         return VMContext.getConstantExprPtrToInt(C, DestTy);
519       } else {
520         C = Offset;
521 
522         // Convert to the appropriate type; this could be an lvalue for
523         // an integer.
524         if (isa<llvm::PointerType>(DestTy))
525           return VMContext.getConstantExprIntToPtr(C, DestTy);
526 
527         // If the types don't match this should only be a truncate.
528         if (C->getType() != DestTy)
529           return VMContext.getConstantExprTrunc(C, DestTy);
530 
531         return C;
532       }
533     }
534     case APValue::Int: {
535       llvm::Constant *C = VMContext.getConstantInt(Result.Val.getInt());
536 
537       if (C->getType() == llvm::Type::Int1Ty) {
538         const llvm::Type *BoolTy = getTypes().ConvertTypeForMem(E->getType());
539         C = VMContext.getConstantExprZExt(C, BoolTy);
540       }
541       return C;
542     }
543     case APValue::ComplexInt: {
544       llvm::Constant *Complex[2];
545 
546       Complex[0] = VMContext.getConstantInt(Result.Val.getComplexIntReal());
547       Complex[1] = VMContext.getConstantInt(Result.Val.getComplexIntImag());
548 
549       return VMContext.getConstantStruct(Complex, 2);
550     }
551     case APValue::Float:
552       return VMContext.getConstantFP(Result.Val.getFloat());
553     case APValue::ComplexFloat: {
554       llvm::Constant *Complex[2];
555 
556       Complex[0] = VMContext.getConstantFP(Result.Val.getComplexFloatReal());
557       Complex[1] = VMContext.getConstantFP(Result.Val.getComplexFloatImag());
558 
559       return VMContext.getConstantStruct(Complex, 2);
560     }
561     case APValue::Vector: {
562       llvm::SmallVector<llvm::Constant *, 4> Inits;
563       unsigned NumElts = Result.Val.getVectorLength();
564 
565       for (unsigned i = 0; i != NumElts; ++i) {
566         APValue &Elt = Result.Val.getVectorElt(i);
567         if (Elt.isInt())
568           Inits.push_back(VMContext.getConstantInt(Elt.getInt()));
569         else
570           Inits.push_back(VMContext.getConstantFP(Elt.getFloat()));
571       }
572       return VMContext.getConstantVector(&Inits[0], Inits.size());
573     }
574     }
575   }
576 
577   llvm::Constant* C = ConstExprEmitter(*this, CGF).Visit(const_cast<Expr*>(E));
578   if (C && C->getType() == llvm::Type::Int1Ty) {
579     const llvm::Type *BoolTy = getTypes().ConvertTypeForMem(E->getType());
580     C = VMContext.getConstantExprZExt(C, BoolTy);
581   }
582   return C;
583 }
584 
585 llvm::Constant *CodeGenModule::EmitNullConstant(QualType T) {
586   // Always return an LLVM null constant for now; this will change when we
587   // get support for IRGen of member pointers.
588   return getLLVMContext().getNullValue(getTypes().ConvertType(T));
589 }
590