diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2017-05-22 19:43:45 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2017-05-22 19:43:45 +0000 |
commit | aa803409c3bd3930126db630c29f63d42f255153 (patch) | |
tree | 042106605c08352895ba4383ef97eae88b6b31aa /lib/CodeGen/CGDecl.cpp | |
parent | 1ce08792766261dcaa25d8215f9d1c2f70d7b7e9 (diff) |
Notes
Diffstat (limited to 'lib/CodeGen/CGDecl.cpp')
-rw-r--r-- | lib/CodeGen/CGDecl.cpp | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/lib/CodeGen/CGDecl.cpp b/lib/CodeGen/CGDecl.cpp index 0fa8eeb1c3e13..d6abfa15e541a 100644 --- a/lib/CodeGen/CGDecl.cpp +++ b/lib/CodeGen/CGDecl.cpp @@ -11,14 +11,15 @@ // //===----------------------------------------------------------------------===// -#include "CodeGenFunction.h" #include "CGBlocks.h" #include "CGCXXABI.h" #include "CGCleanup.h" #include "CGDebugInfo.h" #include "CGOpenCLRuntime.h" #include "CGOpenMPRuntime.h" +#include "CodeGenFunction.h" #include "CodeGenModule.h" +#include "TargetInfo.h" #include "clang/AST/ASTContext.h" #include "clang/AST/CharUnits.h" #include "clang/AST/Decl.h" @@ -1105,6 +1106,21 @@ CodeGenFunction::EmitAutoVarAlloca(const VarDecl &D) { address = Address(vla, alignment); } + // Alloca always returns a pointer in alloca address space, which may + // be different from the type defined by the language. For example, + // in C++ the auto variables are in the default address space. Therefore + // cast alloca to the expected address space when necessary. + auto T = D.getType(); + assert(T.getAddressSpace() == LangAS::Default); + if (getASTAllocaAddressSpace() != LangAS::Default) { + auto *Addr = getTargetHooks().performAddrSpaceCast( + *this, address.getPointer(), getASTAllocaAddressSpace(), + T.getAddressSpace(), + address.getElementType()->getPointerTo( + getContext().getTargetAddressSpace(T.getAddressSpace())), + /*non-null*/ true); + address = Address(Addr, address.getAlignment()); + } setAddrOfLocalVar(&D, address); emission.Addr = address; |