Skip to content

Commit

Permalink
Fix static assert violation in GC_calloc_prepare_explicitly_typed on …
Browse files Browse the repository at this point in the history
…CHERI

(fix of commit 433e2dd)

Issue #627 (bdwgc).

* include/gc/gc_typed.h [!GC_BUILD] (GC_calloc_typed_descr_s): First
define it as a macro (referring to GC_calloc_typed_descr_opaque_s).
* include/gc/gc_typed.h (GC_calloc_typed_descr_s): Undefine (after
definition of struct GC_calloc_typed_descr_s.
* typd_mlc.c (GC_calloc_prepare_explicitly_typed): Compare sizeof
GC_calloc_typed_descr_s to that of GC_calloc_typed_descr_opaque_s in
static assert (instead of computing the struct size using
GC_CALLOC_TYPED_DESCR_PTRS and GC_CALLOC_TYPED_DESCR_WORDS).
  • Loading branch information
ivmai committed Oct 19, 2024
1 parent f264fd7 commit 420b0a8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
6 changes: 4 additions & 2 deletions include/gc/gc_typed.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,14 @@ GC_API GC_ATTR_MALLOC GC_ATTR_CALLOC_SIZE(1, 2) void *GC_CALL

#ifdef GC_BUILD
struct GC_calloc_typed_descr_s;
#else
# define GC_calloc_typed_descr_s GC_calloc_typed_descr_opaque_s
#endif

struct GC_calloc_typed_descr_s {
GC_uintptr_t opaque_p[GC_CALLOC_TYPED_DESCR_PTRS];
GC_word opaque[GC_CALLOC_TYPED_DESCR_WORDS - GC_CALLOC_TYPED_DESCR_PTRS];
};
#endif
#undef GC_calloc_typed_descr_s

/* This is same as GC_calloc_explicitly_typed but more optimal */
/* in terms of the performance and memory usage if the client */
Expand Down
7 changes: 2 additions & 5 deletions typd_mlc.c
Original file line number Diff line number Diff line change
Expand Up @@ -500,11 +500,8 @@ GC_calloc_prepare_explicitly_typed(struct GC_calloc_typed_descr_s *pctd,
size_t ctd_sz, size_t n, size_t lb,
GC_descr d)
{
GC_STATIC_ASSERT(
sizeof(struct GC_calloc_typed_descr_s)
== GC_CALLOC_TYPED_DESCR_PTRS * sizeof(ptr_t)
+ (GC_CALLOC_TYPED_DESCR_WORDS - GC_CALLOC_TYPED_DESCR_PTRS)
* sizeof(word));
GC_STATIC_ASSERT(sizeof(struct GC_calloc_typed_descr_opaque_s)
== sizeof(struct GC_calloc_typed_descr_s));
GC_ASSERT(GC_explicit_typing_initialized);
GC_ASSERT(sizeof(struct GC_calloc_typed_descr_s) == ctd_sz);
(void)ctd_sz; /* unused currently */
Expand Down

0 comments on commit 420b0a8

Please sign in to comment.