[PATCH] D124736: [CodeGen] Use ABI alignment for C++ new expressions

Nico Weber via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue May 10 08:02:46 PDT 2022


This revision was automatically updated to reflect the committed changes.
Closed by commit rG93a8225da1f9: [CodeGen] Use ABI alignment for C++ new expressions (authored by BertalanD, committed by thakis).

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.428383.patch
Type: text/x-patch
Size: 1212 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220510/aef95edb/attachment-0001.bin>


More information about the cfe-commits mailing list