Skip to content
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

Closed
llvmbot opened this issue Apr 25, 2009 · 16 comments
Closed

[Linux kernel] static variable with forward declared type #4437

llvmbot opened this issue Apr 25, 2009 · 16 comments
Labels
bugzilla Issues migrated from bugzilla clang Clang issues not falling into any other category wontfix Issue is real, but we can't or won't fix it. Not invalid

Comments

@llvmbot
Copy link
Collaborator

llvmbot commented Apr 25, 2009

Bugzilla Link 4065
Resolution WONTFIX
Resolved on Feb 22, 2010 12:47
Version unspecified
OS Linux
Blocks llvm/llvm-bugzilla-archive#4068
Attachments pre-processed source code
Reporter LLVM Bugzilla Contributor
CC @DougGregor,@edwintorok,@efriedma-quic

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

@lattner
Copy link
Collaborator

lattner commented Apr 25, 2009

Reduced testcase for the first issue:

struct foo;
static struct foo x;
struct foo {
int a;
};

It looks like static should be handled the same as tentative definitions. No idea if this is standard or a GNU extension.

@lattner
Copy link
Collaborator

lattner commented Apr 25, 2009

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.

@lattner
Copy link
Collaborator

lattner commented Apr 25, 2009

I filed:
http://llvm.org/bugs/show_bug.cgi?id=4070

about the bogus diagnostic.

@efriedma-quic
Copy link
Collaborator

It looks like static should be handled the same as tentative definitions. No
idea if this is standard or a GNU extension.

I'm pretty sure the testcase in comment 2 violates C99 6.9.2p3.

@llvmbot
Copy link
Collaborator Author

llvmbot commented Apr 28, 2009

In file scope (i.e. not in C function), a tentative definition may have an incomplete type.

@DougGregor
Copy link
Contributor

I think Eli is right. C99 sayeth:

If the declaration of an identifier for an object is a tentative definition
and has internal linkage, the declared type shall not be an incomplete type.

static objects have internal linkage.

@llvmbot
Copy link
Collaborator Author

llvmbot commented Apr 28, 2009

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 :)

@efriedma-quic
Copy link
Collaborator

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 :)

See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26581#c5 .

@lattner
Copy link
Collaborator

lattner commented Apr 28, 2009

Can we reasonably support this as an extension?

@DougGregor
Copy link
Contributor

It should be reasonably easy to support as an extension.

@llvmbot
Copy link
Collaborator Author

llvmbot commented Apr 28, 2009

Might want to hold off a bit; this might get fixed in the kernel.

@edwintorok
Copy link
Contributor

*** Bug llvm/llvm-bugzilla-archive#4131 has been marked as a duplicate of this bug. ***

@llvmbot
Copy link
Collaborator Author

llvmbot commented May 4, 2009

Code is too grotty, will fix in kernel.

@edwintorok
Copy link
Contributor

mentioned in issue llvm/llvm-bugzilla-archive#4068

@lattner
Copy link
Collaborator

lattner commented Nov 27, 2021

mentioned in issue llvm/llvm-bugzilla-archive#4070

@edwintorok
Copy link
Contributor

mentioned in issue llvm/llvm-bugzilla-archive#4131

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 3, 2021
@Quuxplusone Quuxplusone added the wontfix Issue is real, but we can't or won't fix it. Not invalid label Jan 20, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla clang Clang issues not falling into any other category wontfix Issue is real, but we can't or won't fix it. Not invalid
Projects
None yet
Development

No branches or pull requests

6 participants