-Wstatic-in-inline when there's both an __extern_inline definition and a non-inline definition

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

-Wstatic-in-inline when there's both an __extern_inline definition and a non-inline definition

suyash singh via cfe-dev

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>


_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev