From 002a5948fc9139abec2ecf92df8b543e093c43fb Mon Sep 17 00:00:00 2001 From: Sergey B Kirpichev Date: Sun, 3 Mar 2024 10:25:39 +0300 Subject: [PATCH] gh-108562: Fix compiler warnings for libmpdec (#114751) If awailable, enable -fstrict-overflow for libmpdec. Also shut off false positive warnings (-Warray-bounds). The later was backported from mpdecimal-4.0.0. --- Makefile.pre.in | 2 +- Misc/sbom.spdx.json | 4 ++-- Modules/_decimal/libmpdec/io.c | 1 + configure | 7 +++++++ configure.ac | 5 +++++ 5 files changed, 16 insertions(+), 3 deletions(-) diff --git a/Makefile.pre.in b/Makefile.pre.in index ee65ecd918c..396a3d4dca3 100644 --- a/Makefile.pre.in +++ b/Makefile.pre.in @@ -1213,7 +1213,7 @@ PYTHON_HEADERS= \ ########################################################################## # Build static libmpdec.a -LIBMPDEC_CFLAGS=@LIBMPDEC_CFLAGS@ $(PY_STDMODULE_CFLAGS) $(CCSHARED) +LIBMPDEC_CFLAGS=$(PY_STDMODULE_CFLAGS) @LIBMPDEC_CFLAGS@ $(CCSHARED) # "%.o: %c" is not portable Modules/_decimal/libmpdec/basearith.o: $(srcdir)/Modules/_decimal/libmpdec/basearith.c $(LIBMPDEC_HEADERS) $(PYTHON_HEADERS) diff --git a/Misc/sbom.spdx.json b/Misc/sbom.spdx.json index 27e6742292a..49c1bf54591 100644 --- a/Misc/sbom.spdx.json +++ b/Misc/sbom.spdx.json @@ -1224,11 +1224,11 @@ "checksums": [ { "algorithm": "SHA1", - "checksumValue": "12402bcf7f0161adb83f78163f41cc10a5e5de5f" + "checksumValue": "9dcb50e3f9c3245972731be5da0b28e7583198d9" }, { "algorithm": "SHA256", - "checksumValue": "cba044c76b6bc3ae6cfa49df1121cad7552140157b9e61e11cbb6580cc5d74cf" + "checksumValue": "7cac49fef5e9d952ec9390bf81c54d83f1b5da32fdf76091c2f0770ed943b7fe" } ], "fileName": "Modules/_decimal/libmpdec/io.c" diff --git a/Modules/_decimal/libmpdec/io.c b/Modules/_decimal/libmpdec/io.c index e7bd6aee170..4e95b8964c8 100644 --- a/Modules/_decimal/libmpdec/io.c +++ b/Modules/_decimal/libmpdec/io.c @@ -48,6 +48,7 @@ #if defined(__GNUC__) && !defined(__INTEL_COMPILER) && __GNUC__ >= 7 #pragma GCC diagnostic ignored "-Wimplicit-fallthrough" #pragma GCC diagnostic ignored "-Wmisleading-indentation" + #pragma GCC diagnostic ignored "-Warray-bounds" #endif diff --git a/configure b/configure index 4a980fea453..c0614138ead 100755 --- a/configure +++ b/configure @@ -14516,6 +14516,13 @@ else $as_nop LIBMPDEC_LDFLAGS="-lm \$(LIBMPDEC_A)" LIBMPDEC_INTERNAL="\$(LIBMPDEC_HEADERS) \$(LIBMPDEC_A)" + if test "x$ac_cv_cc_supports_fstrict_overflow" = xyes +then : + + as_fn_append LIBMPDEC_CFLAGS " -fstrict-overflow" + +fi + if test "x$with_pydebug" = xyes then : diff --git a/configure.ac b/configure.ac index 103c24962b7..e40b8e0d0de 100644 --- a/configure.ac +++ b/configure.ac @@ -3896,6 +3896,11 @@ AS_VAR_IF([with_system_libmpdec], [yes], [ LIBMPDEC_LDFLAGS="-lm \$(LIBMPDEC_A)" LIBMPDEC_INTERNAL="\$(LIBMPDEC_HEADERS) \$(LIBMPDEC_A)" + dnl Enable strict-overflow for libmpdec, if available, see GH-108562 + AS_VAR_IF([ac_cv_cc_supports_fstrict_overflow], [yes], [ + AS_VAR_APPEND([LIBMPDEC_CFLAGS], [" -fstrict-overflow"]) + ]) + dnl Disable forced inlining in debug builds, see GH-94847 AS_VAR_IF([with_pydebug], [yes], [ AS_VAR_APPEND([LIBMPDEC_CFLAGS], [" -DTEST_COVERAGE"])