git » libfiu » commit d323d8d

tests/generated: Disable optimizations to avoid false positives

author Alberto Bertogli
2025-09-06 11:54:59 UTC
committer Alberto Bertogli
2025-09-06 11:54:59 UTC
parent c1ffbbca6640e5e877a3fdd3b3da13361028bba7

tests/generated: Disable optimizations to avoid false positives

The code of the generated tests are fairly simple, and the compiler may
inline or optimize away some of the calls of the functions under test,
causing false positives.

Unfortunately, there's nothing we can do about intercepting inlined
functions (and much less calls that are optimized away), that's an
intrinsic limitation of the library and nothing new. And as compilers
change, the optimizations may cause different false positives in our
tests.

This happened in https://bugs.debian.org/1097184 where the malloc() call
was being optimized away by `gcc-15 -O2`, and causing a new false
positive.

This patch fixes/works around the problem by passing `-O0` to disable
optimizations in the compilation of the generated tests.

Ideally we would do something more targeted, but for now this is good
enough to prevent most of the problems.

tests/generated/Makefile +6 -0

diff --git a/tests/generated/Makefile b/tests/generated/Makefile
index 05e7498..7018801 100644
--- a/tests/generated/Makefile
+++ b/tests/generated/Makefile
@@ -11,6 +11,12 @@ ifdef PROFILE
 ALL_CFLAGS += -g -pg -fprofile-arcs -ftest-coverage
 endif
 
+# Note we pass -O0 (after $CFLAGS) to explicitly disable optimizations;
+# otherwise, the compiler may inline or optimize away some of the functions
+# under test, causing false positives.
+# See https://bugs.debian.org/1097184 for an example.
+ALL_CFLAGS += -O0
+
 ifneq ($(V), 1)
 	NICE_CC = @echo "  CC  $@"; $(CC)
 	NICE_RUN = @echo "  RUN $<"; \