Skip to content

Commit

Permalink
Fix code formatting after migration to clang-format v18
Browse files Browse the repository at this point in the history
* cord/tests/de.c (line_map, history): Define struct type outside
typedef.
* include/private/pthread_support.h (GC_stack_context_t, GC_thread):
Likewise.
* include/private/thread_local_alloc.h (GC_tlfs): Likewise.
* finalize.c (HASH3): Cast 1 to size_t.
* include/gc/cord_pos.h (CORD_pos_advance): Likewise.
* include/gc/gc.h [GC_INITIAL_HEAP_SIZE && !CPPCHECK]
(GC_INIT_CONF_INITIAL_HEAP_SIZE): Cast `GC_INITIAL_HEAP_SIZE` to
`size_t`.
* include/gc/gc_inline.h (GC_FAST_MALLOC_GRANS, GC_MALLOC_WORDS_KIND):
Replace `GC_GRANULE_BYTES*lg` to `GC_RAW_BYTES_FROM_INDEX(lg)`.
* include/private/dbg_mlc.h [(KEEP_BACK_PTRS || MAKE_BACK_GRAPH)
&& !(PARALLEL_MARK && KEEP_BACK_PTRS)] (GC_HAS_DEBUG_INFO): Wrap
`*(GC_uintptr_t*)(base)` into parentheses.
* include/private/gc_priv.h (GRANULES_TO_BYTES, GRANULES_TO_PTRS):
Reverse order of multiplication operands.
* include/private/gc_priv.h [!MARK_BIT_PER_OBJ] (FINAL_MARK_BIT):
Likewise.
* include/private/gc_priv.h [E2K && THREADS] (PS_COMPUTE_ADJUSTED_OFS):
Cast `PS_SYSCALL_TAIL_BYTES` to `unsigned`.
* include/private/gc_priv.h [!_MSC_VER && static_assert && !CPPCHECK
&& __STDC_VERSION__>=201112L] (GC_STATIC_ASSERT): Wrap `static_assert`
into do-while.
* include/private/gcconfig.h [!GC_CLANG_PREREQ(11,0)] (PTR_ALIGN_DOWN,
PTR_ALIGN_UP): Replace `(GC_uintptr_t)((b)-1))` to
`((GC_uintptr_t)(b)-(GC_uintptr_t)1)`.
* include/private/gcconfig.h [I386 && DGUX || X86_64 && MSWIN_XBOX1]
(MAP_FAILED): Replace -1 to `~(GC_uintptr_t)0`.
* win32_threads.c [PARALLEL_MARK && !GC_PTHREADS_PARAMARK && !MSWINCE
&& !MSWIN_XBOX1] (GC_start_mark_threads_inner): Likewise.
* include/private/gcconfig.h [WEBASSEMBLY && WASI] (DATASTART,
DATAEND): Wrap `&` operation into parentheses.
* include/private/gcconfig.h [WEBASSEMBLY && WASI] (STACKBOTTOM):
Change definition to `DATASTART`.
* include/private/gcconfig.h [!FIXUP_POINTER && DYNAMIC_POINTER_MASK]
(FIXUP_POINTER): Wrap `(word)(p)` into parentheses.
* os_dep.c [LINUX && USE_LIBC_PRIVATES && IA64] (os_main_stackbottom):
Move comment into if-else branch; refine comment.
* tests/gctest.c [GC_GCJ_SUPPORT] (gcj_cons): Replace ternary operator
with `if` statement.
* tests/gctest.c (NUMBER_ROUND_UP): Cast 1 to unsigned.
* tests/trace.c (root): Make variable static; define struct type
(`treenode`) before the variable definition.
* win32_threads.c [MSWINCE] (GC_wince_evaluate_stack_min): Cast 1 to
`word`.
  • Loading branch information
ivmai committed Jan 17, 2025
1 parent d398065 commit e32fe7a
Show file tree
Hide file tree
Showing 14 changed files with 80 additions and 62 deletions.
14 changes: 8 additions & 6 deletions cord/tests/de.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,18 +80,20 @@

/* List of line number to position mappings, in descending order. */
/* There may be holes. */
typedef struct LineMapRep {
struct LineMapRep {
int line;
size_t pos;
struct LineMapRep *previous;
} * line_map;
};
typedef struct LineMapRep *line_map;

/* List of file versions, one per edit operation */
typedef struct HistoryRep {
/* List of file versions, one per edit operation. */
struct HistoryRep {
CORD file_contents;
struct HistoryRep *previous;
line_map map; /* Invalid for first record "now" */
} * history;
line_map map; /* invalid for the first record "now" */
};
typedef struct HistoryRep *history;

history now = 0;
CORD current; /* == now -> file_contents. */
Expand Down
2 changes: 1 addition & 1 deletion finalize.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ typedef void (*finalization_mark_proc)(ptr_t /* finalizable_obj_ptr */);

# define HASH3(addr, size, log_size) \
((size_t)((ADDR(addr) >> 3) ^ (ADDR(addr) >> (3 + (log_size)))) \
& ((size)-1))
& ((size) - (size_t)1))
# define HASH2(addr, log_size) HASH3(addr, (size_t)1 << (log_size), log_size)

struct hash_chain_entry {
Expand Down
3 changes: 2 additions & 1 deletion include/gc/cord_pos.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ CORD_API void CORD__prev(CORD_pos);

/* Advance position by n characters; n should be positive and less */
/* than CORD_pos_chars_left(p). */
# define CORD_pos_advance(p, n) ((p)[0].cur_pos += (n)-1, CORD_next(p))
# define CORD_pos_advance(p, n) \
((p)[0].cur_pos += (n) - (size_t)1, CORD_next(p))

/* Address of the current character in cache. */
# define CORD_pos_cur_char_addr(p) \
Expand Down
10 changes: 5 additions & 5 deletions include/gc/gc.h
Original file line number Diff line number Diff line change
Expand Up @@ -2316,11 +2316,11 @@ GC_API void *GC_CALL GC_find_limit(void * /* start */, int /* up */);

#if defined(GC_INITIAL_HEAP_SIZE) && !defined(CPPCHECK)
/* Set heap size to the desired value at start-up */
# define GC_INIT_CONF_INITIAL_HEAP_SIZE \
{ \
size_t heap_size = GC_get_heap_size(); \
if (heap_size < (GC_INITIAL_HEAP_SIZE)) \
(void)GC_expand_hp((GC_INITIAL_HEAP_SIZE)-heap_size); \
# define GC_INIT_CONF_INITIAL_HEAP_SIZE \
{ \
size_t heap_size = GC_get_heap_size(); \
if (heap_size < (size_t)(GC_INITIAL_HEAP_SIZE)) \
(void)GC_expand_hp(((size_t)(GC_INITIAL_HEAP_SIZE)) - heap_size); \
}
#else
# define GC_INIT_CONF_INITIAL_HEAP_SIZE /* empty */
Expand Down
17 changes: 9 additions & 8 deletions include/gc/gc_inline.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ GC_API GC_ATTR_MALLOC GC_ATTR_ALLOC_SIZE(1) void *GC_CALL
GC_end_stubborn_change(my_fl); \
GC_reachable_here(next); \
} \
GC_ASSERT(GC_size(result) >= GC_GRANULE_BYTES * (lg)); \
GC_ASSERT(GC_size(result) >= GC_RAW_BYTES_FROM_INDEX(lg)); \
GC_ASSERT((k) == GC_I_PTRFREE \
|| 0 /* NULL */ == ((void **)result)[1]); \
break; \
Expand All @@ -188,7 +188,7 @@ GC_API GC_ATTR_MALLOC GC_ATTR_ALLOC_SIZE(1) void *GC_CALL
k, my_fl); \
my_entry = *my_fl; \
if (0 /* NULL */ == my_entry) { \
result = (*GC_get_oom_fn())(GC_GRANULE_BYTES * (lg)); \
result = (*GC_get_oom_fn())(GC_RAW_BYTES_FROM_INDEX(lg)); \
break; \
} \
} \
Expand All @@ -203,12 +203,13 @@ GC_API GC_ATTR_MALLOC GC_ATTR_ALLOC_SIZE(1) void *GC_CALL
/* allocator lock. The caller is responsible for supplying a cleared */
/* tiny_fl free-list array. For single-threaded applications, this may */
/* be a global array. */
#define GC_MALLOC_WORDS_KIND(result, n, tiny_fl, k, init) \
do { \
size_t lg = GC_PTRS_TO_WHOLE_GRANULES(n); \
\
GC_FAST_MALLOC_GRANS(result, lg, tiny_fl, 0 /* num_direct */, k, \
GC_malloc_kind((lg)*GC_GRANULE_BYTES, k), init); \
#define GC_MALLOC_WORDS_KIND(result, n, tiny_fl, k, init) \
do { \
size_t lg = GC_PTRS_TO_WHOLE_GRANULES(n); \
\
GC_FAST_MALLOC_GRANS(result, lg, tiny_fl, 0 /* num_direct */, k, \
GC_malloc_kind(GC_RAW_BYTES_FROM_INDEX(lg), k), \
init); \
} while (0)

#define GC_MALLOC_WORDS(result, n, tiny_fl) \
Expand Down
5 changes: 3 additions & 2 deletions include/private/dbg_mlc.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,9 @@ GC_INNER int GC_has_other_debug_info(ptr_t base);
(((GC_uintptr_t)GC_cptr_load((volatile ptr_t *)(base)) & 1) != 0 \
&& GC_has_other_debug_info(base) > 0)
# else
# define GC_HAS_DEBUG_INFO(base) \
((*(GC_uintptr_t *)(base)&1) != 0 && GC_has_other_debug_info(base) > 0)
# define GC_HAS_DEBUG_INFO(base) \
(((*(GC_uintptr_t *)(base)) & 1) != 0 \
&& GC_has_other_debug_info(base) > 0)
# endif
#else
# define GC_HAS_DEBUG_INFO(base) (GC_has_other_debug_info(base) > 0)
Expand Down
29 changes: 16 additions & 13 deletions include/private/gc_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -929,10 +929,10 @@ EXTERN_C_BEGIN
#endif

#define BYTES_TO_GRANULES(lb) ((lb) / GC_GRANULE_BYTES)
#define GRANULES_TO_BYTES(lg) ((lg)*GC_GRANULE_BYTES)
#define GRANULES_TO_BYTES(lg) (GC_GRANULE_BYTES * (lg))
#define BYTES_TO_PTRS(lb) ((lb) / sizeof(ptr_t))
#define PTRS_TO_BYTES(lpw) ((lpw) * sizeof(ptr_t))
#define GRANULES_TO_PTRS(lg) ((lg)*GC_GRANULE_PTRS)
#define GRANULES_TO_PTRS(lg) (GC_GRANULE_PTRS * (lg))

/* Convert size in bytes to that in pointers rounding up (but */
/* not adding extra byte at end). */
Expand Down Expand Up @@ -2032,7 +2032,7 @@ GC_INNER void GC_push_all_register_sections(
# define MARK_BIT_OFFSET(sz) BYTES_TO_GRANULES(sz)
# define FINAL_MARK_BIT(sz) \
((sz) > MAXOBJBYTES ? MARK_BITS_PER_HBLK \
: BYTES_TO_GRANULES((sz)*HBLK_OBJS(sz)))
: BYTES_TO_GRANULES(HBLK_OBJS(sz) * (sz)))
#endif /* !MARK_BIT_PER_OBJ */

/* Important internal collector routines. */
Expand Down Expand Up @@ -2183,15 +2183,15 @@ ptr_t GC_save_regs_in_stack(void);
} while (0)

# ifdef THREADS
# define PS_COMPUTE_ADJUSTED_OFS(padj_ps_ofs, ps_ofs, ofs_sz_ull) \
do { \
if ((ofs_sz_ull) <= (ps_ofs) /* && ofs_sz_ull > 0 */) \
ABORT_ARG2("Incorrect size of procedure stack", \
": ofs= %lu, size= %lu", (unsigned long)(ps_ofs), \
(unsigned long)(ofs_sz_ull)); \
*(padj_ps_ofs) = (ps_ofs) > PS_SYSCALL_TAIL_BYTES \
? (ps_ofs)-PS_SYSCALL_TAIL_BYTES \
: 0; \
# define PS_COMPUTE_ADJUSTED_OFS(padj_ps_ofs, ps_ofs, ofs_sz_ull) \
do { \
if ((ofs_sz_ull) <= (ps_ofs) /* && ofs_sz_ull > 0 */) \
ABORT_ARG2("Incorrect size of procedure stack", \
": ofs= %lu, size= %lu", (unsigned long)(ps_ofs), \
(unsigned long)(ofs_sz_ull)); \
*(padj_ps_ofs) = (ps_ofs) > (unsigned)PS_SYSCALL_TAIL_BYTES \
? (ps_ofs) - (unsigned)PS_SYSCALL_TAIL_BYTES \
: 0; \
} while (0)
# else
/* A simplified variant of the above assuming ps_ofs is a zero const. */
Expand Down Expand Up @@ -3165,7 +3165,10 @@ GC_INNER word GC_compute_root_size(void);
static_assert(expr, "static assertion failed: " #expr)
#elif defined(static_assert) && !defined(CPPCHECK) \
&& (__STDC_VERSION__ >= 201112L)
# define GC_STATIC_ASSERT(expr) static_assert(expr, # expr)
# define GC_STATIC_ASSERT(expr) \
do { /* wrap into do-while for proper formatting by clang-format */ \
static_assert(expr, #expr); \
} while (0)
#elif defined(mips) && !defined(__GNUC__) && !defined(CPPCHECK)
/* DOB: MIPSPro C gets an internal error taking the sizeof an array type.
This code works correctly (ugliness is to avoid "unused var" warnings) */
Expand Down
20 changes: 10 additions & 10 deletions include/private/gcconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -781,10 +781,10 @@ EXTERN_C_BEGIN
# define PTR_ALIGN_UP(p, b) __builtin_align_up(p, b)
#else
# define PTR_ALIGN_DOWN(p, b) \
((ptr_t)((GC_uintptr_t)(p) & ~(GC_uintptr_t)((b)-1)))
# define PTR_ALIGN_UP(p, b) \
((ptr_t)(((GC_uintptr_t)(p) + (GC_uintptr_t)((b)-1)) \
& ~(GC_uintptr_t)((b)-1)))
((ptr_t)((GC_uintptr_t)(p) & ~((GC_uintptr_t)(b) - (GC_uintptr_t)1)))
# define PTR_ALIGN_UP(p, b) \
((ptr_t)(((GC_uintptr_t)(p) + (GC_uintptr_t)(b) - (GC_uintptr_t)1) \
& ~((GC_uintptr_t)(b) - (GC_uintptr_t)1)))
#endif

/* If available, we can use __builtin_unwind_init() to push the */
Expand Down Expand Up @@ -1446,7 +1446,7 @@ extern int _etext, _end;
# ifndef USE_MMAP
# define USE_MMAP 1
# endif
# define MAP_FAILED (void *)((GC_uintptr_t)-1)
# define MAP_FAILED ((void *)(~(GC_uintptr_t)0))
# define HEAP_START ((word)0x40000000)
# endif /* DGUX */
# ifdef LINUX
Expand Down Expand Up @@ -2357,7 +2357,7 @@ LONG64 durango_get_stack_bottom(void);
# define PROT_EXEC 4
# define MAP_PRIVATE 2
# define MAP_FIXED 0x10
# define MAP_FAILED ((void *)-1)
# define MAP_FAILED ((void *)(~(GC_uintptr_t)0))
# endif
# ifdef MSWIN32
# define RETRY_GET_THREAD_CONTEXT
Expand Down Expand Up @@ -2471,9 +2471,9 @@ void *emmalloc_memalign(size_t align, size_t lb);
# ifdef WASI
# define OS_TYPE "WASI"
extern char __global_base, __heap_base;
# define STACKBOTTOM ((ptr_t)&__global_base)
# define DATASTART ((ptr_t)&__global_base)
# define DATAEND ((ptr_t)&__heap_base)
# define DATASTART ((ptr_t)(&__global_base))
# define DATAEND ((ptr_t)(&__heap_base))
# define STACKBOTTOM DATASTART
# ifndef GC_NO_SIGSETJMP
# define GC_NO_SIGSETJMP 1 /* no support of signals */
# endif
Expand Down Expand Up @@ -3408,7 +3408,7 @@ extern ptr_t GC_data_start;
# define NEED_FIXUP_POINTER
#elif defined(DYNAMIC_POINTER_MASK)
# define FIXUP_POINTER(p) \
(p = (ptr_t)(((word)(p)&GC_pointer_mask) << GC_pointer_shift))
(p = (ptr_t)((((word)(p)) & GC_pointer_mask) << GC_pointer_shift))
# undef POINTER_MASK
# undef POINTER_SHIFT
# define NEED_FIXUP_POINTER
Expand Down
10 changes: 6 additions & 4 deletions include/private/pthread_support.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ typedef struct GC_NT_TIB_s GC_NT_TIB;
# endif
# endif

typedef struct GC_StackContext_Rep {
struct GC_StackContext_Rep {
# if defined(THREAD_SANITIZER) && defined(SIGNAL_BASED_STOP_WORLD)
/* A dummy field to avoid TSan false positive about the race */
/* between GC_has_other_debug_info and GC_suspend_handler_inner */
Expand Down Expand Up @@ -133,7 +133,8 @@ typedef struct GC_StackContext_Rep {
/* Points to the "frame" data held in stack by the innermost */
/* GC_call_with_gc_active() of this stack (thread); may be NULL. */
struct GC_traced_stack_sect_s *traced_stack_sect;
} * GC_stack_context_t;
};
typedef struct GC_StackContext_Rep *GC_stack_context_t;

# ifdef GC_WIN32_THREADS
typedef DWORD thread_id_t;
Expand All @@ -150,7 +151,7 @@ typedef pthread_t thread_id_t;
# define THREAD_ID_TO_VPTR(id) PTHREAD_TO_VPTR(id)
# endif

typedef struct GC_Thread_Rep {
struct GC_Thread_Rep {
union {
# if !defined(GC_NO_THREADS_DISCOVERY) && defined(GC_WIN32_THREADS)
/* Updated without a lock. We assert that each unused entry has */
Expand Down Expand Up @@ -278,7 +279,8 @@ typedef struct GC_Thread_Rep {
/* needed for GetThreadContext() to succeed. */
word context_regs[PUSHED_REGS_COUNT];
# endif
} * GC_thread;
};
typedef struct GC_Thread_Rep *GC_thread;

# if defined(GC_PTHREADS) || defined(GC_PTHREADS_PARAMARK)
/* Convert an opaque pthread_t value to a pointer identifying the thread. */
Expand Down
5 changes: 3 additions & 2 deletions include/private/thread_local_alloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ EXTERN_C_BEGIN
/* allocation, equivalent to 0; */
/* - >=HBLKSIZE means pointer to nonempty free list. */

typedef struct thread_local_freelists {
struct thread_local_freelists {
/* Note: Preserve *_freelists names for some clients. */
void *_freelists[THREAD_FREELISTS_KINDS][GC_TINY_FREELISTS];
# define ptrfree_freelists _freelists[PTRFREE]
Expand All @@ -133,7 +133,8 @@ typedef struct thread_local_freelists {

/* Do not use local free lists for up to this much allocation. */
# define DIRECT_GRANULES (HBLKSIZE / GC_GRANULE_BYTES)
} * GC_tlfs;
};
typedef struct thread_local_freelists *GC_tlfs;

# if defined(USE_PTHREAD_SPECIFIC)
# define GC_getspecific pthread_getspecific
Expand Down
7 changes: 4 additions & 3 deletions os_dep.c
Original file line number Diff line number Diff line change
Expand Up @@ -1226,8 +1226,9 @@ os_main_stackbottom(void)
/* low while the initialization code is running. */
if ((ADDR(__libc_stack_end) & 0xfff) + 0x10 < 0x1000) {
return __libc_stack_end + 0x10;
} /* Otherwise it's not safe to add 16 bytes and we fall */
/* back to using /proc. */
} else {
/* It is not safe to add 16 bytes. Thus, fallback to using /proc. */
}
# elif defined(SPARC)
/* Older versions of glibc for 64-bit SPARC do not set this */
/* variable correctly, it gets set to either zero or one. */
Expand Down Expand Up @@ -4872,7 +4873,7 @@ GC_mprotect_thread(void *arg)
# endif
}
} /* switch */
} /* for */
}
}

/* All this SIGBUS code should not be necessary. All protection faults */
Expand Down
12 changes: 8 additions & 4 deletions tests/gctest.c
Original file line number Diff line number Diff line change
Expand Up @@ -381,10 +381,13 @@ gcj_cons(sexpr x, sexpr y)
size_t cnt = (size_t)AO_fetch_and_add1(&extra_count);
const void *d = (cnt & 1) != 0 ? &gcj_class_struct1 : &gcj_class_struct2;
size_t lb = sizeof(struct SEXPR) + sizeof(struct fake_vtable *);
void *r = (cnt & 2) != 0 ? GC_GCJ_MALLOC_IGNORE_OFF_PAGE(
lb + (cnt <= HBLKSIZE / 2 ? cnt : 0), d)
: GC_GCJ_MALLOC(lb, d);
void *r;

if ((cnt & 2) != 0) {
r = GC_GCJ_MALLOC_IGNORE_OFF_PAGE(lb + (cnt <= HBLKSIZE / 2 ? cnt : 0), d);
} else {
r = GC_GCJ_MALLOC(lb, d);
}
CHECK_OUT_OF_MEMORY(r);
AO_fetch_and_add1(&collectable_count);
/* Skip vtable pointer. */
Expand Down Expand Up @@ -2022,7 +2025,8 @@ test_long_mult(void)
#endif
}

#define NUMBER_ROUND_UP(v, bound) ((((v) + (bound)-1) / (bound)) * (bound))
#define NUMBER_ROUND_UP(v, bound) \
((((v) + (bound) - (unsigned)1) / (bound)) * (bound))

static size_t initial_heapsize;

Expand Down
4 changes: 3 additions & 1 deletion tests/trace.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
struct treenode {
struct treenode *x;
struct treenode *y;
} * root[10];
};

static struct treenode *root[10];

static struct treenode *
mktree(int i)
Expand Down
4 changes: 2 additions & 2 deletions win32_threads.c
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ GC_start_world(void)
/* argument later and must not be used as the lower bound for sp */
/* check (since the stack may be bigger than 64 KiB). */
# define GC_wince_evaluate_stack_min(s) \
(ptr_t)(((word)(s)-1) & ~(word)0xFFFF)
(ptr_t)(((word)(s) - (word)1) & ~(word)0xFFFF)
# elif defined(GC_ASSERTIONS)
# define GC_dont_query_stack_min FALSE
# endif
Expand Down Expand Up @@ -1233,7 +1233,7 @@ GC_start_mark_threads_inner(void)
handle = _beginthreadex(NULL /* security_attr */, MARK_THREAD_STACK_SIZE,
GC_mark_thread, NUMERIC_TO_VPTR(i), 0 /* flags */,
&thread_id);
if (EXPECT(!handle || handle == (GC_uintptr_t)-1L, FALSE)) {
if (EXPECT(!handle || handle == ~(GC_uintptr_t)0, FALSE)) {
WARN("Marker thread %" WARN_PRIdPTR " creation failed\n",
(GC_signed_word)i);
/* Don't try to create other marker threads. */
Expand Down

0 comments on commit e32fe7a

Please sign in to comment.