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 1u8MzG-002JkD-PR for pgsql-hackers@arkaria.postgresql.org; Fri, 25 Apr 2025 17:37:19 +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 1u8MzE-00DnEx-UL for pgsql-hackers@arkaria.postgresql.org; Fri, 25 Apr 2025 17:37:17 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1u8MzE-00DnEG-KU for pgsql-hackers@lists.postgresql.org; Fri, 25 Apr 2025 17:37:17 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1u8MzD-001vdk-15 for pgsql-hackers@lists.postgresql.org; Fri, 25 Apr 2025 17:37:16 +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 53PHbFfL1985047 for ; Fri, 25 Apr 2025 13:37:15 -0400 From: Tom Lane To: pgsql-hackers@lists.postgresql.org Subject: gcc 15 "array subscript 0" warning at level -O3 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1985045.1745602635.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Fri, 25 Apr 2025 13:37:15 -0400 Message-ID: <1985046.1745602635@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Whilst poking at Erik Rijkers' nearby report, I found that Fedora 42's gcc 15.0.1 will produce this complaint if you select optimization level -O3: In file included from ../../../../src/include/access/htup_details.h:22, from pl_exec.c:21: In function 'assign_simple_var', inlined from 'exec_set_found' at pl_exec.c:8609:2: ../../../../src/include/varatt.h:230:36: warning: array subscript 0 is out= side array bounds of 'char[0]' [-Warray-bounds=3D] 230 | (((varattrib_1b_e *) (PTR))->va_tag) | ^ ../../../../src/include/varatt.h:94:12: note: in definition of macro 'VART= AG_IS_EXPANDED' 94 | (((tag) & ~1) =3D=3D VARTAG_EXPANDED_RO) | ^~~ ../../../../src/include/varatt.h:284:57: note: in expansion of macro 'VART= AG_1B_E' 284 | #define VARTAG_EXTERNAL(PTR) VARTAG_1B_= E(PTR) | ^~~~~~~~~~= ~ ../../../../src/include/varatt.h:301:57: note: in expansion of macro 'VART= AG_EXTERNAL' 301 | (VARATT_IS_EXTERNAL(PTR) && !VARTAG_IS_EXPANDED(VARTAG_EXT= ERNAL(PTR))) | ^~~~~~~~~~= ~~~~~ pl_exec.c:8797:17: note: in expansion of macro 'VARATT_IS_EXTERNAL_NON_EXP= ANDED' 8797 | VARATT_IS_EXTERNAL_NON_EXPANDED(DatumGetPointer(ne= wvalue))) | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ In function 'exec_set_found': cc1: note: source object is likely at address zero Buildfarm member serinus has been producing the identical warning for some time. I'd been ignoring that because it runs "experimental gcc", but I guess the experiment has leaked out to production distros. What seems to be happening here is that after inlining assign_simple_var into exec_set_found, the compiler decides that "newvalue" might be zero (since it's a BoolGetDatum result), and then it warns -- in a rather strange way -- about the potential null dereference. The dereference is not reachable because of the preceding "var->datatype->typlen =3D=3D -1" check, but that's not stopping the optimizer from bitching. I experimented with modifying exec_set_found thus: var =3D (PLpgSQL_var *) (estate->datums[estate->found_varno]); + Assert(var->datatype->typlen =3D=3D 1); assign_simple_var(estate, var, BoolGetDatum(state), false, false); which should be OK since we're expecting the "found" variable to be boolean. That does silence the warning, but of course only in --enable-cassert builds. Anybody have an idea about how to silence it more effectively? There are going to be more people seeing this as gcc 15 propagates. regards, tom lane