llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
27.01k stars 11.06k forks source link

clang: support "quantum tunneling" #7309

Closed edwintorok closed 14 years ago

edwintorok commented 14 years ago
Bugzilla Link 6937
Resolution DUPLICATE
Resolved on Apr 25, 2010 13:01
Version unspecified
OS Linux
Blocks llvm/llvm-project#4440
CC @efriedma-quic

Extended Description

The Linux kernel fails to build now, and there is no CONFIG_ to turn off this "feature": net/ipv4/netfilter/ip_tables.c:72:9: error: fields must have a constant size: 'variable length array in structure' extension
will never be supported
return xt_alloc_initial_table(ipt, IPT);
^
In file included from net/ipv4/netfilter/ip_tables.c:31:
net/ipv4/netfilter/../../netfilter/xt_repldata.h:14:26: note: instantiated from:
struct type##_standard entries[nhooks]; \

Here is the header: /*

define xt_alloc_initial_table(type, typ2) ({ \

unsigned int hook_mask = info->valid_hooks; \
unsigned int nhooks = hweight32(hook_mask); \
unsigned int bytes = 0, hooknum = 0, i = 0; \
struct { \
    struct type##_replace repl; \
    struct type##_standard entries[nhooks]; \
    struct type##_error term; \
} *tbl = kzalloc(sizeof(*tbl), GFP_KERNEL); \
if (tbl == NULL) \
    return NULL; \

I don't think this is much different from VLAs, but instead of the array size depending on function parameter, it depends on a local variable. It also isn't much different from variable-sized structs, it could convert the last 2 fields into [0xi8], and calculate the sizeof() at runtime.

Here is a workaround for the C code, clang could do this automatically: diff --git a/net/netfilter/xt_repldata.h b/net/netfilter/xt_repldata.h index 6efe4e5..e61924d 100644 --- a/net/netfilter/xt_repldata.h +++ b/net/netfilter/xt_repldata.h @@ -11,13 +11,16 @@ unsigned int bytes = 0, hooknum = 0, i = 0; \ struct { \ struct type##_replace repl; \

efriedma-quic commented 14 years ago

This bug has been marked as a duplicate of bug llvm/llvm-project#3302