public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug analyzer/96228] New: -Wstack-usage does not understand constant __builtin_alloca calls
@ 2020-07-16 22:05 renat at idrisov dot info
  2020-07-16 22:18 ` [Bug middle-end/96228] " pinskia at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: renat at idrisov dot info @ 2020-07-16 22:05 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 96228
           Summary: -Wstack-usage does not understand constant
                    __builtin_alloca calls
           Product: gcc
           Version: 9.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: analyzer
          Assignee: dmalcolm at gcc dot gnu.org
          Reporter: renat at idrisov dot info
  Target Milestone: ---

Hi All,
when compiling the following piece of code:

```
#include <stdio.h>

int main(void) {
  char *a = __builtin_alloca(4);
  a[0] = 0;
  printf("%c", a[0]);
  return 0;
}
```

with:
$ gcc -Wstack-usage=2048 stack.c

gives:
stack.c:3:5: warning: stack usage might be unbounded [-Wstack-usage=]
    3 | int main(void) {

which is too pessimistic on `__builtin_alloca` behavior.
No warning when "char *a = __builtin_alloca(4);" is changed to "char a[4];"

Thank you!

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

* [Bug middle-end/96228] -Wstack-usage does not understand constant __builtin_alloca calls
  2020-07-16 22:05 [Bug analyzer/96228] New: -Wstack-usage does not understand constant __builtin_alloca calls renat at idrisov dot info
@ 2020-07-16 22:18 ` pinskia at gcc dot gnu.org
  2020-07-16 22:20 ` pinskia at gcc dot gnu.org
  2020-07-17  8:51 ` ebotcazou at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2020-07-16 22:18 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |missed-optimization
           Assignee|dmalcolm at gcc dot gnu.org        |unassigned at gcc dot gnu.org
          Component|analyzer                    |middle-end

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
-Wstack-usage is done on the RTL level, this means __builtin_alloca with a
constant is not converted into always allocation.  Usually because of
__builtin_alloca can be conditional.

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

* [Bug middle-end/96228] -Wstack-usage does not understand constant __builtin_alloca calls
  2020-07-16 22:05 [Bug analyzer/96228] New: -Wstack-usage does not understand constant __builtin_alloca calls renat at idrisov dot info
  2020-07-16 22:18 ` [Bug middle-end/96228] " pinskia at gcc dot gnu.org
@ 2020-07-16 22:20 ` pinskia at gcc dot gnu.org
  2020-07-17  8:51 ` ebotcazou at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2020-07-16 22:20 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |WONTFIX
             Status|UNCONFIRMED                 |RESOLVED

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Oh wait this is at -O0.  Well the warning is correct and won't be fixed really.
 -Wstack-usage is done on the RTL level so it can take into account register
spilling and all.

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

* [Bug middle-end/96228] -Wstack-usage does not understand constant __builtin_alloca calls
  2020-07-16 22:05 [Bug analyzer/96228] New: -Wstack-usage does not understand constant __builtin_alloca calls renat at idrisov dot info
  2020-07-16 22:18 ` [Bug middle-end/96228] " pinskia at gcc dot gnu.org
  2020-07-16 22:20 ` pinskia at gcc dot gnu.org
@ 2020-07-17  8:51 ` ebotcazou at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: ebotcazou at gcc dot gnu.org @ 2020-07-17  8:51 UTC (permalink / raw)
  To: gcc-bugs

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

Eric Botcazou <ebotcazou at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ebotcazou at gcc dot gnu.org

--- Comment #3 from Eric Botcazou <ebotcazou at gcc dot gnu.org> ---
The reason is rather that no flow analysis is performed by -Wstack-usage, which
means that it cannot distinguish:

int main(void) {
  char *a = __builtin_alloca(4);
  a[0] = 0;
  __builtin_printf("%c", a[0]);
  return 0;
}

from

int main(void) {
  while (1) {
     char *a = __builtin_alloca(4);
     a[0] = 0;
     __builtin_printf("%c", a[0]);
  }

  return 0;
}

so it assumes the worst.

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

end of thread, other threads:[~2020-07-17  8:51 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-16 22:05 [Bug analyzer/96228] New: -Wstack-usage does not understand constant __builtin_alloca calls renat at idrisov dot info
2020-07-16 22:18 ` [Bug middle-end/96228] " pinskia at gcc dot gnu.org
2020-07-16 22:20 ` pinskia at gcc dot gnu.org
2020-07-17  8:51 ` ebotcazou 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).