|
|
| Bugzilla Link |
40527 |
| Resolution |
FIXED |
| Resolved on |
Oct 22, 2020 06:00 |
| Version |
trunk |
| OS |
Linux |
| CC |
@topperc,@davidbolvansky,@KernelAddress,@efriedma-quic,@fhahn,@kcc,@bryant,@jfbastien,@RKSimon,@rjmccall,@rotateright,@vitalybuka |
| Fixed by commit(s) |
51ff045 |
Extended Description
When compiling the following code:
============================
void alloc_sock(int *err);
int try_send();
int send(int len) {
int err;
if (len) {
err = -1;
alloc_sock(&err);
err = try_send();
}
return -1;
}
with
$ clang -O2 -g -ftrivial-auto-var-init=pattern -enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang -c t.c
Clang produces an extra store of $0xaaaaaaaa to |err|, which is introduced by the -ftrivial-auto-var-init and not removed by other optimizations in the pipeline:
$ objdump -d t.o
0000000000000000 :
0: 50 push %rax
1: c7 44 24 04 aa aa aa movl $0xaaaaaaaa,0x4(%rsp)
8: aa
9: 85 ff test %edi,%edi
b: 74 1d je 2a <send+0x2a>
d: c7 44 24 04 ff ff ff movl $0xffffffff,0x4(%rsp)
14: ff
15: 48 8d 7c 24 04 lea 0x4(%rsp),%rdi
1a: e8 00 00 00 00 callq 1f <send+0x1f>
1f: 31 c0 xor %eax,%eax
21: e8 00 00 00 00 callq 26 <send+0x26>
26: 89 44 24 04 mov %eax,0x4(%rsp)
2a: b8 ff ff ff ff mov $0xffffffff,%eax
2f: 59 pop %rcx
30: c3 retq
As noted by JF Bastien here: https://reviews.llvm.org/D54604, "Seems like the optimizer should sink the store enough that it appears only once on each path."
Extended Description
When compiling the following code:
============================
void alloc_sock(int *err);
int try_send();
int send(int len) {
int err;
if (len) {
err = -1;
alloc_sock(&err);
err = try_send();
}
return -1;
}
with
$ clang -O2 -g -ftrivial-auto-var-init=pattern -enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang -c t.c
Clang produces an extra store of $0xaaaaaaaa to |err|, which is introduced by the -ftrivial-auto-var-init and not removed by other optimizations in the pipeline:
$ objdump -d t.o
0000000000000000 :
0: 50 push %rax
1: c7 44 24 04 aa aa aa movl $0xaaaaaaaa,0x4(%rsp)
8: aa
9: 85 ff test %edi,%edi
b: 74 1d je 2a <send+0x2a>
d: c7 44 24 04 ff ff ff movl $0xffffffff,0x4(%rsp)
14: ff
15: 48 8d 7c 24 04 lea 0x4(%rsp),%rdi
1a: e8 00 00 00 00 callq 1f <send+0x1f>
1f: 31 c0 xor %eax,%eax
21: e8 00 00 00 00 callq 26 <send+0x26>
26: 89 44 24 04 mov %eax,0x4(%rsp)
2a: b8 ff ff ff ff mov $0xffffffff,%eax
2f: 59 pop %rcx
30: c3 retq
As noted by JF Bastien here: https://reviews.llvm.org/D54604, "Seems like the optimizer should sink the store enough that it appears only once on each path."