From 47c778d3b8d09f9ec84f0336db6eafda175e63b3 Mon Sep 17 00:00:00 2001
From: Narek Galstyan <narekg@berkeley.edu>
Date: Sun, 19 Apr 2026 22:11:23 -0400
Subject: [PATCH 2/3] Add minimal lcov --ignore-errors flags to avoid `make
 coverage-html` failure on lcov v2

Without this change, lcov v2 fails with:

genhtml: ERROR: (corrupt) unable to read trace file 'lcov_base.info':
genhtml: ERROR: (inconsistent) "lcov_base.info":507880: duplicate
function 'blockreftable_create' starts on line
"/home/admin/postgres/src/include/lib/simplehash.h":450 but previous
definition started on 447 while merging lcov_base.info while loading
lcov_base.info.
        (use "genhtml --ignore-errors inconsistent ..." to bypass this
error)
        (use "genhtml --ignore-errors corrupt ..." to bypass this error)
make: *** [src/Makefile.global:1055: coverage-html-stamp] Error 1
---
 configure.ac           | 6 ++++++
 src/Makefile.global.in | 4 ++--
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/configure.ac b/configure.ac
index 8d176bd3468..12006b0b4b6 100644
--- a/configure.ac
+++ b/configure.ac
@@ -207,11 +207,17 @@ PGAC_PATH_PROGS(LCOV, lcov)
 if test -z "$LCOV"; then
   AC_MSG_ERROR([lcov not found])
 fi
+lcov_version=$($LCOV --version 2>/dev/null | sed 's/^.* //')
+lcov_major_version=$(echo "$lcov_version" | sed 's/\..*//')
+if test "$lcov_major_version" -ge 2 2>/dev/null; then
+  LCOV_EXTRA_FLAGS="--ignore-errors inconsistent,range"
+fi
 PGAC_PATH_PROGS(GENHTML, genhtml)
 if test -z "$GENHTML"; then
   AC_MSG_ERROR([genhtml not found])
 fi])
 AC_SUBST(enable_coverage)
+AC_SUBST(LCOV_EXTRA_FLAGS)
 
 #
 # DTrace
diff --git a/src/Makefile.global.in b/src/Makefile.global.in
index dbd5f9d3c40..e0766325d60 100644
--- a/src/Makefile.global.in
+++ b/src/Makefile.global.in
@@ -1047,7 +1047,7 @@ coverage: $(local_gcda_files:.gcda=.c.gcov)
 .PHONY: coverage-html
 coverage-html: coverage-html-stamp
 
-GENHTML_FLAGS = -q --legend
+GENHTML_FLAGS = -q --legend @LCOV_EXTRA_FLAGS@
 GENHTML_TITLE = PostgreSQL $(VERSION)
 
 coverage-html-stamp: lcov_base.info lcov_test.info
@@ -1056,7 +1056,7 @@ coverage-html-stamp: lcov_base.info lcov_test.info
 	touch $@
 
 LCOV += --gcov-tool $(GCOV)
-LCOVFLAGS = -q --no-external
+LCOVFLAGS = -q --no-external @LCOV_EXTRA_FLAGS@
 
 all_gcno_files = $(shell find . -name '*.gcno' -print)
 
-- 
2.50.1 (Apple Git-155)

