Skip to content
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

[libc] Fix for unused variable warning #98086

Merged
merged 1 commit into from
Jul 8, 2024

Conversation

Caslyn
Copy link
Contributor

@Caslyn Caslyn commented Jul 8, 2024

This fixes the unused variable 'new_inner_size' warning that arises when new_inner_size is only used by LIBC_ASSERT by performing the calculation directly in the macro.

This fixes the `unused variable 'new_inner_size'` warning that arises
when `new_inner_size` is only used by `LIBC_ASSERT` by performing the
calculation directly in the macro.
@Caslyn Caslyn added the libc label Jul 8, 2024
@Caslyn Caslyn requested a review from PiJoules July 8, 2024 22:14
@Caslyn Caslyn self-assigned this Jul 8, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented Jul 8, 2024

@llvm/pr-subscribers-libc

Author: Caslyn Tonelli (Caslyn)

Changes

This fixes the unused variable 'new_inner_size' warning that arises when new_inner_size is only used by LIBC_ASSERT by performing the calculation directly in the macro.


Full diff: https://github.com/llvm/llvm-project/pull/98086.diff

1 Files Affected:

  • (modified) libc/src/__support/block.h (+1-2)
diff --git a/libc/src/__support/block.h b/libc/src/__support/block.h
index 026ea9063f416..e1b7aeaaf813c 100644
--- a/libc/src/__support/block.h
+++ b/libc/src/__support/block.h
@@ -442,8 +442,7 @@ Block<OffsetType, kAlign>::allocate(Block *block, size_t alignment,
 
   if (!info.block->is_usable_space_aligned(alignment)) {
     size_t adjustment = info.block->padding_for_alignment(alignment);
-    size_t new_inner_size = adjustment - BLOCK_OVERHEAD;
-    LIBC_ASSERT(new_inner_size % ALIGNMENT == 0 &&
+    LIBC_ASSERT((adjustment - BLOCK_OVERHEAD) % ALIGNMENT == 0 &&
                 "The adjustment calculation should always return a new size "
                 "that's a multiple of ALIGNMENT");
 

@Caslyn Caslyn merged commit f6eda6f into llvm:main Jul 8, 2024
6 of 7 checks passed
@Caslyn Caslyn deleted the fix-unused-variable-warning branch July 8, 2024 23:56
aaryanshukla pushed a commit to aaryanshukla/llvm-project that referenced this pull request Jul 14, 2024
This fixes the `unused variable 'new_inner_size'` warning that arises
when `new_inner_size` is only used by `LIBC_ASSERT` by performing the
calculation directly in the macro.
mysterymath added a commit to mysterymath/llvm-project that referenced this pull request Jul 30, 2024
This applies a standard trick from Knuth for storing boundary tags with
only one word of overhead for allocated blocks. The prev_ block is now
only valid if the previous block is free.

This is safe, since only coalescing with a free node requires walking
the blocks backwards. To allow determining whether it's safe to traverse
backwards, the used flag is changed to a prev_free flag. Since it's
still possible to unconditionally traverse forward, the prev_free flag
for the next block can be used wherever the old used flag is, so long as
there is always a next block.

To ensure there is always a next block, a sentinel last block is added
at the end of the range of blocks. Due to the above, this costs only a
single word per heap. This sentinel essentially just stores whether the
last real block of the heap is free. The sentinel is always considered
used and to have a zero inner size.

This completes the block optimizations needed to address llvm#98086. The
block structure should now be size-competitive with dlmalloc, although
there are still a couple of broader fragmentation concerns to address.
mysterymath added a commit that referenced this pull request Aug 5, 2024
This applies a standard trick from Knuth for storing boundary tags with
only one word of overhead for allocated blocks. The prev_ block is now
only valid if the previous block is free.

This is safe, since only coalescing with a free node requires walking
the blocks backwards. To allow determining whether it's safe to traverse
backwards, the used flag is changed to a prev_free flag. Since it's
still possible to unconditionally traverse forward, the prev_free flag
for the next block can be used wherever the old used flag is, so long as
there is always a next block.

To ensure there is always a next block, a sentinel last block is added
at the end of the range of blocks. Due to the above, this costs only a
single word per heap. This sentinel essentially just stores whether the
last real block of the heap is free. The sentinel is always considered
used and to have a zero inner size.

This completes the block optimizations needed to address #98086. The
block structure should now be size-competitive with dlmalloc, although
there are still a couple of broader fragmentation concerns to address.
banach-space pushed a commit to banach-space/llvm-project that referenced this pull request Aug 7, 2024
This applies a standard trick from Knuth for storing boundary tags with
only one word of overhead for allocated blocks. The prev_ block is now
only valid if the previous block is free.

This is safe, since only coalescing with a free node requires walking
the blocks backwards. To allow determining whether it's safe to traverse
backwards, the used flag is changed to a prev_free flag. Since it's
still possible to unconditionally traverse forward, the prev_free flag
for the next block can be used wherever the old used flag is, so long as
there is always a next block.

To ensure there is always a next block, a sentinel last block is added
at the end of the range of blocks. Due to the above, this costs only a
single word per heap. This sentinel essentially just stores whether the
last real block of the heap is free. The sentinel is always considered
used and to have a zero inner size.

This completes the block optimizations needed to address llvm#98086. The
block structure should now be size-competitive with dlmalloc, although
there are still a couple of broader fragmentation concerns to address.
kstoimenov pushed a commit to kstoimenov/llvm-project that referenced this pull request Aug 15, 2024
This applies a standard trick from Knuth for storing boundary tags with
only one word of overhead for allocated blocks. The prev_ block is now
only valid if the previous block is free.

This is safe, since only coalescing with a free node requires walking
the blocks backwards. To allow determining whether it's safe to traverse
backwards, the used flag is changed to a prev_free flag. Since it's
still possible to unconditionally traverse forward, the prev_free flag
for the next block can be used wherever the old used flag is, so long as
there is always a next block.

To ensure there is always a next block, a sentinel last block is added
at the end of the range of blocks. Due to the above, this costs only a
single word per heap. This sentinel essentially just stores whether the
last real block of the heap is free. The sentinel is always considered
used and to have a zero inner size.

This completes the block optimizations needed to address llvm#98086. The
block structure should now be size-competitive with dlmalloc, although
there are still a couple of broader fragmentation concerns to address.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants