[cfe-dev] -Wstatic-in-inline when there's both an __extern_inline definition and a non-inline definition
Jim Newsome via cfe-dev
cfe-dev at lists.llvm.org
Thu Feb 6 16:13:38 PST 2020
For the actual issue I'm debugging, see
https://github.com/shadow/shadow/issues/717. Following is a simplified
repro.
I have a source file:
-------------------------------
#include <stdio.h>
__extern_inline
void foo() {
printf("extern inline\n");
}
static int i = 0;
void foo() {
printf("not inline %d\n", i);
}
int main(int argc, char **argv) {
foo();
return 0;
}
-------------------------------
When I compile and run I get:
-------------------------------
$ clang -Wall -Wstatic-in-inline inline.c
inline.c:11:31: warning: static variable 'i' is used in an inline
function with
external linkage [-Wstatic-in-inline]
printf("not inline %d\n", i);
^
inline.c:8:12: note: 'i' declared here
static int i = 0;
^
$ ./a.out
not inline 0
-------------------------------
Q1: Ignoring the static variable reference for the moment, is it
actually safe to have both an inline and non-inline definition? For a
compilation unit that sees both, is there any guarantee about which
definition it will get? (Both clang and gcc give a redefinition error if
I use "extern inline" instead of __extern_inline; I'm reproducing a
situation I'm getting from pthread.h and stdio.h. I can't find any
documentation about the semantics of __extern_inline)
Q2: Is it a clang bug that -Wstatic-in-inline triggers when the
*non-inline* definition is the one that references the static variable?
i.e. can I safely ignore the warning in this case?
Thanks!
-Jim
P.S. Some additional diagnostics:
$ clang -v
clang version 6.0.0-1ubuntu2 (tags/RELEASE_600/final)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
Found candidate GCC installation: /usr/bin/../lib/gcc/i686-linux-gnu/8
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/7
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/7.4.0
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/8
Found candidate GCC installation: /usr/lib/gcc/i686-linux-gnu/8
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/7
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/7.4.0
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/8
Selected GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/7.4.0
Candidate multilib: .;@m64
Selected multilib: .;@m64
$ clang -E inline.c
<snip>
extern __inline __attribute__ ((__gnu_inline__))
void foo() {
printf("extern inline\n");
}
<snip>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20200206/d99748a5/attachment.html>
More information about the cfe-dev
mailing list