diff --git a/clang/lib/CodeGen/CGExprCXX.cpp b/clang/lib/CodeGen/CGExprCXX.cpp index 54c87a7361b1c4..3cc1443615420b 100644 --- a/clang/lib/CodeGen/CGExprCXX.cpp +++ b/clang/lib/CodeGen/CGExprCXX.cpp @@ -1573,7 +1573,7 @@ llvm::Value *CodeGenFunction::EmitCXXNewExpr(const CXXNewExpr *E) { 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. diff --git a/clang/test/CodeGenCXX/pr54845.cpp b/clang/test/CodeGenCXX/pr54845.cpp new file mode 100644 index 00000000000000..acf2c3121900b3 --- /dev/null +++ b/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); +}