diff options
Diffstat (limited to 'llvm/lib/IR/Value.cpp')
-rw-r--r-- | llvm/lib/IR/Value.cpp | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/llvm/lib/IR/Value.cpp b/llvm/lib/IR/Value.cpp index cc20c48..08b4936 100644 --- a/llvm/lib/IR/Value.cpp +++ b/llvm/lib/IR/Value.cpp @@ -554,9 +554,14 @@ unsigned Value::getPointerAlignment(const DataLayout &DL) const { if (EltTy->isSized()) Align = DL.getABITypeAlignment(EltTy); } - } else if (const AllocaInst *AI = dyn_cast<AllocaInst>(this)) + } else if (const AllocaInst *AI = dyn_cast<AllocaInst>(this)) { Align = AI->getAlignment(); - else if (auto CS = ImmutableCallSite(this)) + if (Align == 0) { + Type *AllocatedType = AI->getAllocatedType(); + if (AllocatedType->isSized()) + Align = DL.getPrefTypeAlignment(AllocatedType); + } + } else if (auto CS = ImmutableCallSite(this)) Align = CS.getAttributes().getParamAlignment(AttributeSet::ReturnIndex); else if (const LoadInst *LI = dyn_cast<LoadInst>(this)) if (MDNode *MD = LI->getMetadata(LLVMContext::MD_align)) { |