From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: Warnings/errors related to possibly clobbered variables Date: Tue, 13 Jan 2015 15:55:12 -0500 Message-ID: References: <54B50246.2070507@yandex.ru> <54B50BC4.3060302@yandex.ru> <83k30q4pnn.fsf@gnu.org> <83egqy4f36.fsf@gnu.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1421182579 21737 80.91.229.3 (13 Jan 2015 20:56:19 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 13 Jan 2015 20:56:19 +0000 (UTC) Cc: schwab@suse.de, dmantipov@yandex.ru, emacs-devel@gnu.org, eggert@cs.ucla.edu To: Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Jan 13 21:56:11 2015 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1YB8VP-00030P-TA for ged-emacs-devel@m.gmane.org; Tue, 13 Jan 2015 21:56:04 +0100 Original-Received: from localhost ([::1]:41379 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YB8VP-0007Yk-8q for ged-emacs-devel@m.gmane.org; Tue, 13 Jan 2015 15:56:03 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:46906) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YB8V8-0007YJ-Vf for emacs-devel@gnu.org; Tue, 13 Jan 2015 15:55:48 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YB8V7-0005dz-VB for emacs-devel@gnu.org; Tue, 13 Jan 2015 15:55:46 -0500 Original-Received: from mercure.iro.umontreal.ca ([132.204.24.67]:59399) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YB8V0-0005bD-Cv; Tue, 13 Jan 2015 15:55:38 -0500 Original-Received: from hidalgo.iro.umontreal.ca (hidalgo.iro.umontreal.ca [132.204.27.50]) by mercure.iro.umontreal.ca (Postfix) with ESMTP id 4069A85065; Tue, 13 Jan 2015 15:55:36 -0500 (EST) Original-Received: from lechon.iro.umontreal.ca (lechon.iro.umontreal.ca [132.204.27.242]) by hidalgo.iro.umontreal.ca (Postfix) with ESMTP id 5E0D21E5B8C; Tue, 13 Jan 2015 15:55:12 -0500 (EST) Original-Received: by lechon.iro.umontreal.ca (Postfix, from userid 20848) id 3BC2DB4102; Tue, 13 Jan 2015 15:55:12 -0500 (EST) In-Reply-To: <83egqy4f36.fsf@gnu.org> (Eli Zaretskii's message of "Tue, 13 Jan 2015 22:10:05 +0200") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (gnu/linux) X-DIRO-MailScanner-Information: Please contact the ISP for more information X-DIRO-MailScanner: Found to be clean X-DIRO-MailScanner-SpamCheck: n'est pas un polluriel, SpamAssassin (score=-2.82, requis 5, autolearn=not spam, ALL_TRUSTED -2.82, MC_TSTLAST 0.00) X-DIRO-MailScanner-From: monnier@iro.umontreal.ca X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 132.204.24.67 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 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.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:181235 Archived-At: >> > Why not declare the offending variables 'volatile' and forget about >> > all this stuff? >> FWIW, `volatile' might not necessarily give us the behavior we >> want/need. > How so? Are you saying that qualifying an automatic variable as > 'volatile' might change the semantics of the program? GCC's warning basically points out that the semantics of the program is unclear, because when we come back from a longjmp we could either see the latest value of the variable, or a value it had earlier when we did the setjmp. So using `volatile' chooses one of the two behaviors, and it might not be the one we need. > IME, adding 'volatile' is generally TRT in these cases. Plus, it's > very simple, and goes "by the book" (a.k.a. the C Standard). FWIW, the last time I had to fight with this kind of interaction between longjmp and local variables, I ended up installing the patch below to fix the random crashes I was seeing: the problem is more subtle than just "add `volatile'". Stefan diff --git a/src/bytecode.c b/src/bytecode.c index 0ea646a..f1bdfd9 100644 --- a/src/bytecode.c +++ b/src/bytecode.c @@ -501,7 +501,6 @@ exec_byte_code (Lisp_Object bytestr, Lisp_Object vector, Lisp_Object maxdepth, Lisp_Object args_template, ptrdiff_t nargs, Lisp_Object *args) { ptrdiff_t count = SPECPDL_INDEX (); - ptrdiff_t volatile count_volatile; #ifdef BYTE_CODE_METER int volatile this_op = 0; int prev_op; @@ -509,14 +508,12 @@ exec_byte_code (Lisp_Object bytestr, Lisp_Object vector, Lisp_Object maxdepth, int op; /* Lisp_Object v1, v2; */ Lisp_Object *vectorp; - Lisp_Object *volatile vectorp_volatile; #ifdef BYTE_CODE_SAFE - ptrdiff_t volatile const_length; - Lisp_Object *volatile stacke; - ptrdiff_t volatile bytestr_length; + ptrdiff_t const_length; + Lisp_Object *stacke; + ptrdiff_t bytestr_length; #endif struct byte_stack stack; - struct byte_stack volatile stack_volatile; Lisp_Object *top; Lisp_Object result; enum handlertype type; @@ -1122,9 +1119,6 @@ exec_byte_code (Lisp_Object bytestr, Lisp_Object vector, Lisp_Object maxdepth, PUSH_HANDLER (c, tag, type); c->bytecode_dest = dest; c->bytecode_top = top; - count_volatile = count; - stack_volatile = stack; - vectorp_volatile = vectorp; if (sys_setjmp (c->jmp)) { @@ -1135,12 +1129,11 @@ exec_byte_code (Lisp_Object bytestr, Lisp_Object vector, Lisp_Object maxdepth, handlerlist = c->next; PUSH (c->val); CHECK_RANGE (dest); - stack = stack_volatile; + /* Might have been re-set by longjmp! */ + stack.byte_string_start = SDATA (stack.byte_string); stack.pc = stack.byte_string_start + dest; } - count = count_volatile; - vectorp = vectorp_volatile; NEXT; }