diff options
author | James Y Knight <jyknight@google.com> | 2022-02-07 11:31:22 -0500 |
---|---|---|
committer | Tom Stellard <tstellar@redhat.com> | 2022-02-08 23:15:52 -0800 |
commit | f5f0bd8e3d972d040827c88adf1a9880ebcb821e (patch) | |
tree | 6d9ee6c9c7c284721a9e25c1399ffd334d778a4f | |
parent | 7246d583d6017dbea8baa453e78f26e145448d6e (diff) |
Revert "[Clang] Propagate guaranteed alignment for malloc and others"llvmorg-14.0.0-rc1
The above change assumed that malloc (and friends) would always
allocate memory to getNewAlign(), even for allocations which have a
smaller size. This is not actually required by spec (a 1-byte
allocation may validly have 1-byte alignment).
Some real-world malloc implementations do not provide this guarantee,
and thus this optimization is breaking programs.
Fixes #53540
This reverts commit c2297544c04764237cedc523083c7be2fb3833d4.
Differential Revision: https://reviews.llvm.org/D118804
(cherry picked from commit 9545976ff160e19805a84a06a7e59d446f9994d9)
-rw-r--r-- | clang/include/clang/Basic/TargetInfo.h | 4 | ||||
-rw-r--r-- | clang/lib/Sema/SemaDecl.cpp | 17 | ||||
-rw-r--r-- | clang/test/CodeGen/alloc-fns-alignment.c | 56 |
3 files changed, 22 insertions, 55 deletions
diff --git a/clang/include/clang/Basic/TargetInfo.h b/clang/include/clang/Basic/TargetInfo.h index a49342a34f3e..e7db877f4e2b 100644 --- a/clang/include/clang/Basic/TargetInfo.h +++ b/clang/include/clang/Basic/TargetInfo.h @@ -644,8 +644,8 @@ public: } /// Return the largest alignment for which a suitably-sized allocation with - /// '::operator new(size_t)' or 'malloc' is guaranteed to produce a - /// correctly-aligned pointer. + /// '::operator new(size_t)' is guaranteed to produce a correctly-aligned + /// pointer. unsigned getNewAlign() const { return NewAlign ? NewAlign : std::max(LongDoubleAlign, LongLongAlign); } diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index cbd9df4d6a7b..bcadf4139046 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp |