Re: [PATCH] LoongArch: BPF: Avoid declare variables in switch-case

From: Tiezhu Yang
Date: Thu Oct 13 2022 - 21:45:47 EST




On 10/13/2022 11:40 PM, Huacai Chen wrote:
Not all compilers support declare variables in switch-case, so move

We know that gcc 13 has no problem, it is better to point out the
compiler version explicitly in the commit message so that the users
can know how to reproduce the build errors.

declarations to the beginning of a function. Otherwise we may get such
build errors:

We can resolve the errors by adding a pair of curly braces around
the statements of the case, like this:

switch (...) {
case ...:
{
int ...;
...
break;
}
}


arch/loongarch/net/bpf_jit.c: In function ‘emit_atomic’:
arch/loongarch/net/bpf_jit.c:362:3: error: a label can only be part of a statement and a declaration is not a statement
u8 r0 = regmap[BPF_REG_0];
^~
arch/loongarch/net/bpf_jit.c: In function ‘build_insn’:
arch/loongarch/net/bpf_jit.c:727:3: error: a label can only be part of a statement and a declaration is not a statement
u8 t7 = -1;
^~
arch/loongarch/net/bpf_jit.c:778:3: error: a label can only be part of a statement and a declaration is not a statement
int ret;
^~~
arch/loongarch/net/bpf_jit.c:779:3: error: expected expression before ‘u64’
u64 func_addr;
^~~
arch/loongarch/net/bpf_jit.c:780:3: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
bool func_addr_fixed;
^~~~
arch/loongarch/net/bpf_jit.c:784:11: error: ‘func_addr’ undeclared (first use in this function); did you mean ‘in_addr’?
&func_addr, &func_addr_fixed);
^~~~~~~~~
in_addr
arch/loongarch/net/bpf_jit.c:784:11: note: each undeclared identifier is reported only once for each function it appears in
arch/loongarch/net/bpf_jit.c:814:3: error: a label can only be part of a statement and a declaration is not a statement
u64 imm64 = (u64)(insn + 1)->imm << 32 | (u32)insn->imm;
^~~


Thanks,
Tiezhu