Re: tapeblocks is uninitialized in logtape.c

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>
Cc: Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com>, Jaime Casanova <jaime(dot)casanova(at)2ndquadrant(dot)com>, Pg Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: tapeblocks is uninitialized in logtape.c
Date: 2018-02-14 21:49:13
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org> writes:
> Tom Lane wrote:
>> Actually, on looking closer, it's more likely got something to do with
>> whether or not you used --enable-cassert. If the Assert at the top of
>> the function is disabled, then IMO a compiler that failed to complain
>> about this coding would be pretty damn broken.

> I tried removing the Assert, and my compiler doesn't complain. I
> noticed that the function is static and the only caller has its own
> assert about ntapes; yet removing that one doesn't cause a warning
> either. I made the function non-static -- still no warning.

If I make the function non-static, I get a warning (note you can't
just remove the "static" on the function itself, you also have to
change the forward declaration earlier in the file). Marking the
function pg_noinline also results in a warning.

It is darn weird that there's no warning after inlining --- the caller
is only asserting ntapes > 0, which is not strong enough to prove
that the loop must be iterated. Moreover, I see the warning even
if I leave in the "Assert(lts->nTapes >= 2)" ... so my compiler, at
least, is not using those assertions to prove the loop must iterate.

I notice that, because "lt" is initialized to NULL, the compiler
might feel it can assume that the loop iterated at least once
if control gets to the use of tapeblocks. But the whole thing
still seems weird. I think we must be looking at some squishy
spots in gcc's rules about when to issue a warning.

regards, tom lane

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Tatsuo Ishii 2018-02-14 22:26:44 Re: Is this a bug?
Previous Message Alvaro Herrera 2018-02-14 21:26:24 Re: FOR EACH ROW triggers on partitioned tables