Apply clang-format update to repo (#1154)

Commit bc6c183 introduced a bunch of discrepancies between what files
look like in the repo and what clang-format says they should look like.
However, there were already a few discrepancies prior to that. Most of
these discrepancies seemed to be unintentional, but a few of them were
load-bearing (e.g., a #include that violated header ordering needing
something to have been #defined by a 'later' #include.)

I opted to take what I hope is a relatively smooth-brained approach: I
reverted the .clang-format change, ran clang-format on the whole repo,
reapplied the .clang-format change, reran clang-format again, and then
reverted the commit that contained the first run. Thus the full effect
of this PR should only be to apply the changed formatting rules to the
repo, and from skimming the results, this seems to be the case.

My work can be checked by applying the short, manual commits, and then
rerunning the command listed in the autogenerated commits (those whose
messages I have prefixed auto:) and seeing if your results agree.

It might be that the other diffs should be fixed at some point but I'm
leaving that aside for now.

fd '\.c(c|pp)?$' --print0| xargs -0 clang-format -i
This commit is contained in:
Jōshin 2024-04-25 10:38:00 -07:00 committed by GitHub
parent 342d0c81e5
commit 6e6fc38935
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
863 changed files with 9201 additions and 4627 deletions

View file

@ -43,7 +43,8 @@
*/
static uint64_t Rando(void) {
uint64_t x;
do x = lemur64();
do
x = lemur64();
while (((x ^ READ64LE("!!!!!!!!")) - 0x0101010101010101) &
~(x ^ READ64LE("!!!!!!!!")) & 0x8080808080808080);
return x;
@ -247,11 +248,15 @@ TEST(kprintf, testFailure_wontClobberErrnoAndBypassesSystemCallSupport) {
ASSERT_EQ(0, errno);
EXPECT_SYS(0, 3, dup(2));
// <LIMBO>
if (close(2)) _Exit(200);
if (close(2))
_Exit(200);
n = __syscount;
if (__syscount != n) _Exit(201);
if (errno != 0) _Exit(202);
if (dup2(3, 2) != 2) _Exit(203);
if (__syscount != n)
_Exit(201);
if (errno != 0)
_Exit(202);
if (dup2(3, 2) != 2)
_Exit(203);
// </LIMBO>
EXPECT_SYS(0, 0, close(3));
}

View file

@ -132,7 +132,8 @@ void TestContendedLock(const char *name, int kind) {
kprintf("clone failed: %s\n", strerror(rc));
_Exit(1);
}
while (!atomic_load(&ready)) donothing;
while (!atomic_load(&ready))
donothing;
t1 = timespec_real();
for (i = 0; i < n; ++i) {
ASSERT_EQ(0, pthread_mutex_lock(&mu));
@ -142,7 +143,8 @@ void TestContendedLock(const char *name, int kind) {
ASSERT_EQ(0, pthread_mutex_unlock(&mu));
}
t2 = timespec_real();
while (tib.tib_tid) donothing;
while (tib.tib_tid)
donothing;
ASSERT_EQ(1, atomic_load(&success));
ASSERT_EQ(0, atomic_load(&counter));
FreeCosmoStack(stk);
@ -178,7 +180,8 @@ int main(int argc, char *argv[]) {
#ifdef __aarch64__
// our usage of raw clone() is probably broken in aarch64
// we should just get rid of clone()
if (1) return 0;
if (1)
return 0;
#endif
if (_weaken(nsync_mu_lock)) {

View file

@ -68,8 +68,10 @@ TEST(memcmp, hug) {
static int coerce(int result) {
#ifdef __aarch64__
// arm's strcmp assembly is nuts and unpredictable, but it's legal
if (result < 0) return -1;
if (result > 0) return +1;
if (result < 0)
return -1;
if (result > 0)
return +1;
return 0;
#else
return result;

View file

@ -27,8 +27,10 @@
static dontasan void *golden(void *p, int c, size_t n) {
size_t i;
if (IsAsan()) __asan_verify(p, n);
for (i = 0; i < n; ++i) ((char *)p)[i] = c;
if (IsAsan())
__asan_verify(p, n);
for (i = 0; i < n; ++i)
((char *)p)[i] = c;
return p;
}

View file

@ -175,9 +175,11 @@ struct MutexContentionArgs {
void *MutexContentionWorker(void *arg) {
struct MutexContentionArgs *a = arg;
while (!atomic_load_explicit(&a->done, memory_order_relaxed)) {
if (pthread_mutex_lock(a->mutex)) notpossible;
if (pthread_mutex_lock(a->mutex))
notpossible;
atomic_store_explicit(&a->ready, 1, memory_order_relaxed);
if (pthread_mutex_unlock(a->mutex)) notpossible;
if (pthread_mutex_unlock(a->mutex))
notpossible;
}
return 0;
}
@ -204,7 +206,8 @@ BENCH(pthread_mutex_lock, bench_contended) {
pthread_spinlock_t s = {0};
struct SpinContentionArgs a = {&s};
pthread_create(&t, 0, SpinContentionWorker, &a);
while (!a.ready) sched_yield();
while (!a.ready)
sched_yield();
EZBENCH2("spin 2x", donothing, BenchSpinUnspin(&s));
a.done = true;
pthread_join(t, 0);
@ -213,7 +216,8 @@ BENCH(pthread_mutex_lock, bench_contended) {
nsync_mu m = {0};
struct NsyncContentionArgs a = {&m};
pthread_create(&t, 0, NsyncContentionWorker, &a);
while (!a.ready) sched_yield();
while (!a.ready)
sched_yield();
EZBENCH2("nsync 2x", donothing, BenchLockUnlockNsync(&m));
a.done = true;
pthread_join(t, 0);
@ -226,7 +230,8 @@ BENCH(pthread_mutex_lock, bench_contended) {
pthread_mutex_init(&m, &attr);
struct MutexContentionArgs a = {&m};
pthread_create(&t, 0, MutexContentionWorker, &a);
while (!a.ready) sched_yield();
while (!a.ready)
sched_yield();
EZBENCH2("normal 2x", donothing, BenchLockUnlock(&m));
a.done = true;
pthread_join(t, 0);
@ -239,7 +244,8 @@ BENCH(pthread_mutex_lock, bench_contended) {
pthread_mutex_init(&m, &attr);
struct MutexContentionArgs a = {&m};
pthread_create(&t, 0, MutexContentionWorker, &a);
while (!a.ready) sched_yield();
while (!a.ready)
sched_yield();
EZBENCH2("recursive 2x", donothing, BenchLockUnlock(&m));
a.done = true;
pthread_join(t, 0);
@ -252,7 +258,8 @@ BENCH(pthread_mutex_lock, bench_contended) {
pthread_mutex_init(&m, &attr);
struct MutexContentionArgs a = {&m};
pthread_create(&t, 0, MutexContentionWorker, &a);
while (!a.ready) sched_yield();
while (!a.ready)
sched_yield();
EZBENCH2("errorcheck 2x", donothing, BenchLockUnlock(&m));
a.done = true;
pthread_join(t, 0);

View file

@ -64,7 +64,8 @@ TEST(_rand64, testLcg_doesntProduceIdenticalValues) {
for (i = 0; i < ARRAYLEN(A); ++i) {
EXPECT_NE(0, A[i], "i=%d", i);
for (j = 0; j < ARRAYLEN(A); ++j) {
if (i == j) continue;
if (i == j)
continue;
EXPECT_NE(A[i], A[j], "i=%d j=%d", i, j);
}
}
@ -93,7 +94,8 @@ TEST(_rand64, testThreadSafety_doesntProduceIdenticalValues) {
for (i = 0; i < ARRAYLEN(A); ++i) {
EXPECT_NE(0, A[i], "i=%d", i);
for (j = 0; j < ARRAYLEN(A); ++j) {
if (i == j) continue;
if (i == j)
continue;
EXPECT_NE(A[i], A[j], "i=%d j=%d", i, j);
}
}

View file

@ -72,8 +72,10 @@ TEST(strchrnul, notFound_returnsPointerToNulByte) {
char *strchr_pure(const char *s, int c) {
for (c &= 0xff;; ++s) {
if ((*s & 0xff) == c) return (char *)s;
if (!*s) return NULL;
if ((*s & 0xff) == c)
return (char *)s;
if (!*s)
return NULL;
}
}
@ -106,7 +108,8 @@ BENCH(strchr, bench) {
char *memchr_pure(const char *m, int c, size_t n) {
const unsigned char *p, *pe;
for (c &= 0xff, p = (const unsigned char *)m, pe = p + n; p < pe; ++p) {
if (*p == c) return (void *)p;
if (*p == c)
return (void *)p;
}
return NULL;
}
@ -126,8 +129,10 @@ TEST(memchr, fuzz) {
char *strchrnul_pure(const char *s, int c) {
for (c &= 0xff;; ++s) {
if ((*s & 0xff) == c) return (char *)s;
if (!*s) return (void *)s;
if ((*s & 0xff) == c)
return (char *)s;
if (!*s)
return (void *)s;
}
}
@ -147,7 +152,8 @@ TEST(strchrnul, fuzz) {
void *rawmemchr_pure(const void *m, int c) {
const unsigned char *s;
for (c &= 255, s = m;; ++s) {
if (*s == c) return (void *)s;
if (*s == c)
return (void *)s;
}
}

View file

@ -491,7 +491,8 @@ TEST(wcsncmp, testTwosComplementBane) {
dontinline int strcmp_pure(const char *a, const char *b) {
for (; *a == *b; a++, b++) {
if (!*a) break;
if (!*a)
break;
}
return (*a & 0xff) - (*b & 0xff);
}

View file

@ -30,7 +30,8 @@ wchar_t u32[] = L"utf32 ☻";
size_t strlen_pure(const char *s) {
size_t n = 0;
while (*s++) ++n;
while (*s++)
++n;
return n;
}
@ -64,7 +65,8 @@ TEST(strlen, test_const) {
TEST(strlen, test_nonconst) {
char buf[256];
unsigned i;
for (i = 0; i < 255; ++i) buf[i] = i + 1;
for (i = 0; i < 255; ++i)
buf[i] = i + 1;
buf[i] = '\0';
ASSERT_EQ(255, strlen(buf));
}
@ -85,7 +87,8 @@ TEST(strlen, testnonconst) {
"m"(*StR) */
char buf[256];
unsigned i;
for (i = 0; i < 250; ++i) buf[i] = i + 1;
for (i = 0; i < 250; ++i)
buf[i] = i + 1;
buf[i] = '\0';
ASSERT_EQ(250, strlen(buf));
}

View file

@ -31,7 +31,8 @@ TEST(strsignal, test) {
}
TEST(strsignal, realtime) {
if (!SIGRTMIN) return;
if (!SIGRTMIN)
return;
EXPECT_STREQ("SIGTHR", strsignal(SIGTHR));
ASSERT_STREQ("SIGRTMIN+1", strsignal(SIGRTMIN + 1));
}