Compilation error with buildtype = release
Hi Tom,
I am seeing following error only with buildtype = release
FAILED: contrib/postgres_fdw/postgres_fdw.so.p/postgres_fdw.c.o
cc -Icontrib/postgres_fdw/postgres_fdw.so.p -Isrc/include
-I../../coderoot/pg/src/include -Isrc/interfaces/libpq
-I../../coderoot/pg/src/interfaces/libpq -fdiagnostics-color=always
-D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Werror -O3
-fno-strict-aliasing -fwrapv -fexcess-precision=standard -D_GNU_SOURCE
-Wmissing-prototypes -Wpointer-arith -Werror=vla -Wendif-labels
-Wmissing-format-attribute -Wimplicit-fallthrough=3
-Wcast-function-type -Wshadow=compatible-local -Wformat-security
-Wdeclaration-after-statement -Wno-format-truncation
-Wno-stringop-truncation -fPIC -pthread -fvisibility=hidden -MD -MQ
contrib/postgres_fdw/postgres_fdw.so.p/postgres_fdw.c.o -MF
contrib/postgres_fdw/postgres_fdw.so.p/postgres_fdw.c.o.d -o
contrib/postgres_fdw/postgres_fdw.so.p/postgres_fdw.c.o -c
../../coderoot/pg/contrib/postgres_fdw/postgres_fdw.c
../../coderoot/pg/contrib/postgres_fdw/postgres_fdw.c: In function
‘postgresAcquireSampleRowsFunc’:
../../coderoot/pg/contrib/postgres_fdw/postgres_fdw.c:5287:28: error:
‘reltuples’ may be used uninitialized in this function
[-Werror=maybe-uninitialized]
5287 | *totalrows = reltuples;
| ~~~~~~~~~~~^~~~~~~~~~~
cc1: all warnings being treated as errors
meson setup command is
meson setup /build/prod --prefix /build/prod --werror --buildtype=release
Looking at the function, reltuples is indeed initialized in all the
cases. All the relevant lines of the function are at least 3 years
old, but I have started seeing this error only after
80aa9848befc13c188d2775a859deaf172fdd3a2.
Reading the code, reltuples is getting initialized in all the cases
when it's used i.e when method != ANALYZE_SAMPLE_OFF. I can't figure
out why that commit would cause this error. If I `git checkout
7d8f5957792421ec3bb9d1b9b6ca25d689d974b7` and build, I do not see the
error.
Compiler version
$ gcc --version
gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0
Copyright (C) 2021 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
If I make the change as per attached patch, it compiles without an
error. I don't claim that the patch is the right thing to do, but it
might provide a hint.
--
Best Wishes,
Ashutosh Bapat
Attachments:
init_reltuples.difftext/x-patch; charset=US-ASCII; name=init_reltuples.diffDownload
diff --git a/contrib/postgres_fdw/postgres_fdw.c b/contrib/postgres_fdw/postgres_fdw.c
index 25b287be069..b51ff108741 100644
--- a/contrib/postgres_fdw/postgres_fdw.c
+++ b/contrib/postgres_fdw/postgres_fdw.c
@@ -5177,6 +5177,8 @@ postgresAcquireSampleRowsFunc(Relation relation, int elevel,
Assert(sample_frac >= 0.0 && sample_frac <= 1.0);
}
}
+ else
+ reltuples = 0;
/*
* For "auto" method, pick the one we believe is best. For servers with
Ashutosh Bapat <ashutosh.bapat.oss@gmail.com> writes:
I am seeing following error only with buildtype = release
Interesting. I noticed skink showing the same thing as a warning,
but no other BF animals have shown it (yet anyway).
Looking at the function, reltuples is indeed initialized in all the
cases. All the relevant lines of the function are at least 3 years
old, but I have started seeing this error only after
80aa9848befc13c188d2775a859deaf172fdd3a2.
Yeah. The variable is clearly initialized in all cases where it's
used, but a compiler doing sloppy flow analysis might complain.
I suspect the relevance of 80aa9848b is that when there was a PG_TRY
in the function, these compilers backed off and didn't try to do flow
analysis at all.
If I make the change as per attached patch, it compiles without an
error. I don't claim that the patch is the right thing to do, but it
might provide a hint.
Usually my answer to this sort of thing is to provide an initializer
for the variable. Will fix.
regards, tom lane
On Tue, Jul 29, 2025 at 6:36 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:
Ashutosh Bapat <ashutosh.bapat.oss@gmail.com> writes:
I am seeing following error only with buildtype = release
Interesting. I noticed skink showing the same thing as a warning,
but no other BF animals have shown it (yet anyway).Looking at the function, reltuples is indeed initialized in all the
cases. All the relevant lines of the function are at least 3 years
old, but I have started seeing this error only after
80aa9848befc13c188d2775a859deaf172fdd3a2.Yeah. The variable is clearly initialized in all cases where it's
used, but a compiler doing sloppy flow analysis might complain.
I suspect the relevance of 80aa9848b is that when there was a PG_TRY
in the function, these compilers backed off and didn't try to do flow
analysis at all.If I make the change as per attached patch, it compiles without an
error. I don't claim that the patch is the right thing to do, but it
might provide a hint.Usually my answer to this sort of thing is to provide an initializer
for the variable. Will fix.
Thanks.
--
Best Wishes,
Ashutosh Bapat