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