[PATCH] D124736: [CodeGen] Use ABI alignment for placement new
Daniel Bertalan via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sun May 1 11:27:40 PDT 2022
BertalanD updated this revision to Diff 426301.
BertalanD added a comment.
Added a test case.
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;
// Emit the allocation call. If the allocator is a global placement
// operator, just "inline" it directly.
@@ -1583,6 +1583,8 @@
assert(E->getNumPlacementArgs() == 1);
const Expr *arg = *E->placement_arguments().begin();
+ allocAlign = getContext().getTypeAlignInChars(allocType);
+
LValueBaseInfo BaseInfo;
allocation = EmitPointerWithAlignment(arg, &BaseInfo);
@@ -1605,6 +1607,8 @@
allocator->getType()->castAs<FunctionProtoType>();
unsigned ParamsToSkip = 0;
+ allocAlign = getContext().getPreferredTypeAlignInChars(allocType);
+
// The allocation size is the first argument.
QualType sizeType = getContext().getSizeType();
allocatorArgs.add(RValue::get(allocSize), sizeType);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D124736.426301.patch
Type: text/x-patch
Size: 1799 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220501/66ea5ebe/attachment.bin>
More information about the cfe-commits
mailing list