From af978bbc91ccd1208b5a11f609a3e89d83252b1c Mon Sep 17 00:00:00 2001 From: dzaima Date: Sat, 3 Dec 2022 23:58:33 +0200 Subject: [PATCH] cave in and initialize variables in gcc --- src/builtins/md1.c | 6 ++---- src/builtins/md2.c | 2 +- src/builtins/sfns.c | 2 +- src/builtins/slash.c | 3 ++- src/h.h | 5 +++++ 5 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/builtins/md1.c b/src/builtins/md1.c index 5f0eea6e..4d17459b 100644 --- a/src/builtins/md1.c +++ b/src/builtins/md1.c @@ -1,6 +1,3 @@ -#if defined(__GNUC__) && !defined(__clang__) // have to do this at the very top because diagnostic ignoring works based on the callee location, not caller - #pragma GCC diagnostic ignored "-Wmaybe-uninitialized" -#endif #include "../core.h" #include "../utils/each.h" #include "../utils/file.h" @@ -150,12 +147,13 @@ static B m1c2(B t, B f, B w, B x) { // consumes w,x #pragma GCC diagnostic push #ifdef __clang__ #pragma GCC diagnostic ignored "-Wsometimes-uninitialized" + // no gcc case because there's no way to do it specifically for this segment of code; X##_csh is just initialized with an unused null pointer #endif #define S_SLICES(X) \ BSS2A X##_slc = TI(X,slice); \ usz X##_csz = 1; \ usz X##_cr = RNK(X)-1; \ - ShArr* X##_csh; \ + ShArr* X##_csh ONLY_GCC(=0); \ if (X##_cr>1) { \ X##_csh = m_shArr(X##_cr); \ PLAINLOOP for (usz i = 0; i < X##_cr; i++) { \ diff --git a/src/builtins/md2.c b/src/builtins/md2.c index 8f95a029..b84f8bdc 100644 --- a/src/builtins/md2.c +++ b/src/builtins/md2.c @@ -316,7 +316,7 @@ B rank_c1(Md2D* d, B x) { B f = d->f; B g = d->g; return r; } usz csz = shProd(xsh, k, xr); - ShArr* csh; + ShArr* csh ONLY_GCC(= NULL); if (cr>1) { csh = m_shArr(cr); shcpy(csh->a, xsh+k, cr); diff --git a/src/builtins/sfns.c b/src/builtins/sfns.c index 6cb09188..35dcf2cf 100644 --- a/src/builtins/sfns.c +++ b/src/builtins/sfns.c @@ -139,7 +139,7 @@ B shape_c2(B t, B w, B x) { } else { SGetU(w) i32 unkPos = -1; - i32 unkInd; + i32 unkInd ONLY_GCC(= 0); bool bad=false, good=false; for (i32 i = 0; i < nr; i++) { B c = GetU(w, i); diff --git a/src/builtins/slash.c b/src/builtins/slash.c index 1c302148..7772dcc7 100644 --- a/src/builtins/slash.c +++ b/src/builtins/slash.c @@ -268,6 +268,7 @@ static B compress_grouped(u64* wp, B x, usz wia, usz wsum, u8 xt) { xp = tyany_ptr(x); rp = m_tyarrv(&r,width,wsum,xt); } else { + ONLY_GCC(r = m_f64(0);) xp = (u8*)arr_bptr(x); usz ria = wsum*csz; if (xp != NULL) { @@ -709,7 +710,7 @@ B slash_c1(B t, B x) { B slash_c2(B t, B w, B x) { i32 wv = -1; - usz wia; + usz wia ONLY_GCC(= 0); if (isArr(w)) { if (depth(w)>1) goto base; ur wr = RNK(w); diff --git a/src/h.h b/src/h.h index 3f87c10a..1d4e2b72 100644 --- a/src/h.h +++ b/src/h.h @@ -152,6 +152,11 @@ typedef double f64; #define NOVECTORIZE #endif #define PLAINLOOP NOUNROLL NOVECTORIZE +#if EXACTLY_GCC + #define ONLY_GCC(X) X +#else + #define ONLY_GCC(X) +#endif #define JOIN0(A,B) A##B #define JOIN(A,B) JOIN0(A,B)