-
Notifications
You must be signed in to change notification settings - Fork 13k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Linux kernel] static variable with forward declared type #4437
Comments
Reduced testcase for the first issue: struct foo; It looks like static should be handled the same as tentative definitions. No idea if this is standard or a GNU extension. |
The "void" problem is a bogus diagnostic that happens because per_cpu__init_cfs_rq is invalid. The only issue here is the one in comment #2. I'll fix the bogus error though. |
I filed: about the bogus diagnostic. |
I'm pretty sure the testcase in comment 2 violates C99 6.9.2p3. |
In file scope (i.e. not in C function), a tentative definition may have an incomplete type. |
I think Eli is right. C99 sayeth: If the declaration of an identifier for an object is a tentative definition static objects have internal linkage. |
It does appear so in C99 6.9.2.3, but it is also true that gcc "-std=c99 -Wall -pedantic" does not complain about this code :) |
|
Can we reasonably support this as an extension? |
It should be reasonably easy to support as an extension. |
Might want to hold off a bit; this might get fixed in the kernel. |
*** Bug llvm/llvm-bugzilla-archive#4131 has been marked as a duplicate of this bug. *** |
Code is too grotty, will fix in kernel. |
mentioned in issue llvm/llvm-bugzilla-archive#4068 |
mentioned in issue llvm/llvm-bugzilla-archive#4070 |
mentioned in issue llvm/llvm-bugzilla-archive#4131 |
Extended Description
The Linux kernel source code file kernel/sched.c builds fine with gcc, but fails under clang:
clang -MD -MF kernel/.sched.o.d -nostdinc -isystem include -Iinclude -I/spare/repo/linux-2.6/arch/x86/include -include include/linux/autoconf.h -D__KERNEL__ -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -Werror-implicit-function-declaration -O2 -m64 -march=core2 -mno-red-zone -mcmodel=kernel -funit-at-a-time -maccumulate-outgoing-args -DCONFIG_AS_CFI=1 -DCONFIG_AS_CFI_SIGNAL_FRAME=1 -pipe -Wno-sign-compare -fno-asynchronous-unwind-tables -mno-sse -mno-mmx -mno-sse2 -mno-3dnow -Wframe-larger-than=2048 -fno-stack-protector -fno-omit-frame-pointer -fno-optimize-sibling-calls -pg -Wdeclaration-after-statement -Wno-pointer-sign -fwrapv -fno-dwarf2-cfi-asm -D"KBUILD_STR(s)=#s" -D"KBUILD_BASENAME=KBUILD_STR(sched)" -D"KBUILD_MODNAME=KBUILD_STR(sched)" -c -o kernel/sched.o kernel/sched.c
clang: warning: the clang compiler does not yet support '-pg'
warning: unknown warning option: -Wframe-larger-than=2048
kernel/sched.c:325:8: error: variable has incomplete type 'typeof(struct cfs_rq)' (aka 'struct cfs_rq')
static DEFINE_PER_CPU(struct cfs_rq, init_cfs_rq) ____cacheline_aligned_in_smp;
^
include/linux/percpu-defs.h:37:2: note: instantiated from:
DEFINE_PER_CPU_SECTION(type, name, "")
^
:44:1: note: instantiated from:
per_cpu__init_cfs_rq
^
In file included from kernel/sched.c:31:
In file included from include/linux/nmi.h:7:
include/linux/sched.h:144:8: note: forward declaration of 'struct cfs_rq'
struct cfs_rq;
^
kernel/sched.c:7760:21: warning: field of variable sized type 'sg' not at the end of a struct or class is a GNU extension
struct sched_group sg;
^
kernel/sched.c:7765:22: warning: field of variable sized type 'sd' not at the end of a struct or class is a GNU extension
struct sched_domain sd;
^
kernel/sched.c:8982:6: error: indirection requires pointer operand ('void' invalid)
&per_cpu(init_cfs_rq, i),
^~~~~~~~~~~~~~~~~~~~~~~
include/asm-generic/percpu.h:53:3: note: instantiated from:
(*SHIFT_PERCPU_PTR(&per_cpu_var(var), per_cpu_offset(cpu)))
^
5 diagnostics generated.
make[1]: *** [kernel/sched.o] Error 1
make: *** [kernel/] Error 2
The text was updated successfully, but these errors were encountered: