Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1u5AXs-00DJsY-QD for pgsql-hackers@arkaria.postgresql.org; Wed, 16 Apr 2025 21:43:49 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1u5AWr-0063eR-4p for pgsql-hackers@arkaria.postgresql.org; Wed, 16 Apr 2025 21:42:45 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1u5AWq-0063bO-QE for pgsql-hackers@lists.postgresql.org; Wed, 16 Apr 2025 21:42:45 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1u5AWo-000SRZ-0n for pgsql-hackers@lists.postgresql.org; Wed, 16 Apr 2025 21:42:45 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 53GLgfVM2074635 for ; Wed, 16 Apr 2025 17:42:41 -0400 From: Tom Lane To: pgsql-hackers@lists.postgresql.org Subject: jsonapi: scary new warnings with LTO enabled MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2074633.1744839761.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Wed, 16 Apr 2025 17:42:41 -0400 Message-ID: <2074634.1744839761@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk I noticed some new warnings from buildfarm member chafer, which I'm able to reproduce locally on a Fedora 41 box by building with "meson setup build -Db_lto=3Dtrue": ninja: Entering directory `build' [1515/2472] Linking target src/interfaces/libpq/libpq.so.5.18 In function 'freeJsonLexContext', inlined from 'freeJsonLexContext' at ../src/common/jsonapi.c:688:1, inlined from 'handle_oauth_sasl_error' at ../src/interfaces/libpq/fe-a= uth-oauth.c:547:2: ../src/common/jsonapi.c:723:17: warning: 'free' called on unallocated obje= ct 'lex' [-Wfree-nonheap-object] 723 | FREE(lex); | ^ ../src/interfaces/libpq/fe-auth-oauth.c: In function 'handle_oauth_sasl_er= ror': ../src/interfaces/libpq/fe-auth-oauth.c:479:24: note: declared here 479 | JsonLexContext lex =3D {0}; | ^ [2407/2472] Linking target src/test/modules/test_json_parser/test_json_par= ser_incremental_shlib In function 'freeJsonLexContext', inlined from 'freeJsonLexContext' at ../src/common/jsonapi.c:688:1, inlined from 'main' at ../src/test/modules/test_json_parser/test_json_= parser_incremental.c:198:2: ../src/common/jsonapi.c:723:17: warning: 'free' called on unallocated obje= ct 'lex' [-Wfree-nonheap-object] 723 | FREE(lex); | ^ ../src/test/modules/test_json_parser/test_json_parser_incremental.c: In fu= nction 'main': ../src/test/modules/test_json_parser/test_json_parser_incremental.c:87:24:= note: declared here 87 | JsonLexContext lex; | ^ [2426/2472] Linking target src/test/modules/test_json_parser/test_json_par= ser_incremental In function 'pg_free', inlined from 'pfree' at ../src/common/fe_memutils.c:135:2, inlined from 'freeJsonLexContext' at ../src/common/jsonapi.c:723:3, inlined from 'freeJsonLexContext' at ../src/common/jsonapi.c:688:1, inlined from 'main' at ../src/test/modules/test_json_parser/test_json_= parser_incremental.c:198:2: ../src/common/fe_memutils.c:107:9: warning: 'free' called on unallocated o= bject 'lex' [-Wfree-nonheap-object] 107 | free(ptr); | ^ ../src/test/modules/test_json_parser/test_json_parser_incremental.c: In fu= nction 'main': ../src/test/modules/test_json_parser/test_json_parser_incremental.c:87:24:= note: declared here 87 | JsonLexContext lex; | ^ AFAICT there is no actual bug here: the FREE() call is reached only if the JSONLEX_FREE_STRUCT flag is set, which it should not be for these call sites. But evidently the LTO optimizer is not quite smart enough to realize that. It seems fairly dangerous to ignore -Wfree-nonheap-object warnings. I feel like we ought to move to prevent these somehow. I'm not sure how other than giving up on stack allocation of JsonLexContexts, though, especially if we consider the jsonapi API frozen. But seeing that there are only three such call sites and none of them seem in the least performance-critical, maybe we should just do that? regards, tom lane