[PATCH] D124736: [CodeGen] Use ABI alignment for placement new

Daniel Bertalan via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon May 9 15:52:42 PDT 2022


BertalanD updated this revision to Diff 428225.
BertalanD added a comment.

Use ABI alignment for allocating operator new as well.

Sorry for the delay.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D124736/new/

https://reviews.llvm.org/D124736

Files:
  clang/lib/CodeGen/CGExprCXX.cpp
  clang/test/CodeGenCXX/pr54845.cpp


Index: clang/test/CodeGenCXX/pr54845.cpp
===================================================================
--- /dev/null
+++ clang/test/CodeGenCXX/pr54845.cpp
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -triple i686-linux-gnu -emit-llvm %s -o - | FileCheck %s
+// https://github.com/llvm/llvm-project/issues/54845
+
+void *operator new(unsigned int, void *);
+
+void test(double *d) {
+  // This store used to have an alignment of 8, which was incorrect as
+  // the i386 psABI only guarantees a 4-byte alignment for doubles.
+
+  // CHECK: store double 0.000000e+00, {{.*}}, align 4
+  new (d) double(0);
+}
Index: clang/lib/CodeGen/CGExprCXX.cpp
===================================================================
--- clang/lib/CodeGen/CGExprCXX.cpp
+++ clang/lib/CodeGen/CGExprCXX.cpp
@@ -1573,7 +1573,7 @@
   llvm::Value *allocSize =
     EmitCXXNewAllocSize(*this, E, minElements, numElements,
                         allocSizeWithoutCookie);
-  CharUnits allocAlign = getContext().getPreferredTypeAlignInChars(allocType);
+  CharUnits allocAlign = getContext().getTypeAlignInChars(allocType);
 
   // Emit the allocation call.  If the allocator is a global placement
   // operator, just "inline" it directly.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D124736.428225.patch
Type: text/x-patch
Size: 1212 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220509/f9772899/attachment.bin>


More information about the cfe-commits mailing list