From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: =?utf-8?Q?=C3=93scar_Fuentes?= Newsgroups: gmane.emacs.devel Subject: Re: Warnings in mingw64 build on emacs-28 branch Date: Sun, 07 Nov 2021 16:51:56 +0100 Message-ID: <87r1bsezfn.fsf@telefonica.net> References: <86y260c9b8.fsf@gmail.com> <83fss880qc.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="16874"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux) To: emacs-devel@gnu.org Cancel-Lock: sha1:qtPiUfXaZRcrV1yK95bE3uc1PAU= Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sun Nov 07 16:53:24 2021 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mjkU0-0004Ep-1i for ged-emacs-devel@m.gmane-mx.org; Sun, 07 Nov 2021 16:53:24 +0100 Original-Received: from localhost ([::1]:36440 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mjkTy-0002Uh-Sm for ged-emacs-devel@m.gmane-mx.org; Sun, 07 Nov 2021 10:53:22 -0500 Original-Received: from [2001:470:142:3::10] (port=53552 helo=eggs.gnu.org) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mjkSr-0001np-7H for emacs-devel@gnu.org; Sun, 07 Nov 2021 10:52:13 -0500 Original-Received: from ciao.gmane.io ([116.202.254.214]:58390) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mjkSo-0001uV-OX for emacs-devel@gnu.org; Sun, 07 Nov 2021 10:52:12 -0500 Original-Received: from list by ciao.gmane.io with local (Exim 4.92) (envelope-from ) id 1mjkSl-0002k5-OM for emacs-devel@gnu.org; Sun, 07 Nov 2021 16:52:07 +0100 X-Injected-Via-Gmane: http://gmane.org/ Received-SPF: pass client-ip=116.202.254.214; envelope-from=ged-emacs-devel@m.gmane-mx.org; helo=ciao.gmane.io X-Spam_score_int: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 5.0 requ) BAYES_00=-1.9, HEADER_FROM_DIFFERENT_DOMAINS=0.248, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:278962 Archived-At: Eli Zaretskii writes: >> 3) This warning is new with gcc 11. >> >> C:/emacs/git/emacs/emacs-28/src/w32heap.c: In function 'getrlimit': >> C:/emacs/git/emacs/emacs-28/src/w32heap.c:853:14: warning: 'm' may be used uninitialized [-Wmaybe-uninitialized] >> 853 | if (!VirtualQuery ((LPCVOID) &m, &m, sizeof m)) >> | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ >> In file included from C:/msys64/mingw64/x86_64-w64-mingw32/include/winbase.h:25, >> from C:/msys64/mingw64/x86_64-w64-mingw32/include/windows.h:70, >> from C:/emacs/git/emacs/emacs-28/src/w32common.h:24, >> from C:/emacs/git/emacs/emacs-28/src/w32heap.c:54: >> C:/msys64/mingw64/x86_64-w64-mingw32/include/memoryapi.h:45:28: note: by argument 1 of type 'LPCVOID' {aka 'const void *'} to 'VirtualQuery' declared here >> 45 | WINBASEAPI SIZE_T WINAPI VirtualQuery (LPCVOID lpAddress, PMEMORY_BASIC_INFORMATION lpBuffer, SIZE_T dwLength); >> | ^~~~~~~~~~~~ >> C:/emacs/git/emacs/emacs-28/src/w32heap.c:844:34: note: 'm' declared here >> 844 | MEMORY_BASIC_INFORMATION m; >> | ^ > > That's a compiler bug, I think. I see nothing wrong in the call. AFAIU that call to VirtualQuery does not do what we want. When lpAddress is provided the function rounds down the address to a page boundary and starts scanning pages *up*. Since we want information about the capacity of the stack, the scan ignores all the space below the current page boundary. There is GetCurrentThreadStackLimits, but requires _WIN32_WINNT >= 0x0602 and it works on allocated pages. OTOH, we could call CreateThread with dwStackSize set to a fixed value and return that value from getrlimit(RLIMIT_STACK...). However, we need the main thread's stack size as well... There is a hack that uses NtCurrentTeb to obtain the lower address of the stack and pass it to VirtualQuery. I don't know how portable it is across Windows versions.