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

            Bug ID: 96407
           Summary: LTO inlined functions don't inherit disabled warnings
           Product: gcc
           Version: 10.1.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: rjones at redhat dot com
  Target Milestone: ---

This is a very reduced example from some real code where we are using -Werror
-Wstack-usage=5000.

We want most functions to have limited stack usage, but in some cases we have
carefully examined functions to ensure their stack usage isn't unbounded - but
it's hard to prove it - so we have disabled the warning for those functions.

--- test.c ---
#include <string.h>

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wstack-usage="

int
test (int i)
{
  char str[i];
  memset (str, 0, sizeof str);
  return str[0]+i;
}

#pragma GCC diagnostic pop

--- main.c ---
#include <stdio.h>

extern int test (int i);

int
main (int argc, char *argv[])
{
  int j = test (argc);
  printf ("%d\n", j);
  return 0;
}

---
$ gcc -O2 -flto main.c test.c -Werror -Wstack-usage=5000 -o a.out 
main.c: In function ‘main’:
main.c:6:1: error: stack usage might be unbounded [-Werror=stack-usage=]
    6 | main (int argc, char *argv[])
      | ^
lto1: all warnings being treated as errors


Note that if you combine these two functions into a single file, it
does *not* warn/error, even though presumably it can easily inline the
test() function.  So LTO seems to be causing the difference.

Reply via email to