Issue 61662
Summary diagnose static variable/function references from gnu_inline functions
Labels new issue
Assignees
Reporter nickdesaulniers
    GCC warns:
```c
static inline void foo (void) {}

__attribute__((gnu_inline))
extern inline void bar (void) { foo(); }
```
```
<source>:4:33: warning: 'foo' is static but used in inline function 'bar' which is not static
    4 | extern inline void bar (void) { foo(); }
      | ^~~
```
I asked around on #gcc and got the following feedback:
```
<jwakely> 
probably because the static inline one can have a different definition in every TU (because C is crazy) and so you don't know which definition the extern inline one will actually call if not inlined
10:02 AM <pinskia> 
https://gcc.gnu.org/PR39556
10:04 AM <ndesaulniers> Nick Desaulniers 
jwakely: so I guess the issue would be if foo and bar were defined in different headers, theoretically foo could have a different definition in a third header, so a different TU could have different implementations of bar based on header inclusion order?
10:07 AM <pinskia> 
the exact reference to the C standard is C99 6.7.4p3
10:10 AM <jakub> 
still the basic C rules apply that even those inlined versions shouldn't refer to static vars or static functions because those can be different in each TU
10:11 AM 
so, either make sure everything you call is also extern inline gnu_inline or similar, or make everything static inline
```
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to