From adce4a9ae4082f96d6028db6f354c78cb4848aba Mon Sep 17 00:00:00 2001 From: Justin Traglia Date: Tue, 24 Feb 2026 14:15:08 -0600 Subject: [PATCH 1/3] Allow compiler overrides & only use some flags for clang --- src/Makefile | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/Makefile b/src/Makefile index 96745cb58..09e3ec373 100644 --- a/src/Makefile +++ b/src/Makefile @@ -20,7 +20,7 @@ ifeq ($(PLATFORM),Darwin) endif # The base compiler flags. More can be added on command line. -CFLAGS += -I. -I../inc -O2 -Werror -Wno-gnu-folding-constant +CFLAGS += -I. -I../inc -O2 # Enable a bunch of optional warnings. CFLAGS += \ -pedantic \ @@ -75,13 +75,15 @@ CFLAGS += \ # Cross-platform compilation settings. ifeq ($(PLATFORM),Windows) - CC = gcc + CC ?= gcc CFLAGS += -D_CRT_SECURE_NO_WARNINGS CFLAGS += -Wno-missing-braces -Wno-format else - CC = clang - CFLAGS += -fPIC - CFLAGS += -Wmissing-braces -Wformat=2 + CC ?= clang + CFLAGS += -fPIC -Wmissing-braces +ifeq ($(CC),clang) + CFLAGS += -Werror -Wno-gnu-folding-constant -Wformat=2 +endif endif # Settings for blst. From c069da9e70a42840a3202f0925a8062cb5bb796e Mon Sep 17 00:00:00 2001 From: Justin Traglia Date: Tue, 24 Feb 2026 14:30:25 -0600 Subject: [PATCH 2/3] Fix braces & require CC=clang for sanitize --- .github/workflows/c-tests.yml | 2 +- src/Makefile | 5 ++++- src/common/ec.h | 2 +- src/common/fr.h | 6 +++--- src/eip7594/fft.c | 4 ++-- src/setup/setup.c | 2 +- 6 files changed, 12 insertions(+), 9 deletions(-) diff --git a/.github/workflows/c-tests.yml b/.github/workflows/c-tests.yml index 7353e59ba..2e3c373d3 100644 --- a/.github/workflows/c-tests.yml +++ b/.github/workflows/c-tests.yml @@ -53,7 +53,7 @@ jobs: # Doesn't work on Windows. - name: Clang Sanitizers if: matrix.os != 'windows-latest' - run: make sanitize + run: CC=clang make sanitize # Run static analyzer. # Doesn't work on Windows. diff --git a/src/Makefile b/src/Makefile index 09e3ec373..9b20452aa 100644 --- a/src/Makefile +++ b/src/Makefile @@ -221,7 +221,10 @@ sanitize_%: blst $(SOURCE_FILES) $(HEADER_FILES) ./$@; rm $@ .PHONY: sanitize -ifeq ($(PLATFORM),Darwin) +ifneq ($(CC),clang) +sanitize: + $(error sanitize requires CC=clang) +else ifeq ($(PLATFORM),Darwin) sanitize: \ sanitize_address \ sanitize_undefined diff --git a/src/common/ec.h b/src/common/ec.h index c2cc0f0cb..0db819814 100644 --- a/src/common/ec.h +++ b/src/common/ec.h @@ -32,7 +32,7 @@ typedef blst_p2 g2_t; /**< Internal G2 group element type. */ /** Deserialized form of the G1 identity/infinity point. */ static const g1_t G1_IDENTITY = { - {0L, 0L, 0L, 0L, 0L, 0L}, {0L, 0L, 0L, 0L, 0L, 0L}, {0L, 0L, 0L, 0L, 0L, 0L} + {{0L, 0L, 0L, 0L, 0L, 0L}}, {{0L, 0L, 0L, 0L, 0L, 0L}}, {{0L, 0L, 0L, 0L, 0L, 0L}} }; //////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/common/fr.h b/src/common/fr.h index 0e97242bb..519051e5e 100644 --- a/src/common/fr.h +++ b/src/common/fr.h @@ -41,16 +41,16 @@ typedef blst_fr fr_t; /**< Internal Fr field element type. */ //////////////////////////////////////////////////////////////////////////////////////////////////// /** The zero field element. */ -static const fr_t FR_ZERO = {0L, 0L, 0L, 0L}; +static const fr_t FR_ZERO = {{0L, 0L, 0L, 0L}}; /** This is 1 in blst's `blst_fr` limb representation. Crazy but true. */ static const fr_t FR_ONE = { - 0x00000001fffffffeL, 0x5884b7fa00034802L, 0x998c4fefecbc4ff5L, 0x1824b159acc5056fL + {0x00000001fffffffeL, 0x5884b7fa00034802L, 0x998c4fefecbc4ff5L, 0x1824b159acc5056fL} }; /** This used to represent a missing element. It's an invalid value. */ static const fr_t FR_NULL = { - 0xffffffffffffffffL, 0xffffffffffffffffL, 0xffffffffffffffffL, 0xffffffffffffffffL + {0xffffffffffffffffL, 0xffffffffffffffffL, 0xffffffffffffffffL, 0xffffffffffffffffL} }; //////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/eip7594/fft.c b/src/eip7594/fft.c index 91ddd83d8..a629652f1 100644 --- a/src/eip7594/fft.c +++ b/src/eip7594/fft.c @@ -35,7 +35,7 @@ * printf("%#018llxL,\n", a.l[i]); */ static const fr_t RECOVERY_SHIFT_FACTOR = { - 0x0000000efffffff1L, 0x17e363d300189c0fL, 0xff9c57876f8457b0L, 0x351332208fc5a8c4L + {0x0000000efffffff1L, 0x17e363d300189c0fL, 0xff9c57876f8457b0L, 0x351332208fc5a8c4L} }; /** @@ -48,7 +48,7 @@ static const fr_t RECOVERY_SHIFT_FACTOR = { * printf("%#018llxL,\n", a.l[i]); */ static const fr_t INV_RECOVERY_SHIFT_FACTOR = { - 0xdb6db6dadb6db6dcL, 0xe6b5824adb6cc6daL, 0xf8b356e005810db9L, 0x66d0f1e660ec4796L + {0xdb6db6dadb6db6dcL, 0xe6b5824adb6cc6daL, 0xf8b356e005810db9L, 0x66d0f1e660ec4796L} }; //////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/setup/setup.c b/src/setup/setup.c index 5d8d4972d..1686afaef 100644 --- a/src/setup/setup.c +++ b/src/setup/setup.c @@ -79,7 +79,7 @@ * factor changes, this constant is no longer correct. */ static const fr_t ROOT_OF_UNITY = { - 0xa33d279ff0ccffc9L, 0x41fac79f59e91972L, 0x065d227fead1139bL, 0x71db41abda03e055L + {0xa33d279ff0ccffc9L, 0x41fac79f59e91972L, 0x065d227fead1139bL, 0x71db41abda03e055L} }; //////////////////////////////////////////////////////////////////////////////////////////////////// From c01d5b4ab9a9e765d11ae42b7fa10c5e190a80d1 Mon Sep 17 00:00:00 2001 From: Justin Traglia Date: Tue, 24 Feb 2026 14:40:45 -0600 Subject: [PATCH 3/3] Move -Wmissing-braces to default flags --- src/Makefile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Makefile b/src/Makefile index 9b20452aa..946c8fd55 100644 --- a/src/Makefile +++ b/src/Makefile @@ -43,6 +43,7 @@ CFLAGS += \ -Winit-self \ -Winline \ -Winvalid-pch \ + -Wmissing-braces \ -Wmissing-declarations \ -Wmissing-field-initializers \ -Wmissing-format-attribute \ @@ -77,10 +78,10 @@ CFLAGS += \ ifeq ($(PLATFORM),Windows) CC ?= gcc CFLAGS += -D_CRT_SECURE_NO_WARNINGS - CFLAGS += -Wno-missing-braces -Wno-format + CFLAGS += -Wno-format else CC ?= clang - CFLAGS += -fPIC -Wmissing-braces + CFLAGS += -fPIC ifeq ($(CC),clang) CFLAGS += -Werror -Wno-gnu-folding-constant -Wformat=2 endif