[PATCH] D24378: [CodeGen] Provide an appropriate alignment for dynamic allocas

David Majnemer via cfe-commits cfe-commits at lists.llvm.org
Thu Oct 27 10:27:59 PDT 2016


This revision was automatically updated to reflect the committed changes.
Closed by commit rL285316: [CodeGen] Provide an appropriate alignment for dynamic allocas (authored by majnemer).

Changed prior to commit:
  https://reviews.llvm.org/D24378?vs=70789&id=76060#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D24378

Files:
  cfe/trunk/lib/CodeGen/CGBuiltin.cpp
  cfe/trunk/test/CodeGen/builtins-ms.c


Index: cfe/trunk/test/CodeGen/builtins-ms.c
===================================================================
--- cfe/trunk/test/CodeGen/builtins-ms.c
+++ cfe/trunk/test/CodeGen/builtins-ms.c
@@ -4,6 +4,6 @@
 void capture(void *);
 void test_alloca(int n) {
   capture(_alloca(n));
-  // CHECK: %[[arg:.*]] = alloca i8, i32 %
+  // CHECK: %[[arg:.*]] = alloca i8, i32 %{{.*}}, align 16
   // CHECK: call void @capture(i8* %[[arg]])
 }
Index: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
===================================================================
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp
@@ -1139,7 +1139,13 @@
   case Builtin::BI_alloca:
   case Builtin::BI__builtin_alloca: {
     Value *Size = EmitScalarExpr(E->getArg(0));
-    return RValue::get(Builder.CreateAlloca(Builder.getInt8Ty(), Size));
+    const TargetInfo &TI = getContext().getTargetInfo();
+    // The alignment of the alloca should correspond to __BIGGEST_ALIGNMENT__.
+    unsigned SuitableAlignmentInBytes =
+        TI.getSuitableAlign() / TI.getCharWidth();
+    AllocaInst *AI = Builder.CreateAlloca(Builder.getInt8Ty(), Size);
+    AI->setAlignment(SuitableAlignmentInBytes);
+    return RValue::get(AI);
   }
   case Builtin::BIbzero:
   case Builtin::BI__builtin_bzero: {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D24378.76060.patch
Type: text/x-patch
Size: 1290 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20161027/29d5140b/attachment.bin>


More information about the cfe-commits mailing list