[PATCH] D115888: [Attributor][Fix] Add default alignment to HeapToStack

Joseph Huber via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 16 10:02:43 PST 2021


jhuber6 created this revision.
jhuber6 added reviewers: jdoerfert, tianshilei1992.
Herald added subscribers: ormris, okura, kuter, uenoku, hiraditya.
Herald added a reviewer: uenoku.
Herald added a reviewer: homerdin.
jhuber6 requested review of this revision.
Herald added a reviewer: sstefan1.
Herald added a reviewer: baziotis.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

This patch adds the default alignment of `16` to the alloca instruction
replacing a dynamic memory allocation. Clang typically assumed `malloc`
will return an address aligned to a 16 byte boundary, so we copy that
assumption here when we replace a memory allocation instruction. This
previously caused errors in cases where the replaced alloca had a
smaller alignment than would have been provided by the malloc call.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D115888

Files:
  llvm/lib/Transforms/IPO/AttributorAttributes.cpp


Index: llvm/lib/Transforms/IPO/AttributorAttributes.cpp
===================================================================
--- llvm/lib/Transforms/IPO/AttributorAttributes.cpp
+++ llvm/lib/Transforms/IPO/AttributorAttributes.cpp
@@ -5928,7 +5928,7 @@
         Size = AI.CB->getOperand(0);
       }
 
-      Align Alignment(1);
+      Align Alignment(16);
       if (AI.Kind == AllocationInfo::AllocationKind::ALIGNED_ALLOC) {
         Optional<APInt> AlignmentAPI =
             getAPInt(A, *this, *AI.CB->getArgOperand(0));


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D115888.394915.patch
Type: text/x-patch
Size: 526 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211216/db079a9a/attachment.bin>


More information about the llvm-commits mailing list