From debbugs-submit-bounces@debbugs.gnu.org Fri Jun 10 18:30:23 2022 Received: (at submit) by debbugs.gnu.org; 10 Jun 2022 22:30:23 +0000 Received: from localhost ([127.0.0.1]:51513 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nzn95-0004dP-AU for submit@debbugs.gnu.org; Fri, 10 Jun 2022 18:30:23 -0400 Received: from lists.gnu.org ([209.51.188.17]:45200) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nzn93-0004dH-2Z for submit@debbugs.gnu.org; Fri, 10 Jun 2022 18:30:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47534) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nzn90-000740-JC for bug-coreutils@gnu.org; Fri, 10 Jun 2022 18:30:20 -0400 Received: from outgoing-auth-1.mit.edu ([18.9.28.11]:53402 helo=outgoing.mit.edu) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nzn8y-00060J-FX for bug-coreutils@gnu.org; Fri, 10 Jun 2022 18:30:17 -0400 Received: from localhost (TARDIS-ON-THE-DOME.MIT.EDU [18.9.64.28]) (authenticated bits=0) (User authenticated as andersk@ATHENA.MIT.EDU) by outgoing.mit.edu (8.14.7/8.12.4) with ESMTP id 25AMOFpM023432 for ; Fri, 10 Jun 2022 18:24:15 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mit.edu; s=outgoing; t=1654899856; bh=VWiBcjKz5sHVVIFtfFjsX+ZA+DXQjHpFx07OR39Yf+o=; h=Date:From:To:Subject; b=qV5gjdPWXrpi8MPaxrdCEv6lG9AHlgZ+12e2OTKYEd0b9chx2Wr3GKCGxQ+NXyigg ECBTOO86OYYur++1Aq8Px2+rf2l80daLVSiIIfvyBNqyYcePjKisao4iS9YqjFOQhk ntJvb//aYnt4O4agQgTDmrjJ7FMbR+I/2xdtwIE0CXOUzY4jaTVMlXln6b3+l7DssI q6Mr5r3W2gPB52Yk1p5w+R1363PGAbPp+nHOcrhoMmmgN6sLeg/MM7KecPCl8qL3jq 0NFPW0g07gDT5dU9QyypM3XAuLtBn3Y6NZm1IeB9J/MUP01F06kqcBfn34kTe7AIcC 09UdRHwECp5Ag== Date: Fri, 10 Jun 2022 18:24:15 -0400 (EDT) From: Anders Kaseorg To: bug-coreutils@gnu.org Subject: [PATCH] maint: Fix ptr_align signature to silence -Wmaybe-uninitialized Message-ID: User-Agent: Alpine 2.21.999 (DEB 260 2018-02-26) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Received-SPF: pass client-ip=18.9.28.11; envelope-from=andersk@mit.edu; helo=outgoing.mit.edu X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: -1.4 (-) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.4 (--) ptr_align is always called with a pointer to uninitialized memory, so it does not make sense for that pointer to be const. This change avoids -Wmaybe-uninitialized warnings from GCC 11. Signed-off-by: Anders Kaseorg --- Some of the warnings from GCC 11.3.0 without this patch: CC src/cksum-digest.o src/digest.c: In function 'digest_check': src/digest.c:1036:31: error: 'bin_buffer_unaligned' may be used uninitialized [-Werror=maybe-uninitialized] 1036 | unsigned char *bin_buffer = ptr_align (bin_buffer_unaligned, DIGEST_ALIGN); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ In file included from src/digest.c:24: src/system.h:493:1: note: by argument 1 of type 'const void *' to 'ptr_align' declared here 493 | ptr_align (void const *ptr, size_t alignment) | ^~~~~~~~~ src/digest.c:1034:17: note: 'bin_buffer_unaligned' declared here 1034 | unsigned char bin_buffer_unaligned[DIGEST_BIN_BYTES + DIGEST_ALIGN]; | ^~~~~~~~~~~~~~~~~~~~ src/digest.c: In function 'main': src/digest.c:1247:31: error: 'bin_buffer_unaligned' may be used uninitialized [-Werror=maybe-uninitialized] 1247 | unsigned char *bin_buffer = ptr_align (bin_buffer_unaligned, DIGEST_ALIGN); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ In file included from src/digest.c:24: src/system.h:493:1: note: by argument 1 of type 'const void *' to 'ptr_align' declared here 493 | ptr_align (void const *ptr, size_t alignment) | ^~~~~~~~~ src/digest.c:1245:17: note: 'bin_buffer_unaligned' declared here 1245 | unsigned char bin_buffer_unaligned[DIGEST_BIN_BYTES + DIGEST_ALIGN]; | ^~~~~~~~~~~~~~~~~~~~ cc1: all warnings being treated as errors make[2]: *** [Makefile:20574: src/cksum-digest.o] Error 1 src/system.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/system.h b/src/system.h index 0c5c9b900..120fd15e4 100644 --- a/src/system.h +++ b/src/system.h @@ -490,7 +490,7 @@ lcm (size_t u, size_t v) locations. */ static inline void * -ptr_align (void const *ptr, size_t alignment) +ptr_align (void *ptr, size_t alignment) { char const *p0 = ptr; char const *p1 = p0 + alignment - 1; -- 2.36.1 From debbugs-submit-bounces@debbugs.gnu.org Fri Jun 10 23:23:29 2022 Received: (at 55895) by debbugs.gnu.org; 11 Jun 2022 03:23:29 +0000 Received: from localhost ([127.0.0.1]:51627 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nzrij-00044P-ID for submit@debbugs.gnu.org; Fri, 10 Jun 2022 23:23:29 -0400 Received: from zimbra.cs.ucla.edu ([131.179.128.68]:46654) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nzrig-000446-O4 for 55895@debbugs.gnu.org; Fri, 10 Jun 2022 23:23:28 -0400 Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id BB06616023C; Fri, 10 Jun 2022 20:23:20 -0700 (PDT) Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id ONzoVcP23tD6; Fri, 10 Jun 2022 20:23:20 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 01E9A16023E; Fri, 10 Jun 2022 20:23:20 -0700 (PDT) X-Virus-Scanned: amavisd-new at zimbra.cs.ucla.edu Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id 7f8Wo2-8pgy2; Fri, 10 Jun 2022 20:23:19 -0700 (PDT) Received: from [192.168.1.9] (cpe-172-91-119-151.socal.res.rr.com [172.91.119.151]) by zimbra.cs.ucla.edu (Postfix) with ESMTPSA id CDEA416023C; Fri, 10 Jun 2022 20:23:19 -0700 (PDT) Message-ID: <6290f2cc-b654-0e94-74ed-5b1f0c079e41@cs.ucla.edu> Date: Fri, 10 Jun 2022 20:23:19 -0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.9.1 Content-Language: en-US To: Anders Kaseorg References: From: Paul Eggert Organization: UCLA Computer Science Department Subject: Re: bug#55895: [PATCH] maint: Fix ptr_align signature to silence -Wmaybe-uninitialized In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 55895 Cc: 55895@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) On 6/10/22 15:24, Anders Kaseorg wrote: > ptr_align is always called with a pointer to uninitialized memory, so > it does not make sense for that pointer to be const. I don't see why not. ptr_align does not modify the referenced storage so "void const *" is appropriate. If we changed the type to "void *" we'd unnecessarily limit ptr_align's applicability. > This change avoids -Wmaybe-uninitialized warnings from GCC 11. I can't reproduce the problem with the latest coreutils commit 93e099e4c3b659b2e329f655fbdc73fdf594a66e on Savannah master on Ubuntu 22.04 LTS x86-64, I don't get warnings with either gcc (Ubuntu 11.2.0-19ubuntu1) 11.2.0 or with gcc-12 (Ubuntu 12-20220319-1ubuntu1) 12.0.1 20220319 (experimental) [master r12-7719-g8ca61ad148f]. I also don't see a problem on Fedora 36 x86-64 with gcc (GCC) 12.1.1 20220507 (Red Hat 12.1.1-1) . In all cases I configured and built with "./configure --enable-gcc-warnings; make". Perhaps the problem (whatever it was) has already been fixed in coreutils. If not, I guess that the issue has something to do with the particular platform and options you configured with. If it's an older compiler like GCC 11.3.0 I wouldn't worry too much about it, as older GCCs are notorious for false alarms and not worth the trouble of pacifying. Most likely the warnings are false positives (though I haven't checked this). From debbugs-submit-bounces@debbugs.gnu.org Sat Jun 11 00:12:08 2022 Received: (at 55895) by debbugs.gnu.org; 11 Jun 2022 04:12:08 +0000 Received: from localhost ([127.0.0.1]:51657 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nzsTo-0005Pl-JP for submit@debbugs.gnu.org; Sat, 11 Jun 2022 00:12:08 -0400 Received: from outgoing-auth-1.mit.edu ([18.9.28.11]:37987 helo=outgoing.mit.edu) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nzsTj-0005P8-LI for 55895@debbugs.gnu.org; Sat, 11 Jun 2022 00:12:07 -0400 Received: from [192.168.9.206] (157-131-223-124.fiber.dynamic.sonic.net [157.131.223.124]) (authenticated bits=0) (User authenticated as andersk@ATHENA.MIT.EDU) by outgoing.mit.edu (8.14.7/8.12.4) with ESMTP id 25B4BnWH030035 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=NOT); Sat, 11 Jun 2022 00:11:50 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mit.edu; s=outgoing; t=1654920711; bh=VcHyf1QDT9Pl7c845HBMbIXQ+frOMoVPXE190esBLGE=; h=Date:Subject:To:Cc:References:From:In-Reply-To; b=HTl7TsQBvlN5rl0COyrX5XmpI4KlKhIlXCX2NAa8MYwdiPHo9IQ2cndqwW06rhxmg rOb2DwGc1PsDQHoe5WF8MBgTzWS28sBA/FD0p64kvo6TDox+pBfbS5iIKNw8/IRrhy mGxSU9ELGAS1fII6zBR4sutZ9tGO5AsTe1VkUS0KtWtZxPD4Di2Z7uuuoMu74aYiEl Y1N12cIaHQy7mUyD1xGPfmV2gEJZbcznhoebk7zVzv5e33obwn5LJvd8dVKRvrNorY s5ggXomQ6LYAwD0kEmtO5IhXlGCE/vLtCmYNB/ayOD9mahWiGjLNm48taa4fny61Tj cTRqM+hlXHgng== Message-ID: <02620239-0ce4-3e44-f25d-ed764199cc68@mit.edu> Date: Fri, 10 Jun 2022 21:11:48 -0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.9.1 Subject: Re: bug#55895: [PATCH] maint: Fix ptr_align signature to silence -Wmaybe-uninitialized Content-Language: en-US To: Paul Eggert References: <6290f2cc-b654-0e94-74ed-5b1f0c079e41@cs.ucla.edu> From: Anders Kaseorg In-Reply-To: <6290f2cc-b654-0e94-74ed-5b1f0c079e41@cs.ucla.edu> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 55895 Cc: 55895@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) Thanks for checking. I should have nailed down the reproduction recipe more precisely; sorry for that. It seems the important step I should have included was CFLAGS=-O0. Full recipe, using the same systems you checked: Ubuntu 22.04 LTS x86-64 gcc (Ubuntu 11.2.0-19ubuntu1) 11.2.0 coreutils master, commit 93e099e4c3b659b2e329f655fbdc73fdf594a66e ./bootstrap --skip-po ./configure CFLAGS=-O0 (with or without --enable-gcc-warnings) make or Fedora 36 x86-64 gcc (GCC) 12.1.1 20220507 (Red Hat 12.1.1-1) coreutils master, commit 93e099e4c3b659b2e329f655fbdc73fdf594a66e ./bootstrap --skip-po ./configure CFLAGS=-O0 (with or without --enable-gcc-warnings) make -k (With GCC 12.1.1 I get the same error and also additional errors that might merit further investigation.) Can you reproduce with CFLAGS=-O0? On 6/10/22 20:23, Paul Eggert wrote: > On 6/10/22 15:24, Anders Kaseorg wrote: >> ptr_align is always called with a pointer to uninitialized memory, so >> it does not make sense for that pointer to be const. > > I don't see why not. ptr_align does not modify the referenced storage so > "void const *" is appropriate. If we changed the type to "void *" we'd > unnecessarily limit ptr_align's applicability. My claim is that there’s never a reason to call ptr_align with a const pointer, because if the memory is initialized the pointer would have already been aligned, and if the memory is uninitialized you’re going to need to write to it somewhere. Also, the current signature converts a const pointer to a mutable pointer. Given the squishy nature of const in C (and the general lack of language features that would make it a more reliably useful signal), I know this kind of “safety hole” is so common that I hesitate to suggest it’s really a hole. But given that it’s unnecessary we might as well avoid it. GCC’s -Wmaybe-uninitialized seems to assume that a const pointer might be read, in the absense of better information from higher optimization levels. Although this heuristic isn’t perfect (I’m not suggesting that the code is actually _wrong_), it seems reasonable enough to be worth appeasing, given that there doesn’t seem to be a notable downside. Anders From debbugs-submit-bounces@debbugs.gnu.org Sat Jun 11 12:12:19 2022 Received: (at 55895-done) by debbugs.gnu.org; 11 Jun 2022 16:12:19 +0000 Received: from localhost ([127.0.0.1]:53765 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1o03ik-0006KW-PT for submit@debbugs.gnu.org; Sat, 11 Jun 2022 12:12:19 -0400 Received: from zimbra.cs.ucla.edu ([131.179.128.68]:42344) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1o03ii-0006KF-90 for 55895-done@debbugs.gnu.org; Sat, 11 Jun 2022 12:12:17 -0400 Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 070A016011D; Sat, 11 Jun 2022 09:12:10 -0700 (PDT) Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id L_YSrHceA_Co; Sat, 11 Jun 2022 09:12:09 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 23FAD160122; Sat, 11 Jun 2022 09:12:09 -0700 (PDT) X-Virus-Scanned: amavisd-new at zimbra.cs.ucla.edu Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id yFm7c_A7JEUe; Sat, 11 Jun 2022 09:12:09 -0700 (PDT) Received: from [192.168.1.9] (cpe-172-91-119-151.socal.res.rr.com [172.91.119.151]) by zimbra.cs.ucla.edu (Postfix) with ESMTPSA id EDBF416011D; Sat, 11 Jun 2022 09:12:08 -0700 (PDT) Message-ID: Date: Sat, 11 Jun 2022 09:12:08 -0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.9.1 Content-Language: en-US To: Anders Kaseorg References: <6290f2cc-b654-0e94-74ed-5b1f0c079e41@cs.ucla.edu> <02620239-0ce4-3e44-f25d-ed764199cc68@mit.edu> From: Paul Eggert Organization: UCLA Computer Science Department Subject: Re: bug#55895: [PATCH] maint: Fix ptr_align signature to silence -Wmaybe-uninitialized In-Reply-To: <02620239-0ce4-3e44-f25d-ed764199cc68@mit.edu> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 55895-done Cc: 55895-done@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) On 6/10/22 21:11, Anders Kaseorg wrote: > It seems the important step I should=20 > have included was CFLAGS=3D-O0. Ah, OK. Since you're building from Git, I can refer you to=20 README-hacking which is intended for that. It says, "If you get warnings=20 with other configurations, you can run './configure --disable-gcc-warnings' or 'make WERROR_CFLAGS=3D' to build quietly or verbosely, respectively. " Here, "other configurations" refers to what you're doing. > (With GCC 12.1.1 I get the same error and also additional errors that m= ight merit further investigation.)=20 Like most static analysis tools, GCC generates a bunch of false=20 positives unless you baby it just right. We do the babying only for the=20 latest GCC with the default configuration; otherwise, it's typically not=20 worth the trouble. Feel free to investigate the other warnings, but=20 they're important only if they're true positives (and most likely=20 they're not, because gcc -O0 is dumber than gcc -O2). > there=E2=80=99s never a reason to call ptr_align with a const pointer, = because if the memory is initialized the pointer would have already been = aligned First, a const pointer can point to uninitialized storage. Second, even=20 if the referenced memory is initialized the pointer need not be aligned=20 already. For example, this is valid: char *p =3D malloc (1024); if (!p) return; char const *q =3D p; // q points to uninitialized storage char const *r =3D ptr_align (q, 512); // q is not aligned already memset (p, 127, 1024); ... Replacing 'malloc (1024)' with 'calloc (1024, 1)' (thus initializing the=20 storage before aligning the pointer) wouldn't affect the validity of the=20 code. > Also, the current signature converts a const pointer to a mutable point= er. Yes, it's like strchr which is annoying but that's the best C can do. You're right that changing it from void const * to void * won't hurt=20 coreutils' current callers but I'd rather not massage the code merely to=20 pacify nondefault configurations. There are too many nondefault=20 configurations to worry about and massaging the code to pacify them all=20 would waste our time and confuse the code. Instead, we pacify only=20 default configurations with current GCC. From debbugs-submit-bounces@debbugs.gnu.org Sat Jun 11 12:30:45 2022 Received: (at 55895) by debbugs.gnu.org; 11 Jun 2022 16:30:45 +0000 Received: from localhost ([127.0.0.1]:53793 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1o040b-0000b9-2M for submit@debbugs.gnu.org; Sat, 11 Jun 2022 12:30:45 -0400 Received: from outgoing-auth-1.mit.edu ([18.9.28.11]:32788 helo=outgoing.mit.edu) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1o040V-0000ab-53 for 55895@debbugs.gnu.org; Sat, 11 Jun 2022 12:30:41 -0400 Received: from [192.168.9.206] (157-131-223-124.fiber.dynamic.sonic.net [157.131.223.124]) (authenticated bits=0) (User authenticated as andersk@ATHENA.MIT.EDU) by outgoing.mit.edu (8.14.7/8.12.4) with ESMTP id 25BGUTaL024155 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=NOT); Sat, 11 Jun 2022 12:30:31 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mit.edu; s=outgoing; t=1654965031; bh=DmD7D2WUp7jHkyPScKcsH/+MUnxxlEKaOQsqbu5ZecE=; h=Date:Subject:To:Cc:References:From:In-Reply-To; b=eza1gXBB18DDn/adloMCFric+iMtgvpbiCE3pcQN23XYOGHGl2v/udiyFgJVMCWN7 a5jlwYafOV5wnvcigJVklx/IMNvVZzMn4vP9f5BF5cpz8L3j4cvyEtZQJDr6sPtWpn vtnswlUGByKKrsQEDH6Q71JlemMn7E8t7QTYWuN6a09rW6/uCxD/t34fmBB4NuwPCx 9MzaU/w9TuM5zgb5/ForI06b9cMAd74V7jAkFreg6m9+Cb2aMQUp4rLt+rDEGDfP6O B6WrXVQ3s1XTMphGd2DqHBYVLNQBV2fiz6cAMsb630OZTaU+L6Uds6ESjMYsEzzMIz FWYsPn1E8+VBg== Message-ID: Date: Sat, 11 Jun 2022 09:30:28 -0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.9.1 Subject: Re: bug#55895: [PATCH] maint: Fix ptr_align signature to silence -Wmaybe-uninitialized Content-Language: en-US To: Paul Eggert References: <6290f2cc-b654-0e94-74ed-5b1f0c079e41@cs.ucla.edu> <02620239-0ce4-3e44-f25d-ed764199cc68@mit.edu> From: Anders Kaseorg In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 55895 Cc: 55895@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) On 6/11/22 09:12, Paul Eggert wrote: > First, a const pointer can point to uninitialized storage. Of course it can, but my claim was there’s never a reason. A pointer to uninitialized (or zero-initialized) memory that won’t be written is valid but not _useful_. The reason you’d align a pointer is so you can store something there that needs to be aligned. It’s not an accident that all of the current callers work that way. Anders From debbugs-submit-bounces@debbugs.gnu.org Sat Jun 11 13:13:29 2022 Received: (at 55895) by debbugs.gnu.org; 11 Jun 2022 17:13:29 +0000 Received: from localhost ([127.0.0.1]:53853 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1o04fx-0001jW-5X for submit@debbugs.gnu.org; Sat, 11 Jun 2022 13:13:29 -0400 Received: from zimbra.cs.ucla.edu ([131.179.128.68]:47494) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1o04fv-0001jI-03 for 55895@debbugs.gnu.org; Sat, 11 Jun 2022 13:13:27 -0400 Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 1A6D5160134; Sat, 11 Jun 2022 10:13:21 -0700 (PDT) Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id TM10bIbdHeKh; Sat, 11 Jun 2022 10:13:20 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 6B863160137; Sat, 11 Jun 2022 10:13:20 -0700 (PDT) X-Virus-Scanned: amavisd-new at zimbra.cs.ucla.edu Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id OK-6FvqqF2ub; Sat, 11 Jun 2022 10:13:20 -0700 (PDT) Received: from [192.168.1.9] (cpe-172-91-119-151.socal.res.rr.com [172.91.119.151]) by zimbra.cs.ucla.edu (Postfix) with ESMTPSA id 3E521160134; Sat, 11 Jun 2022 10:13:20 -0700 (PDT) Message-ID: <7a75f892-a88c-02e6-7c2d-9b0cf58aaeff@cs.ucla.edu> Date: Sat, 11 Jun 2022 10:13:19 -0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.9.1 Content-Language: en-US To: Anders Kaseorg References: <6290f2cc-b654-0e94-74ed-5b1f0c079e41@cs.ucla.edu> <02620239-0ce4-3e44-f25d-ed764199cc68@mit.edu> From: Paul Eggert Organization: UCLA Computer Science Department Subject: Re: bug#55895: [PATCH] maint: Fix ptr_align signature to silence -Wmaybe-uninitialized In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 55895 Cc: 55895@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) On 6/11/22 09:30, Anders Kaseorg wrote: > A pointer to uninitialized (or zero-initialized) memory that won=E2=80=99= t be=20 > written is valid but not _useful_. But in the example I gave, the memory *is* written to later. A const * pointer lets a C program have a read-only window into memory=20 that other parts of the program can write to, which can be a useful=20 thing to have. In C and C++, "const *" doesn't mean a pointer to storage=20 that does not change; it merely means a pointer that can't be used to=20 write the referenced storage. From debbugs-submit-bounces@debbugs.gnu.org Sat Jun 11 17:18:23 2022 Received: (at 55895) by debbugs.gnu.org; 11 Jun 2022 21:18:23 +0000 Received: from localhost ([127.0.0.1]:54134 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1o08Ux-0001hT-Ke for submit@debbugs.gnu.org; Sat, 11 Jun 2022 17:18:23 -0400 Received: from outgoing-exchange-5.mit.edu ([18.9.28.59]:45771) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1o08Ut-0001hE-Od for 55895@debbugs.gnu.org; Sat, 11 Jun 2022 17:18:22 -0400 Received: from oc11exedge2.exchange.mit.edu (OC11EXEDGE2.EXCHANGE.MIT.EDU [18.9.3.18]) by outgoing-exchange-5.mit.edu (8.14.7/8.12.4) with ESMTP id 25BLHvVK009271; Sat, 11 Jun 2022 17:18:06 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mit.edu; s=outgoing; t=1654982286; bh=wzoF2YitGATWtvTFnEMnZ1+BuiGHAzdDwdB+T0/6jTc=; h=From:To:CC:Subject:Date:References:In-Reply-To; b=HVNkljAPyuhTucqJ5ViYsXLPk7ZKJbWX1QhRq1iIjjDEhnE7YSs6BcvsBLxFK4tXu 3TKHQ+1OCKkZ9C7PLQ8rjeCZhid6uklIsQCVlt0vVpAV3UR6NBj21R9GG2+5XkddeJ s0UJhlEFQqoc1UyX1N2NRYtqDvC3DY65YspN69G+Ii9QZVMtEyhu3SiozFxZt7pZAm vaNc7fvolzS9aDO7KHyBTv5cb9FK/Iq3hgveBsCXj/mvS3oDQsMrpTIW4GSirOQXTp NrFwFPLOqWK/wovqLje/UbJ/sdQfnCoRzWfbhgi0kfDWEqYLvTcFG1Kn8J5NZgQV1R 5fkPoTdkPDGnw== Received: from w92expo7.exchange.mit.edu (18.7.74.61) by oc11exedge2.exchange.mit.edu (18.9.3.18) with Microsoft SMTP Server (TLS) id 15.0.1497.36; Sat, 11 Jun 2022 17:17:40 -0400 Received: from oc11expo7.exchange.mit.edu (18.9.4.12) by w92expo7.exchange.mit.edu (18.7.74.61) with Microsoft SMTP Server (TLS) id 15.0.1497.23; Sat, 11 Jun 2022 17:18:00 -0400 Received: from oc11expo7.exchange.mit.edu ([18.9.4.12]) by oc11expo7.exchange.mit.edu ([18.9.4.12]) with mapi id 15.00.1497.023; Sat, 11 Jun 2022 17:18:00 -0400 From: Anders Kaseorg To: Paul Eggert Subject: Re: bug#55895: [PATCH] maint: Fix ptr_align signature to silence -Wmaybe-uninitialized Thread-Topic: bug#55895: [PATCH] maint: Fix ptr_align signature to silence -Wmaybe-uninitialized Thread-Index: AQHYfRjRoPHR/DC320iAE7pQn89Efa1Jzg2A//+YMwCAAT6bAP//j8cAgACBUoD///zz5Q== Date: Sat, 11 Jun 2022 21:18:00 +0000 Message-ID: <1654982280591.82594@mit.edu> References: <6290f2cc-b654-0e94-74ed-5b1f0c079e41@cs.ucla.edu> <02620239-0ce4-3e44-f25d-ed764199cc68@mit.edu> , <7a75f892-a88c-02e6-7c2d-9b0cf58aaeff@cs.ucla.edu> In-Reply-To: <7a75f892-a88c-02e6-7c2d-9b0cf58aaeff@cs.ucla.edu> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-messagesentrepresentingtype: 1 x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [157.131.223.124] Content-Type: text/plain; charset="Windows-1252" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 55895 Cc: "55895@debbugs.gnu.org" <55895@debbugs.gnu.org> X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) I know C. I=92m not saying that const implies writes don=92t happen elsewhe= re. I=92m saying that _aligning_ a const pointer implies it=92s not _useful= _ for _unaligned_ writes to happen elsewhere. And if you align the mutable = pointer, you don=92t need to separately align a const pointer.=0A= =0A= Anders=0A= From debbugs-submit-bounces@debbugs.gnu.org Sat Jun 11 20:14:58 2022 Received: (at 55895) by debbugs.gnu.org; 12 Jun 2022 00:14:58 +0000 Received: from localhost ([127.0.0.1]:54297 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1o0BFp-0008Ic-U9 for submit@debbugs.gnu.org; Sat, 11 Jun 2022 20:14:58 -0400 Received: from zimbra.cs.ucla.edu ([131.179.128.68]:48858) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1o0BFn-0008IO-8u for 55895@debbugs.gnu.org; Sat, 11 Jun 2022 20:14:56 -0400 Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id BA10216013C; Sat, 11 Jun 2022 17:14:49 -0700 (PDT) Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id Z1A3qD36BM3W; Sat, 11 Jun 2022 17:14:48 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 18D1E160140; Sat, 11 Jun 2022 17:14:48 -0700 (PDT) X-Virus-Scanned: amavisd-new at zimbra.cs.ucla.edu Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id Fa03ztb20_10; Sat, 11 Jun 2022 17:14:47 -0700 (PDT) Received: from [192.168.1.9] (cpe-172-91-119-151.socal.res.rr.com [172.91.119.151]) by zimbra.cs.ucla.edu (Postfix) with ESMTPSA id DBD5516013C; Sat, 11 Jun 2022 17:14:47 -0700 (PDT) Message-ID: Date: Sat, 11 Jun 2022 17:14:47 -0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.9.1 Content-Language: en-US To: Anders Kaseorg References: <6290f2cc-b654-0e94-74ed-5b1f0c079e41@cs.ucla.edu> <02620239-0ce4-3e44-f25d-ed764199cc68@mit.edu> <7a75f892-a88c-02e6-7c2d-9b0cf58aaeff@cs.ucla.edu> <1654982280591.82594@mit.edu> From: Paul Eggert Organization: UCLA Computer Science Department Subject: Re: bug#55895: [PATCH] maint: Fix ptr_align signature to silence -Wmaybe-uninitialized In-Reply-To: <1654982280591.82594@mit.edu> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 55895 Cc: 55895@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) On 6/11/22 14:18, Anders Kaseorg wrote: > if you align the mutable pointer, you don=E2=80=99t need to separately = align a const pointer. Of course one can alter code by aligning a mutable pointer first and=20 then converting it to a const pointer, instead of first converting it to=20 const and then aligning the result. But that might not be convenient.=20 The part of the code that needs alignment might have access to only the=20 const pointer, and should be able to align the const pointer on its own=20 without bothering the part of the code that doesn't need alignment. Anyway, we're getting a long way from the original bug report. I'll let=20 you have the last word on this tangential topic, if you like. From unknown Tue Jun 17 01:49:20 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Sun, 10 Jul 2022 11:24:08 +0000 User-Agent: Fakemail v42.6.9 # This is a fake control message. # # The action: # bug archived. thanks # This fakemail brought to you by your local debbugs # administrator