summaryrefslogtreecommitdiffstats
path: root/clang/lib
diff options
context:
space:
mode:
authorYaxun Liu <Yaxun.Liu@amd.com>2017-10-30 14:38:30 +0000
committerYaxun Liu <Yaxun.Liu@amd.com>2017-10-30 14:38:30 +0000
commit561ac06ff29f5890939394084c9b079d0d4d89ac (patch)
treeadc66e88694a13185c56fc725b52c2a462862899 /clang/lib
parent85b60ff68c4951c728fc0c2c266618ab9ec4cd24 (diff)
downloadbcm5719-llvm-561ac06ff29f5890939394084c9b079d0d4d89ac.tar.gz
bcm5719-llvm-561ac06ff29f5890939394084c9b079d0d4d89ac.zip
CodeGen: Fix insertion position of addrspace cast for alloca
For non-zero alloca addr space, alloca is usually casted to default addr space immediately. For non-vla, alloca is inserted at AllocaInsertPt, therefore the addr space cast should also be insterted at AllocaInsertPt. However, for vla, alloca is inserted at the current insertion point of IRBuilder, therefore the addr space cast should also inserted at the current insertion point of IRBuilder. Currently clang always insert addr space cast at AllocaInsertPt, which causes invalid IR. This patch fixes that. Differential Revision: https://reviews.llvm.org/D39374 llvm-svn: 316909
Diffstat (limited to 'clang/lib')
-rw-r--r--clang/lib/CodeGen/CGExpr.cpp6
1 files changed, 5 insertions, 1 deletions
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index 431ffa55d13..d3c2f47093c 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -75,7 +75,11 @@ Address CodeGenFunction::CreateTempAlloca(llvm::Type *Ty, CharUnits Align,
if (CastToDefaultAddrSpace && getASTAllocaAddressSpace() != LangAS::Default) {
auto DestAddrSpace = getContext().getTargetAddressSpace(LangAS::Default);
llvm::IRBuilderBase::InsertPointGuard IPG(Builder);
- Builder.SetInsertPoint(AllocaInsertPt);
+ // When ArraySize is nullptr, alloca is inserted at AllocaInsertPt,
+ // otherwise alloca is inserted at the current insertion point of the
+ // builder.
+ if (!ArraySize)
+ Builder.SetInsertPoint(AllocaInsertPt);
V = getTargetHooks().performAddrSpaceCast(
*this, V, getASTAllocaAddressSpace(), LangAS::Default,
Ty->getPointerTo(DestAddrSpace), /*non-null*/ true);
OpenPOWER on IntegriCloud