Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iwEV0-0001Mx-MU for pgsql-hackers@arkaria.postgresql.org; Tue, 28 Jan 2020 00:12:58 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iwEUy-0001fv-Tg for pgsql-hackers@arkaria.postgresql.org; Tue, 28 Jan 2020 00:12:56 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iwEUy-0001fn-KH for pgsql-hackers@lists.postgresql.org; Tue, 28 Jan 2020 00:12:56 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1iwEUr-00069o-7i for pgsql-hackers@lists.postgresql.org; Tue, 28 Jan 2020 00:12:56 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id 00S0Ckv2021548 for ; Mon, 27 Jan 2020 19:12:46 -0500 From: Tom Lane To: pgsql-hackers@lists.postgresql.org Subject: New compiler warning in jsonb_plpython.c MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <21546.1580170366.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Mon, 27 Jan 2020 19:12:46 -0500 Message-ID: <21547.1580170366@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk I see that buildfarm member caiman is generating a warning [1]: jsonb_plpython.c: In function \xe2\x80\x98PLyObject_ToJsonbValue\xe2\x80\x= 99: cc1: warning: function may return address of local variable [-Wreturn-loca= l-addr] jsonb_plpython.c:413:13: note: declared here 413 | JsonbValue buf; | ^~~ It wasn't doing that a week or two ago when I last trawled the buildfarm for warnings ... but this is unsurprising considering that the compiler it's using is hot off the presses: configure: using compiler=3Dgcc (GCC) 10.0.1 20200121 (Red Hat 10.0.1-0.4) The warning is from code like this: { JsonbValue buf; JsonbValue *out; ... if (*jsonb_state) out =3D &buf; else out =3D palloc(sizeof(JsonbValue)); ... return (*jsonb_state ? pushJsonbValue(jsonb_state, is_elem ? WJB_ELEM : WJB_VALUE, ou= t) : out); } so I can't say I blame gcc for being unhappy. This code is safe as long as *jsonb_state doesn't change in between, and as long as pushJsonbValue doesn't expect its last argument to point at non-transient storage. But gcc doesn't want to assume that, and I don't really like the assumption either. I am thinking of trying to silence the warning by changing the return to be like return (out =3D=3D &buf ? pushJsonbValue(jsonb_state, is_elem ? WJB_ELEM : WJB_VALUE, ou= t) : out); If that doesn't work, or if anyone thinks it's too ugly, I think we should just drop the optimization of avoiding a palloc, and make this function do a palloc always. It seems unlikely that anyone would notice a performance difference, and the code would surely be less rickety. Thoughts? regards, tom lane [1] https://buildfarm.postgresql.org/cgi-bin/show_log.pl?nm=3Dcaiman&dt=3D= 2020-01-25%2015%3A00%3A52