[GH-ISSUE #278] HeapImp.h: static_assert may fail with regard to BlkPrefix and DLink sizes #86

Open
opened 2026-05-05 03:38:47 -06:00 by gitea-mirror · 4 comments
Owner

Originally created by @barracuda156 on GitHub (Jun 6, 2025).
Original GitHub issue: https://github.com/ultimatepp/ultimatepp/issues/278

Could someone say if exact sizes of these structs are critical or not?

In file included from ./uppsrc/Core/heaputil.cpp:11:
./uppsrc/Core/HeapImp.h:350:41: error: static assertion failed: Wrong sizeof(BlkPrefix)
  350 |         static_assert(sizeof(BlkPrefix) == 16, "Wrong sizeof(BlkPrefix)");
      |                       ~~~~~~~~~~~~~~~~~~^~~~~
./uppsrc/Core/HeapImp.h:350:41: note: the comparison reduces to '(20 == 16)'
./uppsrc/Core/HeapImp.h:351:37: error: static assertion failed: Wrong sizeof(DLink)
  351 |         static_assert(sizeof(DLink) == 64, "Wrong sizeof(DLink)");
      |                       ~~~~~~~~~~~~~~^~~~~
./uppsrc/Core/HeapImp.h:351:37: note: the comparison reduces to '(68 == 64)'
make: *** [.cache/upp.out/Core/GCC-Gcc-Gui-Linux-Posix-Shared/heaputil.o] Error 1
In file included from ./uppsrc/Core/hheap.cpp:10:
./uppsrc/Core/HeapImp.h:350:41: error: static assertion failed: Wrong sizeof(BlkPrefix)
  350 |         static_assert(sizeof(BlkPrefix) == 16, "Wrong sizeof(BlkPrefix)");
      |                       ~~~~~~~~~~~~~~~~~~^~~~~
./uppsrc/Core/HeapImp.h:350:41: note: the comparison reduces to '(20 == 16)'
./uppsrc/Core/HeapImp.h:351:37: error: static assertion failed: Wrong sizeof(DLink)
  351 |         static_assert(sizeof(DLink) == 64, "Wrong sizeof(DLink)");
      |                       ~~~~~~~~~~~~~~^~~~~
./uppsrc/Core/HeapImp.h:351:37: note: the comparison reduces to '(68 == 64)'
In file included from ./uppsrc/Core/sheap.cpp:9:
./uppsrc/Core/HeapImp.h:350:41: error: static assertion failed: Wrong sizeof(BlkPrefix)
  350 |         static_assert(sizeof(BlkPrefix) == 16, "Wrong sizeof(BlkPrefix)");
      |                       ~~~~~~~~~~~~~~~~~~^~~~~
./uppsrc/Core/HeapImp.h:350:41: note: the comparison reduces to '(20 == 16)'
./uppsrc/Core/HeapImp.h:351:37: error: static assertion failed: Wrong sizeof(DLink)
  351 |         static_assert(sizeof(DLink) == 64, "Wrong sizeof(DLink)");
      |                       ~~~~~~~~~~~~~~^~~~~
./uppsrc/Core/HeapImp.h:351:37: note: the comparison reduces to '(68 == 64)'
make: *** [.cache/upp.out/Core/GCC-Gcc-Gui-Linux-Posix-Shared/hheap.o] Error 1
make: *** [.cache/upp.out/Core/GCC-Gcc-Gui-Linux-Posix-Shared/sheap.o] Error 1
In file included from ./uppsrc/Core/lheap.cpp:11:
./uppsrc/Core/HeapImp.h:350:41: error: static assertion failed: Wrong sizeof(BlkPrefix)
  350 |         static_assert(sizeof(BlkPrefix) == 16, "Wrong sizeof(BlkPrefix)");
      |                       ~~~~~~~~~~~~~~~~~~^~~~~
./uppsrc/Core/HeapImp.h:350:41: note: the comparison reduces to '(20 == 16)'
./uppsrc/Core/HeapImp.h:351:37: error: static assertion failed: Wrong sizeof(DLink)
  351 |         static_assert(sizeof(DLink) == 64, "Wrong sizeof(DLink)");
      |                       ~~~~~~~~~~~~~~^~~~~
./uppsrc/Core/HeapImp.h:351:37: note: the comparison reduces to '(68 == 64)'
make: *** [.cache/upp.out/Core/GCC-Gcc-Gui-Linux-Posix-Shared/lheap.o] Error 1

For the first look it does not seem that anything actually requires them to be exactly 64 and 16. But if it is important, I will try to find a way to fit sizes to what is expected.

Originally created by @barracuda156 on GitHub (Jun 6, 2025). Original GitHub issue: https://github.com/ultimatepp/ultimatepp/issues/278 Could someone say if exact sizes of these structs are critical or not? ``` In file included from ./uppsrc/Core/heaputil.cpp:11: ./uppsrc/Core/HeapImp.h:350:41: error: static assertion failed: Wrong sizeof(BlkPrefix) 350 | static_assert(sizeof(BlkPrefix) == 16, "Wrong sizeof(BlkPrefix)"); | ~~~~~~~~~~~~~~~~~~^~~~~ ./uppsrc/Core/HeapImp.h:350:41: note: the comparison reduces to '(20 == 16)' ./uppsrc/Core/HeapImp.h:351:37: error: static assertion failed: Wrong sizeof(DLink) 351 | static_assert(sizeof(DLink) == 64, "Wrong sizeof(DLink)"); | ~~~~~~~~~~~~~~^~~~~ ./uppsrc/Core/HeapImp.h:351:37: note: the comparison reduces to '(68 == 64)' make: *** [.cache/upp.out/Core/GCC-Gcc-Gui-Linux-Posix-Shared/heaputil.o] Error 1 In file included from ./uppsrc/Core/hheap.cpp:10: ./uppsrc/Core/HeapImp.h:350:41: error: static assertion failed: Wrong sizeof(BlkPrefix) 350 | static_assert(sizeof(BlkPrefix) == 16, "Wrong sizeof(BlkPrefix)"); | ~~~~~~~~~~~~~~~~~~^~~~~ ./uppsrc/Core/HeapImp.h:350:41: note: the comparison reduces to '(20 == 16)' ./uppsrc/Core/HeapImp.h:351:37: error: static assertion failed: Wrong sizeof(DLink) 351 | static_assert(sizeof(DLink) == 64, "Wrong sizeof(DLink)"); | ~~~~~~~~~~~~~~^~~~~ ./uppsrc/Core/HeapImp.h:351:37: note: the comparison reduces to '(68 == 64)' In file included from ./uppsrc/Core/sheap.cpp:9: ./uppsrc/Core/HeapImp.h:350:41: error: static assertion failed: Wrong sizeof(BlkPrefix) 350 | static_assert(sizeof(BlkPrefix) == 16, "Wrong sizeof(BlkPrefix)"); | ~~~~~~~~~~~~~~~~~~^~~~~ ./uppsrc/Core/HeapImp.h:350:41: note: the comparison reduces to '(20 == 16)' ./uppsrc/Core/HeapImp.h:351:37: error: static assertion failed: Wrong sizeof(DLink) 351 | static_assert(sizeof(DLink) == 64, "Wrong sizeof(DLink)"); | ~~~~~~~~~~~~~~^~~~~ ./uppsrc/Core/HeapImp.h:351:37: note: the comparison reduces to '(68 == 64)' make: *** [.cache/upp.out/Core/GCC-Gcc-Gui-Linux-Posix-Shared/hheap.o] Error 1 make: *** [.cache/upp.out/Core/GCC-Gcc-Gui-Linux-Posix-Shared/sheap.o] Error 1 In file included from ./uppsrc/Core/lheap.cpp:11: ./uppsrc/Core/HeapImp.h:350:41: error: static assertion failed: Wrong sizeof(BlkPrefix) 350 | static_assert(sizeof(BlkPrefix) == 16, "Wrong sizeof(BlkPrefix)"); | ~~~~~~~~~~~~~~~~~~^~~~~ ./uppsrc/Core/HeapImp.h:350:41: note: the comparison reduces to '(20 == 16)' ./uppsrc/Core/HeapImp.h:351:37: error: static assertion failed: Wrong sizeof(DLink) 351 | static_assert(sizeof(DLink) == 64, "Wrong sizeof(DLink)"); | ~~~~~~~~~~~~~~^~~~~ ./uppsrc/Core/HeapImp.h:351:37: note: the comparison reduces to '(68 == 64)' make: *** [.cache/upp.out/Core/GCC-Gcc-Gui-Linux-Posix-Shared/lheap.o] Error 1 ``` For the first look it does not seem that anything actually requires them to be exactly 64 and 16. But if it is important, I will try to find a way to fit sizes to what is expected.
Author
Owner

@mirek-fidler commented on GitHub (Jun 10, 2025):

They are critical.

U++ heap is designed around enconding one critical bit into heap block address (it is basically a bit that tells MemoryFree whether the block is "small" or "large"). Those sizeofs are required to maintain correct alignement for all that to work.

<!-- gh-comment-id:2958447008 --> @mirek-fidler commented on GitHub (Jun 10, 2025): They are critical. U++ heap is designed around enconding one critical bit into heap block address (it is basically a bit that tells MemoryFree whether the block is "small" or "large"). Those sizeofs are required to maintain correct alignement for all that to work.
Author
Owner

@barracuda156 commented on GitHub (Jun 10, 2025):

There are perhaps two typical reasons for sizes to differ: either some struct uses bool, assuming it must be 1 byte, while it is not on ppc (32-bit ABI has 4-byte bool), or assumptions on type alignments are wrong (this might be remedied with a flag, to switch from “natural” to “power” alignment, for example). Or maybe rearrange some members inside those.

I can try a possible fix, if any idea comes to mind.

<!-- gh-comment-id:2958991867 --> @barracuda156 commented on GitHub (Jun 10, 2025): There are perhaps two typical reasons for sizes to differ: either some struct uses bool, assuming it must be 1 byte, while it is not on ppc (32-bit ABI has 4-byte bool), or assumptions on type alignments are wrong (this _might_ be remedied with a flag, to switch from “natural” to “power” alignment, for example). Or maybe rearrange some members inside those. I can try a possible fix, if any idea comes to mind.
Author
Owner

@mirek-fidler commented on GitHub (Jun 10, 2025):

Hey, admittedly, puting bool there is a mistake. I think byte will work
just as well, without changing anything in the code.

That said, this is what the assert was for - and it worked.

If you can test bool / byte, I will be glag to replace it.

(BTW, what exotic architecture are you playing with? :)

On Tue, Jun 10, 2025 at 2:21 PM Sergey Fedorov @.***>
wrote:

barracuda156 left a comment (ultimatepp/ultimatepp#278)
https://github.com/ultimatepp/ultimatepp/issues/278#issuecomment-2958991867

There are perhaps two typical reasons for sizes to differ: either some
struct uses bool, assuming it must be 1 byte, while it is not on ppc
(32-bit ABI has 4-byte bool), or assumptions on type alignments are wrong
(this might be remedied with a flag, to switch from “natural” to
“power” alignment, for example). Or maybe rearrange some members inside
those.

I can try a possible fix, if any idea comes to mind.


Reply to this email directly, view it on GitHub
https://github.com/ultimatepp/ultimatepp/issues/278#issuecomment-2958991867,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AARH232GCDIYSYREKFL2C2L3C3EURAVCNFSM6AAAAAB6X6L65GVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDSNJYHE4TCOBWG4
.
You are receiving this because you commented.Message ID:
@.***>

<!-- gh-comment-id:2959055704 --> @mirek-fidler commented on GitHub (Jun 10, 2025): Hey, admittedly, puting bool there is a mistake. I think byte will work just as well, without changing anything in the code. That said, this is what the assert was for - and it worked. If you can test bool / byte, I will be glag to replace it. (BTW, what exotic architecture are you playing with? :) On Tue, Jun 10, 2025 at 2:21 PM Sergey Fedorov ***@***.***> wrote: > *barracuda156* left a comment (ultimatepp/ultimatepp#278) > <https://github.com/ultimatepp/ultimatepp/issues/278#issuecomment-2958991867> > > There are perhaps two typical reasons for sizes to differ: either some > struct uses bool, assuming it must be 1 byte, while it is not on ppc > (32-bit ABI has 4-byte bool), or assumptions on type alignments are wrong > (this *might* be remedied with a flag, to switch from “natural” to > “power” alignment, for example). Or maybe rearrange some members inside > those. > > I can try a possible fix, if any idea comes to mind. > > — > Reply to this email directly, view it on GitHub > <https://github.com/ultimatepp/ultimatepp/issues/278#issuecomment-2958991867>, > or unsubscribe > <https://github.com/notifications/unsubscribe-auth/AARH232GCDIYSYREKFL2C2L3C3EURAVCNFSM6AAAAAB6X6L65GVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDSNJYHE4TCOBWG4> > . > You are receiving this because you commented.Message ID: > ***@***.***> >
Author
Owner

@barracuda156 commented on GitHub (Jun 10, 2025):

BTW, what exotic architecture are you playing with?

powerpc-apple-darwin :)

I think Apple made size of bool 4 bytes in 32-bit ABI to retain compatibility with old code inherited from m68k. In ppc64 ABI bool is the standard 1 byte (but there are other pains with ppc64).

I will try if replacement with byte works.

<!-- gh-comment-id:2959203289 --> @barracuda156 commented on GitHub (Jun 10, 2025): > BTW, what exotic architecture are you playing with? powerpc-apple-darwin :) I think Apple made size of bool 4 bytes in 32-bit ABI to retain compatibility with old code inherited from m68k. In ppc64 ABI bool is the standard 1 byte (but there are other pains with ppc64). I will try if replacement with byte works.
Sign in to join this conversation.
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: github-starred/ultimatepp#86
No description provided.