Skip to content

[flang] Fix excess allocation #96663

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions flang/runtime/pointer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ void RTDEF(PointerAssociateRemapping)(Descriptor &pointer,
RT_API_ATTRS void *AllocateValidatedPointerPayload(std::size_t byteSize) {
// Add space for a footer to validate during deallocation.
constexpr std::size_t align{sizeof(std::uintptr_t)};
byteSize = ((byteSize / align) + 1) * align;
byteSize = ((byteSize + align - 1) / align) * align;
std::size_t total{byteSize + sizeof(std::uintptr_t)};
void *p{std::malloc(total)};
if (p) {
Expand Down Expand Up @@ -197,7 +197,7 @@ static RT_API_ATTRS std::size_t GetByteSize(
bool RT_API_ATTRS ValidatePointerPayload(const ISO::CFI_cdesc_t &desc) {
std::size_t byteSize{GetByteSize(desc)};
constexpr std::size_t align{sizeof(std::uintptr_t)};
byteSize = ((byteSize / align) + 1) * align;
byteSize = ((byteSize + align - 1) / align) * align;
const void *p{desc.base_addr};
const std::uintptr_t *footer{reinterpret_cast<const std::uintptr_t *>(
static_cast<const char *>(p) + byteSize)};
Expand Down
Loading