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 1rXoaH-00CnOm-Ey for pgsql-hackers@arkaria.postgresql.org; Wed, 07 Feb 2024 20:31:55 +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 1rXoaF-00DEua-ET for pgsql-hackers@arkaria.postgresql.org; Wed, 07 Feb 2024 20:31:51 +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 1rXoaD-00DEuS-N0 for pgsql-hackers@lists.postgresql.org; Wed, 07 Feb 2024 20:31:51 +0000 Received: from wout1-smtp.messagingengine.com ([64.147.123.24]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rXoa9-0060XS-0j for pgsql-hackers@lists.postgresql.org; Wed, 07 Feb 2024 20:31:48 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailout.west.internal (Postfix) with ESMTP id 1EB543200A12; Wed, 7 Feb 2024 15:31:41 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Wed, 07 Feb 2024 15:31:41 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=anarazel.de; h= cc:cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm3; t=1707337900; x=1707424300; bh=Es6XSVW31+udLkRR1QYwKGV8gjttbYVF7lycYKMLuZg=; b= vW85s6OoAfQZBtvTsPcaAMsi5M09/+0Mb1ZtIAIdnGNBLj9E1KqIvy+7ACMP5Occ rd6ZRbRHKvUNphgez5t0zInEbz5H+9JXYQTblUVikNfrjNpoekFvZxDIE4iwd1G8 IejuGHAOh0Fe2kAbnc1K7dic1/HCTF3j4tmo9UU+gFCF6fkf8hZNvYgA2zMS1R5Q z1KHO2VeSbR9uUnNaiPUbiuHBNJ0KW0hxF6kVJyc5LmNIYIkRNINRYyV2U3Ugg9V hNOnczeFxshA3ucTTqf2f0gHKHlxRwhqx04ARCcpksom4jfPyrchsAmmpZbrnEHd Lmq/6zvCp8knWkC7Ew2Hog== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t=1707337900; x= 1707424300; bh=Es6XSVW31+udLkRR1QYwKGV8gjttbYVF7lycYKMLuZg=; b=Y WEi+vE708dpjVn8DeDRgrH3pBd1BvNNviyueV1LZ1juHrSa4weJ67MWwKaKH85/l Mta59QfitQ+a9SmT0bdcNwC1xrBAjF1+Zjxddsc2kdFGP77lfN3GRnECTTyPCDnp ChTDM79eZesnp0W5cuHsPFVri7kqyw0G8a53JGelHbC7JEYabmg2fwohsuHuVK6P gAlmeAKhU7nZMctehHawtL78QXOIUmBGQGGNiQ/5uIyK7jG0JO58q2V01n3LgKPQ injFzD4Z5Ibdc2KIXr194GzHG1v3EieY5LGLaGbcTkOGFowH9JrUsAH56TQkUKz7 TX61G3o9DRSI+pXviHpHA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrtddvgddufeehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggugfgjsehtkeertddttdejnecuhfhrohhmpeetnhgu rhgvshcuhfhrvghunhguuceorghnughrvghssegrnhgrrhgriigvlhdruggvqeenucggtf frrghtthgvrhhnpefhieetgfelveettdffjeevudejkeejudfgtdevffejledvtdefkeeg gfejhffggeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhroh hmpegrnhgurhgvshesrghnrghrrgiivghlrdguvg X-ME-Proxy: Feedback-ID: id4a34324:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 7 Feb 2024 15:31:39 -0500 (EST) Date: Wed, 7 Feb 2024 12:31:38 -0800 From: Andres Freund To: Tom Lane Cc: Bharath Rupireddy , Alexander Korotkov , pgsql-hackers@lists.postgresql.org Subject: gcc build warnings at -O3 Message-ID: <20240207203138.sknifhlppdtgtxnk@awork3.anarazel.de> References: <375043.1705028119@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <375043.1705028119@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, On 2024-01-11 21:55:19 -0500, Tom Lane wrote: > Bharath Rupireddy writes: > > Hi, I'm seeing a compiler warning with CFLAGS -O3 but not with -O2. > > > In file included from dbcommands.c:20: > > dbcommands.c: In function ‘createdb’: > > ../../../src/include/postgres.h:104:16: warning: ‘src_hasloginevt’ may > > be used uninitialized in this function [-Wmaybe-uninitialized] > > Hmm, I also see that at -O3 (not at -O2) when using Fedora 39's > gcc 13.2.1, but *not* when using RHEL8's gcc 8.5.0. It's visible here with gcc >= 10. That's enough versions that I think we should care. Interestingly enough, it seems to have recently have gotten fixed in gcc master (14 to be). > Some of them match up with warnings we're seeing on buildfarm member > serinus, which I seem to recall that Andres had tracked to a known gcc bug. Some, but I don't think all. > In file included from ../../../../src/include/executor/instrument.h:16, > from pgstat_io.c:19: > pgstat_io.c: In function 'pgstat_count_io_op_time': > pgstat_io.c:149:60: warning: array subscript 2 is above array bounds of 'instr_time[2][4][8]' [-Warray-bounds=] > 149 | INSTR_TIME_ADD(PendingIOStats.pending_times[io_object][io_context][io_op], > | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~ Huh, I don't see that with any version of gcc I tried. > 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:8349:2: > ../../../../src/include/varatt.h:230:36: warning: array subscript 0 is outside array bounds of 'char[0]' [-Warray-bounds=] > 230 | (((varattrib_1b_e *) (PTR))->va_tag) > | ^ > ../../../../src/include/varatt.h:94:12: note: in definition of macro 'VARTAG_IS_EXPANDED' > 94 | (((tag) & ~1) == VARTAG_EXPANDED_RO) > | ^~~ > ../../../../src/include/varatt.h:284:57: note: in expansion of macro 'VARTAG_1B_E' > 284 | #define VARTAG_EXTERNAL(PTR) VARTAG_1B_E(PTR) > | ^~~~~~~~~~~ > ../../../../src/include/varatt.h:301:57: note: in expansion of macro 'VARTAG_EXTERNAL' > 301 | (VARATT_IS_EXTERNAL(PTR) && !VARTAG_IS_EXPANDED(VARTAG_EXTERNAL(PTR))) > | ^~~~~~~~~~~~~~~ > pl_exec.c:8537:17: note: in expansion of macro 'VARATT_IS_EXTERNAL_NON_EXPANDED' > 8537 | VARATT_IS_EXTERNAL_NON_EXPANDED(DatumGetPointer(newvalue))) > | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > In function 'exec_set_found': > cc1: note: source object is likely at address zero This I see. If I hint to the compiler that var->datatype->typlen != 1 when called from exec_set_found(), the warning vanishes. E.g. with if (var->datatype->typlen == -1) __builtin_unreachable(); I see one more warning: [1390/2375 42 58%] Compiling C object src/backend/postgres_lib.a.p/utils_adt_jsonb_util.c.o ../../../../../home/andres/src/postgresql/src/backend/utils/adt/jsonb_util.c: In function 'compareJsonbContainers': ../../../../../home/andres/src/postgresql/src/backend/utils/adt/jsonb_util.c:296:34: warning: 'va.type' may be used uninitialized [-Wmaybe-uninitialized] 296 | res = (va.type > vb.type) ? 1 : -1; | ~~^~~~~ ../../../../../home/andres/src/postgresql/src/backend/utils/adt/jsonb_util.c:204:33: note: 'va' declared here 204 | JsonbValue va, | ^~ I can't really blame the compiler here. There's a fairly lengthy comment explaining that va.type/vb.type are set, and it took me a while to understand: /* * It's safe to assume that the types differed, and that the va * and vb values passed were set. * * If the two values were of the same container type, then there'd * have been a chance to observe the variation in the number of * elements/pairs (when processing WJB_BEGIN_OBJECT, say). They're * either two heterogeneously-typed containers, or a container and * some scalar type. * * We don't have to consider the WJB_END_ARRAY and WJB_END_OBJECT * cases here, because we would have seen the corresponding * WJB_BEGIN_ARRAY and WJB_BEGIN_OBJECT tokens first, and * concluded that they don't match. */ It's not surprising that the compiler can't understand that you can't get ra = WJB_DONE, rb = WJB_END_ARRAY or such. Greetings, Andres Freund