public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/98055] New: __builtin_alloca should not have warn_unused_result attribute
@ 2020-11-29 19:51 psmith at gnu dot org
  2020-11-29 20:22 ` [Bug c/98055] " pinskia at gcc dot gnu.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: psmith at gnu dot org @ 2020-11-29 19:51 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98055

            Bug ID: 98055
           Summary: __builtin_alloca should not have warn_unused_result
                    attribute
           Product: gcc
           Version: 10.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: psmith at gnu dot org
  Target Milestone: ---

Code that wants to use alloca() and still be portable will often include
replacements where memory is allocated on the heap, and the user is expected to
invoke alloca(0) periodically to free up this memory.  See for example the GNU
gnulib replacement alloca().

(Please no comments about the usefulness or not of alloca()--I'm not interested
in that discussion.  alloca() has problems but it's strictly more powerful than
VLAs, while providing the possibility of portability to compilers that don't
support them).

In this situation (invoking alloca(0)) there's no point in assigning the return
value, and older versions of GCC this works fine but when I try to compile the
same code with GCC 10.2.0 compilation fails because apparently
__builtin_alloca() now has the warn_unused_result attribute applied to it (this
isn't documented anywhere that I can find, but appears to be the case):

In file included from src/makeint.h:31,
                 from src/read.c:17:
src/read.c: In function 'eval_makefile':
lib/alloca.h:46:18: error: ignoring return value of '__builtin_alloca' declared
with attribute 'warn_unused_result' [-Werror=unused-result]
   46 | #  define alloca __builtin_alloca
src/read.c:435:3: note: in expansion of macro 'alloca'
  435 |   alloca (0);
      |   ^~~~~~

Because (void) doesn't work around this attribute there's no easy way to
resolve this; I don't think it's appropriate to add this attribute to alloca()
and it should be removed.

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2020-12-01 16:33 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-29 19:51 [Bug c/98055] New: __builtin_alloca should not have warn_unused_result attribute psmith at gnu dot org
2020-11-29 20:22 ` [Bug c/98055] " pinskia at gcc dot gnu.org
2020-11-29 21:18 ` [Bug middle-end/98055] " psmith at gnu dot org
2020-11-29 23:45 ` msebor at gcc dot gnu.org
2020-11-30  0:09 ` egallager at gcc dot gnu.org
2020-11-30 22:04 ` psmith at gnu dot org
2020-12-01 16:33 ` msebor at gcc dot gnu.org

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).