Re: Extraneous test in setsignal()?
Herbert Xu <[email protected]> Mon, 16 Mar 2026 10:41:05 +0900
| Newsgroups | org.kernel.vger.dash |
|---|---|
| Message-ID | <[email protected]> |
Denys Vlasenko <[email protected]> wrote: > void setsignal(int signo) > { > ... > if ((t = trap[signo]) == NULL) > action = S_DFL; > else if (*t != '\0') > action = S_CATCH; > else > action = S_IGN; > if (rootshell && action == S_DFL && !lvforked) { > ... > > If you read the above carefully, you see that action == S_DFL check > can be eliminated if we rewrite the above like this: > > new_act = S_DFL; > if ((t = trap[signo]) != NULL) > new_act = S_CATCH; > if (t[0] == '\0') > new_act = S_IGN; > } else if (rootshell && !lvforked) { > ... > > Thanks. But that's exactly what gcc 14 generates anyway: b2: 44 8b 35 00 00 00 00 mov 0x0(%rip),%r14d # b9 <setsignal+0x29> b5: R_X86_64_PC32 vforked-0x4 if ((t = trap[signo]) == NULL) b9: 48 85 c0 test %rax,%rax bc: 0f 84 ee 00 00 00 je 1b0 <setsignal+0x120> ... if (rootshell && action == S_DFL && !lvforked) { 1b0: 44 89 f0 mov %r14d,%eax 1b3: 0b 05 00 00 00 00 or 0x0(%rip),%eax # 1b9 <setsignal+0x129> 1b5: R_X86_64_PC32 shlvl-0x4 1b9: 75 1d jne 1d8 <setsignal+0x148> switch (signo) { 1bb: 83 fa 16 cmp $0x16,%edx 1be: 77 18 ja 1d8 <setsignal+0x148> Cheers, -- Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt