bug-gnulib@gnu.org mirror (unofficial)
 help / color / mirror / Atom feed
From: Keith Marshall <keith@users.osdn.me>
To: Eli Zaretskii <eliz@gnu.org>, Bruno Haible <bruno@clisp.org>
Cc: eggert@cs.ucla.edu, bug-gnulib@gnu.org
Subject: Re: Gnulib's alloca.h used even when there is a system header
Date: Sat, 9 Mar 2019 19:25:06 +0000	[thread overview]
Message-ID: <5C841312.7080403@users.osdn.me> (raw)
In-Reply-To: <83imxfitns.fsf@gnu.org>


[-- Attachment #1.1: Type: text/plain, Size: 2427 bytes --]

On 19/02/19 17:18, Eli Zaretskii wrote:
>> From: Bruno Haible <bruno@clisp.org>
>> Cc: Eli Zaretskii <eliz@gnu.org>, Paul Eggert <eggert@cs.ucla.edu>
>> Date: Tue, 19 Feb 2019 00:32:24 +0100
>>
>> Hi Eli,
>>
>>>      ./alloca.h:40:18: error: inlining failed in call to always_inline '__builtin_alloca': function not considered for inlining
>>>       #  define alloca __builtin_alloca
>>> 		       ^
>>
>> GCC never inlines a function that calls alloca() or
>> __builtin_alloca().

With respect, while that may be true of ancient historical versions of
GCC, my own testing shows it to be untrue for modern releases; I cannot
reproduce[1] anything resembling the above diagnostic, unless I resort
to archaeological investigation, compiling with mingw32-gcc-3.4.5.  The
next version, which I still have available, is mingw32-gcc-4.8.2; with
that, and with all subsequent releases up to mingw32-gcc-8.2.0, other
than at -O0, GCC generates identical code for alloca() expressed as an
in-line function, to that which is generated when it is expressed as a
macro.  (Furthermore, the difference in code generated at -O0 is
inconsequential, and will have no effect on behaviour).

>> The reason is that if you call this function in a loop, then
>> without inlining it will consume a bounded amount of stack whereas
>> with inlining it might cause a stack overflow.

I'm sorry to say this, but that just seems disingenuous.  For every
version of GCC which I have available, *including* mingw32-gcc-3.4.5, if
I place a call to alloca(), *implemented as a macro*, within a loop,
then the stack grows on each iteration of the loop.  The growth is not
bounded, even for your macro implementation, with mingw32-gcc-3.4.5, but
for all versions from mingw32-gcc-4.8.2 onwards it *is* bounded, (by
calling __chkstk_ms(), before adjusting the stack pointer), for *both*
your macro implementation, and for in-line function expansion.

[1] Well, I actually can reproduce it, even with mingw32-gcc-8.2.0, but
*only* when I deliberately introduce the very bug which Eli has noted,
*and* I compile at -O0; at any other optimization level, this gnulib bug
seems to be optimized away, with __builtin_alloca() itself being
expanded to in-line intrinsic code, as intended.

-- 
Regards,
Keith.

Public key available from keys.gnupg.net
Key fingerprint: C19E C018 1547 DE50 E1D4 8F53 C0AD 36C6 347E 5A3F


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

  parent reply	other threads:[~2019-03-09 21:33 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-17 17:20 Gnulib's alloca.h used even when there is a system header Eli Zaretskii
2019-02-17 20:06 ` Paul Eggert
2019-02-17 20:24   ` Eli Zaretskii
2019-02-17 21:09     ` Paul Eggert
2019-02-17 23:32       ` Bruno Haible
2019-02-18 16:59       ` Eli Zaretskii
2019-02-18 23:32         ` Bruno Haible
2019-02-19 17:18           ` Eli Zaretskii
2019-02-28 18:40             ` Eli Zaretskii
2019-03-09 19:25             ` Keith Marshall [this message]
2019-03-10 19:03               ` Bruno Haible
2019-03-10 19:39                 ` Eli Zaretskii
2019-03-10 19:54                   ` Bruno Haible
2019-03-10 20:00                     ` Eli Zaretskii
2019-02-17 23:28 ` Bruno Haible

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://lists.gnu.org/mailman/listinfo/bug-gnulib

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5C841312.7080403@users.osdn.me \
    --to=keith@users.osdn.me \
    --cc=bruno@clisp.org \
    --cc=bug-gnulib@gnu.org \
    --cc=eggert@cs.ucla.edu \
    --cc=eliz@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).