CGDecl.cpp revision 730203088e9909e304c4868cbca72ee2652335bf
1//===--- CGDecl.cpp - Emit LLVM Code for declarations ---------------------===//
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 Decl nodes as LLVM code.
11//
12//===----------------------------------------------------------------------===//
13
14#include "CGDebugInfo.h"
15#include "CodeGenFunction.h"
16#include "CodeGenModule.h"
17#include "clang/AST/ASTContext.h"
18#include "clang/AST/Decl.h"
19#include "clang/AST/DeclObjC.h"
20#include "clang/Basic/SourceManager.h"
21#include "clang/Basic/TargetInfo.h"
22#include "clang/CodeGen/CodeGenOptions.h"
23#include "llvm/GlobalVariable.h"
24#include "llvm/Intrinsics.h"
25#include "llvm/Target/TargetData.h"
26#include "llvm/Type.h"
27using namespace clang;
28using namespace CodeGen;
29
30
31void CodeGenFunction::EmitDecl(const Decl &D) {
32  switch (D.getKind()) {
33  default:
34    CGM.ErrorUnsupported(&D, "decl");
35    return;
36  case Decl::ParmVar:
37    assert(0 && "Parmdecls should not be in declstmts!");
38  case Decl::Function:  // void X();
39  case Decl::Record:    // struct/union/class X;
40  case Decl::Enum:      // enum X;
41  case Decl::EnumConstant: // enum ? { X = ? }
42  case Decl::CXXRecord: // struct/union/class X; [C++]
43  case Decl::Using:          // using X; [C++]
44  case Decl::UsingShadow:
45  case Decl::UsingDirective: // using namespace X; [C++]
46    // None of these decls require codegen support.
47    return;
48
49  case Decl::Var: {
50    const VarDecl &VD = cast<VarDecl>(D);
51    assert(VD.isBlockVarDecl() &&
52           "Should not see file-scope variables inside a function!");
53    return EmitBlockVarDecl(VD);
54  }
55
56  case Decl::Typedef: {   // typedef int X;
57    const TypedefDecl &TD = cast<TypedefDecl>(D);
58    QualType Ty = TD.getUnderlyingType();
59
60    if (Ty->isVariablyModifiedType())
61      EmitVLASize(Ty);
62  }
63  }
64}
65
66/// EmitBlockVarDecl - This method handles emission of any variable declaration
67/// inside a function, including static vars etc.
68void CodeGenFunction::EmitBlockVarDecl(const VarDecl &D) {
69  if (D.hasAttr<AsmLabelAttr>())
70    CGM.ErrorUnsupported(&D, "__asm__");
71
72  switch (D.getStorageClass()) {
73  case VarDecl::None:
74  case VarDecl::Auto:
75  case VarDecl::Register:
76    return EmitLocalBlockVarDecl(D);
77  case VarDecl::Static:
78    return EmitStaticBlockVarDecl(D);
79  case VarDecl::Extern:
80  case VarDecl::PrivateExtern:
81    // Don't emit it now, allow it to be emitted lazily on its first use.
82    return;
83  }
84
85  assert(0 && "Unknown storage class");
86}
87
88llvm::GlobalVariable *
89CodeGenFunction::CreateStaticBlockVarDecl(const VarDecl &D,
90                                          const char *Separator,
91                                          llvm::GlobalValue::LinkageTypes
92                                          Linkage) {
93  QualType Ty = D.getType();
94  assert(Ty->isConstantSizeType() && "VLAs can't be static");
95
96  std::string Name;
97  if (getContext().getLangOptions().CPlusPlus) {
98    Name = CGM.getMangledName(&D);
99  } else {
100    std::string ContextName;
101    if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(CurFuncDecl))
102      ContextName = CGM.getMangledName(FD);
103    else if (isa<ObjCMethodDecl>(CurFuncDecl))
104      ContextName = CurFn->getName();
105    else
106      assert(0 && "Unknown context for block var decl");
107
108    Name = ContextName + Separator + D.getNameAsString();
109  }
110
111  const llvm::Type *LTy = CGM.getTypes().ConvertTypeForMem(Ty);
112  llvm::GlobalVariable *GV =
113    new llvm::GlobalVariable(CGM.getModule(), LTy,
114                             Ty.isConstant(getContext()), Linkage,
115                             CGM.EmitNullConstant(D.getType()), Name, 0,
116                             D.isThreadSpecified(), Ty.getAddressSpace());
117  GV->setAlignment(getContext().getDeclAlignInBytes(&D));
118  return GV;
119}
120
121void CodeGenFunction::EmitStaticBlockVarDecl(const VarDecl &D) {
122  llvm::Value *&DMEntry = LocalDeclMap[&D];
123  assert(DMEntry == 0 && "Decl already exists in localdeclmap!");
124
125  llvm::GlobalVariable *GV =
126    CreateStaticBlockVarDecl(D, ".", llvm::GlobalValue::InternalLinkage);
127
128  // Store into LocalDeclMap before generating initializer to handle
129  // circular references.
130  DMEntry = GV;
131
132  // Make sure to evaluate VLA bounds now so that we have them for later.
133  //
134  // FIXME: Can this happen?
135  if (D.getType()->isVariablyModifiedType())
136    EmitVLASize(D.getType());
137
138  if (D.getInit()) {
139    llvm::Constant *Init = CGM.EmitConstantExpr(D.getInit(), D.getType(), this);
140
141    // If constant emission failed, then this should be a C++ static
142    // initializer.
143    if (!Init) {
144      if (!getContext().getLangOptions().CPlusPlus)
145        CGM.ErrorUnsupported(D.getInit(), "constant l-value expression");
146      else
147        EmitStaticCXXBlockVarDeclInit(D, GV);
148    } else {
149      // The initializer may differ in type from the global. Rewrite
150      // the global to match the initializer.  (We have to do this
151      // because some types, like unions, can't be completely represented
152      // in the LLVM type system.)
153      if (GV->getType() != Init->getType()) {
154        llvm::GlobalVariable *OldGV = GV;
155
156        GV = new llvm::GlobalVariable(CGM.getModule(), Init->getType(),
157                                      OldGV->isConstant(),
158                                      OldGV->getLinkage(), Init, "",
159                                      0, D.isThreadSpecified(),
160                                      D.getType().getAddressSpace());
161
162        // Steal the name of the old global
163        GV->takeName(OldGV);
164
165        // Replace all uses of the old global with the new global
166        llvm::Constant *NewPtrForOldDecl =
167          llvm::ConstantExpr::getBitCast(GV, OldGV->getType());
168        OldGV->replaceAllUsesWith(NewPtrForOldDecl);
169
170        // Erase the old global, since it is no longer used.
171        OldGV->eraseFromParent();
172      }
173
174      GV->setInitializer(Init);
175    }
176  }
177
178  // FIXME: Merge attribute handling.
179  if (const AnnotateAttr *AA = D.getAttr<AnnotateAttr>()) {
180    SourceManager &SM = CGM.getContext().getSourceManager();
181    llvm::Constant *Ann =
182      CGM.EmitAnnotateAttr(GV, AA,
183                           SM.getInstantiationLineNumber(D.getLocation()));
184    CGM.AddAnnotation(Ann);
185  }
186
187  if (const SectionAttr *SA = D.getAttr<SectionAttr>())
188    GV->setSection(SA->getName());
189
190  if (D.hasAttr<UsedAttr>())
191    CGM.AddUsedGlobal(GV);
192
193  // We may have to cast the constant because of the initializer
194  // mismatch above.
195  //
196  // FIXME: It is really dangerous to store this in the map; if anyone
197  // RAUW's the GV uses of this constant will be invalid.
198  const llvm::Type *LTy = CGM.getTypes().ConvertTypeForMem(D.getType());
199  const llvm::Type *LPtrTy =
200    llvm::PointerType::get(LTy, D.getType().getAddressSpace());
201  DMEntry = llvm::ConstantExpr::getBitCast(GV, LPtrTy);
202
203  // Emit global variable debug descriptor for static vars.
204  CGDebugInfo *DI = getDebugInfo();
205  if (DI) {
206    DI->setLocation(D.getLocation());
207    DI->EmitGlobalVariable(static_cast<llvm::GlobalVariable *>(GV), &D);
208  }
209}
210
211unsigned CodeGenFunction::getByRefValueLLVMField(const ValueDecl *VD) const {
212  assert(ByRefValueInfo.count(VD) && "Did not find value!");
213
214  return ByRefValueInfo.find(VD)->second.second;
215}
216
217/// BuildByRefType - This routine changes a __block variable declared as T x
218///   into:
219///
220///      struct {
221///        void *__isa;
222///        void *__forwarding;
223///        int32_t __flags;
224///        int32_t __size;
225///        void *__copy_helper;       // only if needed
226///        void *__destroy_helper;    // only if needed
227///        char padding[X];           // only if needed
228///        T x;
229///      } x
230///
231const llvm::Type *CodeGenFunction::BuildByRefType(const ValueDecl *D) {
232  std::pair<const llvm::Type *, unsigned> &Info = ByRefValueInfo[D];
233  if (Info.first)
234    return Info.first;
235
236  QualType Ty = D->getType();
237
238  std::vector<const llvm::Type *> Types;
239
240  const llvm::PointerType *Int8PtrTy = llvm::Type::getInt8PtrTy(VMContext);
241
242  llvm::PATypeHolder ByRefTypeHolder = llvm::OpaqueType::get(VMContext);
243
244  // void *__isa;
245  Types.push_back(Int8PtrTy);
246
247  // void *__forwarding;
248  Types.push_back(llvm::PointerType::getUnqual(ByRefTypeHolder));
249
250  // int32_t __flags;
251  Types.push_back(llvm::Type::getInt32Ty(VMContext));
252
253  // int32_t __size;
254  Types.push_back(llvm::Type::getInt32Ty(VMContext));
255
256  bool HasCopyAndDispose = BlockRequiresCopying(Ty);
257  if (HasCopyAndDispose) {
258    /// void *__copy_helper;
259    Types.push_back(Int8PtrTy);
260
261    /// void *__destroy_helper;
262    Types.push_back(Int8PtrTy);
263  }
264
265  bool Packed = false;
266  unsigned Align = getContext().getDeclAlignInBytes(D);
267  if (Align > Target.getPointerAlign(0) / 8) {
268    // We have to insert padding.
269
270    // The struct above has 2 32-bit integers.
271    unsigned CurrentOffsetInBytes = 4 * 2;
272
273    // And either 2 or 4 pointers.
274    CurrentOffsetInBytes += (HasCopyAndDispose ? 4 : 2) *
275      CGM.getTargetData().getTypeAllocSize(Int8PtrTy);
276
277    // Align the offset.
278    unsigned AlignedOffsetInBytes =
279      llvm::RoundUpToAlignment(CurrentOffsetInBytes, Align);
280
281    unsigned NumPaddingBytes = AlignedOffsetInBytes - CurrentOffsetInBytes;
282    if (NumPaddingBytes > 0) {
283      const llvm::Type *Ty = llvm::Type::getInt8Ty(VMContext);
284      // FIXME: We need a sema error for alignment larger than the minimum of
285      // the maximal stack alignmint and the alignment of malloc on the system.
286      if (NumPaddingBytes > 1)
287        Ty = llvm::ArrayType::get(Ty, NumPaddingBytes);
288
289      Types.push_back(Ty);
290
291      // We want a packed struct.
292      Packed = true;
293    }
294  }
295
296  // T x;
297  Types.push_back(ConvertType(Ty));
298
299  const llvm::Type *T = llvm::StructType::get(VMContext, Types, Packed);
300
301  cast<llvm::OpaqueType>(ByRefTypeHolder.get())->refineAbstractTypeTo(T);
302  CGM.getModule().addTypeName("struct.__block_byref_" + D->getNameAsString(),
303                              ByRefTypeHolder.get());
304
305  Info.first = ByRefTypeHolder.get();
306
307  Info.second = Types.size() - 1;
308
309  return Info.first;
310}
311
312/// EmitLocalBlockVarDecl - Emit code and set up an entry in LocalDeclMap for a
313/// variable declaration with auto, register, or no storage class specifier.
314/// These turn into simple stack objects, or GlobalValues depending on target.
315void CodeGenFunction::EmitLocalBlockVarDecl(const VarDecl &D) {
316  QualType Ty = D.getType();
317  bool isByRef = D.hasAttr<BlocksAttr>();
318  bool needsDispose = false;
319  unsigned Align = 0;
320
321  llvm::Value *DeclPtr;
322  if (Ty->isConstantSizeType()) {
323    if (!Target.useGlobalsForAutomaticVariables()) {
324
325      // All constant structs and arrays should be global if
326      // their initializer is constant and if the element type is POD.
327      if (CGM.getCodeGenOpts().MergeAllConstants) {
328        if (Ty.isConstant(getContext())
329            && (Ty->isArrayType() || Ty->isRecordType())
330            && (D.getInit()
331                && D.getInit()->isConstantInitializer(getContext()))
332            && Ty->isPODType()) {
333          EmitStaticBlockVarDecl(D);
334          return;
335        }
336      }
337
338      // A normal fixed sized variable becomes an alloca in the entry block.
339      const llvm::Type *LTy = ConvertTypeForMem(Ty);
340      Align = getContext().getDeclAlignInBytes(&D);
341      if (isByRef)
342        LTy = BuildByRefType(&D);
343      llvm::AllocaInst *Alloc = CreateTempAlloca(LTy);
344      Alloc->setName(D.getNameAsString().c_str());
345
346      if (isByRef)
347        Align = std::max(Align, unsigned(Target.getPointerAlign(0) / 8));
348      Alloc->setAlignment(Align);
349      DeclPtr = Alloc;
350    } else {
351      // Targets that don't support recursion emit locals as globals.
352      const char *Class =
353        D.getStorageClass() == VarDecl::Register ? ".reg." : ".auto.";
354      DeclPtr = CreateStaticBlockVarDecl(D, Class,
355                                         llvm::GlobalValue
356                                         ::InternalLinkage);
357    }
358
359    // FIXME: Can this happen?
360    if (Ty->isVariablyModifiedType())
361      EmitVLASize(Ty);
362  } else {
363    EnsureInsertPoint();
364
365    if (!DidCallStackSave) {
366      // Save the stack.
367      const llvm::Type *LTy = llvm::Type::getInt8PtrTy(VMContext);
368      llvm::Value *Stack = CreateTempAlloca(LTy, "saved_stack");
369
370      llvm::Value *F = CGM.getIntrinsic(llvm::Intrinsic::stacksave);
371      llvm::Value *V = Builder.CreateCall(F);
372
373      Builder.CreateStore(V, Stack);
374
375      DidCallStackSave = true;
376
377      {
378        // Push a cleanup block and restore the stack there.
379        DelayedCleanupBlock scope(*this);
380
381        V = Builder.CreateLoad(Stack, "tmp");
382        llvm::Value *F = CGM.getIntrinsic(llvm::Intrinsic::stackrestore);
383        Builder.CreateCall(F, V);
384      }
385    }
386
387    // Get the element type.
388    const llvm::Type *LElemTy = ConvertTypeForMem(Ty);
389    const llvm::Type *LElemPtrTy =
390      llvm::PointerType::get(LElemTy, D.getType().getAddressSpace());
391
392    llvm::Value *VLASize = EmitVLASize(Ty);
393
394    // Downcast the VLA size expression
395    VLASize = Builder.CreateIntCast(VLASize, llvm::Type::getInt32Ty(VMContext),
396                                    false, "tmp");
397
398    // Allocate memory for the array.
399    llvm::AllocaInst *VLA =
400      Builder.CreateAlloca(llvm::Type::getInt8Ty(VMContext), VLASize, "vla");
401    VLA->setAlignment(getContext().getDeclAlignInBytes(&D));
402
403    DeclPtr = Builder.CreateBitCast(VLA, LElemPtrTy, "tmp");
404  }
405
406  llvm::Value *&DMEntry = LocalDeclMap[&D];
407  assert(DMEntry == 0 && "Decl already exists in localdeclmap!");
408  DMEntry = DeclPtr;
409
410  // Emit debug info for local var declaration.
411  if (CGDebugInfo *DI = getDebugInfo()) {
412    assert(HaveInsertPoint() && "Unexpected unreachable point!");
413
414    DI->setLocation(D.getLocation());
415    if (Target.useGlobalsForAutomaticVariables()) {
416      DI->EmitGlobalVariable(static_cast<llvm::GlobalVariable *>(DeclPtr), &D);
417    } else
418      DI->EmitDeclareOfAutoVariable(&D, DeclPtr, Builder);
419  }
420
421  // If this local has an initializer, emit it now.
422  const Expr *Init = D.getInit();
423
424  // If we are at an unreachable point, we don't need to emit the initializer
425  // unless it contains a label.
426  if (!HaveInsertPoint()) {
427    if (!ContainsLabel(Init))
428      Init = 0;
429    else
430      EnsureInsertPoint();
431  }
432
433  if (Init) {
434    llvm::Value *Loc = DeclPtr;
435    if (isByRef)
436      Loc = Builder.CreateStructGEP(DeclPtr, getByRefValueLLVMField(&D),
437                                    D.getNameAsString());
438
439    bool isVolatile = (getContext().getCanonicalType(D.getType())
440                       .isVolatileQualified());
441    if (Ty->isReferenceType()) {
442      RValue RV = EmitReferenceBindingToExpr(Init, Ty, /*IsInitializer=*/true);
443      EmitStoreOfScalar(RV.getScalarVal(), Loc, false, Ty);
444    } else if (!hasAggregateLLVMType(Init->getType())) {
445      llvm::Value *V = EmitScalarExpr(Init);
446      EmitStoreOfScalar(V, Loc, isVolatile, D.getType());
447    } else if (Init->getType()->isAnyComplexType()) {
448      EmitComplexExprIntoAddr(Init, Loc, isVolatile);
449    } else {
450      EmitAggExpr(Init, Loc, isVolatile);
451    }
452  }
453
454  if (isByRef) {
455    const llvm::PointerType *PtrToInt8Ty = llvm::Type::getInt8PtrTy(VMContext);
456
457    EnsureInsertPoint();
458    llvm::Value *isa_field = Builder.CreateStructGEP(DeclPtr, 0);
459    llvm::Value *forwarding_field = Builder.CreateStructGEP(DeclPtr, 1);
460    llvm::Value *flags_field = Builder.CreateStructGEP(DeclPtr, 2);
461    llvm::Value *size_field = Builder.CreateStructGEP(DeclPtr, 3);
462    llvm::Value *V;
463    int flag = 0;
464    int flags = 0;
465
466    needsDispose = true;
467
468    if (Ty->isBlockPointerType()) {
469      flag |= BLOCK_FIELD_IS_BLOCK;
470      flags |= BLOCK_HAS_COPY_DISPOSE;
471    } else if (BlockRequiresCopying(Ty)) {
472      flag |= BLOCK_FIELD_IS_OBJECT;
473      flags |= BLOCK_HAS_COPY_DISPOSE;
474    }
475
476    // FIXME: Someone double check this.
477    if (Ty.isObjCGCWeak())
478      flag |= BLOCK_FIELD_IS_WEAK;
479
480    int isa = 0;
481    if (flag&BLOCK_FIELD_IS_WEAK)
482      isa = 1;
483    V = llvm::ConstantInt::get(llvm::Type::getInt32Ty(VMContext), isa);
484    V = Builder.CreateIntToPtr(V, PtrToInt8Ty, "isa");
485    Builder.CreateStore(V, isa_field);
486
487    Builder.CreateStore(DeclPtr, forwarding_field);
488
489    V = llvm::ConstantInt::get(llvm::Type::getInt32Ty(VMContext), flags);
490    Builder.CreateStore(V, flags_field);
491
492    const llvm::Type *V1;
493    V1 = cast<llvm::PointerType>(DeclPtr->getType())->getElementType();
494    V = llvm::ConstantInt::get(llvm::Type::getInt32Ty(VMContext),
495                               (CGM.getTargetData().getTypeStoreSizeInBits(V1)
496                                / 8));
497    Builder.CreateStore(V, size_field);
498
499    if (flags & BLOCK_HAS_COPY_DISPOSE) {
500      BlockHasCopyDispose = true;
501      llvm::Value *copy_helper = Builder.CreateStructGEP(DeclPtr, 4);
502      Builder.CreateStore(BuildbyrefCopyHelper(DeclPtr->getType(), flag, Align),
503                          copy_helper);
504
505      llvm::Value *destroy_helper = Builder.CreateStructGEP(DeclPtr, 5);
506      Builder.CreateStore(BuildbyrefDestroyHelper(DeclPtr->getType(), flag,
507                                                  Align),
508                          destroy_helper);
509    }
510  }
511
512  // Handle CXX destruction of variables.
513  QualType DtorTy(Ty);
514  while (const ArrayType *Array = getContext().getAsArrayType(DtorTy))
515    DtorTy = getContext().getBaseElementType(Array);
516  if (const RecordType *RT = DtorTy->getAs<RecordType>())
517    if (CXXRecordDecl *ClassDecl = dyn_cast<CXXRecordDecl>(RT->getDecl())) {
518      if (!ClassDecl->hasTrivialDestructor()) {
519        const CXXDestructorDecl *D = ClassDecl->getDestructor(getContext());
520        assert(D && "EmitLocalBlockVarDecl - destructor is nul");
521
522        if (const ConstantArrayType *Array =
523              getContext().getAsConstantArrayType(Ty)) {
524          DelayedCleanupBlock Scope(*this);
525          QualType BaseElementTy = getContext().getBaseElementType(Array);
526          const llvm::Type *BasePtr = ConvertType(BaseElementTy);
527          BasePtr = llvm::PointerType::getUnqual(BasePtr);
528          llvm::Value *BaseAddrPtr =
529            Builder.CreateBitCast(DeclPtr, BasePtr);
530          EmitCXXAggrDestructorCall(D, Array, BaseAddrPtr);
531
532          // Make sure to jump to the exit block.
533          EmitBranch(Scope.getCleanupExitBlock());
534        } else {
535          DelayedCleanupBlock Scope(*this);
536          EmitCXXDestructorCall(D, Dtor_Complete, DeclPtr);
537
538          // Make sure to jump to the exit block.
539          EmitBranch(Scope.getCleanupExitBlock());
540        }
541      }
542  }
543
544  // Handle the cleanup attribute
545  if (const CleanupAttr *CA = D.getAttr<CleanupAttr>()) {
546    const FunctionDecl *FD = CA->getFunctionDecl();
547
548    llvm::Constant* F = CGM.GetAddrOfFunction(FD);
549    assert(F && "Could not find function!");
550
551    DelayedCleanupBlock scope(*this);
552
553    const CGFunctionInfo &Info = CGM.getTypes().getFunctionInfo(FD);
554
555    // In some cases, the type of the function argument will be different from
556    // the type of the pointer. An example of this is
557    // void f(void* arg);
558    // __attribute__((cleanup(f))) void *g;
559    //
560    // To fix this we insert a bitcast here.
561    QualType ArgTy = Info.arg_begin()->type;
562    DeclPtr = Builder.CreateBitCast(DeclPtr, ConvertType(ArgTy));
563
564    CallArgList Args;
565    Args.push_back(std::make_pair(RValue::get(DeclPtr),
566                                  getContext().getPointerType(D.getType())));
567
568    EmitCall(Info, F, Args);
569  }
570
571  if (needsDispose && CGM.getLangOptions().getGCMode() != LangOptions::GCOnly) {
572    DelayedCleanupBlock scope(*this);
573    llvm::Value *V = Builder.CreateStructGEP(DeclPtr, 1, "forwarding");
574    V = Builder.CreateLoad(V);
575    BuildBlockRelease(V);
576  }
577}
578
579/// Emit an alloca (or GlobalValue depending on target)
580/// for the specified parameter and set up LocalDeclMap.
581void CodeGenFunction::EmitParmDecl(const VarDecl &D, llvm::Value *Arg) {
582  // FIXME: Why isn't ImplicitParamDecl a ParmVarDecl?
583  assert((isa<ParmVarDecl>(D) || isa<ImplicitParamDecl>(D)) &&
584         "Invalid argument to EmitParmDecl");
585  QualType Ty = D.getType();
586  CanQualType CTy = getContext().getCanonicalType(Ty);
587
588  llvm::Value *DeclPtr;
589  if (!Ty->isConstantSizeType()) {
590    // Variable sized values always are passed by-reference.
591    DeclPtr = Arg;
592  } else {
593    // A fixed sized single-value variable becomes an alloca in the entry block.
594    const llvm::Type *LTy = ConvertTypeForMem(Ty);
595    if (LTy->isSingleValueType()) {
596      // TODO: Alignment
597      std::string Name = D.getNameAsString();
598      Name += ".addr";
599      DeclPtr = CreateTempAlloca(LTy);
600      DeclPtr->setName(Name.c_str());
601
602      // Store the initial value into the alloca.
603      EmitStoreOfScalar(Arg, DeclPtr, CTy.isVolatileQualified(), Ty);
604    } else {
605      // Otherwise, if this is an aggregate, just use the input pointer.
606      DeclPtr = Arg;
607    }
608    Arg->setName(D.getNameAsString());
609  }
610
611  llvm::Value *&DMEntry = LocalDeclMap[&D];
612  assert(DMEntry == 0 && "Decl already exists in localdeclmap!");
613  DMEntry = DeclPtr;
614
615  // Emit debug info for param declaration.
616  if (CGDebugInfo *DI = getDebugInfo()) {
617    DI->setLocation(D.getLocation());
618    DI->EmitDeclareOfArgVariable(&D, DeclPtr, Builder);
619  }
620}
621